Check-in [6cd1c31096]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add tkzinc to [undroidwish] builds
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6cd1c31096bb793654b8d8a07625bcc3413238d4
User & Date: chw 2017-10-03 18:16:50
Context
2017-10-04
06:43
add two missing defines to sdltk check-in: 9fe193774a user: chw tags: trunk
2017-10-03
18:31
merge with trunk check-in: f1d3d998cb user: chw tags: wtf-8-experiment
18:16
add tkzinc to [undroidwish] builds check-in: 6cd1c31096 user: chw tags: trunk
18:02
make FBO for SDL GL context with both depth and stencil buffers if possible check-in: b3100836b5 user: chw tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added jni/tkzinc/BUGS.

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Text stippling is not available under openGL.

Line ends and line joins are not fully implemented under openGL.
The default behavior if to draw round ends and joins.

Line dashes are not really usable in openGL. Some cases work ok,
like aligned rectangles and other not, like curves and arcs.

Tiling/stippling begin on the item or item bounding box edge
rather than on the border edge so that the tile/stipple is
partially masked by the border.

Item tiling is not available for Windows GDI.

Maps are not rendered filled in openGL. The code of maps still
lags behind.

Added jni/tkzinc/Copyright.

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Copyright (c) 2005, Centre d'études de la Navigation Aérienne, Patrick Lecoanet
All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Added jni/tkzinc/LGPL.txt.





















































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
		  GNU LESSER GENERAL PUBLIC LICENSE
		       Version 2.1, February 1999

 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
     51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

[This is the first released version of the Lesser GPL.  It also counts
 as the successor of the GNU Library Public License, version 2, hence
 the version number 2.1.]

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.

  This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it.  You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.

  When we speak of free software, we are referring to freedom of use,
not price.  Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.

  To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights.  These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.

  For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you.  You must make sure that they, too, receive or can get the source
code.  If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it.  And you must show them these terms so they know their rights.

  We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.

  To protect each distributor, we want to make it very clear that
there is no warranty for the free library.  Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.

  Finally, software patents pose a constant threat to the existence of
any free program.  We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder.  Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.

  Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License.  This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License.  We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.

  When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library.  The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom.  The Lesser General
Public License permits more lax criteria for linking other code with
the library.

  We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License.  It also provides other free software developers Less
of an advantage over competing non-free programs.  These disadvantages
are the reason we use the ordinary General Public License for many
libraries.  However, the Lesser license provides advantages in certain
special circumstances.

  For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard.  To achieve this, non-free programs must be
allowed to use the library.  A more frequent case is that a free
library does the same job as widely used non-free libraries.  In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.

  In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software.  For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.

  Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.

  The precise terms and conditions for copying, distribution and
modification follow.  Pay close attention to the difference between a
"work based on the library" and a "work that uses the library".  The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.

		  GNU LESSER GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".

  A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.

  The "Library", below, refers to any such software library or work
which has been distributed under these terms.  A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language.  (Hereinafter, translation is
included without limitation in the term "modification".)

  "Source code" for a work means the preferred form of the work for
making modifications to it.  For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.

  Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it).  Whether that is true depends on what the Library does
and what the program that uses the Library does.
  
  1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.

  You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.

  2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) The modified work must itself be a software library.

    b) You must cause the files modified to carry prominent notices
    stating that you changed the files and the date of any change.

    c) You must cause the whole of the work to be licensed at no
    charge to all third parties under the terms of this License.

    d) If a facility in the modified Library refers to a function or a
    table of data to be supplied by an application program that uses
    the facility, other than as an argument passed when the facility
    is invoked, then you must make a good faith effort to ensure that,
    in the event an application does not supply such function or
    table, the facility still operates, and performs whatever part of
    its purpose remains meaningful.

    (For example, a function in a library to compute square roots has
    a purpose that is entirely well-defined independent of the
    application.  Therefore, Subsection 2d requires that any
    application-supplied function or table used by this function must
    be optional: if the application does not supply it, the square
    root function must still compute square roots.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.

In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library.  To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License.  (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.)  Do not make any other change in
these notices.

  Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.

  This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.

  4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.

  If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.

  5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library".  Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.

  However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library".  The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.

  When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library.  The
threshold for this to be true is not precisely defined by law.

  If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work.  (Executables containing this object code plus portions of the
Library will still fall under Section 6.)

  Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.

  6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.

  You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License.  You must supply a copy of this License.  If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License.  Also, you must do one
of these things:

    a) Accompany the work with the complete corresponding
    machine-readable source code for the Library including whatever
    changes were used in the work (which must be distributed under
    Sections 1 and 2 above); and, if the work is an executable linked
    with the Library, with the complete machine-readable "work that
    uses the Library", as object code and/or source code, so that the
    user can modify the Library and then relink to produce a modified
    executable containing the modified Library.  (It is understood
    that the user who changes the contents of definitions files in the
    Library will not necessarily be able to recompile the application
    to use the modified definitions.)

    b) Use a suitable shared library mechanism for linking with the
    Library.  A suitable mechanism is one that (1) uses at run time a
    copy of the library already present on the user's computer system,
    rather than copying library functions into the executable, and (2)
    will operate properly with a modified version of the library, if
    the user installs one, as long as the modified version is
    interface-compatible with the version that the work was made with.

    c) Accompany the work with a written offer, valid for at
    least three years, to give the same user the materials
    specified in Subsection 6a, above, for a charge no more
    than the cost of performing this distribution.

    d) If distribution of the work is made by offering access to copy
    from a designated place, offer equivalent access to copy the above
    specified materials from the same place.

    e) Verify that the user has already received a copy of these
    materials or that you have already sent this user a copy.

  For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it.  However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.

  It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system.  Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.

  7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

    a) Accompany the combined library with a copy of the same work
    based on the Library, uncombined with any other library
    facilities.  This must be distributed under the terms of the
    Sections above.

    b) Give prominent notice with the combined library of the fact
    that part of it is a work based on the Library, and explaining
    where to find the accompanying uncombined form of the same work.

  8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License.  Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License.  However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.

  9. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Library or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.

  10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.

  11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all.  For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.

If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded.  In such case, this License incorporates the limitation as if
written in the body of this License.

  13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number.  If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation.  If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.

  14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission.  For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this.  Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.

			    NO WARRANTY

  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

		     END OF TERMS AND CONDITIONS

Added jni/tkzinc/Makefile.in.





































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#  Copyright (c) 1993 - 2005 CENA, Patrick Lecoanet --
#
# See the file "Copyright" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Revision$
#
#
# This Makefile.in is derived from the Sample TEA template which is:
#
# Copyright (c) 1999 Scriptics Corporation.
# Copyright (c) 2002 ActiveState SRL.
#

PACKAGE_NAME      = @PACKAGE_NAME@
PACKAGE_VERSION   = @PACKAGE_VERSION@

PKG_SOURCES	      = @PKG_SOURCES@
PKG_OBJECTS	      = @PKG_OBJECTS@

PKG_STUB_SOURCES	= @PKG_STUB_SOURCES@
PKG_STUB_OBJECTS	= @PKG_STUB_OBJECTS@

PKG_TCL_SOURCES   = @PKG_TCL_SOURCES@

PKG_HEADERS       = @PKG_HEADERS@

PKG_LIB_FILE      = @PKG_LIB_FILE@
PKG_STUB_LIB_FILE = @PKG_STUB_LIB_FILE@

BINARIES	= $(PKG_LIB_FILE) $(PKG_STUB_LIB_FILE)

SHELL		= @SHELL@

srcdir		= @srcdir@
prefix		= @prefix@
exec_prefix	= @exec_prefix@

libdir		= @libdir@
includedir	= @includedir@

DESTDIR		=

PKG_DIR		= $(PACKAGE_NAME)$(PACKAGE_VERSION)
pkglibdir	= $(libdir)/$(PKG_DIR)

top_builddir	= .

INSTALL		= @INSTALL@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@
INSTALL_DATA	= @INSTALL_DATA@
INSTALL_SCRIPT	= @INSTALL_SCRIPT@

CC		= @CC@
CFLAGS_DEBUG	= @CFLAGS_DEBUG@
CFLAGS_DEFAULT	= @CFLAGS_DEFAULT@
CFLAGS_OPTIMIZE	= @CFLAGS_OPTIMIZE@
CFLAGS_WARNING	= @CFLAGS_WARNING@
CLEANFILES	= @CLEANFILES@
EXEEXT		= @EXEEXT@
LDFLAGS_DEFAULT = @LDFLAGS_DEFAULT@
MAKE_LIB	= @MAKE_LIB@
MAKE_STUB_LIB	= @MAKE_STUB_LIB@
MAKE_SHARED_LIB	= @MAKE_SHARED_LIB@
MAKE_STATIC_LIB	= @MAKE_STATIC_LIB@
OBJEXT		= @OBJEXT@
RANLIB		= @RANLIB@
SHLIB_CFLAGS	= @SHLIB_CFLAGS@
SHLIB_LD	= @SHLIB_LD@
SHLIB_LD_LIBS	= @SHLIB_LD_LIBS@
STLIB_LD	= @STLIB_LD@
TCL_BIN_DIR	= @TCL_BIN_DIR@
TCL_SRC_DIR	= @TCL_SRC_DIR@
TK_BIN_DIR	= @TK_BIN_DIR@
TK_SRC_DIR	= @TK_SRC_DIR@
#
# This is necessary for packages that use private Tcl headers
TCL_TOP_DIR_NATIVE	= @TCL_TOP_DIR_NATIVE@
TK_TOP_DIR_NATIVE	= @TK_TOP_DIR_NATIVE@
# Not used, but retained for reference of what libs Tcl required
TCL_LIBS	= @TCL_LIBS@


#========================================================================
# TCLLIBPATH seeds the auto_path in Tcl's init.tcl so we can test our
# package without installing.  The other environment variables allow us
# to test against an uninstalled Tcl.  Add special env vars that you
# require for testing here (like TCLX_LIBRARY).
#========================================================================

EXTRA_PATH	= $(top_builddir):$(TCL_BIN_DIR)
TCLSH_ENV	= TCL_LIBRARY=`@CYGPATH@ $(TCL_SRC_DIR)/library` \
		  LD_LIBRARY_PATH="$(EXTRA_PATH):$(LD_LIBRARY_PATH)" \
		  LIBPATH="$(EXTRA_PATH):${LIBPATH}" \
		  SHLIB_PATH="$(EXTRA_PATH):${SHLIB_PATH}" \
		  PATH="$(EXTRA_PATH):$(PATH)" \
		  TCLLIBPATH="$(top_builddir)"
TCLSH_PROG	= @TCLSH_PROG@
WISH_PROG	= @WISH_PROG@
TCLSH		= $(TCLSH_ENV) $(TCLSH_PROG)
WISH		= $(TCLSH_ENV) $(WISH_PROG)
SHARED_BUILD	= @SHARED_BUILD@

# The local includes must come first, because the TK_XINCLUDES can be
# just a comment
TCL_INCLUDES = @TCL_INCLUDES@
TK_INCLUDES = @TK_INCLUDES@
GL_INCLUDES = @GL_INCLUDES@
INCLUDES	= -I$(srcdir)/generic @TCL_INCLUDES@ @TK_INCLUDES@ @GL_INCLUDES@

TCL_EXTRA_CFLAGS	= $(MEM_DEBUG_FLAGS) @TCL_EXTRA_CFLAGS@

DEFS		= @DEFS@ @PKG_CFLAGS@ $(TCL_EXTRA_CFLAGS)

CONFIG_CLEAN_FILES = Makefile

CPPFLAGS	= @CPPFLAGS@
LIBS		= @PKG_LIBS@ @LIBS@
AR		= @AR@
CFLAGS		= @CFLAGS@
COMPILE		= $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)


#
# No stubs build right now
#all: package libraries
all: package

package: $(PKG_LIB_FILE) pkgIndex.tcl

libraries: $(PKG_STUB_LIB_FILE)


#========================================================================
# The doc target is for building man pages. Currently the zinc doc is
# only available in html and pdf formats. These formats require tools
# (LaTeX, pdfTeX, h4tex) that are not readily available on all
# platforms. To ease automatic construction of the package the target
# doc does not involve the construction of pdf and html.
#========================================================================

doc:

doc-clean:
	(cd doc; \
				rm -f refman.aux refman.idx refman.ind refman.lof refman.lot; \
				rm -f refman.log refman.out refman.toc texput.log refman.tpt; \
				rm -f idxmake.dvi idxmake.log refman.4ct refman.4dx refman.4ix; \
				rm -f refman.4tc refman.dvi refman.idx refman.ilg refman.ind; \
				rm -f refman.log refman.tmp refman.xref refman.lg refman.idv)

pdf: doc-clean doc/refman.tex
	(cd doc; \
	  pdflatex refman.tex; \
		makeindex -o refman.ind refman.idx; \
	  pdflatex refman.tex; \
	  pdflatex refman.tex)

html: doc-clean doc/refman.tex
	(cd doc; \
	  htlatex refman.tex refman; \
	  tex '\def\filename{{refman}{idx}{4dx}{ind}}' '\input' idxmake.4ht; \
		makeindex -o refman.ind refman.4dx; \
		htlatex refman.tex refman)

#
# No stubs and no headers installed right now
#install: install-package install-libraries install-headers install-demos
install: install-package install-demos

install-package:
	@mkdir -p $(DESTDIR)$(pkglibdir)
	$(INSTALL_PROGRAM) $(PKG_LIB_FILE) $(DESTDIR)$(pkglibdir)/$(PKG_LIB_FILE)
	for p in $(srcdir)/library/*.tcl ; do \
		destp=`basename $$p`; \
		echo " Install $$destp $(DESTDIR)$(pkglibdir)/$$destp"; \
		$(INSTALL_DATA) $$p $(DESTDIR)$(pkglibdir)/$$destp; \
	done
	cat pkgIndex.tcl >> $(DESTDIR)$(pkglibdir)/pkgIndex.tcl

install-headers:
	echo "Installing header files in $(DESTDIR)$(includedir)"; \
	mkdir -p $(DESTDIR)$(includedir); \
	for i in "$(PKG_HEADERS)" ; do \
		echo "Install $(srcdir)/$$i" ; \
		destp=`basename $$i`; \
		$(INSTALL_DATA) $(srcdir)/$$i $(DESTDIR)$(includedir)/$$destp ; \
	done

install-libraries:
	@echo "Installing $(PKG_STUB_LIB_FILE) in $(DESTDIR)$(libdir)"
	@mkdir -p $(DESTDIR)$(libdir)
	$(INSTALL_PROGRAM) $(PKG_STUB_LIB_FILE) $(DESTDIR)$(libdir)

install-demos:
	@mkdir -p $(DESTDIR)$(pkglibdir)/demos
	@echo "Installing demo files in $(DESTDIR)$(pkglibdir)/demos"
	@for p in $(srcdir)/demos/*; do \
		p=`basename $$p`; \
		echo " Install $$p $(DESTDIR)$(pkglibdir)/demos/$$p"; \
		$(INSTALL_DATA) $(srcdir)/demos/$$p $(DESTDIR)$(pkglibdir)/demos/$$p; \
	done
	@mkdir -p $(DESTDIR)$(pkglibdir)/demos/images
	@mkdir -p $(DESTDIR)$(pkglibdir)/demos/data
	@for p in $(srcdir)/demos/images/*; do \
		p=`basename $$p`; \
		echo " Install $$p $(DESTDIR)$(pkglibdir)/demos/images/$$p"; \
		$(INSTALL_DATA) $(srcdir)/demos/images/$$p $(DESTDIR)$(pkglibdir)/demos/images/$$p; \
	done
	@for p in $(srcdir)/demos/data/*; do \
		p=`basename $$p`; \
		echo " Install $$p $(DESTDIR)$(pkglibdir)/demos/data/$$p"; \
		$(INSTALL_DATA) $(srcdir)/demos/data/$$p $(DESTDIR)$(pkglibdir)/demos/data/$$p; \
	done

test: package libraries
	$(TCLSH) `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS) ; \

shell: package libraries
	@$(TCLSH) $(SCRIPT)

gdb:
	$(TCLSH_ENV) gdb $(TCLSH_PROG) $(SCRIPT)

depend:

$(PKG_LIB_FILE): $(PKG_OBJECTS)
	-rm -f $(PKG_LIB_FILE)
	${MAKE_LIB}
	$(RANLIB) $(PKG_LIB_FILE)

$(PKG_STUB_LIB_FILE): $(PKG_STUB_OBJECTS)
	-rm -f $(PKG_STUB_LIB_FILE)
	${MAKE_STUB_LIB}
	$(RANLIB) $(PKG_STUB_LIB_FILE)
  
#========================================================================
# We need to enumerate the list of .c to .o lines here.
#
# In the following lines, $(srcdir) refers to the toplevel directory
# containing your extension.  If your sources are in a subdirectory,
# you will have to modify the paths to reflect this:
#
# sample.$(OBJEXT): $(srcdir)/generic/sample.c
# 	$(COMPILE) -c `@CYGPATH@ $(srcdir)/generic/sample.c` -o $@
#
# Setting the VPATH variable to a list of paths will cause the makefile
# to look into these paths when resolving .c to .obj dependencies.
# As necessary, add $(srcdir):$(srcdir)/compat:....
#========================================================================

VPATH = $(srcdir):$(srcdir)/generic:$(srcdir)/unix:$(srcdir)/win:$(srcdir)/macosx

.SUFFIXES: .c .$(OBJEXT)

.c.$(OBJEXT):
	$(COMPILE) -c `@CYGPATH@ $<` -o $@

#========================================================================
# Create the pkgIndex.tcl file.
# It is usually easiest to let Tcl do this for you with pkg_mkIndex, but
# you may find that you need to customize the package.  If so, either
# modify the -hand version, or create a pkgIndex.tcl.in file and have
# the configure script output the pkgIndex.tcl by editing configure.in.
#========================================================================

pkgIndex.tcl:
	(echo 'package ifneeded $(PACKAGE_NAME) $(PACKAGE_VERSION) \
	    [list load [file join $$dir $(PKG_LIB_FILE)]]'\
	) > pkgIndex.tcl

#========================================================================
# Don't modify the file to clean here.  Instead, set the "CLEANFILES"
# variable in configure.in
#========================================================================

clean: doc-clean 
	-test -z "$(BINARIES)" || rm -f $(BINARIES)
	-rm -f *.$(OBJEXT) core *.core
	-test -z "$(CLEANFILES)" || rm -Rf $(CLEANFILES)

distclean: clean
	-rm -f *.tab.c *~
	-rm -f $(CONFIG_CLEAN_FILES)
	-rm -f config.cache config.log config.status

#========================================================================
# Install binary object libraries.  On Windows this includes both .dll and
# .lib files.  Because the .lib files are not explicitly listed anywhere,
# we need to deduce their existence from the .dll file of the same name.
# Library files go into the lib directory.
# In addition, this will generate the pkgIndex.tcl
# file in the install location (assuming it can find a usable tclsh shell)
#
# You should not have to modify this target.
#========================================================================

Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
	cd $(top_builddir) \
	  && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status

.PHONY: all package clean depend distclean doc install libraries test

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

Added jni/tkzinc/Perl/Makefile.PL.



















































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use 5.006;
use Tk;
use Config;
use Tk::Config;
use ExtUtils::MakeMaker;
use strict;

my $TkLibDir = $Tk::library;
my $platform = $Tk::platform;

my $VERSION = SEEexport2cpan;


if (!$TkLibDir)
{
    print stderr "==================================================================\n";
    print stderr "Could not find the Perl/Tk (pTk) library.\n";
    print stderr "Please, install first Perl/Tk interface before installing Tk::Zinc\n";
    print stderr "==================================================================\n";
    die;
}


print "Configuring version $VERSION for $platform platform...\n";
print "Using $TkLibDir as Tk library...\n";

my @GENERIC_C = ('Tabular.c', 'Rectangle.c', 'Arc.c', 'Curve.c',
		 'Item.c', 'PostScript.c', 'Attrs.c', 'Draw.c', 'Geo.c', 'List.c',
		 'perfos.c', 'Transfo.c', 'Group.c', 'Icon.c', 'Text.c', 'Image.c', 'Color.c',
		 'Field.c', 'Triangles.c', 'Viewport.c', 'WindowUtils.c', 'Window.c', 'tkZinc.c');

my @ATC_C = ('OverlapMan.c', 'Track.c', 'Reticle.c', 'Map.c', 'MapInfo.c');

my @WIN_C = ('WinPort.c');

my @C;

my $WIN = ($platform =~ /win/i);

push @C, @GENERIC_C ;

my $NeededLibs = ['-L/usr/X11R6/lib -lXext -lX11 -lGLU -lGL -L.'];

if ($WIN) {
    push @C, @WIN_C;
    $NeededLibs = ['-lglu32 -lopengl32']
}
my $ZincObj = "Zinc" . $Config{"_o"};

my $INC = "-I. -I$TkLibDir -I$TkLibDir/pTk -I$TkLibDir/X11";

unless ($WIN) {
  $INC .= " -I/usr/X11R6/include";
}

#For some reason which the author of ExtUtils::MM_Unix forget, Unix machines like to have
#PERL_DL_NONLAZY set for tests. This is FALSE for TkZinc.

if ($] >= 5.008000) {
  *ExtUtils::MM_Unix::test_via_harness = sub {
    my($self, $perl, $tests) = @_;
#    return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests);
    # I should use the SUPER method, but this needs some import tunning...
    return ExtUtils::MM_Any::test_via_harness($self, $perl, $tests);
  };

#Again, the PERL_DL_NONLAZY thing.
  *ExtUtils::MM_Unix::test_via_script = sub {
    my($self, $perl, $script) = @_;
#    return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script);
    # I should use the SUPER method, but this needs some import tunning...
    return ExtUtils::MM_Any::test_via_script($self, $perl, $script);
  };
}

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.

my $mm_ver = $ExtUtils::MakeMaker::VERSION;
if ($mm_ver =~ /_/) { # dev version
    $mm_ver = eval $mm_ver;
    die $@ if $@;
}

WriteMakefile(
    'ABSTRACT'      => 'a canvas offering groups, tranformations, transparency, color gradient...',
    'AUTHOR'        => 'Patrick Lecoanet <lecoanet@cena.fr>',
    'NAME'          => 'Tk::Zinc',
    'PREREQ_PM'     => $WIN ? {Tk => 8.004} : {Tk => 8.0},
    'LIBS'          => $NeededLibs, 
    'OPTIMIZE'      => &optimize,
    'DEFINE'        => &get_flags,
    'INC'           => $INC,
    'C'             => [@C],
    'XS_VERSION'    => $Tk::Config::VERSION,
    'XS'            => {'Zinc.xs' => 'Zinc.c'},
    'linkext'       => {LINKTYPE => 'dynamic'},
    'depend'        => {$ZincObj => '$(O_FILES) Zinc.c'},
    'LDFROM'        => "\$(O_FILES) $ZincObj",
    ($mm_ver <= 6.45
        ? ()
        : (META_MERGE => {
            'meta-spec' => { version => 2 },
            resources => {
                repository  => {
                    type => 'hg',
                    web  => 'https://bitbucket.org/plecoanet/tkzinc',
                    url  => 'https://bitbucket.org/plecoanet/tkzinc/src',
                },
            },
          })
    ),
);

sub optimize {
  foreach my $arg (@ARGV) {
    if ($arg =~ /(enable-symbols)/i) {
      return "-g";
    }
  }
  return "-O";
}

sub get_flags {
    my %DEF_FLAGS = ('GL'        => 1,
		     'SHAPE'     => 1,
		     'ATC'        => 1
		     );
    
    foreach my $arg (@ARGV) {
	print "$arg ....\n";
	my ($name, $value) = split(/[=]+/, $arg);
	if ($name =~ /(with-gl)/i) {
	    if ($value =~ /no/i) {
		$DEF_FLAGS{'GL'} = 0;
	    }
	}
	elsif ($name =~ /(with-atc)/i) {
	    if ($value =~ /no/i) {
		$DEF_FLAGS{'ATC'} = 0;
	    }
	}
	elsif ($name =~ /(with-shape)/i) {
	    if ($value =~ /no/i) {
		$DEF_FLAGS{'SHAPE'} = 0;
	    }
	}
    }
    
    my $defines = "-DPTK -DPACKAGE_VERSION=\\\"$VERSION\\\"";

    if ($WIN) {
	#
	# No shape extension on Windows (planned later).
	$DEF_FLAGS{'SHAPE'} = 0;
	#
	# Visual C++ does not define __STDC__ by default
	$defines .= ' -D__STDC__';
    }

    print "Configuring with:\n    ";
    foreach my $flag (keys %DEF_FLAGS) {
	print "$flag=", $DEF_FLAGS{$flag} ? 'ok' : 'no', " ";
	if ($DEF_FLAGS{$flag}) {	    
	    $defines = $defines . " " . "-D$flag";
	    if ($flag eq 'ATC') {
		push @C, @ATC_C
	    }
	}
    }
    if ($Tk::VERSION =~ /^800/) {
      $defines .= " -DPTK_800";
      print "PTK=800";
    } else {
      print "PTK=804";
    }
    print "\n";
    return $defines;
}

#
# For the demo
#
# perl -Mblib demos/zinc-demos

Added jni/tkzinc/Perl/README.



































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Tk::Zinc - another Canvas which proposes many new functions, some based on openGL

Tk::Zinc for Perl/Tk is available for Linux, Windows and MacOSX. 
the easiest way could be to use he CPAN. However new releases are usually 
first available on www.tkzinc.org
To build it you need:

* On a Linux system, you need Perl (>= 5.6) and perl-tk (800 or 804) as well as
  perl-tk developpement packages.

* On MacOSX you need:
  - fink with tk-pm package and its dependencies (http://fink.sf.net)
    tk-pm is available in unstable. You can add this binary unstable tree to you /sw/etc/apt/sources.list:
    deb http://fink.opendarwin.org/bbraun 10.3/unstable main crypto
    deb http://fink.opendarwin.org/bbraun 10.3/stable main crypto
  - X11 et X11 sdk from Apple (http://www.apple.com/macosx/x11/)

* On WinXP you need:
  - activeperl (5.8.6.811 or higher) from activatestate.com 
  - and
    - if you want to compile TkZinc by yourself:
      Visual C++ or the Free Visual C++ Command Line Tools
    - or the TkZinc msi package available from www.tkzinc.org


Install:

  perl Makefile.PL
  # you can use the following options: --with-gl=yes|no --with-atc=yes|no --with-shape=yes|no
  # current defaults are  --with-gl=yes --with-atc=yes --with-shape=yes

  make
  make test

  # to run demos before installing:
  perl -Iblib/arch -Iblib/lib demos/zinc-demos

  make install



WATCH OUT! On Linux it is quite frequent to have both Mesa and proprietary
           openGL libraries installed. This may lead to big problems at
           runtime if the linker picks the wrong library. It is often the
           the case between the static (libGL.a) Mesa library and the dynamic
           (libGL.so) NVidia library. It is very important to assert that
           the link is done with the library matching the openGL driver
           loaded in the X server.

In the case you need to use another version of perl-tk than the one installed in the 
system, you should use the following command as a template to adapt to follow your 
specific pathes of the alternative perl-tk installation:

  env PERL5LIB=/usr/local/test/804_027/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi perl Makefile.PL
  make
  env PERL5LIB=/usr/local/test/804_027/lib/perl5/5.8.1/i386-linux-thread-multi:/usr/local/test/804_027/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi make test

  # to run demos before installing:
  env PERL5LIB=/usr/local/test/804_027/lib/perl5/5.8.1/i386-linux-thread-multi:/usr/local/test/804_027/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi perl -Iblib/arch -Iblib/lib demos/zinc-demos

  # and finally
  make install

  # and to run your script:
  env PERL5LIB=/usr/local/test/804_027/lib/perl5/5.8.1/i386-linux-thread-multi:/usr/local/test/804_027/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi perl <your_script.pl>




up-to-date documentation is also available at https://bitbucket.org/plecoanet/tkzinc
The source of the reference manual is available in the full source package,
which also includes TkZinc for Tcl/Tk, for Perl/Tk, and for Python.


After installation, we recommend you to launch the zinc-demos script,
a frontend to more than 30 small demos.

For more information on building Tk::Zinc, a README is available in 
the tkzinc-*tgz tar file (on Tkzinc web site) used for building all
flavor of TkZinc (ie tcl, perl and python)

This software is delivered under new  BSD licence.
For the copyright, please, read the Copyright file.

For any question on Tk::Zinc usage, build or installation pb,
please create an inquiry on Bitbucket: https://bitbucket.org/plecoanet/tkzinc/issues


Authors and Contributors:

Tk::Zinc main author is Patrick Lecoanet (CENA)
Sub-Modules, demos and documentation have been developped by
Daniel Etienne (CENA), Christophe Mertz (formerly CENA and now IntuiLab), 
Jean-Luc Vinot (CENA), with contributions from Stéphane Chatty (Intuilab), 
Céline Schlienger (IntuiLab), Alexandre Lemort (IntuiLab)
Stéphane Conversy (CENA) contributed to the MacOSX port.
Many others contributed with their bug reports!

Added jni/tkzinc/Perl/Zinc.pm.





























































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# $Id$
# $Name$

package Tk::Zinc;

use Tk;
use Tk::Photo;
use Carp;

use base qw(Tk::Widget); 
Construct Tk::Widget 'Zinc';


use vars qw($VERSION $REVISION);

$REVISION = q$Revision$ ;  # this line is automagically modified by CVS
$VERSION = SEEexport2cpan;


bootstrap Tk::Zinc $Tk::VERSION;

sub Tk_cmd { \&Tk::zinc }

sub CreateOptions
{
 return (shift->SUPER::CreateOptions,'-render')
}

Tk::Methods("add", "addtag", "anchorxy", "bbox", "becomes", "bind", "cget",
	    "chggroup", "clone", "collapsemotions", "configure", "contour", "coords",
      "currentpart", "cursor", "dchars", "dtag", "find", "fit", "focus",
      "gdelete", "gettags", "gname", "group", "hasanchors", "hasfields",
      "hastag", "index", "insert", "itemcget", "itemconfigure", "lower",
      "monitor", "numparts", "postscript", "raise", "remove", "rotate",
      "scale", "select", "skew", "smooth", "tapply", "tcompose", "tdelete",
      "tget", "transform", "translate", "treset", "trestore", "tsave", "tset",
	    "type", "vertexat", "xview", "yview");

## coord0 is a compatibility function usefull for porting old application
## previously running with Tk::Zinc V <= 3.2.6a
## The Zinc methode coords0 can/should replace coords as long as no control points are
## used in curve or rectangle or an arc...
## This can dramaticaly simplify the port of an old application from Zinc V<3.2.6a to
## a newer version of Zinc. HOWEVER YOU STILL MUST CHANGE THE CODE OF THIS OLD APPICATION
##
## Remember: the incompatible change in Zinc is due to the introduction of
## control points in curves (and a future release, in arc or rectangle items...)
sub coords0 {
    if (wantarray) {
	## we are in list context, so we should convert the returned value
	## to match the specification of Zinc Version <= 3.2.6a
	my @res = &Tk::Zinc::coords(@_);
	if ( !ref $res[0] ) {
	    ## The first item of the list is not a reference, so the
	    ## list is guarranted to be a flat list (x, y, x, y, ... x, y)
	    return @res;
	}
	else {
	    ## The list is a list of references like : [x y] or [x y symbol] 
	    ## In the latter case, coord0 should warn that there is a control point!
	    ## coord0 will return a flatten list of (x, y, ... x , y)
	    my @res0;
	    foreach my $ref (@res) {
		my @array = @{$ref};
	        if ($#array > 1) {
		   my $item = $_[1];
		   my $zinc = $_[0];
		   my $type = $zinc->type($item);
		   carp "Using Zinc coord0 compatibility method with item $item (type=$type) which contains a control point: @array";
	        }
		push @res0, $array[0];
		push @res0, $array[1];
	    }
	    return @res0;
        }
    }
    else {
	## contexte scalaire
	## le résultat n'était pas utilisé jusqu'à présent, vu le bug...
	## donc inutile de le convertir!
	return &Tk::Zinc::coords(@_);
    }
}

1;

__END__

=head1 NAME

Tk::Zinc - TkZinc is another Canvas which proposes many new functions, some based on openGL

=for category Tk Widget Classes

=head1 SYNOPSIS

I<$zinc> = I<$parent>-E<gt>B<Zinc>(?I<options>?);

=head1 DESCRIPTION

I<Zinc> widget is very similar to Tk Canvase in that it supports
structured graphics. Like the Canvas, TkZinc implements items used to
display graphical entities. Those items can be manipulated and bindings can be
associated with them to implement interaction behaviors. But unlike the
Canvas, TkZinc can structure the items in a hierarchy (with the use of
group items), has support for affine 2D transforms (i.e. translation, scaling, and
rotation), clipping can be set for sub-trees of the item hierarchy, the item set
is quite more powerful including field specific items for Air Traffic systems and
new rendering techniques such as transparency and gradients.

Since the 3.2.2 version, TkZinc also offers as a runtime option, the support
for openGL rendering, giving access to features such as antialiasing, transparency,
color gradients and even a new, openGL oriented, item type triangles.

TkZinc full documentation is available as part of the Zinc software as a
pdf file, B<refman.pdf> and html pages B<refman/index.html>.

As a complement to the reference manual, small Perl/Tk demos of TkZinc are
also available through a small application named zinc-demos, highly inspired
from the widget application included in Tk. The aim of these demos are both
to demonstrates the power of TkZinc and to help newcomers start using
TkZinc with small examples.

=head1 WHERE CAN I FIND TkZinc?

TkZinc is available as source in tar.gz format at L<https://bitbucket.org/plecoanet/tkzinc>.
There is some old packages at http://freshmeat.net/projects/zincisnotcanvas/, but please use the Bitbucket repo.

TkZinc is also available on CPAN since v3.294 (a kind of 3.2.94)

=head1 AUTHOR

Patrick Lecoanet <lecoanet@cena.fr>

=head1 COPYRIGHT

Zinc has been developed by the CENA (Centres d'Etudes de la Navigation
Aérienne) for its own needs in advanced HMI (Human Machine Interfaces or Interactions).
Because we are confident in the benefit of free software, the CENA delivered this
toolkit under the GNU Library General Public License.

This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

Parts of this software are derived from the Tk toolkit which is copyrighted
under another open source license by The Regents of the University of California
and Sun Microsystems, Inc. The GL
font rendering is derived from Mark Kilgard code described in 'A Simple OpenGL-based
API for Texture Mapped Text' and is copyrighted by Mark Kilgard under an open source license.

=head1 SEE ALSO

L<Tk(1)>, L<zinc-demos(1)>.

=cut

Added jni/tkzinc/Perl/Zinc.xs.























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
  Copyright (c) 1995-1997 Nick Ing-Simmons. All rights reserved.
  This program is free software; you can redistribute it and/or
  modify it under the same terms as Perl itself.
*/

#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>

#include <tkGlue.def>

#include <pTk/tkPort.h>
#include <pTk/tkInt.h>
#ifdef _WIN32
#include <pTk/tkWinInt.h>
#endif
#include <pTk/tkImgPhoto.h>
#include <pTk/tkVMacro.h>
#include <tkGlue.h>
#include <tkGlue.m>

extern int
ZincObjCmd(
	   ClientData client_data,
	   Tcl_Interp* interp,
	   int argc,
	   Tcl_Obj* CONST args[]);

extern int
ZnVideomapObjCmd(
	         ClientData client_data,
	         Tcl_Interp* interp,
	         int argc,
	         Tcl_Obj* CONST args[]);

extern int
ZnMapInfoObjCmd(
	        ClientData client_data,
	        Tcl_Interp* interp,
	        int argc,
	        Tcl_Obj* CONST args[]);

DECLARE_VTABLES;
TkimgphotoVtab *TkimgphotoVptr;

MODULE = Tk::Zinc	PACKAGE = Tk::Zinc

PROTOTYPES: DISABLE

BOOT:
 {
  IMPORT_VTABLES;
  TkimgphotoVptr = (TkimgphotoVtab *) SvIV(perl_get_sv("Tk::TkimgphotoVtab",GV_ADDWARN|GV_ADD));

  Lang_TkCommand("zinc", ZincObjCmd);
  Lang_TkCommand("videomap", ZnVideomapObjCmd);
  Lang_TkCommand("mapinfo", ZnMapInfoObjCmd);
 }

Added jni/tkzinc/Perl/Zinc/Debug.pm.































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
#        Tk::Zinc::Debug Perl Module :
#
#        For debugging/analysing a Zinc application.
#
#        Author : Daniel Etienne <etienne@cena.fr>
#
# $Id$
#---------------------------------------------------------------------------
package Tk::Zinc::Debug;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use strict 'vars';
use vars qw(@ISA @EXPORT @EXPORT_OK $WARNING $endoptions);
use Carp;
use English;
require Exporter;
use File::Basename;
use Tk::Dialog;
use Tk::Tree;
use Tk::ItemStyle;
use Tk::Pane;
use Tk::FBox;
use Tk::Balloon;

@ISA = qw(Exporter);
@EXPORT = qw(finditems snapshot tree init);
@EXPORT_OK = qw(finditems snapshot tree init);

my ($itemstyle, $groupstyle, $step);
my (%result_tl, $result_fm, $search_tl, $helptree_tl, %coords_tl, %transfo_tl,
    $helpcoords_tl, $searchtree_tl, $tree_tl, %alloptions_tl, $tree,
    $cursorxy_tl, $cursorxy);
my $showitemflag;
my ($x0, $y0);
my ($help_print, $imagecounter, $saving) = (0, 0, 0);
my %searchEntryValue;
my $searchTreeEntryValue;
my %wwidth;
my %wheight;
my $preload;
my %defaultoptions;
my %instances;
my @instances;
my %cmdoptions;
my $initobjectfunction;
my %userbindings;
my $selectedzinc;
my $control_tl;
my %button;
my %on_command;
my %off_command;
my @znpackinfo;
my $screenwidth;
my $balloonhelp;
#---------------------------------------------------------------------------
#
# Initialisation functions for plugin usage
#
#---------------------------------------------------------------------------

# Hack to overload the Tk::Zinc::InitObject method
#
BEGIN {
    
    # test if Tk::Zinc::Debug is loaded using the -M perl option
    $preload = 1 if (caller(2))[2] == 0;
    return unless $preload;
    # parse Tk::Zinc::Debug options
    require Getopt::Long;
    Getopt::Long::Configure('pass_through');
    Getopt::Long::GetOptions(\%cmdoptions, 'optionsToDisplay=s', 'optionsFormat=s',
			     'snapshotBasename=s', 'expandTagsField=i');
    # save current Tk::Zinc::InitObject function; it will be invoked in
    # overloaded one (see below)
    use Tk;
    use Tk::Zinc;
    $initobjectfunction = Tk::Zinc->can('InitObject');
    
} # end BEGIN


# Hack to capture the instance(s) of zinc. Tk::Zinc::Debug init function
# is invoked here.
#
sub Tk::Zinc::InitObject {
    
    # invoke function possibly overloaded in other modules
    &$initobjectfunction(@_) if $initobjectfunction;
    return unless $preload;
    my $zinc = $_[0];
    &init($zinc);
   
} # end Tk::Zinc::InitObject


#---------------------------------------------------------------------------
#
# Initialisation function
#
#---------------------------------------------------------------------------

sub init {

    my $zinc = shift;
    $screenwidth = $zinc->screenwidth;
    my %options = @_;
    for my $opt (keys(%options)) {
        carp "in Tk::Zinc::Debug initialisation function, unknown option $opt\n"
            unless $opt eq '-optionsToDisplay' or $opt eq '-optionsFormat'
		or $opt eq '-snapshotBasename' or $opt eq '-expandTagsField' ;
    }
    $cmdoptions{optionsToDisplay} = $options{-optionsToDisplay} if
	not defined $cmdoptions{optionsToDisplay} and
	    defined $options{-optionsToDisplay};
    $cmdoptions{optionsFormat} = $options{-optionsFormat} if
	not defined $cmdoptions{optionsFormat} and
	    defined $options{-optionsFormat};
    $cmdoptions{snapshotBasename} = $options{-snapshotBasename} if
	not defined $cmdoptions{snapshotBasename} and
	    defined $options{-snapshotBasename};
    $cmdoptions{expandTagsField} = $options{-expandTagsField} if
	not defined $cmdoptions{expandTagsField} and
	    defined $options{-expandTagsField};
	
    &newinstance($zinc);
    return if Tk::Exists($control_tl);
    print "Tk::Zinc::Debug is ON\n";
    my $bitmaps = &createBitmaps($zinc);
    $control_tl = $zinc->Toplevel;
    $control_tl->title("Tk::Zinc::Debug (V $VERSION)");
    my $fm1 = $control_tl->Frame()->pack(-side => 'left', -padx => 0);
    my $fm2 = $control_tl->Frame()->pack(-side => 'left', -padx => 20);
    my $fm3 = $control_tl->Frame()->pack(-side => 'left', -padx => 0);
    
    for (qw(zn findenclosed findoverlap tree item id snapshot cursorxy)) {
	$button{$_} = $fm1->Checkbutton(-image => $bitmaps->{$_},
					-indicatoron => 0,
					-foreground => 'gray20')->pack(-side => 'left');
    }
    for (qw(zoomminus zoomplus move)) {
	$button{$_} = $fm2->Checkbutton(-image => $bitmaps->{$_},
					-indicatoron => 0,
					-foreground => 'gray20')->pack(-side => 'left');
    }
    for (qw(balloon close)) {
	$button{$_} = $fm3->Checkbutton(-image => $bitmaps->{$_},
					-indicatoron => 0,
					-foreground => 'gray20')->pack(-side => 'left');
    }
    my $bg = $button{zn}->cget(-background);
    for (values(%button)) {
	$_->configure(-selectcolor => $bg);
    }
    $balloonhelp = &balloonhelp();
    $button{balloon}->toggle;
    $control_tl->withdraw();
    $button{zn}->configure(-command => \&focuscommand);
    $button{balloon}->configure(-command => sub {
				    if ($button{balloon}->{Value} == 0) {
					$balloonhelp->configure(-state => 'none');
				    } else {
					$balloonhelp->configure(-state => 'balloon');
				    }
			 });
    #--------------------------------------------------
    # on/off commands for exclusive modes :
    #--------------------------------------------------
    
    # findenclosed mode
    $on_command{findenclosed} = sub {
	&saveDragAndDropBindings($selectedzinc);
	$button{findenclosed}->{Value} = 1;
	$selectedzinc->Tk::bind("<ButtonPress-1>",
				[\&startrectangle, 'simple', 'Enclosed',
				       'sienna']);
	$selectedzinc->Tk::bind("<B1-Motion>", \&resizerectangle);
	$selectedzinc->Tk::bind("<ButtonRelease-1>",
				[\&stoprectangle, 'enclosed',
				 'Items enclosed in rectangle']);
    };
    $off_command{findenclosed} = sub {
	$button{findenclosed}->{Value} = 0;
	&restoreDragAndDropBindings($selectedzinc);
	$selectedzinc->remove("zincdebugrectangle", "zincdebuglabel");
    };
    # findoverlap mode
    $on_command{findoverlap} = sub {
	&saveDragAndDropBindings($selectedzinc);
	$button{findoverlap}->{Value} = 1;
	$selectedzinc->Tk::bind("<ButtonPress-1>", [\&startrectangle, 'mixed',
						    'Overlap', 'sienna']);
	$selectedzinc->Tk::bind("<B1-Motion>", \&resizerectangle);
	$selectedzinc->Tk::bind("<ButtonRelease-1>",
				[\&stoprectangle, 'overlapping',
				 'Items which overlap rectangle']);
    };
    $off_command{findoverlap} = sub {
	$button{findoverlap}->{Value} = 0;
	&restoreDragAndDropBindings($selectedzinc);
	$selectedzinc->remove("zincdebugrectangle", "zincdebuglabel");
    };
    # item mode
    $on_command{item} = sub {
	&saveDragAndDropBindings($selectedzinc);
	$button{item}->{Value} = 1;
	$selectedzinc->Tk::bind("<ButtonPress-1>", [\&findintree]);
    };
    $off_command{item} = sub {
	$button{item}->{Value} = 0;
	&restoreDragAndDropBindings($selectedzinc);
    };
    # cursor device position mode
    $on_command{cursorxy} = sub {
	&saveMotionBinding($selectedzinc);
	$button{cursorxy}->{Value} = 1;
	&cursorxyOpen;
	$selectedzinc->Tk::bind("<Motion>", [\&cursorxy]);
    };
    $off_command{cursorxy} = sub {
	$button{cursorxy}->{Value} = 0;
	&cursorxyClose;
	&restoreMotionBinding($selectedzinc);
    };
    
    # move mode
    $on_command{move} = sub {
	&saveDragAndDropBindings($selectedzinc);
	$button{move}->{Value} = 1;
	my ($x0, $y0);
	$selectedzinc->Tk::bind('<ButtonPress-1>', sub {
	    my $ev = $selectedzinc->XEvent;
	    ($x0, $y0) = ($ev->x, $ev->y);
	});
	$selectedzinc->Tk::bind('<B1-Motion>', sub {
	    my $ev = $selectedzinc->XEvent;
	    my ($x, $y) = ($ev->x, $ev->y);
	    $selectedzinc->translate(1, $x-$x0, $y-$y0) if defined $x0;
	    ($x0, $y0) = ($x, $y);
	});
    };
    $off_command{move} = sub {
	$button{move}->{Value} = 0;
	&restoreDragAndDropBindings($selectedzinc);
    };
    # zn mode
    $on_command{zn} = sub {
	$button{zn}->{Value} = 1;
	for my $zinc (&instances) {
	    $zinc->remove("zincdebugrectangle", "zincdebuglabel");
	    &saveDragAndDropBindings($zinc);
	    my $r;
	    $zinc->Tk::bind("<ButtonPress-1>", sub {
		$zinc->update;
		my ($w, $h) = ($zinc->cget(-width), $zinc->cget(-height));
		$zinc->tsave(1, 'transfoTopgroup', 1);
		$r = $zinc->add('rectangle', 1, [30, 30, $w-30, $h-30],
				-linecolor => 'red',
				-linewidth => 10);
		$zinc->trestore($r, 'transfoTopgroup');
		$zinc->raise($r);
		$selectedzinc = $zinc;
	    });
	    $zinc->Tk::bind("<ButtonRelease-1>", sub {
		$zinc->remove($r);
	    });
	}
    };
    $off_command{zn} = sub {
	$button{zn}->{Value} = 0;
        for my $zinc (&instances) {
	    &restoreDragAndDropBindings($zinc);
	}
    };

    my @but = qw(findenclosed findoverlap item move zn cursorxy);
    for my $name (@but) {
	$button{$name}->configure(-command => sub {
	    if ($button{$name}->{Value} == 1) {
		for my $other (@but) {
		    &{$off_command{$other}} unless $other eq $name;
		}
	    &{$on_command{$name}};
	    } else {
		&{$off_command{$name}};
	    }});
    }

    $button{id}->configure(-command => sub {
	$button{id}->update;
	&searchentry($zinc);
	$button{id}->toggle;
    });
    
    $button{snapshot}->configure(-command => sub {
	$button{snapshot}->update;
	&printWindow($zinc);
	$button{snapshot}->toggle;
    });
    
    $button{zoomminus}->configure(-command => sub {
	$button{zoomminus}->update;
	my $w = $selectedzinc->cget(-width);
	my $h = $selectedzinc->cget(-height);
	$selectedzinc->translate(1, -$w/2, -$h/2);
	$selectedzinc->scale(1, 1/1.1, 1/1.1);
	$selectedzinc->translate(1, $w/2, $h/2);
	$button{zoomminus}->toggle;
	});
    
    $button{zoomplus}->configure(-command => sub {
	$button{zoomplus}->update;
	my $w = $selectedzinc->cget(-width);
	my $h = $selectedzinc->cget(-height);
	$selectedzinc->translate(1, -$w/2, -$h/2);
	$selectedzinc->scale(1, 1.1, 1.1);
	$selectedzinc->translate(1, $w/2, $h/2);
	$button{zoomplus}->toggle;
	});
        
    $button{tree}->configure(-command => sub {
	$button{tree}->update;
	&showtree($selectedzinc);
	$button{tree}->toggle;
	});
    
    $button{close}->configure(-command => sub {
	$button{close}->update;
	&Tk::Zinc::Debug::iconify;
	&restoreDragAndDropBindings($selectedzinc);
	for my $name (@but) {
	    &{$off_command{$name}};
	}
	$button{close}->toggle;
    });
    
} # end init


#---------------------------------------------------------------------------
#
# Deprecated functions
#
#---------------------------------------------------------------------------

sub tree {
    
    carp "in Tk::Zinc::Debug module, tree() function is deprecated.\n";
    &init($_[0]);
    
} # end tree


sub finditems {
    
    carp "in Tk::Zinc::Debug module, finditems() function is deprecated.\n";
    &init($_[0]);
    
} # end finditems



sub snapshot {
    
    carp "in Tk::Zinc::Debug module, snapshot() function is deprecated.\n";
    &init($_[0]);

} # end snapshot


#---------------------------------------------------------------------------
#
# Functions related to cursor position
#
#---------------------------------------------------------------------------
sub cursorxy {

    my $ev = shift->XEvent;
    $cursorxy = $ev->x.", ".$ev->y;
    
} # end cursorxy


sub cursorxyOpen {

    if (Tk::Exists($cursorxy_tl)) {
	$cursorxy_tl->raise;
	return;
    }
    $cursorxy_tl = $control_tl->Toplevel;
    $cursorxy_tl->Label(-text => "Cursor device position")->pack;
    $cursorxy_tl->Label(-textvariable => \$cursorxy)->pack;
    $cursorxy_tl->minsize(150, 40);
    $cursorxy_tl->raise;
    
} # end cursorxyOpen


sub cursorxyClose {

    $cursorxy_tl->destroy if Tk::Exists($cursorxy_tl);

} # end cursorxyClose


#---------------------------------------------------------------------------
#
# Functions related to items tree
#
#---------------------------------------------------------------------------

# build or rebuild the items tree
sub showtree {
    
    my $zinc = shift;
    my $optionstodisplay = $cmdoptions{optionsToDisplay};
    my $optionsFormat = $cmdoptions{optionsFormat};
    # styles definition
    $itemstyle =
	$zinc->ItemStyle('text', -stylename => "item", -foreground => 'black')
	    unless $itemstyle;
    $groupstyle =
	$zinc->ItemStyle('text', -stylename => "group", -foreground => 'black')
	    unless $groupstyle;

    $WARNING = 0;
    my @optionstodisplay = split(/,/, $optionstodisplay);
    $WARNING = 1;
    &hidetree();
    $tree_tl = $control_tl->Toplevel;
    $tree_tl->minsize(280, 200);
    $tree_tl->title("Zinc Items Tree");
    $tree = $tree_tl->Scrolled('Tree',
			       -scrollbars => 'se',
			       -height => 40,
			       -width => 50,
			       -itemtype => 'text',
			       -selectmode => 'single',
			       -separator => '.',
			       -drawbranch => 1,
			       -indent => 30,
			       -command => sub {
				   my $path = shift;
				   my $item = (split(/\./, $path))[-1];
				   &showresult("Attributes of item $item", $zinc, $item);
				   $zinc->after(100, sub {
				       &undohighlightitem(undef, $zinc)});
			       },
			       );
    &wheelmousebindings($tree);
    $tree->bind('<1>', [sub {
	my $path = $tree->nearest($_[1]);
	my $item = (split(/\./, $path))[-1];
	&highlightitem($tree, $zinc, $item, 0);
		       
    }, Ev('y')]);
    
    $tree->bind('<2>', [sub {
	my $path = $tree->nearest($_[1]);
	return if $path eq 1;
	$tree->selectionClear;
	$tree->selectionSet($path);
	$tree->anchorSet($path);
	my $item = (split(/\./, $path))[-1];
	&highlightitem($tree, $zinc, $item, 1);
		       
    }, Ev('y')]);

    $tree->bind('<3>', [sub {
	my $path = $tree->nearest($_[1]);
	return if $path eq 1;
	$tree->selectionClear;
	$tree->selectionSet($path);
	$tree->anchorSet($path);
	my $item = (split(/\./, $path))[-1];
	&highlightitem($tree, $zinc, $item, 2);
		       
    }, Ev('y')]);
    
    $tree->add("1", -text => "Group(1)", -state => 'disabled');
    &scangroup($zinc, $tree, 1, "1", $optionsFormat, @optionstodisplay);
    $tree->autosetmode;
    # control buttons frame
    my $tree_butt_fm = $tree_tl->Frame(-height => 40)->pack(-side => 'bottom',
							    -fill => 'y');
    $tree_butt_fm->Button(-text => 'Help',
			  -command => [\&showHelpAboutTree, $zinc],
			  )->pack(-side => 'left', -pady => 10,
				  -padx => 10, -fill => 'both');
    
    $tree_butt_fm->Button(-text => 'Search',
			  -command => [\&searchInTree, $zinc],
			  )->pack(-side => 'left', -pady => 10,
				  -padx => 10, -fill => 'both');
    $tree_butt_fm->Button(-text => "Build\ncode",
			  -command => [\&buildCode, $zinc, $tree],
			  )->pack(-side => 'left', -pady => 10,
				  -padx => 10, -fill => 'both');
    
    $tree_butt_fm->Button(-text => "Attributes",
			  -command => sub {
			      my $path = $tree->selectionGet;
			      $path = 1 unless $path;
			      my $item = (split(/\./, $path))[-1];
			      &showresult("Attributes of item $item", $zinc, $item);
			  },
			  )->pack(-side => 'left', -pady => 10,
				  -padx => 10, -fill => 'both');
    

    $tree_butt_fm->Button(-text => 'Close',
			  -command => sub {$zinc->remove("zincdebug");
					   $tree_tl->destroy},
			  )->pack(-side => 'left', -pady => 10,
				  -padx => 20, -fill => 'both');
    # pack tree
    $tree->pack(-padx => 10, -pady => 10,
		-ipadx => 10,
		-side => 'top',
		-fill => 'both',
		-expand => 1,
		);
    

} # end showtree


# destroy the items tree
sub hidetree {
    
    $tree_tl->destroy if $tree_tl and Tk::Exists($tree_tl);
    
} # end hidetree


# find a pointed item in the items tree
sub findintree {
    
    my $zinc = shift;
    if (not Tk::Exists($tree_tl)) {
	&showtree($zinc);
    }
    my $ev = $zinc->XEvent;
    ($x0, $y0) = ($ev->x, $ev->y);
    my @atomicgroups = &unsetAtomicity($zinc);
    my $item = $zinc->find('closest', $x0, $y0);
    &restoreAtomicity($zinc, @atomicgroups);
    return unless $item > 1;
    my @ancestors = reverse($zinc->find('ancestors', $item));
    my $path = join('.', @ancestors).".".$item;
    # tree is rebuilded unless path exists
    unless ($tree->info('exists', $path)) {
	$tree_tl->destroy;
	#print "path=$path rebuild tree\n";
	&showtree($zinc);
    }
    $tree->see($path);
    $tree->selectionClear;
    $tree->anchorSet($path);
    $tree->selectionSet($path);
    &surrounditem($zinc, $item);
    $tree->focus;

} # end findintree


sub searchInTree {
    
    my $zinc = shift;
    $searchtree_tl->destroy if $searchtree_tl and Tk::Exists($searchtree_tl);
    $searchtree_tl = $tree_tl->Toplevel;
    $searchtree_tl->transient($tree_tl);
    $searchtree_tl->title("Find string in tree");
    my $fm = $searchtree_tl->Frame->pack(-side => 'top');
    $fm->Label(-text => "Find : ",
	       )->pack(-side => 'left', -padx => 10, -pady => 10);
    my $entry = $fm->Entry(-width => 20)->pack(-side => 'left',
					       -padx => 10, -pady => 10);
    my $status = $searchtree_tl->Label(-foreground => 'sienna',
				   )->pack(-side => 'top');
    my $ep = 1;
    my $searchfunc =  sub {
	my $side = shift;
	my $found = 0;
        #print "ep=$ep side=$side\n";
	$status->configure(-text => "");
	$status->update;
	$searchTreeEntryValue = $entry->get();
	$searchTreeEntryValue = quotemeta($searchTreeEntryValue);
	my $text;
	while ($ep) {
 	    $ep = $tree->info($side, $ep);
	    unless ($ep) {
		$ep = 1;
		$found = 0;
		last;
	    }
	    $text = $tree->entrycget($ep, -text);
	    if ($text =~ /$searchTreeEntryValue/) {
		$tree->see($ep);
		$tree->selectionClear;
		$tree->anchorSet($ep);
		$tree->selectionSet($ep);
		$found = 1;
		last;
	    }
	}
	#print "searchTreeEntryValue=$searchTreeEntryValue found=$found\n";
	$status->configure(-text => "Search string not found") unless $found > 0;
    };

    my $fm2 = $searchtree_tl->Frame->pack(-side => 'top');
    $fm2->Button(-text => 'Prev',
		 -command => sub {&$searchfunc('prev');},
		 )->pack(-side => 'left', -pady => 10);
    $fm2->Button(-text => 'Next',
		 -command => sub {&$searchfunc('next');},
		 )->pack(-side => 'left', -pady => 10);
    $fm2->Button(-text => 'Close',
		 -command => sub {$searchtree_tl->destroy},
		 )->pack(-side => 'right', -pady => 10);
    $entry->focus;
    $entry->delete(0, 'end');
    $entry->insert(0, $searchTreeEntryValue) if $searchTreeEntryValue;
    $entry->bind('<Key-Return>', sub {&$searchfunc('next');});
    
} # end searchInTree


sub extractinfo {
    my $zinc = shift;
    my $item = shift;
    my $format = shift;
    my $option = shift;
    my $titleflag = shift;
    $option =~ s/^\s+//;
    $option =~ s/\s+$//;
    #print "option=[$option]\n";
    my @info;
    $WARNING = 0;
    eval {@info = $zinc->itemcget($item, $option)};
    #print "eval $option = (@info) $@\n";
    return if $@;
    return if @info == 0;
    my $info;
    my $sep = ($format eq 'column') ? "\n  " : ", ";
    if ($titleflag) {
	$info = $sep."[$option] ".$info[0];
    } else {
	$info = $sep.$info[0];
    }
    if (@info > 1) {
	shift(@info);
	for (@info) {
	    if ($format eq 'column') {
		if (length($info." ".$_) > 40) {
		    if ($titleflag) {
			$info .= $sep."[$option] ".$_;
		    } else {
			$info .= $sep.$_;
		    }
		} else {
		    $info .= ", $_";
		}
	    } else {
		$info .= $sep.$_;
	    }
	}
    }
    $WARNING = 1;
    return $info;
    
} # end extractinfo


sub scangroup {
    
    my ($zinc, $tree, $group, $path, $format, @optionstodisplay) = @_;
    my @items = $zinc->find('withtag', "$group.");
    for my $item (@items) {
	my $Type = ucfirst($zinc->type($item));
	my $info = " ";
	if (@optionstodisplay == 1) {
	    $info .= &extractinfo($zinc, $item, $format, $optionstodisplay[0]);
	} elsif (@optionstodisplay > 1) {
	    for my $opt (@optionstodisplay) {
		$info .= &extractinfo($zinc, $item, $format, $opt, 1);
	    }
	}
	if ($Type eq "Group") {
	    $tree->add($path.".".$item,
		       -text => "$Type($item)$info",
		       -style => 'group',
		       );
	    &scangroup($zinc, $tree, $item, $path.".".$item, $format, @optionstodisplay);
	} else {
	    $tree->add($path.".".$item,
		       -text => "$Type($item)$info",
		       -style => 'item',
		       );
	}
    }

} # end scangroup

#---------------------------------------------------------------------------
#
# Functions used to build code
#
#---------------------------------------------------------------------------

# build perl code corresponding to a branch of the items tree
sub buildCode {
    
    my $zinc = shift;
    my $tree = shift;
    my @code;
    push(@code, 'use Tk;');
    push(@code, 'use Tk::Zinc;');
    push(@code, 'my $mw = MainWindow->new();');
    push(@code, 'my $zinc = $mw->Zinc(-render => '.$zinc->cget(-render).
	 ')->pack(-expand => 1, -fill => "both");');
    push(@code, '# hash %items : keys are original items ID, values are built items ID');
    push(@code, 'my %items;');
    push(@code, '');
    my $path = $tree->selectionGet;
    $path = 1 unless $path;
    my $item = (split(/\./, $path))[-1];
    $endoptions = [];
    if ($zinc->type($item) eq 'group') {
	push(@code, &buildGroup($zinc, $item, 1));
	for(@$endoptions) {
	    my ($item, $option, $value) = @$_;
	    push(@code,
		 '$zinc->itemconfigure('.$item.', '.$option.' => '.$value.');');
	}
    } else {
	push(@code, &buildItem($zinc, $item, 1));
    }
    push(@code, &buildEnd);
    
    my $file = $zinc->getSaveFile(-filetypes => [['Perl Files',   '.pl'],
                                               ['All Files',   '*']],
				  -initialfile => 'zincdebug.pl',
				  -title => 'Save code',
				  );
    return unless defined $file;
    $zinc->Busy;
    open (OUT, ">$file");
    for (@code) {
	print OUT $_."\n";
    }
    close(OUT);
    $zinc->Unbusy;
    
} # end buildCode


sub buildEnd {

    my @code;
    push(@code, 'for (keys(%items)) {');
    push(@code, '   $zinc->addtag(\'orig\'.$_, "withtag", $items{$_});');
    push(@code, '}');
    push(@code, 'MainLoop;');
    return @code
	
} # end buildEnd


# build a node of tree (corresponding to a TkZinc group item)
sub buildGroup {
    
    my $zinc = shift;
    my $item = shift;
    my $group = shift;
    my @code;
    # creation
    push(@code, '$items{'.$item.'}=$zinc->add("group", '.$group.', ');
    # options
    push(@code, &buildOptions($zinc, $item));
    push(@code, ');');
    push(@code, '');
    # coords
    push(@code, '$zinc->coords($items{'.$item.'}, ['.
	 join(',', $zinc->coords($item)).']);');
    # transformations
    push(@code, &buildTransformations($zinc, $item));
    
    my @items = $zinc->find('withtag', "$item.");
    for my $it (reverse(@items)) {
	if ($zinc->type($it) eq 'group') {
	    push(@code, &buildGroup($zinc, $it, '$items{'.$item.'}'));
	} else {
	    push(@code, &buildItem($zinc, $it, '$items{'.$item.'}'));
	}
    }
    return @code;

} # end buildGroup


# build a leaf of tree (corresponding to a TkZinc non-group item)
sub buildItem {
    
    my $zinc = shift;
    my $item = shift;
    my $group = shift;
    my $type = $zinc->type($item);
    my @code;
    my $numfields = 0;
    my $numcontours = 0;
    # creation    
    my $initstring = '$items{'.$item.'}=$zinc->add("'.$type.'", '.$group.', ';
    if ($type eq 'tabular' or $type eq 'track' or $type eq 'waypoint') {
	$numfields = $zinc->itemcget($item, -numfields);
	$initstring .= $numfields.' ,';
    } elsif ($type eq 'curve' or $type eq 'triangles' or
	     $type eq 'arc' or $type eq 'rectangle') {
	$initstring .= "[ ";
	my (@coords) = $zinc->coords($item);
	if (ref($coords[0]) eq 'ARRAY') {
	    my @coords2;
	    for my $c (@coords) {
		if (@$c > 2) {
		     push(@coords2, '['.$c->[0].', '.$c->[1].', "'.$c->[2].'"]');
		} else {
		     push(@coords2, '['.$c->[0].', '.$c->[1].']');
		    
		}
	    }
	    $initstring .= join(', ', @coords2);
	} else {
	    $initstring .= join(', ', @coords);
	}
	$initstring .= " ], ";
	$numcontours = $zinc->contour($item);
    } 
    push(@code, $initstring);
    # options
    push(@code, &buildOptions($zinc, $item));
    push(@code, ');');
    push(@code, '');
    # fields
    if ($numfields > 0) {
    	for (my $i=0; $i < $numfields; $i++) {
	    push(@code, &buildField($zinc, $item, $i));
	}
    }
    # contours
    if ($numcontours > 1) {
	for (my $i=1; $i < $numcontours; $i++) {
	    my (@coords) = $zinc->coords($item);
	    my @coords2;
	    for my $c (@coords) {
		if (@$c > 2) {
		    push(@coords2, '['.$c->[0].', '.$c->[1].', "'.$c->[2].'"]');
		} else {
		    push(@coords2, '['.$c->[0].', '.$c->[1].']');
		}
	    }
	    my $coordstr = '[ '.join(', ', @coords2).' ]';
	    push(@code, '$zinc->contour($items{'.$item.'}, "add", 0, ');
	    push(@code, '            '.$coordstr.');');
	}
    }
    # transformations
    push(@code, &buildTransformations($zinc, $item));
    
    return @code;

} # end buildItem


# add an information field to an item of the tree
sub buildField {
    
    my $zinc = shift;
    my $item = shift;
    my $field = shift;
    my @code;
    # type group and initargs
    push(@code, '$zinc->itemconfigure($items{'.$item.'}, '.$field.', ');
    # options
    push(@code, &buildOptions($zinc, $item, $field));
    push(@code, ');');
    push(@code, '');
    return @code;

} # end buildField


sub buildTransformations {

    my $zinc = shift;
    my $item = shift;
    my @tr = $zinc->tget($item);
    my @code;
    return ('$zinc->tset($items{'.$item.'}, '.join(", ", @tr).');');

} # end buildTransformations


sub buildOptions {
    
    my $zinc = shift;
    my $item = shift;
    my $field = shift;
    my @code;
    my @args = defined($field) ? ($item, $field) : ($item);
    my @options = $zinc->itemconfigure(@args);
    for my $elem (@options) {
	my ($option, $type, $readonly, $value) = (@$elem)[0, 1, 2, 4];
	next if $value eq '';
	next if $readonly;
	if ($type eq 'point') {
	    push(@code, "           ".$option." => [".join(',', @$value)."], ");
	    
	} elsif (($type eq 'bitmap' or $type eq 'image') and $value !~ /^AtcSymbol/
	    and $value !~ /^AlphaStipple/) {
	    push(@code, "#           ".$option." => '".$value."', ");
	    
	} elsif ($type eq 'item') {
	    $endoptions->[@$endoptions] =
		['$items{'.$item.'}', $option, '$items{'.$value.'}'];
	    
	} elsif ($option eq '-text') {
	    $value =~ s/\"/\\"/;       # comment for emacs legibility => "
	    push(@code, "           ".$option.' => "'.$value.'", ');

	} elsif (ref($value) eq 'ARRAY') {
	    push(@code, "           ".$option." => [qw(".join(' ', @$value).")], ");

	} else {
	    push(@code, "           ".$option." => '".$value."', ");
	}
    }
    return @code;

} # end buildOptions

#---------------------------------------------------------------------------
#
# Functions related to search in a rectangular area
#
#---------------------------------------------------------------------------

# begin to draw rectangular area for search
sub startrectangle {
    
    my ($zinc, $style, $text, $color) = @_;
    $zinc->remove("zincdebugrectangle", "zincdebuglabel");
    my $ev = $zinc->XEvent;
    ($x0, $y0) = ($ev->x, $ev->y);
    # store and name the inverted transformation of top group
    $zinc->tsave(1, 'zoom+move', 1);
    $zinc->add('rectangle', 1, [$x0, $y0, $x0, $y0],
	       -linecolor => $color,
	       -linewidth => 2,
	       -linestyle => $style,
	       -tags => ["zincdebugrectangle"],
			       );
    $zinc->add('text', 1,
	       -color => $color,
	       -font => '7x13',
	       -position => [$x0+5, $y0-15],
	       -text => $text,
	       -tags => ["zincdebuglabel"],
	       );
    # apply to new rectangle the (inverted) transformation stored below
    $zinc->trestore("zincdebugrectangle", 'zoom+move');
    $zinc->trestore("zincdebuglabel", 'zoom+move');
  
} # end startrectangle


# resize the rectangular area for search
sub resizerectangle {
    
    my $zinc = shift;
    my $ev = $zinc->XEvent;
    my ($x, $y) = ($ev->x, $ev->y);
    return unless ($zinc->find('withtag', "zincdebugrectangle"));

    $zinc->coords("zincdebugrectangle", 1, 1, [$x, $y]);
    if ($x < $x0) {
	if ($y < $y0) {
	    $zinc->coords("zincdebuglabel", [$x+5, $y-15]);
	} else {
	    $zinc->coords("zincdebuglabel", [$x+5, $y0-15]);
	}
    } else {
	if ($y < $y0) {
	    $zinc->coords("zincdebuglabel", [$x0+5, $y-15]);
	} else {
	    $zinc->coords("zincdebuglabel", [$x0+5, $y0-15]);
	}
    }
    $zinc->raise("zincdebugrectangle");
    $zinc->raise("zincdebuglabel");

} # end resizerectangle


# stop drawing rectangular area for search
sub stoprectangle {
    
    my ($zinc, $searchtype, $text) = @_;
    return unless ($zinc->find('withtag', "zincdebugrectangle"));

    my @atomicgroups = &unsetAtomicity($zinc);
    $zinc->update;
    my ($c0, $c1) = $zinc->coords("zincdebugrectangle");
    my @coords = (@$c0, @$c1);
    my @items;
    for my $item ($zinc->find($searchtype, @coords, 1, 1)) {
	push (@items, $item) unless $zinc->hastag($item, "zincdebugrectangle") or
	    $zinc->hastag($item, "zincdebuglabel");
    }
    &restoreAtomicity($zinc, @atomicgroups);
    if (@items) {
	&showresult($text, $zinc, @items);
    } else {
	$zinc->remove("zincdebugrectangle", "zincdebuglabel");
    }

} # end stoprectangle


# in order to avoid find problems with group atomicity, we set all -atomic
# attributes to 0
sub unsetAtomicity {
    
    my $zinc = shift;
    my @groups = $zinc->find('withtype', 'group');
    my @atomicgroups;
    for my $group (@groups) {
	if ($zinc->itemcget($group, -atomic)) {
	    push(@atomicgroups, $group);
	    $zinc->itemconfigure($group, -atomic => 0);
	}
    }
    return @atomicgroups;
    
} # end unsetAtomicity


sub restoreAtomicity {
    
    my $zinc = shift;
    my @atomicgroups = @_;
    for my $group (@atomicgroups) {
	$zinc->itemconfigure($group, -atomic => 1);
    }

} # end restoreAtomicity


#---------------------------------------------------------------------------
#
# Function related to item's id search 
#
#---------------------------------------------------------------------------

sub searchentry {
    
    my $zinc = shift;
    $search_tl->destroy if $search_tl and Tk::Exists($search_tl);
    $search_tl = $control_tl->Toplevel;
    $search_tl->title("Specific search");
    my $fm = $search_tl->Frame->pack(-side => 'top');
    $fm->Label(-text => "Item TagOrId : ",
	       )->pack(-side => 'left', -padx => 10, -pady => 10);
    my $entry = $fm->Entry(-width => 20)->pack(-side => 'left',
					       -padx => 10, -pady => 10);
    my $status = $search_tl->Label(-foreground => 'sienna',
				   )->pack(-side => 'top');
    $search_tl->Button(-text => 'Close',
		       -command => sub {$search_tl->destroy},
		       )->pack(-side => 'top', -pady => 10);
    $entry->focus;
    $entry->delete(0, 'end');
    $entry->insert(0, $searchEntryValue{$zinc}) if $searchEntryValue{$zinc};
    $entry->bind('<Key-Return>', [sub {
	$status->configure(-text => "");
	$status->update;
	$searchEntryValue{$zinc} = $entry->get();
	my @items = $zinc->find('withtag', $searchEntryValue{$zinc});
	if (@items) {
	    my $label;
	    if ($searchEntryValue{$zinc} =~ /^\d/) {
		$label = "Attributes of item $searchEntryValue{$zinc}";
	    } else {
		$label = "Attributes of item(s) with tag $searchEntryValue{$zinc}"
	    }
	    &showresult($label, $zinc, @items);
	} else {
	    $status->configure(-text => "No such tagOrId ($searchEntryValue{$zinc})");
	}
    }]);
    
} # end searchentry


#---------------------------------------------------------------------------
#
# Functions related to transformations parameters
#
#---------------------------------------------------------------------------

sub showtransfoparams {

    my ($label, $zinc, $item) = @_;
    my @m = $zinc->tget($item);
    my ($m00, $m01, $m10, $m11, $m20, $m21) = @m;
    my ($xt, $yt, $xsc, $ysc, $a, $xsk, $ysk) = $zinc->tget($item, 'all');
    # bug zinc 
    $ysk = 0 unless defined $ysk;
    for ($m00, $m01, $m10, $m11, $m20, $m21, $xt, $yt, $xsc, $ysc, $a, $xsk, $ysk) {
	$_ = sprintf("%.2f", $_) if /^-?\d+\.\d/;
    }
    $transfo_tl{$item}->destroy if Tk::Exists($transfo_tl{$item});
    $transfo_tl{$item} = $control_tl->Toplevel();
    $transfo_tl{$item}->transient($result_tl{$label})
	if Tk::Exists($result_tl{$label});
    my $title = "Transformations of item $item";
    $transfo_tl{$item}->title($title);
    my $bgcolor = 'ivory';
    my $fm1 = $transfo_tl{$item}->Frame()->pack(-side => 'top',
						-padx => 20,
						-pady => 10,
						-expand => 1,
						-fill => 'x',
						);
    # set transformation to ident
    my $btn = $fm1->Button(-text => "Show item with transformation\nset to identity",
			   -bg => $bgcolor,
			   )->pack(-side => 'top', -padx => 5, -pady => 10);
    $balloonhelp->attach($btn,-balloonmsg =>
			 "Click and maintain to show the transformation  \n".
			 "animation. Use btn1, btn2 or btn3 to select the\n".
			 "best background color for a good visibility.   ");
    $btn->bind('<1>', [\&showtransfo, $zinc, $item, 0]);
    $btn->bind('<2>', [\&showtransfo, $zinc, $item, 1]);
    $btn->bind('<3>', [\&showtransfo, $zinc, $item, 2]);
    
    my $fm11 = $fm1->Frame()->pack(-side => 'left',
				   -padx => 20,
				   );

    my ($set_cb, $reset_cb, $upd_cb);
    
    # matrix
    my $r = 0;
    my $c = 0;
    $fm11->Label(-text => 'matrix', -relief => 'ridge', -bg => $bgcolor)
	->grid(-row => $r++, -columnspan => 2,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm11->Label(-textvariable => \$m00, -relief => 'ridge')
	->grid(-row => $r, -column => $c,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm11->Label(-textvariable => \$m01, -relief => 'ridge')
	->grid(-row => $r++, -column => $c+1,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm11->Label(-textvariable => \$m10, -relief => 'ridge')
	->grid(-row => $r, -column => $c,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm11->Label(-textvariable => \$m11, -relief => 'ridge')
	->grid(-row => $r++, -column => $c+1,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm11->Label(-textvariable => \$m20, -relief => 'ridge')
	->grid(-row => $r, -column => $c,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm11->Label(-textvariable => \$m21, -relief => 'ridge')
	->grid(-row => $r++, -column => $c+1,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    


    my $fm12 = $fm1->Frame()->pack(-side => 'left',
				   -padx => 20,
				   );
    my ($e_xt, $e_yt, $e_xsc, $e_ysc, $e_a, $e_xsk, $e_ysk);

    $set_cb = sub {
	$zinc->treset($item);
	$zinc->translate($item, $e_xt, $e_yt);
	$zinc->rotate($item, $e_a);
	$zinc->scale($item, $e_xsc, $e_ysc);
	$zinc->skew($item, $e_xsk, $e_ysk);
	($m00, $m01, $m10, $m11, $m20, $m21) = $zinc->tget($item);
	for ($m00, $m01, $m10, $m11, $m20, $m21) {
	    $_ = sprintf("%.2f", $_) if /^-?\d+\.\d/;
	}
    };

    # translate params
    $r = 0;
    $c = 0;    
    $fm12->Label(-text => 'translate', -relief => 'ridge', -bg => $bgcolor)
	->grid(-row => $r, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');

    &entrytransfo($fm12, $item, $zinc, 'xt', $xt, \$e_xt, 4, $set_cb)
    	->grid(-row => $r, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    
    &entrytransfo($fm12, $item, $zinc, 'yt', $yt, \$e_yt, 4, $set_cb)
	->grid(-row => $r++, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    
    # rotate params
    $c = 0;
    $fm12->Label(-text => 'rotate', -relief => 'ridge', -bg => $bgcolor)
	->grid(-row => $r, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');

    &entrytransfo($fm12, $item, $zinc, 'a', $a, \$e_a, 4, $set_cb)
	->grid(-row => $r++, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');

    # scale params
    $c = 0;
    $fm12->Label(-text => 'scale', -relief => 'ridge', -bg => $bgcolor)
	->grid(-row => $r, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');

    &entrytransfo($fm12, $item, $zinc, 'xsc', $xsc, \$e_xsc, 4, $set_cb)
	->grid(-row => $r, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    &entrytransfo($fm12, $item, $zinc, 'ysc', $ysc, \$e_ysc, 4, $set_cb)
	->grid(-row => $r++, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    
    # skew params
    $c = 0;
    $fm12->Label(-text => 'skew', -relief => 'ridge', -bg => $bgcolor)
	->grid(-row => $r, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    
    &entrytransfo($fm12, $item, $zinc, 'xsk', $xsk, \$e_xsk, 4, $set_cb)
	->grid(-row => $r, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    &entrytransfo($fm12, $item, $zinc, 'ysk', $ysk, \$e_ysk, 4, $set_cb)
	->grid(-row => $r++, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');


    my $fm2 = $transfo_tl{$item}->Frame()->pack(-side => 'top',
						-padx => 20,
						-pady => 0,
						);
    $fm2->Button(-text => 'Close',
		-command => sub {
		    $transfo_tl{$item}->destroy;
		    delete $transfo_tl{$item};
		})->pack(-side => 'top', -padx => 40, -pady => 20);
    
    
    
} # end showtransfoparams


#---------------------------------------------------------------------------
#
# Functions related to results tables display
#
#---------------------------------------------------------------------------

# display in a toplevel the result of search ; a new toplevel destroyes the
# previous one
sub showresult {
    
    my ($label, $zinc, @items) = @_;
    # toplevel (re-)creation
    $result_tl{$label}->destroy if Tk::Exists($result_tl{$label});
    $result_tl{$label} = $control_tl->Toplevel();
    my $title = "TK::Zinc Debug";
    $title .= " - $label" if $label;
    $result_tl{$label}->title($title);
    $result_tl{$label}->geometry('+10+20');
    $control_tl->raise;
    my $fm = $result_tl{$label}->Frame()->pack(-side => 'bottom',
				       );
    $fm->Button(-text => 'Close',
		-command => sub {
		    $result_tl{$label}->destroy;
		    delete $result_tl{$label};
		    $zinc->remove("zincdebugrectangle", "zincdebuglabel");
		})->pack(-side => 'left', -padx => 40, -pady => 10);
    
    # scrolled pane creation
    $result_fm = $result_tl{$label}->Scrolled('Pane',
					      -scrollbars => 'osoe',
					      -height => 200,
					      -width => 1024,
					      );
    &wheelmousebindings($result_fm);
    my $fm2 = $result_fm->Frame->pack;
    # attributes display
    &showattributes($zinc, $fm2, $label, \@items);
    $result_fm->update;
    $fm2->update;
    my $width = $fm2->width + 10;
    $width = $screenwidth if $width > $screenwidth;
    $result_fm->configure(-width => $width);
    $result_fm->pack(-padx => 10, -pady => 10,
		     -ipadx => 10,
		     -fill => 'both',
		     -expand => 1,
		     );

} # end showresult

# display table containing additionnal options/values
sub showalloptions {
    
    my ($label, $zinc, $item, $fmp) = @_;
    $alloptions_tl{$item}->destroy if Tk::Exists($alloptions_tl{$item});
    $alloptions_tl{$item} = $control_tl->Toplevel();
    $alloptions_tl{$item}->transient($result_tl{$label})
	if Tk::Exists($result_tl{$label});
    my $tl = $alloptions_tl{$item};
    my $title = "All options of item $item";
    $tl->title($title);
    $tl->geometry('-10+0');
    

    # footer
    #----------------
    $tl->Button(-text => 'Close',
		-command => sub {
		    $alloptions_tl{$item}->destroy;
		    delete $alloptions_tl{$item};
		})->pack(-side => 'bottom');
    # option scrolled frame
    #-----------------------
    my $fm = $tl->Scrolled('Pane',
			   -scrollbars => 'oe',
			   -height => 500,
			   )->pack(-padx => 10, -pady => 10,
				   -ipadx => 10,
				   -expand => 1,
				   -fill => 'both');
    
    my $bgcolor = 'ivory';
    my $i = 1;
    $fm->Label(-text => $title, -background => $bgcolor,
	       -fg => 'sienna', -relief => 'ridge')
	->grid(-row => $i++, -column => 1, -ipady => 5, -ipadx => 5,
	       -columnspan => 2, -sticky => 'nswe') if $label;
    $fm->Label(-text => 'Option', -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => 1, -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => 'Value', -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i++, -column => 2, -ipady => 10, -ipadx => 5, -sticky => 'nswe');

    my @options = $zinc->itemconfigure($item);
    for my $elem (@options) {
	my ($option, $type, $value) = (@$elem)[0,1,4];
	$fm->Label(-text => $option, -relief => 'ridge')
	    ->grid(-row => $i, -column => 1,
		   -ipady => 5, -ipadx => 5, -sticky => 'nswe');
	if ($option eq '-tags') {
	    &entryoption($fm, $item, $zinc, $option,
			 join("\n", @$value), 30, 30, scalar @$value)
		->grid(-row => $i, -column => 2, -ipady => 5,
		       -ipadx => 5, -sticky => 'nswe');
	} else {
	    &entryoption($fm, $item, $zinc, $option, undef, 50, 25)
		->grid(-row => $i, -column => 2, -ipady => 5,
		       -ipadx => 5, -sticky => 'nswe');
	}
	$i++;
    }
    
} # end showalloptions


# display device coords table
sub showdevicecoords {
    
    my ($label, $zinc, $item) = @_;
    &showcoords($label, $zinc, $item, 1);

} # end showdevicecoords


# display coords table
sub showcoords {
    
    my ($label, $zinc, $item, $deviceflag) = @_;
    my $bgcolor = 'ivory';
    my $bgcolor2 = 'gray75';
    $coords_tl{$item}->destroy if Tk::Exists($coords_tl{$item}) and not $deviceflag;
    $coords_tl{$item} = $control_tl->Toplevel();
    $coords_tl{$item}->transient($result_tl{$label}) if Tk::Exists($result_tl{$label});
    my $title = "Zinc Debug";
    if ($deviceflag) {
	$title .= " - Coords of item $item";
    } else {
	$title .= " - Device coords of item $item";
    }
    $coords_tl{$item}->title($title);
    $coords_tl{$item}->geometry('+10+20');
    my $coords_fm0 = $coords_tl{$item}->Frame()->pack(-side => 'bottom');
    $coords_fm0->Button(-text => 'Help',
			-command => [\&showHelpAboutCoords, $zinc]
			)->pack(-side => 'left', -padx => 40, -pady => 10);
    $coords_fm0->Button(-text => 'Close',
			-command => sub {
			    &hidecontour($zinc);
			    $coords_tl{$item}->destroy;
			    delete $coords_tl{$item};
			})->pack(-side => 'left', -padx => 40, -pady => 10);
    # scrolled pane creation
    my $coords_fm = $coords_tl{$item}->Scrolled('Pane',
					 -scrollbars => 'oe',
					 -height => 200,
					 )->pack(-padx => 10, -pady => 10,
						 -ipadx => 10,
						 -expand => 1,
						 -fill => 'both');
    my @contour;
    my $contournum = $zinc->contour($item);
    for (my $i=0; $i < $contournum; $i++) {
	my @coords = $zinc->coords($item, $i);
	if (!ref $coords[0]) {
	    ## The first item of the list is not a reference, so the
	    ## list is guarranted to be a flat list (x, y, ...)
	    ## normaly of only one pair of (x y)
	    @coords = $zinc->transform($item, 'device', [@coords])
		if $deviceflag;
	    for (my $j=0; $j < @coords; $j += 2) {
		push(@{$contour[$i]}, [$coords[$j], $coords[$j+1]]);
	    }
	}
	else {
	    ## the first element is an array reference, as every
	    ## other elements of the list
	    for (my $j=0; $j < @coords; $j ++) {
		my @c = @{$coords[$j]};
		@c = $zinc->transform($item, 'device', [@c])
		    if $deviceflag;
		push(@{$contour[$i]}, [@c]);
	    }
	}
    }
    my $row = 1;
    my $col = 1;
    for (my $i=0; $i < @contour; $i++) {
	$col = 1;
	my $lab = $coords_fm->Label(-text => "Contour $i",
				    -background => $bgcolor,
				    -relief => 'ridge')->grid(-row => $row,
							      -column => $col,
							      -ipadx => 5,
							      -ipady => 5,
							      -sticky => 'nswe');
	$lab->bind('<1>', [\&showcontour, $zinc, 'black', $item, $contour[$i],
			   $deviceflag]);
	$lab->bind('<2>', [\&showcontour, $zinc, 'white', $item, $contour[$i],
			   $deviceflag]);
	$lab->bind('<3>', [\&showcontour, $zinc, 'red', $item, $contour[$i],
			   $deviceflag]);
	$lab->bind('<ButtonRelease-1>', sub { &hidecontour($zinc); });
	$lab->bind('<ButtonRelease-2>', sub { &hidecontour($zinc); });
	$lab->bind('<ButtonRelease-3>', sub { &hidecontour($zinc); });
	my $lab1 = $coords_fm->Label(-text => scalar(@{$contour[$i]})." points",
				     -background => $bgcolor,
				     -relief => 'ridge')->grid(-row => $row+1,
							       -column => $col,
							       -ipadx => 5,
							       -ipady => 5,
							       -sticky => 'nswe');
	$lab1->bind('<1>', [\&showcontourpts, $zinc, 'black', $item, $contour[$i],
			    $deviceflag]);
	$lab1->bind('<2>', [\&showcontourpts, $zinc, 'white', $item, $contour[$i],
			    $deviceflag]);
	$lab1->bind('<3>', [\&showcontourpts, $zinc, 'red', $item, $contour[$i],
			    $deviceflag]);
	$lab1->bind('<ButtonRelease-1>', sub { &hidecontour($zinc); });
	$lab1->bind('<ButtonRelease-2>', sub { &hidecontour($zinc); });
	$lab1->bind('<ButtonRelease-3>', sub { &hidecontour($zinc); });
	$col++;
	my @lab;
	for my $coords (@{$contour[$i]}) {
	    if ($col > 10) {
		$col = 2;
		$row++;
	    }
	    $coords->[0] =~ s/\.(\d\d).*/\.$1/;
	    $coords->[1] =~ s/\.(\d\d).*/\.$1/;
	    my @opt;
	    if (defined $coords->[2]) {
		@opt = (-text => sprintf('%s, %s, %s', @$coords),
			-underline => length(join(',', @$coords)) + 1,
			);
	    } else {
		@opt = (-text => sprintf('%s, %s', @{$coords}[0,1]));
	    }
	    push (@lab, $coords_fm->Label(@opt,
					  -width => 15,
					  -relief => 'ridge')->grid(-row => $row,
								    -ipadx => 5,
								    -ipady => 5,
								    -column => $col++,
								    -sticky => 'nswe'));
	}
	$row++ if (@{$contour[$i]} < 10);
	$row++;
	my $j = 0;
	for (@lab) {
	    $_->bind('<1>', [\&showcontourpt, $zinc, 'black',
			     $item, $j, $deviceflag, \@lab, @{$contour[$i]}]);
	    $_->bind('<2>', [\&showcontourpt, $zinc, 'white',
			     $item, $j, $deviceflag, \@lab, @{$contour[$i]}]);
	    $_->bind('<3>', [\&showcontourpt, $zinc, 'red',
			     $item, $j, $deviceflag, \@lab, @{$contour[$i]}]);
	    $j++;
	}

    }

} # end showcoords



# display in a grid the values of most important attributes 
sub showattributes {
    
    my ($zinc, $fm, $label, $items, $expandTagsFlag) = @_;
    $expandTagsFlag = 1;
    &getsize($zinc);
    my $bgcolor = 'ivory';
    my $i = 1;
    $fm->Label(-text => $label, -background => $bgcolor,
	       -fg => 'sienna', -relief => 'ridge')
	->grid(-row => $i++, -column => 0, -ipady => 0, -ipadx => 5,
	       -columnspan => 7, -sticky => 'nswe') if $label;

    &showbanner($fm, $i++);
    $i++;
    for my $item (@$items) {
	my $c = 0;
	my $type = $zinc->type($item);
	# id
	my $idbtn =
	    $fm->Button(-text => $item,
			-foreground => 'sienna'
			)->grid(-row => $i, -column => $c++, -sticky => 'nswe',
				-ipadx => 5);
	$idbtn->bind('<1>', [\&highlightitem, $zinc, $item, 0]);
	$idbtn->bind('<2>', [\&highlightitem, $zinc, $item, 1]);
	$idbtn->bind('<3>', [\&highlightitem, $zinc, $item, 2]);
	$balloonhelp->attach($idbtn,-balloonmsg =>
			     "Click and maintain to show the item.     \n".
			     "Use btn1, btn2 or btn3 to select the best\n".
			     "background color for a good visibility.  ");
	# type
	if ($type eq 'group') {
	    my $gbtn =
		$fm->Button(-text => $type,
			    -command => sub {
				my @items = $zinc->find('withtag', $item.".");
				&showresult("Content of group $item", $zinc, @items);
			    });
	    $gbtn->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	    $balloonhelp->attach($gbtn,-balloonmsg =>
				 "Click to display the group's content.");
	} else {
	    $fm->Label(-text => $type, -relief => 'ridge')
		->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	}
	# parent group
	my $group = $zinc->group($item);
	my $pgbtn =
	    $fm->Button(-text => $group,
			-command => [\&showresult,
				     "Attributes of group $group (parent of $item)",
				     $zinc, $group]);
	$pgbtn->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	$balloonhelp->attach($pgbtn,-balloonmsg =>
			     "Click to display the parent group's attributes.");
	# priority
	&entryoption($fm, $item, $zinc, -priority)
	    ->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 2);
	# sensitiveness
	&entryoption($fm, $item, $zinc, -sensitive)
	    ->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 2);
	# visibility
	&entryoption($fm, $item, $zinc, -visible)
	    ->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 2);
	# other options
	$fm->Button(-text => 'show',
		    -command => [\&showalloptions, $label, $zinc, $item, $fm])
	    ->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	# transformations
	my $tlabel = 'yes';
	my ($xt, $yt, $xsc, $ysc, $a, $xsk) = $zinc->tget($item, 'all');
	$tlabel = 'no' if ($xt == 0 and $yt == 0 and $xsc == 1 and $ysc == 1 and
			   $a == 0 and $xsk == 0);
	my $tbtn =
	    $fm->Button(-text => $tlabel, 
			-command => [\&showtransfoparams, $label, $zinc, $item],
			);
	$tbtn->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	$balloonhelp->attach($tbtn,-balloonmsg =>
			     "Click to display transformation parameters.\n".
			     "Some of them can be updated.               ");
	
	# coords
	my @coords = $zinc->coords($item);
	my $coords;
	if (!ref $coords[0]) {
	    my $x0 = int($coords[0]);
	    my $y0 = int($coords[1]);
	    $coords = "($x0, $y0)";
	} else {
	    my @points0 = @{$coords[0]};
	    my $n = $#coords;
	    my @pointsN = @{$coords[$n]};
	    my $x0 = int($points0[0]);
	    my $y0 = int($points0[1]);
	    my $xn = int($pointsN[0]);
	    my $yn = int($pointsN[1]);
	    if ($n == 1) { ## a couple of points
		$coords = "($x0, $y0, $xn, $yn)";
	    } else {
		$coords = "P0=($x0, $y0), ..., P".$n."=($xn, $yn)";
	    }
	}
	if (@coords > 2) {
	    my $cbtn = $fm->Button(-text => $coords,
				   -command => [\&showcoords, $label, $zinc, $item]);
	    $cbtn->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 2);
	    $balloonhelp->attach($cbtn,-balloonmsg =>
				 "Click to show all coordinates.");
	} else {
	    $fm->Label(-text => $coords, -relief => 'ridge')
		->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	}
	# device coords
	@coords = $zinc->transform($item, 'device', [@coords]);
	if (!ref $coords[0]) {
	    my $x0 = int($coords[0]);
	    my $y0 = int($coords[1]);
	    $coords = "($x0, $y0)";
	} else {
	    my @points0 = @{$coords[0]};
	    my $n = $#coords;
	    my @pointsN = @{$coords[$n]};
	    my $x0 = int($points0[0]);
	    my $y0 = int($points0[1]);
	    my $xn = int($pointsN[0]);
	    my $yn = int($pointsN[1]);
	    if ($n == 1) { ## a couple of points
		$coords = "($x0, $y0, $xn, $yn)";
	    } else {
		$coords = "P0=($x0, $y0), ..., P".$n."=($xn, $yn)";
	    }
	}
	if (@coords > 2) {
	    my $dcbtn =
		$fm->Button(-text => $coords,
			    -command => [\&showdevicecoords, $label, $zinc, $item]);
	    $dcbtn->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 2);
	    $balloonhelp->attach($dcbtn,-balloonmsg =>
				 "Click to show all device coordinates.");
	} else {
	    $fm->Label(-text => $coords, -relief => 'ridge')
		->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	}
	# bounding box
	my @bbox = $zinc->bbox($item);
	if (@bbox == 4) {
	    my ($b0, $b1, $b2, $b3) = @bbox;
	    $b0 = sprintf("%.2f", $b0) if int($b0) ne $b0;
	    $b1 = sprintf("%.2f", $b1) if int($b1) ne $b1;
	    $b2 = sprintf("%.2f", $b2) if int($b2) ne $b2;
	    $b3 = sprintf("%.2f", $b3) if int($b3) ne $b3;
	    my $btn = $fm->Button(-text => "($b0, $b1), ($b2, $b3)")
		->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	    $btn->bind('<1>', [\&showbbox, $zinc, $item]);
	    $btn->bind('<ButtonRelease-1>', [\&hidebbox, $zinc]) ;
	    $balloonhelp->attach($btn,-balloonmsg =>
				 "Click to show the bounding box.");
	} else {
	    $fm->Label(-text => "--", , -relief => 'ridge')
		->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);
	}
	# tags
  	my @tags = $zinc->gettags($item);
	my $height = 2;
	$height = scalar @tags if $cmdoptions{expandTagsField};
	&entryoption($fm, $item, $zinc, -tags, join("\n", @tags), 30, 30, $height)
	    ->grid(-row => $i, -column => $c++, -sticky => 'nswe', -ipadx => 5);

	$i++;
	&showbanner($fm, $i++) if ($i % 15 == 0);
    }
    
} # end showattributes


sub showbanner {
    
    my $fm = shift;
    my $i = shift;
    my $bgcolor = 'ivory';
    my $c = 0;
    $fm->Label(-text => "Item\nId", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++, -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => "Item\nType", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++, -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => "Parent\ngroup", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++, -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => "P\nr\ni\no", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++, -ipady => 2, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => "S\ne\nn\ns", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++, -ipady => 2, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => "V\ni\ns\ni", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++, -ipady => 2, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => "All\noptions", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++,
	       -ipady => 5, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => "Transfo", -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++,
	       -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => 'Coords', -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++,
	       -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => 'Device coords', -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++,
	       -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => 'Bounding box', -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++,
	       -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => 'Tags', -background => $bgcolor, -relief => 'ridge')
	->grid(-row => $i, -column => $c++,
	       -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label()->grid(-row => 1, -column => $c++, -pady => 10);

} # end showbanner


#---------------------------------------------------------------------------
#
# Functions related to contours display
#
#---------------------------------------------------------------------------

# display contour (as simple curve)
sub showcontour {
    my ($widget, $zinc, $color, $item, $contourcoords, $deviceflag) = @_;
    if ($deviceflag) {
	$zinc->add('curve', 1, $contourcoords,
		   -filled => 0,
		   -linecolor => $color,
		   -tags => ['zincdebugcontour']);

    } else {
	$zinc->add('curve', 1, [$zinc->transform($item, 1, $contourcoords)],
		   -filled => 0,
		   -linecolor => $color,
		   -tags => ['zincdebugcontour']);
    }
    $zinc->raise('zincdebugcontour');
    
} # end showcontour


sub hidecontour {
    
    my ($zinc) = @_;
    $zinc->remove('zincdebugcontour');
    
} # end hidecontour


# display contours points (one rectangle per point)
sub showcontourpts {
    my ($widget, $zinc, $color, $item, $contourcoords, $deviceflag) = @_;
    my $i = 0;
    for my $coords (@$contourcoords) {
	my ($x, $y);
	if ($deviceflag) {
	    ($x, $y) = @$coords;
	} else {
	    ($x, $y) = $zinc->transform($item, 1, $coords);
	}
	if ($i == 0) {
	    $zinc->add('arc', 1, [$x-10, $y-10, $x+10, $y+10],
		       -filled => 0,
		       -linewidth => 1,
		       -linecolor => $color,
		       -tags => ['zincdebugcontour']);
	} elsif ($i == @$contourcoords -1) {
	    $zinc->add('arc', 1, [$x-10, $y-10, $x+10, $y+10],
		       -filled => 0,
		       -linewidth => 1,
		       -linecolor => $color,
		       -tags => ['zincdebugcontour']);
	    $zinc->add('arc', 1, [$x-13, $y-13, $x+13, $y+13],
		       -filled => 0,
		       -linewidth => 1,
		       -linecolor => $color,
		       -tags => ['zincdebugcontour']);
	}
	my $dx = 3;
	if (@$coords > 2) {
	    $zinc->add('rectangle', 1, [$x-$dx, $y-$dx, $x+$dx, $y+$dx],
		       -filled => 0,
		       -linewidth => 1,
		       -linecolor => $color,
		       -tags => ['zincdebugcontour']);
	} else {
	    $zinc->add('rectangle', 1, [$x-$dx, $y-$dx, $x+$dx, $y+$dx],
		       -filled => 1,
		       -linewidth => 1,
		       -fillcolor => $color,
		       -linecolor => $color,
		       -tags => ['zincdebugcontour']);
	}
	$i++;
    }
    $zinc->raise('zincdebugcontour');
    
} # end showcontourpts


# display one point of a contour (as a rectangle)
sub showcontourpt {
    
    my ($widget, $zinc, $color, $item, $index, $deviceflag, $labels, @contour) = @_;
    $widget->focus;
    if ($index < 0 or $index >= @contour) {
	$widget->bell;
	return;
    }
    &hidecontour($zinc);
    my $bgcolor = ($labels->[0]->configure(-background))[3];
    for (@$labels) {
	$_->configure(-background => $bgcolor);
    }
    $labels->[$index]->configure(-background => 'bisque');
    my @coords = @{$contour[$index]};
    my ($x, $y);
    if ($deviceflag) {
	($x, $y) = @coords;
    } else {
	($x, $y) = $zinc->transform($item, 1, [@coords]);
    }
    my $dx = 3;
    if (@coords > 2) {
	$zinc->add('rectangle', 1, [$x-$dx, $y-$dx, $x+$dx, $y+$dx],
		   -filled => 0,
		   -linewidth => 1,
		   -linecolor => $color,
		   -tags => ['zincdebugcontour']);
    } else {
	$zinc->add('rectangle', 1, [$x-$dx, $y-$dx, $x+$dx, $y+$dx],
		   -filled => 1,
		   -linewidth => 1,
		   -fillcolor => $color,
		   -linecolor => $color,
		   -tags => ['zincdebugcontour']);
    }
    $widget->bind('<Key-Down>', [\&showcontourpt, $zinc, $color,
				 $item, $index+1, $deviceflag, $labels, @contour]);
    $widget->bind('<Key-Right>', [\&showcontourpt, $zinc, $color,
				 $item, $index+1, $deviceflag, $labels, @contour]);
    $widget->bind('<Key-Up>', [\&showcontourpt, $zinc, $color,
				$item, $index-1, $deviceflag, $labels, @contour]);
    $widget->bind('<Key-Left>', [\&showcontourpt, $zinc, $color,
				$item, $index-1, $deviceflag, $labels, @contour]);
    $zinc->raise('zincdebugcontour');

} # end showcontourpt


#---------------------------------------------------------------------------
#
# Functions related to items graphical presentation
#
#---------------------------------------------------------------------------

# display the bbox of a group item
sub showbbox {
    
    my ($btn, $zinc, $item) = @_;
    $zinc->tsave(1, 'zoom+move', 1);
    my @bbox  = $zinc->bbox($item);
    if (scalar @bbox == 4) {
	# If item is visible, rectangle is drawm surround it.
	# Else, a warning is displayed.
	unless (&itemisoutside($zinc, @bbox)) {
	    my $i = -2;
	    for ('white', 'blue', 'white') {
		$zinc->add('rectangle', 1,
			   [$bbox[0] + $i, $bbox[1] + $i,
			    $bbox[2] - $i, $bbox[3] - $i],
			   -linecolor => $_,
			   -linewidth => 1,
			   -tags => ['zincdebugbbox']);
		$i += 2;
	    }
	}
    }
    $zinc->trestore('zincdebugbbox', 'zoom+move');
    $zinc->raise('zincdebugbbox');

} # end showbbox


sub hidebbox {
    
    my ($btn, $zinc) = @_;
    $zinc->remove("zincdebugbbox");

} # end hidebbox


# display a message box when an item is not visible because outside window
sub itemisoutside {
    
    my $zinc = shift;
    my @bbox = @_;
    return unless @bbox == 4;
    &getsize($zinc);
    #print "bbox=(@bbox) wheight=$wheight{$zinc} wwidth=$wwidth{$zinc}\n";
    my $outflag;
    $WARNING = 0;
    if ($bbox[2] < 0) {
	if ($bbox[1] >  $wheight{$zinc}) {
	    $outflag = 'left+bottom';
	} elsif ($bbox[3] < 0) {
	    $outflag = 'left+top';
	} else {
	    $outflag = 'left';
	} 
    } elsif ($bbox[0] > $wwidth{$zinc}) {
	if ($bbox[1] >  $wheight{$zinc}) {
	    $outflag = 'right+bottom';
	} elsif ($bbox[3] < 0) {
	    $outflag = 'right+top';
	} else {
	    $outflag = 'right';
	}
    } elsif ($bbox[3] < 0) {
	$outflag = 'top';
    } elsif ($bbox[1] > $wheight{$zinc}) {
	$outflag = 'bottom';
    }
    #print "outflag=$outflag bbox=@bbox\n";
    return 0 unless $outflag;
    # create first group which will be translated. We will apply to this group
    # the reverse transformation of topgroup. 
    my $g = $zinc->add('group', 1, -tags => ['zincdebug']);
    # create child group which won't be affected by ancestor's scale.
    my $g1 = $zinc->add('group', $g, -composescale => 0);
    my $hw = 110;
    my $hh = 80;
    my $r = 5;
    $zinc->add('rectangle', $g1, [-$hw, -$hh, $hw, $hh],
	       -filled => 1,
	       -linecolor => 'sienna',
	       -linewidth => 3,
	       -fillcolor => 'bisque',
	       -priority => 1,
	       );
    $zinc->add('text', $g1,
	       -position => [0, 0],
	       -color => 'sienna',
	       -font => '-b&h-lucida-bold-i-normal-sans-34-240-*-*-p-*-iso8859-1',
	       -anchor => 'center',
	       -priority => 2,
	       -text => "Item is\noutside\nwindow\n");
    my ($x, $y);
    if ($outflag eq 'bottom') {
	$x = $bbox[0] + ($bbox[2]-$bbox[0])/2;
	$x = $hw + 10 if $x < $hw + 10;
	$x = $wwidth{$zinc} - $hw - 10 if $x > $wwidth{$zinc} - $hw - 10;
	$y = $wheight{$zinc} - $hh - 10;
    } elsif ($outflag eq 'top') {
	$x = $bbox[0] + ($bbox[2]-$bbox[0])/2;
	$x = $hw + 10 if $x < $hw + 10;
	$x = $wwidth{$zinc} - $hw - 10if $x > $wwidth{$zinc} - $hw - 10;
	$y = $hh + 10;
    } elsif ($outflag eq 'left') {
	$x = $hw + 10;
	$y = $bbox[1] + ($bbox[3]-$bbox[1])/2;
	$y = $hh + 10 if $y < $hh + 10;
	$y = $wheight{$zinc} - $hh - 10 if $y > $wheight{$zinc} - $hh - 10;
    } elsif ($outflag eq 'right') {
	$x = $wwidth{$zinc} - $hw - 10;
	$y = $bbox[1] + ($bbox[3]-$bbox[1])/2;
	$y = $hh + 10 if $y < $hh + 10;
	$y = $wheight{$zinc} - $hh - 10 if $y > $wheight{$zinc} - $hh - 10;
    } elsif ($outflag eq 'left+top') {
	$x = $hw + 10;
	$y = $hh + 10;
    } elsif ($outflag eq 'left+bottom') {
	$x = $hw + 10;
	$y = $wheight{$zinc} - $hh - 10;
    } elsif ($outflag eq 'right+top') {
	$x = $wwidth{$zinc} - $hw - 10;
	$y = $hh + 10;
    } elsif ($outflag eq 'right+bottom') {
	$x = $wwidth{$zinc} - $hw - 10;
	$y = $wheight{$zinc} - $hh - 10;
    }
    # apply the reverse transformation of topgroup to group $g
    $zinc->tsave(1, 'transfo', 1);
    $zinc->trestore($g, 'transfo');
    # then translate group $g1
    $zinc->coords($g1, [$x, $y]);
    $zinc->raise('zincdebug');
    
} # end itemisoutside



# highlight an item (by cloning it and hiding other found items)
# why cloning? because we can't simply make visible an item which
# belongs to an invisible group.
sub highlightitem {
    
    my ($btn, $zinc, $item, $level) = @_;
    return if $showitemflag or $item == 1;
    $showitemflag = 1;
    &surrounditem($zinc, $item, $level);
    
    $btn->bind('<ButtonRelease>', [\&undohighlightitem, $zinc]) if $btn;

} # end highlightitem


sub undohighlightitem {
    
    my ($btn, $zinc) = @_;
    #print "undohighlightitem\n";
    $btn->bind('ReleaseButton', '') if $btn;
    $zinc->remove('zincdebug');
    $showitemflag = 0;

} # end undohighlightitem


sub surrounditem {
    
    my ($zinc, $item, $level) = @_;
    $zinc->remove("zincdebug");
    # cloning
    my $clone = $zinc->clone($item, -visible => 1, -tags => ['zincdebug']);
    $zinc->tsave(1, 'zoom+move', 1);
    $zinc->chggroup($clone, 1, 1);
    my @bbox = $zinc->bbox($clone);
    # create a rectangle around 
    if (scalar @bbox == 4) {
	# If item is visible, rectangle is drawm surround it.
	# Else, a warning is displayed.
	unless (&itemisoutside($zinc, @bbox)) {
	    if (defined($level) and $level > 0) {
		my $r = $zinc->add('rectangle', 1,
				   [$bbox[0] - 10, $bbox[1] - 10,
				    $bbox[2] + 10, $bbox[3] + 10],
				   -linewidth => 0,
				   -filled => 1,
				   -tags => ['zincdebug', 'zincdebugdecorator'],
				   -fillcolor => "gray20");
		$zinc->itemconfigure($r, -fillcolor => "gray80") if $level == 1;
	    } 
	    my $i = 0;
	    for ('white', 'red', 'white') {
		$zinc->add('rectangle', 1,
			   [$bbox[0] - 5 - 2*$i, $bbox[1] - 5 - 2*$i,
			    $bbox[2] + 5 + 2*$i, $bbox[3] + 5 + 2*$i],
			   -linecolor => $_,
			   -linewidth => 1,
			   -tags => ['zincdebug', 'zincdebugdecorator']);
		$i++;
	    }
	}
    }
    # raise
    $zinc->trestore('zincdebugdecorator', 'zoom+move');
    $zinc->raise('zincdebug');
    $zinc->raise($clone);

} # end surrounditem


# functions related to transformation animations
sub showtransfo {
    
    my ($btn, $zinc, $item, $level) = @_;
    my $anim = &highlighttransfo($zinc, $item, $level);
    $btn->bind('<ButtonRelease>', [\&undohighlighttransfo, $zinc, $anim]) if $btn;

} # end showtransfo


sub highlighttransfo {
    
    my ($zinc, $item, $level) = @_;
    $zinc->remove("zincdebug");
    my $g = $zinc->add('group', 1);
    my $g0 = $zinc->add('group', $g, -alpha => 0);
    my $g1 = $zinc->add('group', $g);
    # clone item and reset its transformation
    my $clone0 = $zinc->clone($item, -visible => 1, -tags =>['zincdebug']);
    $zinc->treset($clone0);
    # clone item and preserve its transformation
    my $clone1 = $zinc->clone($item, -visible => 1, -tags => ['zincdebug']);
    # move clones is dedicated group
    $zinc->chggroup($clone0, $g0, 1);
    $zinc->chggroup($clone1, $g1, 1);
    # create a rectangle around 
    my @bbox0  = $zinc->bbox($g);
    if (scalar @bbox0 == 4) {
	$zinc->tsave(1, 'transfo', 1);
	my @bbox = $zinc->transform(1, $g, [@bbox0]);
	# If item is visible, rectangle is drawm surround it.
	# Else, a warning is displayed.
	unless (&itemisoutside($zinc, @bbox0)) {
	    my $r = $zinc->add('rectangle', $g,
			       [$bbox[0] - 10, $bbox[1] - 10,
				$bbox[2] + 10, $bbox[3] + 10],
			       -filled => 1,
			       -linewidth => 0,
			       -tags => ['zincdebug'],
			       -fillcolor => "gray90");
	    $zinc->itemconfigure($r, -fillcolor => "gray50") if $level == 1;
	    $zinc->itemconfigure($r, -fillcolor => "gray20") if $level == 2;
	    $zinc->trestore($r, 'transfo');
	}
    }
    # raise
    $zinc->raise($g);
    $zinc->raise($g0);
    $zinc->raise($g1);
    # animation
    my $anim;
    if ($zinc->cget(-render) == 0) {
	$anim = $zinc->after(150, [sub {
	    $zinc->itemconfigure($g1, -visible => 0);
	    $zinc->itemconfigure($g0, -visible => 1);
	    $zinc->update;
	}]);
    } else {
	my $maxsteps = 5;
	$step = $maxsteps;
	$anim = $zinc->repeat(100, [sub {
	    return if $step < 0;
	    $zinc->itemconfigure($g1, -alpha => ($step)*100/$maxsteps);
	    $zinc->itemconfigure($g0, -alpha => ($maxsteps-$step)*100/$maxsteps);
	    $zinc->update;
	    $step--;
	}]);


    }
    return $anim;

} # end highlighttransfo


sub undohighlighttransfo {
    
    my ($btn, $zinc, $anim) = @_;
    $btn->bind('ReleaseButton', '') if $btn;
    $zinc->remove('zincdebug');
    $zinc->afterCancel($anim);

} # end undohighlighttransfo


#---------------------------------------------------------------------------
#
# Snapshot functions
#
#---------------------------------------------------------------------------

# print a zinc window in png format
sub printWindow {
    
    exit if $saving;
    $saving = 1;
    my ($zinc) = @_;
    my $basename = $cmdoptions{snapshotBasename};
    my $id = $zinc->id;
    my $filename = $basename . $imagecounter . ".png";
    $imagecounter++;
    my $original_cursor = ($zinc->configure(-cursor))[3];
    $zinc->configure(-cursor => 'watch');
    $zinc->update;
    my $res = system("import", -window, $id, $filename);
    $zinc->configure(-cursor => $original_cursor);
    
    $saving = 0;
    if ($res) {
	&showErrorWhilePrinting($zinc, $res)
	}
    else {
	my $dir = `pwd`; chomp ($dir);
	print "Tk::Zinc::Debug: Zinc window snapshot saved in $dir". "/$filename\n";
    }

} # end printWindow


# display complete help screen
sub showErrorWhilePrinting {
    
    my ($zinc, $res) = @_;
    my $dir = `pwd`; chomp ($dir);
    $help_print->destroy if $help_print and Tk::Exists($help_print);
    $help_print = $zinc->Dialog(-title => 'Zinc Print info',
				-text =>
				"To acquire a TkZinc window snapshot, you must " .
				"have access to the import command, which is ".
				"part of imageMagic package\n\n".
				"You must also have the rights to write ".
				"in the current dir : $dir",
				-bitmap => 'warning',
				);
    $help_print->after(300, sub {$help_print->grabRelease});
    $help_print->Show();

} # end showErrorWhilePrinting

#---------------------------------------------------------------------------
#
# Help functions
#
#---------------------------------------------------------------------------

# display help about tree
sub showHelpAboutTree {
    
    my $zinc = shift;
    $helptree_tl->destroy if $helptree_tl and Tk::Exists($helptree_tl);
    $helptree_tl = $tree_tl->Toplevel;
    $helptree_tl->title("Help about Tree");

    my $text = $helptree_tl->Scrolled('Text',
					-font => scalar $zinc->cget(-font),
					-wrap => 'word',
					-foreground => 'gray10',
					-scrollbars => 'osoe',
					);
    &wheelmousebindings($text);
    $text->tagConfigure('keyword', -foreground => 'darkblue');
    $text->insert('end', "\nNAVIGATION IN TREE\n\n");
    $text->insert('end', "<Up>", "keyword");
    $text->insert('end', " arrow key moves the anchor point to the item right on ".
		  "top of the current anchor item. ");
    $text->insert('end', "<Down>", "keyword");
    $text->insert('end', " arrow key moves the anchor point to the item right below ".
		  "the current anchor item. ");
    $text->insert('end', "<Left>", "keyword");
    $text->insert('end', " arrow key moves the anchor to the parent item of the ".
		  "current anchor item. ");
    $text->insert('end', "<Right>", "keyword");
    $text->insert('end', " moves the anchor to the first child of the current anchor ".
		  "item. If the current anchor item does not have any children, moves ".
		  "the anchor to the item right below the current anchor item.\n\n");
    $text->insert('end', "\nHIGHLIGHTING ITEMS\n\n");
    $text->insert('end', "To display item's features, ");
    $text->insert('end', "double-click", "keyword");
    $text->insert('end', " on it, press ");
    $text->insert('end', "<Return>", "keyword");
    $text->insert('end', " key or click on the ");
    $text->insert('end', "Attributes", "keyword");
    $text->insert('end', " button.\n\n");
    $text->insert('end', "To highlight item in the application, simply ");
    $text->insert('end', "click", "keyword");
    $text->insert('end', " on it.");
    &infoAboutHighlighting($text);
    $text->insert('end', "\n\n\nBUILDING CODE\n\n");
    $text->insert('end', "To build perl code, select a branch or a leaf ".
		  "and click on the ");
    $text->insert('end', "Build code", "keyword");
    $text->insert('end', " button. Then select an output file with the ".
		  "file selector.\n\n");
     $text->configure(-state => 'disabled');
    
    $helptree_tl->Button(-command => sub {$helptree_tl->destroy},
			 -text => 'Close')->pack(-side => 'bottom',
						 -pady => 10);
    $text->pack->pack(-side => 'top', -pady => 10, -padx => 10);

} # end showHelpAboutTree


sub showHelpAboutCoords {
    
    my $zinc = shift;
    $helpcoords_tl->destroy if $helpcoords_tl and Tk::Exists($helpcoords_tl);
    $helpcoords_tl = $zinc->Toplevel;
    $helpcoords_tl->title("Help about coordinates");

    my $text = $helpcoords_tl->Scrolled('Text',
				      -font => scalar $zinc->cget(-font),
				      -wrap => 'word',
				      -height => 30,
				      -foreground => 'gray10',
				      -scrollbars => 'oe',
				      );
    &wheelmousebindings($text);
    $text->tagConfigure('keyword', -foreground => 'darkblue');
    $text->tagConfigure('title', -foreground => 'ivory',
			-background => 'gray60',
			-spacing1 => 3,
			-spacing3 => 3);

    
    $text->insert('end', " To display a contour\n", 'title');
    $text->insert('end', "Press button labeled ");
    $text->insert('end', 'Contour i', 'keyword');
    $text->insert('end', " (*). Release it to hide contour.");
    $text->insert('end', "\n\n");
    $text->insert('end', " To display all the points of a contour\n", 'title');
    $text->insert('end', "Press button labeled ");
    $text->insert('end', 'n points', 'keyword');
    $text->insert('end', " (*). Release it to hide points. First plot is ".
		  "particularized by a circle, last one by a double circle. ".
		  "Non-filled plots represent control points of a Bezier curve.");
    $text->insert('end', "\n\n");
    $text->insert('end', " To navigate in the contour\n", 'title');
    $text->insert('end', "Select first a point by clicking in the coordinates table ");
    $text->insert('end', "(*). Th corresponding plot is displayed. Then use the ");
    $text->insert('end', "Up/Down", 'keyword');
    $text->insert('end', " (or ");
    $text->insert('end', "Left/Right", 'keyword');
    $text->insert('end', ") arrows keys to navigate in the contour");
    $text->insert('end', "\n\n");
    $text->insert('end', "\n\n");
    $text->insert('end', "(*) The color of displayed elements depends on the mouse ".
		  "button you press.");
    $text->insert('end', "\n\n");
    $text->configure(-state => 'disabled');
    
    $helpcoords_tl->Button(-command => sub {$helpcoords_tl->destroy},
			 -text => 'Close')->pack(-side => 'bottom',
						 -pady => 10);
    $text->pack->pack(-side => 'top', -pady => 10, -padx => 10);

} # end showHelpAboutCoords



sub infoAboutHighlighting {
    
    my $text = shift;
    $text->insert('end', "By default, using ");
    $text->insert('end', "left mouse button", "keyword");
    $text->insert('end', ", highlighting is done by raising selected item and drawing ".
		  "a rectangle arround. ");
    $text->insert('end', "In order to improve visibility, ");
    $text->insert('end', "item will be light backgrounded if you use ");
    $text->insert('end', "center mouse button", "keyword");
    $text->insert('end', " and dark backgrounded if you use ");
    $text->insert('end', "right mouse button", "keyword");
    $text->insert('end', ". ");
    
} # end infoAboutHighlighting


sub entryballoonhelp {

    my $e = shift;
    my $msg = shift;
    $msg .= "Editable field. To restore the inital value\n".
	    "after edition, enter <Control-z> sequence. ";
    $balloonhelp->attach($e, -balloonposition => 'mouse',
			 -balloonmsg => $msg);
    
} # end entryballoonhelp


sub balloonhelp {
    
    my $b = $control_tl->Balloon(-balloonposition => 'widget',
				 -font => '6x13');
    $b->attach($button{zn},-balloonmsg =>
	       "Widget instance selector. Use it when \n".
	       "your application takes more than one  \n".
	       "TkZinc instance. When this mode is on,\n".
	       "select the TkZinc instance you want   \n".
	       "inspect just by clicking on it.       ");
    $b->attach($button{findenclosed}, -balloonmsg =>
	       "Inspect all items *enclosed* in a  \n".
	       "rectangular area. When this mode is\n".
	       "selected, draw rectangle using left\n".
	       "mouse button.                      ");
    $b->attach($button{findoverlap}, -balloonmsg =>
	       "Inspect all items which *overlap* \n".
	       "a rectangular area. When this mode\n".
	       "is selected, draw rectangle using \n".
	       "left mouse button.                ");
    $b->attach($button{tree}, -balloonmsg =>
	       #"Display the items hierarchy. Can\n".
	       #"build perl code corresponding to\n".
	       #"a specific branch.              ");
	       "Display the items hierarchy. Provide\n".
	       "some related functions, like building\n".
	       "perl code corresponding to a branch.");
    $b->attach($button{item}, -balloonmsg =>
	       "Locate an item in the items tree.  \n".
	       "When this mode is on, select in   \n".
	       "your application the item you want\n".
	       "to inspect just by clicking on it.");
    $b->attach($button{id}, -balloonmsg =>
	       "Open an entry field in which you will  \n".
	       "enter an item's id you want to inspect.");
    $b->attach($button{snapshot}, -balloonmsg =>
	       "Snapshot the application window.");
    $b->attach($button{cursorxy}, -balloonmsg =>
	       "Display the device coordinates\n".
	       "of the X cursor.              ");
    $b->attach($button{zoomminus}, -balloonmsg =>
	       "Shrink the top group.");
    $b->attach($button{zoomplus}, -balloonmsg =>
	       "Expand the top group.");
    $b->attach($button{move}, -balloonmsg =>
	       "Translate the top group. When this\n".
	       "mode is selected, move the top    \n".
	       "group using left mouse button.    ");
    $b->attach($button{balloon},-balloonmsg =>
	       "Balloon help toggle.");
    $b->attach($button{close},-balloonmsg =>
	       "Close this buttons bar.");
    return $b;

} # end balloonhelp



#---------------------------------------------------------------------------
#
# Bitmaps creation for the buttons of the control bar 
#
#---------------------------------------------------------------------------

sub createBitmaps {

    my $zinc = shift;
    my $bitmaps;
    
    $bitmaps->{close} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define close_width 29
#define close_height 29
static unsigned char close_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x00,
   0x00, 0x07, 0x1c, 0x00, 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x1c, 0x07, 0x00,
   0x00, 0xb8, 0x03, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00,
   0x00, 0xf0, 0x01, 0x00, 0x00, 0xb8, 0x03, 0x00, 0x00, 0x1c, 0x07, 0x00,
   0x00, 0x0e, 0x0e, 0x00, 0x00, 0x07, 0x1c, 0x00, 0x00, 0x02, 0x08, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
EOF
    $bitmaps->{zn} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define focus_width 29
#define focus_height 29
static unsigned char focus_bits[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0x60, 0x38, 0x00, 0x00,
  0x20, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x8e, 0x33, 0x00,
  0x00, 0x06, 0x7b, 0x00, 0x00, 0x07, 0x67, 0x00, 0x80, 0x03, 0x63, 0x00,
  0xc0, 0x01, 0x63, 0x00, 0xc0, 0x00, 0x63, 0x00, 0xe0, 0x20, 0x63, 0x00,
  0x70, 0x30, 0x63, 0x00, 0xf0, 0xbf, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
EOF
    $bitmaps->{findenclosed} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define findenclosed_width 29
#define findenclosed_height 29
static unsigned char findenclosed_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
   0xfc, 0xff, 0xff, 0x03, 0xfc, 0xff, 0xff, 0x03, 0x3c, 0x00, 0x00, 0x03,
   0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03,
   0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03,
   0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03,
   0x18, 0x80, 0x00, 0x03, 0x18, 0x00, 0x01, 0x03, 0x18, 0x00, 0x22, 0x03,
   0x18, 0x00, 0x24, 0x03, 0x18, 0x00, 0x28, 0x03, 0x18, 0x00, 0x20, 0x03,
   0x18, 0x00, 0x3e, 0x03, 0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03,
   0xf8, 0xff, 0xff, 0x03, 0xf8, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
EOF
    $bitmaps->{findoverlap} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define findoverlap_width 29
#define findoverlap_height 29
static unsigned char findoverlap_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
   0xfc, 0xb6, 0x6d, 0x03, 0xfc, 0xb6, 0x6d, 0x03, 0x3c, 0x00, 0x00, 0x00,
   0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
   0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
   0x18, 0x00, 0x00, 0x03, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
   0x18, 0x80, 0x00, 0x03, 0x18, 0x00, 0x01, 0x03, 0x00, 0x00, 0x22, 0x00,
   0x18, 0x00, 0x24, 0x03, 0x18, 0x00, 0x28, 0x03, 0x00, 0x00, 0x20, 0x00,
   0x18, 0x00, 0x3e, 0x03, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
   0xd8, 0xb6, 0x6d, 0x03, 0xd8, 0xb6, 0x6d, 0x03, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
EOF
    $bitmaps->{tree} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define tree_width 29
#define tree_height 29
static unsigned char tree_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0xf0, 0x07, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x10, 0x04, 0x00,
   0xc0, 0x1f, 0x04, 0x00, 0x40, 0x10, 0x04, 0x00, 0x40, 0x10, 0x04, 0x00,
   0x40, 0xf0, 0x07, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0xe0, 0x0f,
   0x40, 0x00, 0x20, 0x08, 0x7c, 0x00, 0x20, 0x08, 0x40, 0x00, 0x3f, 0x08,
   0x40, 0x00, 0x21, 0x08, 0x40, 0x00, 0x21, 0x08, 0x40, 0x00, 0xe1, 0x0f,
   0x40, 0x00, 0x01, 0x00, 0x40, 0x00, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00,
   0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
   0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5f, 0x01, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
EOF
    $bitmaps->{item} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define item_width 29
#define item_height 29
static unsigned char item_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00,
   0xe0, 0x03, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xc0, 0x1f, 0x00, 0x00,
   0xc0, 0x7f, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0xff, 0x03, 0x00,
   0x00, 0xff, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00,
   0x00, 0xdc, 0x01, 0x00, 0x00, 0x8c, 0x03, 0x00, 0x00, 0x08, 0x07, 0x00,
   0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x38, 0x00,
   0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x40, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
EOF
    $bitmaps->{id} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define id_width 29
#define id_height 29
static unsigned char id_bits[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00, 0x06, 0x0c, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x87, 0x0f, 0x00,
  0x00, 0xc6, 0x0c, 0x00, 0x00, 0x66, 0x0c, 0x00, 0x00, 0x66, 0x0c, 0x00,
  0x00, 0x66, 0x0c, 0x00, 0x00, 0x66, 0x0c, 0x00, 0x00, 0x66, 0x0c, 0x00,
  0x00, 0xc6, 0x0c, 0x00, 0x00, 0x8f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
EOF
    $bitmaps->{snapshot} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define snapshot_width 29
#define snapshot_height 29
static unsigned char snapshot_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x1f, 0x00,
   0x80, 0x03, 0x11, 0x00, 0xe0, 0xff, 0xf1, 0x00, 0xf0, 0xff, 0xff, 0x01,
   0xf0, 0xff, 0xff, 0x01, 0xf0, 0xff, 0xff, 0x01, 0xf0, 0x0f, 0xfe, 0x01,
   0xf0, 0xe7, 0xfc, 0x01, 0xf0, 0x13, 0xf9, 0x01, 0xf0, 0x09, 0xf2, 0x01,
   0xf0, 0x05, 0xf4, 0x01, 0xf0, 0x05, 0xf4, 0x01, 0xf0, 0x05, 0xf4, 0x01,
   0xf0, 0x09, 0xf2, 0x01, 0xf0, 0x13, 0xf9, 0x01, 0xf0, 0xe7, 0xfc, 0x01,
   0xf0, 0x0f, 0xfe, 0x01, 0xf0, 0xff, 0xff, 0x01, 0xe0, 0xff, 0xff, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
EOF
    $bitmaps->{zoomminus} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define zoomminus_width 29
#define zoomminus_height 29
static unsigned char zoomminus_bits[] = {
   0x00, 0x0e, 0x00, 0x00, 0xc0, 0x71, 0x00, 0x00, 0x30, 0x80, 0x01, 0x00,
   0x08, 0x00, 0x02, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00,
   0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x08, 0x00,
   0xe1, 0xff, 0x10, 0x00, 0xe1, 0xff, 0x10, 0x00, 0xe1, 0xff, 0x10, 0x00,
   0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x08, 0x00,
   0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x08, 0x00, 0x02, 0x00,
   0x30, 0x80, 0x05, 0x00, 0xc0, 0x71, 0x28, 0x00, 0x00, 0x0e, 0x70, 0x00,
   0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0xe0, 0x03,
   0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x1f,
   0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04};
EOF

    $bitmaps->{zoomplus} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define zoomplus_width 29
#define zoomplus_height 29
static unsigned char zoomplus_bits[] = {
   0x00, 0x0e, 0x00, 0x00, 0xc0, 0x71, 0x00, 0x00, 0x30, 0x80, 0x01, 0x00,
   0x08, 0x00, 0x02, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x0e, 0x04, 0x00,
   0x02, 0x0e, 0x08, 0x00, 0x02, 0x0e, 0x08, 0x00, 0x02, 0x0e, 0x08, 0x00,
   0xe1, 0xff, 0x10, 0x00, 0xe1, 0xff, 0x10, 0x00, 0xe1, 0xff, 0x10, 0x00,
   0x02, 0x0e, 0x08, 0x00, 0x02, 0x0e, 0x08, 0x00, 0x02, 0x0e, 0x08, 0x00,
   0x04, 0x0e, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x08, 0x00, 0x02, 0x00,
   0x30, 0x80, 0x05, 0x00, 0xc0, 0x71, 0x28, 0x00, 0x00, 0x0e, 0x70, 0x00,
   0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0xe0, 0x03,
   0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x1f,
   0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04};
EOF

    $bitmaps->{move} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define hand_width 29
#define hand_height 29
static unsigned char hand_bits[] = {
   0x00, 0xe0, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x80, 0x13, 0x0f, 0x00,
   0x40, 0x12, 0x11, 0x00, 0x40, 0x14, 0x11, 0x00, 0x40, 0x14, 0xd1, 0x01,
   0x80, 0x14, 0x31, 0x02, 0x80, 0x14, 0x31, 0x02, 0x80, 0x18, 0x31, 0x02,
   0x80, 0x18, 0x31, 0x02, 0x00, 0x11, 0x31, 0x02, 0x00, 0x11, 0x11, 0x01,
   0x1c, 0x11, 0x11, 0x01, 0x22, 0x01, 0x11, 0x01, 0x42, 0x01, 0x10, 0x01,
   0x84, 0x01, 0x00, 0x01, 0x88, 0x01, 0x00, 0x01, 0x08, 0x01, 0x00, 0x02,
   0x08, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x02,
   0x20, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x01,
   0x80, 0x00, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x06, 0x40, 0x00,
   0x00, 0x08, 0x40, 0x00, 0x00, 0x08, 0x40, 0x00};
EOF

    $bitmaps->{balloon} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define balloon_width 29
#define balloon_height 29
static unsigned char balloon_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x00,
   0x10, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x02,
   0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x02,
   0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x02,
   0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x02,
   0x10, 0x00, 0x00, 0x01, 0xe0, 0xe0, 0xff, 0x00, 0x00, 0x11, 0x00, 0x00,
   0x00, 0x09, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00,
   0x40, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
EOF

    $bitmaps->{cursorxy} = $zinc->toplevel->Bitmap(-data => <<EOF);
#define balloon_width 29
#define balloon_height 29
static unsigned char balloon_bits[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00,
  0x00, 0x1c, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00,
  0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
  0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x30, 0x06, 0x8c, 0x01, 0x70, 0x07, 0x8c, 0x01, 0x60, 0x03, 0x8c, 0x01,
  0xc0, 0x01, 0xd8, 0x00, 0xc0, 0x01, 0xd8, 0x00, 0x60, 0xe3, 0xd8, 0x00,
  0x70, 0x66, 0x70, 0x00, 0x30, 0x66, 0x70, 0x00, 0x00, 0x30, 0x60, 0x00,
  0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
EOF

    return $bitmaps;
   
} # end  createBitmaps


#---------------------------------------------------------------------------
#
# Miscellaneous
#
#---------------------------------------------------------------------------

sub getsize {
    
    my $zinc = shift;
    $wwidth{$zinc} = $zinc->cget(-width);
    $wheight{$zinc} = $zinc->cget(-height);
        
} # end getsize


sub entryoption {
    
    my ($fm, $item, $zinc, $option, $def, $widthmax, $widthmin, $height) = @_;
    my $arrayflag;
    unless (defined $def) {
	my @def = $zinc->itemcget($item, $option);
	if (@def > 1) {
	    $arrayflag = 1;
	    $def = join(', ', @def);
	} else {
	    $def = $def[0];
	}
    }
    $def = "" unless defined $def;
    my $i0;
    my $e;
    if ($def =~ /\n/) {
	$height = 1 unless defined($height);
	$e = $fm->Text(-height => $height, -width => 1, -wrap => 'none');
	$i0 = '0.0';
    } else {
	$e = $fm->Entry();
	$i0 = 0;
    }
    &entryballoonhelp($e);
    my $width = length($def);
    $width = $widthmax if defined($widthmax) and $width > $widthmax;
    $width = $widthmin if defined($widthmin) and $width < $widthmin;
    $e->configure(-width => $width);
    if ($defaultoptions{$item}->{$option} and
	$def ne $defaultoptions{$item}->{$option}) {
	$e->configure(-foreground => 'blue');
    }
    
    $e->insert($i0, $def);
    $e->bind('<Control-z>', sub {
	return unless defined $defaultoptions{$item}->{$option};
	my $bg = $e->cget(-background);
	$zinc->itemconfigure($item, $option => $defaultoptions{$item}->{$option});
	$e->delete($i0, 'end');
	$e->insert($i0, $defaultoptions{$item}->{$option});
	$e->configure(-background => 'ivory');
	$e->after(80, sub {$e->configure(-background => $bg, -foreground => 'black')});
    });
    $e->bind('<Key-Return>',
	     sub {my $val = $e->get;
		  my $bg = $e->cget(-background);
		  $e->configure(-background => 'ivory');
		  if ($def ne $val) {
		      $defaultoptions{$item}->{$option} = $def
			  unless $defaultoptions{$item}->{$option};
		  }
		  my $fg = ($val ne $defaultoptions{$item}->{$option}) ?
		      'blue' : 'black';
		  $e->after(80, sub {
		      $e->configure(-background => $bg, -foreground => $fg);
		  });
		  if ($arrayflag) {
		      $zinc->itemconfigure($item, $option => [split(/,/, $val)]);
		  } else {
		      $zinc->itemconfigure($item, $option => $val);
		  }
	      });

    return $e;

} # end entryoption


sub entrytransfo {
    
    my ($fm, $item, $zinc, $attr, $def, $var, $width, $set_cb) = @_;
    my $i0;
    my $e;
    $e = $fm->Entry(-textvariable => $var);
    &entryballoonhelp($e);
    $i0 = 0;
    $width = length($def) unless $width;
    $e->configure(-width => $width);   
    $e->insert($i0, $def);
    $e->bind('<Control-z>', sub {
	my $bg = $e->cget(-background);
	$e->delete($i0, 'end');
	$e->insert($i0, $def);
	$e->configure(-background => 'ivory');
	$e->after(80, sub {$e->configure(-background => $bg, -foreground => 'black')});
	&$set_cb;
    });
    $e->bind('<Key-Return>',
	     sub {my $val = $e->get;
		  my $bg = $e->cget(-background);
		  $e->configure(-background => 'ivory');
		  my $fg = ($val ne $def) ? 'blue' : 'black';
		  $e->after(80, sub {
		      $e->configure(-background => $bg, -foreground => $fg);
		  });
		  &$set_cb;
	      });

    return $e;

} # end entrytransfo


sub instances {
    
    return @instances;
    
} # end instances


sub saveMotionBinding {

    my ($zinc) = @_;
    for my $seq ('Motion') {
	$userbindings{$zinc}->{$seq} = $zinc->Tk::bind('<'.$seq.'>')
	    unless defined $userbindings{$zinc}->{$seq};
	$userbindings{$zinc}->{$seq} = "" unless defined $userbindings{$zinc}->{$seq};
	$zinc->Tk::bind('<'.$seq.'>', "");
    }
    
} # end saveMotionBinding


sub restoreMotionBinding {

    my ($zinc) = @_;
    for my $seq ('Motion') {
	next unless defined $userbindings{$zinc}->{$seq};
	$zinc->Tk::bind('<'.$seq.'>', $userbindings{$zinc}->{$seq});
	delete $userbindings{$zinc}->{$seq};
    }
    
} # end restoreMotionBinding


sub saveDragAndDropBindings {

    my ($zinc) = @_;
    for my $seq ('ButtonPress-1', 'B1-Motion', 'ButtonRelease-1') {
	$userbindings{$zinc}->{$seq} = $zinc->Tk::bind('<'.$seq.'>')
	    unless defined $userbindings{$zinc}->{$seq};
	$userbindings{$zinc}->{$seq} = "" unless defined $userbindings{$zinc}->{$seq};
	#print "saveDragAndDropBindings seq=$seq cb=$userbindings{$zinc}->{$seq}\n";
	$zinc->Tk::bind('<'.$seq.'>', "");
    }
    
} # end saveDragAndDropBindings


sub restoreDragAndDropBindings {

    my ($zinc) = @_;
    for my $seq ('ButtonPress-1', 'B1-Motion', 'ButtonRelease-1') {
	next unless defined $userbindings{$zinc}->{$seq};
	$zinc->Tk::bind('<'.$seq.'>', $userbindings{$zinc}->{$seq});
	#print "restoreDragAndDropBindings seq=$seq cb=$userbindings{$zinc}->{$seq}\n";
	delete $userbindings{$zinc}->{$seq};
    }
    
} # end restoreDragAndDropBindings


sub newinstance {
    
    my $zinc = shift;
    return if $instances{$zinc};
    $zinc->toplevel->Tk::bind('<Key-Escape>', \&Tk::Zinc::Debug::deiconify);
    $instances{$zinc} = 1;    
    push(@instances, $zinc);
    $zinc->Tk::focus;
    $selectedzinc = $zinc;
    
} # end newinstance


sub deiconify {

    $button{zn}->destroy() if @instances == 1 and Tk::Exists($button{zn});
    $control_tl->deiconify();
    for (values %result_tl) {
	$_->deiconify if Tk::Exists($_);
    }
    for (values %coords_tl) {
	$_->deiconify if Tk::Exists($_);
    }
    for (values %alloptions_tl) {
	$_->deiconify if Tk::Exists($_);
    }
    $tree_tl->deiconify if Tk::Exists($tree_tl);
    $search_tl->deiconify if Tk::Exists($search_tl);
    $searchtree_tl->deiconify if Tk::Exists($searchtree_tl);
    $cursorxy_tl->deiconify if Tk::Exists($cursorxy_tl);
    $control_tl->raise();

} # end deiconify


sub iconify {

    for (values %result_tl) {
	$_->withdraw if Tk::Exists($_);
    }
    for (values %coords_tl) {
	$_->withdraw if Tk::Exists($_);
    }
    for (values %alloptions_tl) {
	$_->withdraw if Tk::Exists($_);
    }
    $tree_tl->withdraw if Tk::Exists($tree_tl);
    $search_tl->withdraw if Tk::Exists($search_tl);
    $searchtree_tl->withdraw if Tk::Exists($searchtree_tl);
    $cursorxy_tl->withdraw if Tk::Exists($cursorxy_tl);
    $control_tl->withdraw();

} # end iconify

# wheelmousebindings doesn't work for Tk::Pane widgets...
sub wheelmousebindings {
    my $w = shift;
    my $count = shift;
    $count = 3 unless $count > 0;

    $w->bind('<Control-ButtonPress-4>', sub {$w->yview('scroll', -1, 'page')});
    $w->bind('<Shift-ButtonPress-4>', sub {$w->yview('scroll', -1, 'unit')});
    $w->bind('<ButtonPress-4>', sub {$w->yview('scroll', -$count, 'unit')});
    
    $w->bind('<Control-ButtonPress-5>', sub {$w->yview('scroll', 1, 'page')});
    $w->bind('<Shift-ButtonPress-5>', sub {$w->yview('scroll', 1, 'unit')});
    $w->bind('<ButtonPress-5>', sub {$w->yview('scroll', $count, 'unit')});

} # end wheelmousebindings

1;

__END__

    
=head1 NAME

Tk::Zinc::Debug - a perl module for analysing a Zinc application. 


=head1 SYNOPSIS

 perl -MTk::Zinc::Debug zincscript [zincscript-opts] [Debug-initopts]
    
     or
    
 use Tk::Zinc::Debug;
 my $zinc = MainWindow->new()->Zinc()->pack;
 Tk::Zinc::Debug::init($zinc, [options]);


=head1 DESCRIPTION

Tk::Zinc::Debug provides an interface to help developers to inspect Zinc applications.

Press the B<Escape> key in the toplevel of your application to display the Tk::Zinc::Debug buttons bar.


Features :

=over
    
=item B<o> scan a rectangular area

Scan all items which are enclosed in a rectangular area you have first drawn by drag & drop, or all items which overlap it. Result is a Tk table which presents details (options, coordinates, ...) about found items; you can also highlight a particular item, even if it's not visible, by clicking on its corresponding button in the table. You can also display particular item's features by entering this id in dedicated entry field

=item B<o> display items hierarchy

You can find a particular item's position in the tree and you can highlight items and see their features as described above. You can also generate the perl code corresponding to a selected branch (but images can't be reproduced).

=item B<o> snapshot the application window

In order to illustrate a graphical bug for example.
    
=item B<o> display coordinates of the X cursor.
    
=item B<o> zoom/translate the top group
    
=back


=head2 Loading Tk::Zinc::Debug as a plugin
    
If you load Tk::Zinc::Debug using the -M perl option, B<nothing needs to be added to your code>. In this case, the B<init()> function is automatically invoked with its default attributes for each instance of Zinc widget. You can overload these by passing the same options to the command. 

=head1 FUNCTION


=over

=item B<init>($zinc, ?option => value, ...?)

This function creates required Tk bindings to permit items search. You can specify the following options :

=over

=item E<32>E<32>E<32>B<-optionsToDisplay> => opt1[,..,optN]

Used to display some option's values associated to items of the tree. Expected argument is a string of commas separated options.

=item E<32>E<32>E<32>B<-optionsFormat> => row | column

Defines the display format of option's values. Default is 'row'.
    
=item E<32>E<32>E<32>B<-snapshotBasename> => string

Defines the basename used for the file containing the snaphshot. The filename will be <current­dir>/basename<n>.png  Defaulted to 'zincsnapshot'.

=item E<32>E<32>E<32>B<-expandTagsField> => 0 | 1

Specifies if the tags field in the attributes window will be expanded to show all the items tags (it should take up a lot of space). In the default case (value is set to 0), only the head of the list is displayed.


=back


=back
    

=head1 AUTHOR

Daniel Etienne <etienne@cena.fr>

    
=head1 HISTORY

Oct 5 2004 : transformations are correctly managed in built code. Transfo parameters can be displayed and set. new mode to display coordinateds of X cursor.

Oct 14 2003 : add a control bar, and zoom/translate new functionalities. finditems(), tree(), snapshot() functions become deprecated, initialisation is done using the new init() function.

Oct 07 2003 : contours of curves can be displayed and explored.

Sep 15 2003 : due to CPAN-isation, the ZincDebug module has been renamed Tk::Zinc::Debug

May 20 2003 : perl code can be generated from the items tree, with some limitations concerning transformations and images.

Mar 11 2003 : ZincDebug can manage several instances of Zinc widget. Options of ZincDebug functions can be set on the command line. 

Jan 20 2003 : item's attributes can be edited.

Jan 14 2003 : ZincDebug can be loaded at runtime using the -M perl option without any change in the application's code.

Nov 6 2002 : some additional informations (like tags or other attributes values) can be displayed in the items tree. Add feedback when selected item is not visible because outside window.

Sep 2 2002 : add the tree() function

May 27 2002 : add the snapshot() function contributed by Ch. Mertz.
    
Jan 28 2002 : Zincdebug provides the finditems() function and can manage only one instance of Zinc widget. 

Added jni/tkzinc/Perl/Zinc/Graphics.pm.























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
#-----------------------------------------------------------------------------------
#
#      Graphics.pm
#      some graphic design functions
#
#-----------------------------------------------------------------------------------
#  Functions to create complexe graphic component :
#  ------------------------------------------------
#      buildZincItem          (realize a zinc item from description hash table
#                              management of enhanced graphics functions)
#
#      repeatZincItem         (duplication of given zinc item)
#
#  Function to compute complexe geometrical forms :
#  (text header of functions explain options for each form,
#  function return curve coords using control points of cubic curve)
#  -----------------------------------------------------------------
#      roundedRectangleCoords (return curve coords of rounded rectangle)
#      hippodromeCoords       (return curve coords of circus form)
#      ellipseCoords          (return curve coords of ellipse form)
#      polygonCoords          (return curve coords of regular polygon)
#      roundedCurveCoords     (return curve coords of rounded curve)
#      polylineCoords         (return curve coords of polyline)
#      shiftPathCoords        (return curve coords of shifting path)
#      tabBoxCoords           (return curve coords of tabBox's pages)
#      pathLineCoords         (return triangles coords of pathline)
#
#  Function to compute 2D 1/2 relief and shadow :
#  function build zinc items (triangles and curve) to simulate this
#  -----------------------------------------------------------------
#      graphicItemRelief      (return triangle items simulate relief of given item)
#      polylineReliefParams   (return triangle coords and lighting triangles color list)
#      graphicItemShadow      (return triangles and curve items simulate shadow of given item))
#      polylineShadowParams   (return triangle and curve coords and shadow triangles color list))
#
#  Geometrical basic Functions :
#  -----------------------------
#      perpendicularPoint
#      lineAngle
#      lineNormal
#      vertexAngle
#      arc_pts
#      rad_point
#      bezierCompute
#      bezierSegment
#      bezierPoint
#
#  Pictorial Functions  :
#  ----------------------
#      setGradients
#      getPattern
#      getTexture
#      getImage
#      init_pixmaps
#      zincItemPredominantColor
#      ZnColorToRGB
#      hexaRGBcolor
#      createGraduate
#      pathGraduate
#      MedianColor
#      LightingColor
#      RGBtoLCH
#      LCHtoRGB
#      RGBtoHLS
#      HLStoRGB
#
#-----------------------------------------------------------------------------------
#      Authors: Jean-Luc Vinot <vinot@cena.fr>
#
# $Id$ 
#-----------------------------------------------------------------------------------
package Tk::Zinc::Graphics;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(&buildZincItem &repeatZincItem &buidTabBoxItem

	     &roundedRectangleCoords &hippodromeCoords &polygonCoords &ellipseCoords
	     &roundedCurveCoords &polylineCoords &tabBoxCoords &pathLineCoords &shiftPathCoords

	     &perpendicularPoint &lineAngle &vertexAngle &rad_point &arc_pts &lineNormal
	     &curve2polylineCoords &curveItem2polylineCoords &bezierSegment &bezierCompute

	     &graphicItemRelief &graphicItemShadow

	     &setGradients &getPattern &getTexture &getImage &init_pixmaps

	     &hexaRGBcolor &createGraduate &lightingColor &zincItemPredominantColor
	     &MedianColor &RGBtoLCH &LCHtoRGB &RGBtoHLS &HLStoRGB
	     );

use strict;
use Carp;
use Tk;
use Tk::PNG;
use Tk::JPEG;
use Math::Trig;

# constante facteur point directeur (conique -> quadratique)
my $const_ptd_factor = .5523;

# constante white point (conversion couleur espace CIE XYZ)
my ($Xw, $Yw, $Zw) = (95.047, 100.0, 108.883);

# limite globale d'approximation courbe bezier
my $bezierClosenessThreshold = .2;

# initialisation et partage de ressources couleurs et images
my @Gradients;
my %textures;
my %images;
my %bitmaps;



#-----------------------------------------------------------------------------------
# Graphics::buildZincItem
# Création d'un objet Zinc de représentation
#-----------------------------------------------------------------------------------
# types d'items valides :
# les items natifs zinc : group, rectangle, arc, curve, text, icon
# les items ci-après permettent de spécifier des curves 'particulières' :
# -roundedrectangle : rectangle à coin arrondi
#       -hippodrome : hippodrome
#          -ellipse : ellipse un centre 2 rayons
#         -polygone : polygone régulier à n cotés (convexe ou en étoile)
#     -roundedcurve : curve multicontours à coins arrondis (rayon unique)
#         -polyline : curve multicontours à coins arrondis (le rayon pouvant être défini 
#                     spécifiquement pour chaque sommet)
#         -pathline : création d'une ligne 'épaisse' avec l'item Zinc triangles
#                     décalage par rapport à un chemin donné (largeur et sens de décalage)
#                     dégradé de couleurs de la ligne (linéaire, transversal ou double)
#-----------------------------------------------------------------------------------
# paramètres :
# widget : <widget> identifiant du widget Zinc
# parentgroup : <tagOrId> identifiant du group parent
#
# options :
#   -itemtype : type de l'item à construire (type zinc ou metatype)
#     -coords : <coords|coordsList> coordonnées de l'item
# -metacoords : <hastable> calcul de coordonnées par type d'item différent de -itemtype
#   -contours : <contourList> paramètres multi-contours
#     -params : <hastable> arguments spécifiques de l'item à passer au widget
#    -addtags : [list of specific tags] to add to params -tags
#    -texture : <imagefile> ajout d'une texture à l'item
#    -pattern : <imagefile> ajout d'un pattern à l'item
#     -relief : <hastable> création d'un relief à l'item invoque la fonction &graphicItemRelief()
#     -shadow : <hastable> création d'une ombre portée à l'item invoque la fonction &graphicItemShadow()
#      -scale : <scale_factor|[xscale_factor,yscale_factor]> application d'une transformation zinc->scale à l'item
#  -translate : <[dx,dy]> application d'un transformation zinc->translate à l'item.
#     -rotate : <angle> application d'une transformation zinc->rotate (en degré) à l'item
#       -name : <str> nom de l'item
# spécifiques item group :
#       -clip : <coordList|hashtable> paramètres de clipping d'un item group (coords ou item)
#      -items : <hashtable> appel récursif de la fonction permettant d'inclure des items au groupe
#-----------------------------------------------------------------------------------
#
#-----------------------------------------------------------------------------------
sub buildZincItem {
  my ($widget, $parentgroup, %options) = @_;
  $parentgroup = 1 if !$parentgroup;

  my $itemtype = $options{'-itemtype'};
  my $coords = $options{'-coords'};
  my $params = $options{'-params'};

  return unless ($widget and $itemtype and ($coords or $options{'-metacoords'}));

  my $name = ($options{'-name'}) ? $options{'-name'} : 'none';

  my $item;
  my $metatype;
  my (@items, @reliefs, @shadows);
  my @tags;


  #--------------------
  # GEOMETRIE DES ITEMS

  # gestion des types d'items particuliers et à raccords circulaires
  if ($itemtype eq 'roundedrectangle'
      or $itemtype eq 'hippodrome'
      or $itemtype eq 'polygone'
      or $itemtype eq 'ellipse'
      or $itemtype eq 'roundedcurve'
      or $itemtype eq 'polyline'
      or $itemtype eq 'curveline') {

    # par défaut la curve sera fermée -closed = 1
    $params->{'-closed'} = 1 if (!defined $params->{'-closed'});
    $metatype = $itemtype;
    $itemtype = 'curve';

    # possibilité de définir les coordonnées initiales par metatype
    if ($options{'-metacoords'}) {
      $options{'-coords'} = &metaCoords(%{$options{'-metacoords'}});

    }

  # création d'une pathline à partir d'item zinc triangles
  } elsif ($itemtype eq 'pathline') {

    $itemtype = 'triangles';
    if ($options{'-metacoords'}) {
      $coords = &metaCoords(%{$options{'-metacoords'}});

    }

    if ($options{'-graduate'}) {
      my $numcolors = scalar(@{$coords});
      $params->{'-colors'} = &pathGraduate($widget, $numcolors, $options{'-graduate'});
    }

    $coords = &pathLineCoords($coords, %options);


  # création d'une boite à onglet
  } elsif ($itemtype eq 'tabbox') {
    return &buildTabBoxItem($widget, $parentgroup, %options);

  }

  # calcul des coordonnées finales de la curve
  $coords = &metaCoords(-type => $metatype, %options) if ($metatype);


  # gestion du multi-contours (accessible pour tous les types d'items géometriques)
  if ($options{'-contours'} and $metatype) {
    my @contours = @{$options{'-contours'}};
    my $numcontours = scalar(@contours);
    for (my $i = 0; $i < $numcontours; $i++) {
      # radius et corners peuvent être défini spécifiquement pour chaque contour
      my ($type, $way, $addcoords, $radius, $corners, $corners_radius) = @{$contours[$i]};
      $radius = $options{'-radius'} if (!defined $radius);

      my $newcoords = &metaCoords(-type => $metatype,
				  -coords => $addcoords,
				  -radius => $radius,
				  -corners => $corners,
				  -corners_radius => $corners_radius
				 );

      $options{'-contours'}->[$i] = [$type, $way, $newcoords];
    }
  }


  #----------------------
  # REALISATION DES ITEMS

  # ITEM GROUP
  # gestion des coordonnées et du clipping
  if ($itemtype eq 'group') {
    $item = $widget->add($itemtype,
			 $parentgroup,
			 %{$params});

    $widget->coords($item, $coords) if $coords;

    # clipping du groupe par item ou par géometrie
    if ($options{'-clip'}) {
      my $clipbuilder = $options{'-clip'};
      my $clip;

      # création d'un item de clipping
      if ($clipbuilder->{'-itemtype'}) {
	$clip = &buildZincItem($widget, $item, %{$clipbuilder});

      } elsif (ref($clipbuilder) eq 'ARRAY' or $widget->type($clipbuilder)) {
	$clip = $clipbuilder;
      }

      $widget->itemconfigure($item, -clip => $clip) if ($clip);
    }

    # créations si besoin des items contenus dans le groupe
    if ($options{'-items'} and ref($options{'-items'}) eq 'HASH') {
      while (my ($itemname, $itemstyle) = each(%{$options{'-items'}})) {
	$itemstyle->{'-name'} = $itemname if (!$itemstyle->{'-name'});
	&buildZincItem($widget, $item, %{$itemstyle});
      }
    }


  # ITEM TEXT ou ICON
  } elsif ($itemtype eq 'text' or $itemtype eq 'icon') {
    my $imagefile;
    if ($itemtype eq 'icon') {
      $imagefile = $params->{'-image'};
      my $image = &getImage($widget, $imagefile);
      $params->{'-image'} = ($image) ? $image : "";
    }

    $item = $widget->add($itemtype,
		       $parentgroup,
		       -position => $coords,
		       %{$params},
		      );

    $params->{'-image'} = $imagefile if $imagefile;


  # ITEMS GEOMETRIQUES -> CURVE
  } else {

    $item = $widget->add($itemtype,
			 $parentgroup,
			 $coords,
			 %{$params},
			);

    if ($itemtype eq 'curve' and $options{'-contours'}) {
      foreach my $contour (@{$options{'-contours'}}) {
	$widget->contour($item, @{$contour});
      }
    }
	
    # gestion du mode norender
    if ($options{'-texture'}) {
      my $texture = &getTexture($widget, $options{'-texture'});
      $widget->itemconfigure($item, -tile => $texture) if $texture;
    }

    if ($options{'-pattern'}) {
      my $bitmap = &getBitmap($options{'-pattern'});
      $widget->itemconfigure($item, -fillpattern => $bitmap) if $bitmap;
    }

  }


  # gestion des tags spécifiques
  if ($options{'-addtags'}) {
    my @tags = @{$options{'-addtags'}};

    my $params_tags = $params->{'-tags'};
    push (@tags, @{$params_tags}) if $params_tags;

    $widget->itemconfigure($item, -tags => \@tags);

  }


  #-------------------------------
  # TRANSFORMATIONS ZINC DE L'ITEM

  # transformation scale de l'item si nécessaire
  if ($options{'-scale'}) {
    my $scale = $options{'-scale'};
    $scale = [$scale, $scale] if (ref($scale) ne 'ARRAY');
    $widget->scale($item, @{$scale}) ;
  }

  # transformation rotate de l'item si nécessaire
  $widget->rotate($item, deg2rad($options{'-rotate'})) if ($options{'-rotate'});

  # transformation translate de l'item si nécessaire
  $widget->translate($item, @{$options{'-translate'}}) if ($options{'-translate'});


  # répétition de l'item
  if ($options{'-repeat'}) {
    push (@items, $item,
	  &repeatZincItem($widget, $item, %{$options{'-repeat'}}));
  }


  #-----------------------
  # RELIEF ET OMBRE PORTEE

  # gestion du relief
  if ($options{'-relief'}) {
    my $target = (@items) ? \@items : $item;
    push (@reliefs, &graphicItemRelief($widget, $target, %{$options{'-relief'}}));
  }

  # gestion de l'ombre portée
  if ($options{'-shadow'}) {
    my $target = (@items) ? \@items : $item;
    push (@shadows, &graphicItemShadow($widget, $target, %{$options{'-shadow'}}));
  }

  push(@items, @reliefs) if @reliefs;
  push(@items, @shadows) if @shadows;

  return (@items) ? @items : $item;

}


#-----------------------------------------------------------------------------------
# Graphics::repeatZincItem
# Duplication (clonage) d'un objet Zinc de représentation
#-----------------------------------------------------------------------------------
# paramètres :
# widget : <widget> identifiant du widget zinc
#   item : <tagOrId> identifiant de l'item source
# options :
#     -num : <n> nombre d'item total (par defaut 2)
#     -dxy : <[dx, dy]> translation entre 2 duplications (par defaut [0,0])
#   -angle : <angle> rotation entre 2 duplications
# -copytag : <sting> ajout d'un tag indexé pour chaque copie
#  -params : <hashtable> {clef => [value list]}> valeur de paramètre de chaque copie
#-----------------------------------------------------------------------------------
sub repeatZincItem {
  my ($widget, $item, %options) = @_;
  my @clones;

  # duplication d'une liste d'items -> appel récursif
  if (ref($item) eq 'ARRAY') {
    foreach my $part (@{$item}) {
      push (@clones, &repeatZincItem($widget, $part, %options));
    }

    return wantarray ? @clones : \@clones;
  }

  my $num = ($options{'-num'}) ? $options{'-num'} : 2;
  my ($dx, $dy) = (defined $options{'-dxy'}) ? @{$options{'-dxy'}} : (0, 0);
  my $angle = $options{'-angle'};
  my $params = $options{'-params'};
  my $copytag = $options{'-copytag'};
  my @tags;

  if ($copytag) {
    @tags = $widget->itemcget($item, -tags);
    unshift (@tags, $copytag."0");
    $widget->itemconfigure($item, -tags => \@tags);
  }

  for (my $i = 1; $i < $num; $i++) {
    my $clone;

    if ($copytag) {
      $tags[0] = $copytag.$i;
      $clone = $widget->clone($item, -tags => \@tags);

    } else {
      $clone = $widget->clone($item);
    }

    push(@clones, $clone);
    $widget->translate($clone, $dx*$i, $dy*$i);
    $widget->rotate($clone, deg2rad($angle*$i)) if $angle;

    if ($params) {
      while (my ($attrib, $value) = each(%{$params})) {
	$widget->itemconfigure($clone, $attrib => $value->[$i]);
      }
    }
  }

  return wantarray ? @clones : \@clones;

}


#-----------------------------------------------------------------------------------
# FONCTIONS GEOMETRIQUES
#-----------------------------------------------------------------------------------

#-----------------------------------------------------------------------------------
# Graphics::metaCoords
# retourne une liste de coordonnées en utilisant la fonction du type d'item spécifié
#-----------------------------------------------------------------------------------
# paramètres : (passés par %options)
#   -type : <string> type de primitive utilisée
# -coords : <coordsList> coordonnées nécessitée par la fonction [type]Coords
#
# les autres options spécialisées au type seront passés à la fonction [type]coords
#-----------------------------------------------------------------------------------
sub metaCoords {
  my (%options) = @_;
  my $pts;

  my $type = delete $options{'-type'};
  my $coords = delete $options{'-coords'};

  if ($type eq 'roundedrectangle') {
    $pts = &roundedRectangleCoords($coords, %options);

  } elsif ($type eq 'hippodrome') {
    $pts = &hippodromeCoords($coords, %options);

  } elsif ($type eq 'ellipse') {
    $pts = &ellipseCoords($coords, %options);

  } elsif ($type eq 'roundedcurve') {
    $pts = &roundedCurveCoords($coords, %options);

  } elsif ($type eq 'polygone') {
    $pts = &polygonCoords($coords, %options);

  } elsif ($type eq 'polyline') {
    $pts = &polylineCoords($coords, %options);

  } elsif ($type eq 'curveline') {
    $pts = &curveLineCoords($coords, %options);
  }

  return $pts;
}


#-----------------------------------------------------------------------------------
# Graphics::ZincItem2CurveCoords
# retourne une liste des coordonnées 'Curve' d'un l'item Zinc
# rectangle, arc ou curve
#-----------------------------------------------------------------------------------
# paramètres :
# widget : <widget> identifiant du widget zinc
#   item : <tagOrId> identifiant de l'item source
# options :
#     -linear : <boolean> réduction à des segments non curviligne (par défaut 0)
# -realcoords : <boolean> coordonnées à transformer dans le groupe père (par défaut 0)
#     -adjust : <boolean> ajustement de la courbe de bezier (par défaut 1)
#-----------------------------------------------------------------------------------
sub ZincItem2CurveCoords {
  my ($widget, $item, %options) = @_;

  my $itemtype = $widget->type($item);
  return unless ($itemtype);

  my $linear = $options{-linear};
  my $realcoords = $options{-realcoords};
  my $adjust = (defined $options{-adjust}) ? $options{-adjust} : 1;

  my @itemcoords = $widget->coords($item);

  my $coords;
  my @multi;

  if ($itemtype eq 'rectangle') {
    $coords = &roundedRectangleCoords(\@itemcoords, -radius => 0);

  } elsif ($itemtype eq 'arc') {
    $coords = &ellipseCoords(\@itemcoords);
    $coords = &curve2polylineCoords($coords, $adjust) if $linear;

  } elsif ($itemtype eq 'curve') {
      my $numcontours = $widget->contour($item);

      if ($numcontours < 2) {
      $coords = \@itemcoords;
      $coords = &curve2polylineCoords($coords, $adjust) if $linear;


    } else {
      if ($linear) {
	@multi = &curveItem2polylineCoords($widget, $item);

      } else {
	for (my $contour = 0; $contour < $numcontours; $contour++) {
	  my @points = $widget->coords($item, $contour);
	  push (@multi, \@points);
	}
      }

      $coords = \@multi;
    }
  }

  if ($realcoords) {
    my $parentgroup = $widget->group($item);
    if (@multi) {
      my @newcoords;
      foreach my $points (@multi) {
	my @transcoords = $widget->transform($item, $parentgroup, $points);
	push(@newcoords, \@transcoords);
      }

      $coords = \@newcoords;

    } else {
      my @transcoords = $widget->transform($item, $parentgroup, $coords);
      $coords = \@transcoords;
    }

  }

  if (@multi) {
    return (wantarray) ? @{$coords} : $coords;
  } else {
    return (wantarray) ? ($coords) : $coords;
  }
}

#-----------------------------------------------------------------------------------
# Graphics::roundedRectangleCoords
# calcul des coords du rectangle à coins arrondis
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> coordonnées bbox (haut-gauche et bas-droite) du rectangle
# options :
#  -radius : <dimension> rayon de raccord d'angle
# -corners : <booleanList> liste des raccords de sommets [0 (aucun raccord)|1] par défaut [1,1,1,1]
#-----------------------------------------------------------------------------------
sub roundedRectangleCoords {
  my ($coords, %options) = @_;
  my ($x0, $y0, $xn, $yn) = ($coords->[0]->[0], $coords->[0]->[1],
			     $coords->[1]->[0], $coords->[1]->[1]);

  my $radius = $options{'-radius'};
  my $corners = $options{'-corners'} ? $options{'-corners'} : [1, 1, 1, 1];

  # attention aux formes 'négatives'
  if ($xn < $x0) {
    my $xs = $x0;
    ($x0, $xn) = ($xn, $xs);
  }
   if ($yn < $y0) {
    my $ys = $y0;
    ($y0, $yn) = ($yn, $ys);
  }

  my $height = &_min($xn -$x0, $yn - $y0);

  if (!defined $radius) {
    $radius = int($height/10);
    $radius = 3 if $radius < 3;
  }

  if (!$radius or $radius < 2) {
    return [[$x0, $y0],[$x0, $yn],[$xn, $yn],[$xn, $y0]];

  }


  # correction de radius si necessaire
  my $max_rad = $height;
  $max_rad /= 2 if (!defined $corners);
  $radius = $max_rad if $radius > $max_rad;

  # points remarquables
  my $ptd_delta = $radius * $const_ptd_factor;
  my ($x2, $x3) = ($x0 + $radius, $xn - $radius);
  my ($x1, $x4) = ($x2 - $ptd_delta, $x3 + $ptd_delta);
  my ($y2, $y3) = ($y0 + $radius, $yn - $radius);
  my ($y1, $y4) = ($y2 - $ptd_delta, $y3 + $ptd_delta);

  # liste des 4 points sommet du rectangle : angles sans raccord circulaire
  my @angle_pts = ([$x0, $y0],[$x0, $yn],[$xn, $yn],[$xn, $y0]);

  # liste des 4 segments quadratique : raccord d'angle = radius
  my @roundeds = ([[$x2, $y0],[$x1, $y0, 'c'],[$x0, $y1, 'c'],[$x0, $y2],],
		  [[$x0, $y3],[$x0, $y4, 'c'],[$x1, $yn, 'c'],[$x2, $yn],],
		  [[$x3, $yn],[$x4, $yn, 'c'],[$xn, $y4, 'c'],[$xn, $y3],],
		  [[$xn, $y2],[$xn, $y1, 'c'],[$x4, $y0, 'c'],[$x3, $y0],]);

  my @pts = ();
  my $previous;
  for (my $i = 0; $i < 4; $i++) {
    if ($corners->[$i]) {
      if ($previous) {
	# on teste si non duplication de point
	my ($nx, $ny) = @{$roundeds[$i]->[0]};
	if ($previous->[0] == $nx and $previous->[1] == $ny) {
	  pop(@pts);
	}
      }
      push(@pts, @{$roundeds[$i]});
      $previous = $roundeds[$i]->[3];

    } else {
      push(@pts, $angle_pts[$i]);
    }
  }

  return \@pts;
}

#-----------------------------------------------------------------------------------
# Graphics::ellipseCoords
# calcul des coords d'une ellipse
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> coordonnées bbox du rectangle exinscrit
# options :
# -corners : <booleanList> liste des raccords de sommets [0 (aucun raccord)|1] par défaut [1,1,1,1]
#-----------------------------------------------------------------------------------
sub ellipseCoords {
  my ($coords, %options) = @_;
  my ($x0, $y0, $xn, $yn) = ($coords->[0]->[0], $coords->[0]->[1],
			     $coords->[1]->[0], $coords->[1]->[1]);

  my $corners = $options{'-corners'} ? $options{'-corners'} : [1, 1, 1, 1];

  # attention aux formes 'négatives'
  if ($xn < $x0) {
    my $xs = $x0;
    ($x0, $xn) = ($xn, $xs);
  }
   if ($yn < $y0) {
    my $ys = $y0;
    ($y0, $yn) = ($yn, $ys);
  }

  # points remarquables
  my $dx = ($xn - $x0)/2 * $const_ptd_factor;
  my $dy = ($yn - $y0)/2 * $const_ptd_factor;
  my ($x2, $y2) = (($x0+$xn)/2, ($y0+$yn)/2);
  my ($x1, $x3) = ($x2 - $dx, $x2 + $dx);
  my ($y1, $y3) = ($y2 - $dy, $y2 + $dy);

  # liste des 4 points sommet de l'ellipse : angles sans raccord circulaire
  my @angle_pts = ([$x0, $y0],[$x0, $yn],[$xn, $yn],[$xn, $y0]);

  # liste des 4 segments quadratique : raccord d'angle = arc d'ellipse
  my @roundeds = ([[$x2, $y0],[$x1, $y0, 'c'],[$x0, $y1, 'c'],[$x0, $y2],],
		  [[$x0, $y2],[$x0, $y3, 'c'],[$x1, $yn, 'c'],[$x2, $yn],],
		  [[$x2, $yn],[$x3, $yn, 'c'],[$xn, $y3, 'c'],[$xn, $y2],],
		  [[$xn, $y2],[$xn, $y1, 'c'],[$x3, $y0, 'c'],[$x2, $y0],]);

  my @pts = ();
  my $previous;
  for (my $i = 0; $i < 4; $i++) {
    if ($corners->[$i]) {
      if ($previous) {
	# on teste si non duplication de point
	my ($nx, $ny) = @{$roundeds[$i]->[0]};
	if ($previous->[0] == $nx and $previous->[1] == $ny) {
	  pop(@pts);
	}
      }
      push(@pts, @{$roundeds[$i]});
      $previous = $roundeds[$i]->[3];

    } else {
      push(@pts, $angle_pts[$i]);
    }
  }

  return \@pts;

}


#-----------------------------------------------------------------------------------
# Graphics::hippodromeCoords
# calcul des coords d'un hippodrome
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> coordonnées bbox du rectangle exinscrit
# options :
# -orientation : orientation forcée de l'hippodrome [horizontal|vertical]
#     -corners : liste des raccords de sommets [0|1] par défaut [1,1,1,1]
#       -trunc : troncatures [left|right|top|bottom|both]
#-----------------------------------------------------------------------------------
sub hippodromeCoords {
  my ($coords, %options) = @_;
  my ($x0, $y0, $xn, $yn) = ($coords->[0]->[0], $coords->[0]->[1],
			     $coords->[1]->[0], $coords->[1]->[1]);

  my $orientation = ($options{'-orientation'}) ? $options{'-orientation'} : 'none';

  # orientation forcée de l'hippodrome (sinon hippodrome sur le plus petit coté)
  my $height = ($orientation eq 'horizontal') ? abs($yn - $y0)
    : ($orientation eq 'vertical') ? abs($xn - $x0) : &_min(abs($xn - $x0), abs($yn - $y0));
  my $radius = $height/2;
  my $corners = [1, 1, 1, 1];

  if  ($options{'-corners'}) {
    $corners = $options{'-corners'};

  } elsif ($options{'-trunc'}) {
    my $trunc = $options{'-trunc'};
    if ($trunc eq 'both') {
      return [[$x0, $y0],[$x0, $yn],[$xn, $yn],[$xn, $y0]];

    } else {
      $corners = ($trunc eq 'left') ? [0, 0, 1, 1] :
	($trunc eq 'right') ? [1, 1, 0, 0] :
	  ($trunc eq 'top') ? [0, 1, 1, 0] : 
	    ($trunc eq 'bottom') ? [1, 0, 0, 1] : [1, 1, 1, 1];

    }
  }

  # l'hippodrome est un cas particulier de roundedRectangle
  # on retourne en passant la 'configuration' à la fonction générique roundedRectangleCoords
  return &roundedRectangleCoords($coords, -radius => $radius, -corners => $corners);
}


#-----------------------------------------------------------------------------------
# Graphics::polygonCoords
# calcul des coords d'un polygone régulier
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coords> point centre du polygone
# options :
#      -numsides : <integer> nombre de cotés
#        -radius : <dimension> rayon de définition du polygone (distance centre-sommets)
#  -inner_radius : <dimension> rayon interne (polygone type étoile)
#       -corners : <booleanList> liste des raccords de sommets [0|1] par défaut [1,1,1,1]
# -corner_radius : <dimension> rayon de raccord des cotés
#    -startangle : <angle> angle de départ en degré du polygone
#-----------------------------------------------------------------------------------
sub polygonCoords {
  my ($coords, %options) = @_;

  my $numsides = $options{'-numsides'};
  my $radius = $options{'-radius'};
  if ($numsides < 3 or !$radius) {
    print "Vous devez au moins spécifier un nombre de cotés >= 3 et un rayon...\n";
    return undef;
  }

  $coords = [0, 0] if (!defined $coords);
  my $startangle = ($options{'-startangle'}) ? $options{'-startangle'} : 0;
  my $anglestep = 360/$numsides;
  my $inner_radius = $options{'-inner_radius'};
  my @pts;

  # points du polygone
  for (my $i = 0; $i < $numsides; $i++) {
    my ($xp, $yp) = &rad_point($coords, $radius, $startangle + ($anglestep*$i));
    push(@pts, ([$xp, $yp]));

    # polygones 'étoiles'
    if ($inner_radius) {
      ($xp, $yp) = &rad_point($coords, $inner_radius, $startangle + ($anglestep*($i+ 0.5)));
      push(@pts, ([$xp, $yp]));
    }
  }


  @pts = reverse @pts;

  if ($options{'-corner_radius'}) {
    return &roundedCurveCoords(\@pts, -radius => $options{'-corner_radius'}, -corners => $options{'-corners'});
  } else {
    return \@pts;
  }
}



#-----------------------------------------------------------------------------------
# Graphics::roundedAngle
# THIS FUNCTION IS NO MORE USED, NEITHER EXPORTED
# curve d'angle avec raccord circulaire
#-----------------------------------------------------------------------------------
# paramètres :
# widget : identifiant du widget Zinc
# parentgroup : <tagOrId> identifiant de l'item group parent
# coords : <coordsList> les 3 points de l'angle
# radius : <dimension> rayon de raccord
#-----------------------------------------------------------------------------------
sub roundedAngle {
  my ($widget, $parentgroup, $coords, $radius) = @_;
  my ($pt0, $pt1, $pt2) = @{$coords};

  my ($corner_pts, $center_pts) = &roundedAngleCoords($coords, $radius);
  my ($cx0, $cy0) = @{$center_pts};

  # valeur d'angle et angle formé par la bisectrice
  my ($angle)  = &vertexAngle($pt0, $pt1, $pt2);

  $parentgroup = 1 if (!defined $parentgroup);

  $widget->add('curve', $parentgroup,
	     [$pt0,@{$corner_pts},$pt2],
	     -closed => 0, 
	     -linewidth => 1,
	     -priority => 20,
	    );

}

#-----------------------------------------------------------------------------------
# Graphics::roundedAngleCoords
# calcul des coords d'un raccord d'angle circulaire
#-----------------------------------------------------------------------------------
# le raccord circulaire de 2 droites sécantes est traditionnellement réalisé par un
# arc (conique) du cercle inscrit de rayon radius tangent à ces 2 droites
#
# Quadratique :
# une approche de cette courbe peut être réalisée simplement par le calcul de 4 points
# spécifiques qui définiront - quelle que soit la valeur de l'angle formé par les 2
# droites - le segment de raccord :
# - les 2 points de tangence au cercle inscrit seront les points de début et de fin
# du segment de raccord
# - les 2 points de controle seront situés chacun sur le vecteur reliant le point de
# tangence au sommet de l'angle (point secant des 2 droites)
# leur position sur ce vecteur peut être simplifiée comme suit :
# - à un facteur de 0.5523 de la distance au sommet pour un angle >= 90° et <= 270°
# - à une 'réduction' de ce point vers le point de tangence pour les angles limites
# de 90° vers 0° et de 270° vers 360°
# ce facteur sera légérement modulé pour recouvrir plus précisement l'arc correspondant
#-----------------------------------------------------------------------------------
# coords : <coordsList> les 3 points de l'angle
# radius : <dimension> rayon de raccord
#-----------------------------------------------------------------------------------
sub roundedAngleCoords {
  my ($coords, $radius) = @_;
  my ($pt0, $pt1, $pt2) = @{$coords};

  # valeur d'angle et angle formé par la bisectrice
  my ($angle, $bisecangle)  = &vertexAngle($pt0, $pt1, $pt2);

  # distance au centre du cercle inscrit : rayon/sinus demi-angle
  my $sin = sin(deg2rad($angle/2));
  my $delta = ($sin) ? abs($radius / $sin) : $radius;

  # point centre du cercle inscrit de rayon $radius
  my $refangle = ($angle < 180) ? $bisecangle+90 : $bisecangle-90;
  my ($cx0, $cy0) = rad_point($pt1, $delta, $refangle);

  # points de tangeance : pts perpendiculaires du centre aux 2 droites
  my ($px1, $py1) = &perpendicularPoint([$cx0, $cy0], [$pt0, $pt1]);
  my ($px2, $py2) = &perpendicularPoint([$cx0, $cy0], [$pt1, $pt2]);

  # point de controle de la quadratique
  # facteur de positionnement sur le vecteur pt.tangence, sommet
  my $ptd_factor =  $const_ptd_factor;
  if ($angle < 90 or $angle > 270) {
    my $diffangle = ($angle < 90) ? $angle : 360 - $angle;
    $ptd_factor -= (((90 - $diffangle)/90) * ($ptd_factor/4)) if $diffangle > 15 ;
    $ptd_factor = ($diffangle/90) * ($ptd_factor + ((1 - $ptd_factor) * (90 - $diffangle)/90));
  } else {
    my $diffangle = abs(180 - $angle);
    $ptd_factor += (((90 - $diffangle)/90) * ($ptd_factor/3)) if $diffangle > 15;
  }

  # delta xy aux pts de tangence
  my ($d1x, $d1y) = (($pt1->[0] - $px1) * $ptd_factor, ($pt1->[1] - $py1) *  $ptd_factor);
  my ($d2x, $d2y) = (($pt1->[0] - $px2) * $ptd_factor, ($pt1->[1] - $py2) *  $ptd_factor);

  # les 4 points de l'arc 'quadratique'
  my $corner_pts = [[$px1, $py1],[$px1+$d1x, $py1+$d1y, 'c'],
		    [$px2+$d2x, $py2+$d2y, 'c'],[$px2, $py2]];


  # retourne le segment de quadratique et le centre du cercle inscrit
  return ($corner_pts, [$cx0, $cy0]);

}


#-----------------------------------------------------------------------------------
# Graphics::roundedCurveCoords
# retourne les coordonnées d'une curve à coins arrondis
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> liste de coordonnées des points de la curve
# options :
#  -radius : <dimension> rayon de raccord d'angle
# -corners : <booleanList> liste des raccords de sommets [0|1] par défaut [1,1,1,1]
#-----------------------------------------------------------------------------------
sub roundedCurveCoords {
  my ($coords, %options) = @_;
  my $numfaces = scalar(@{$coords});
  my @curve_pts;

  my $radius = (defined $options{'-radius'}) ? $options{'-radius'} : 0;
  my $corners = $options{'-corners'};

  for (my $index = 0; $index < $numfaces; $index++) {
    if ($corners and !$corners->[$index]) {
      push(@curve_pts, $coords->[$index]);

    } else {
      my $prev = ($index) ? $index - 1 : $numfaces - 1;
      my $next = ($index > $numfaces - 2) ? 0 : $index + 1;
      my $anglecoords = [$coords->[$prev], $coords->[$index], $coords->[$next]];

      my ($quad_pts) = &roundedAngleCoords($anglecoords, $radius);
      push(@curve_pts, @{$quad_pts});
    }
  }

  return \@curve_pts;

}


#-----------------------------------------------------------------------------------
# Graphics::polylineCoords
# retourne les coordonnées d'une polyline
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> liste de coordonnées des sommets de la polyline
# options :
#  -radius : <dimension> rayon global de raccord d'angle
# -corners : <booleanList> liste des raccords de sommets [0|1] par défaut [1,1,1,1],
# -corners_radius : <dimensionList> liste des rayons de raccords de sommets
#-----------------------------------------------------------------------------------
sub polylineCoords {
  my ($coords, %options) = @_;
  my $numfaces = scalar(@{$coords});
  my @curve_pts;

  my $radius = ($options{'-radius'}) ? $options{'-radius'} : 0;
  my $corners_radius = $options{'-corners_radius'};
  my $corners = ($corners_radius) ? $corners_radius : $options{'-corners'};

  for (my $index = 0; $index < $numfaces; $index++) {
    if ($corners and !$corners->[$index]) {
      push(@curve_pts, $coords->[$index]);

    } else {
      my $prev = ($index) ? $index - 1 : $numfaces - 1;
      my $next = ($index > $numfaces - 2) ? 0 : $index + 1;
      my $anglecoords = [$coords->[$prev], $coords->[$index], $coords->[$next]];

      my $rad = ($corners_radius) ? $corners_radius->[$index] : $radius;
      my ($quad_pts) = &roundedAngleCoords($anglecoords, $rad);
      push(@curve_pts, @{$quad_pts});
    }
  }

  return \@curve_pts;

}

#-----------------------------------------------------------------------------------
# Graphics::pathLineCoords
# retourne les coordonnées d'une pathLine
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> liste de coordonnées des points du path
# options :
#    -closed : <boolean> ligne fermée
#  -shifting : <out|center|in> sens de décalage du path (par défaut center)
# -linewidth : <dimension> epaisseur de la ligne
#-----------------------------------------------------------------------------------
sub pathLineCoords {
  my ($coords, %options) = @_;
  my $numfaces = scalar(@{$coords});
  my @pts;

  my $closed = $options{'-closed'};
  my $linewidth = ($options{'-linewidth'}) ? $options{'-linewidth'} : 2;
  my $shifting = ($options{'-shifting'}) ? $options{'-shifting'} : 'center';

  return undef if (!$numfaces or $linewidth < 2);

  my $previous = ($closed) ? $coords->[$numfaces - 1] : undef;
  my $next = $coords->[1];
  $linewidth /= 2 if ($shifting eq 'center');

  for (my $i = 0; $i < $numfaces; $i++) {
    my $pt = $coords->[$i];

    if (!$previous) {
      # extrémité de curve sans raccord -> angle plat
      $previous = [$pt->[0] + ($pt->[0] - $next->[0]), $pt->[1] + ($pt->[1] - $next->[1])];
    }

    my ($angle, $bisecangle) = &vertexAngle($previous, $pt, $next);

    # distance au centre du cercle inscrit : rayon/sinus demi-angle
    my $sin = sin(deg2rad($angle/2));
    my $delta = ($sin) ? abs($linewidth / $sin) : $linewidth;

    if ($shifting eq 'out' or $shifting eq 'in') {
      my $adding = ($shifting eq 'out') ? -90 : 90;
      push (@pts,  &rad_point($pt, $delta, $bisecangle + $adding));
      push (@pts,  @{$pt});

    } else {
      push (@pts,  &rad_point($pt, $delta, $bisecangle-90));
      push (@pts,  &rad_point($pt, $delta, $bisecangle+90));

    }

    if ($i == $numfaces - 2) {
      $next = ($closed) ? $coords->[0] :
	[$coords->[$i+1]->[0] + ($coords->[$i+1]->[0] - $pt->[0]), $coords->[$i+1]->[1] + ($coords->[$i+1]->[1] - $pt->[1])];
    } else {
      $next = $coords->[$i+2];
    }

    $previous = $coords->[$i];
  }

  if ($closed) {
    push (@pts, ($pts[0], $pts[1], $pts[2], $pts[3]));
  }

  return \@pts;
}

#-----------------------------------------------------------------------------------
# Graphics::curveLineCoords
# retourne les coordonnées d'une curveLine
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> liste de coordonnées des points de la ligne
# options :
#    -closed : <boolean> ligne fermée
#  -shifting : <out|center|in> sens de décalage du contour (par défaut center)
# -linewidth : <dimension> epaisseur de la ligne
#-----------------------------------------------------------------------------------
sub curveLineCoords {
  my ($coords, %options) = @_;
  my $numfaces = scalar(@{$coords});
  my @gopts;
  my @backpts;
  my @pts;

  my $closed = $options{'-closed'};
  my $linewidth = (defined $options{'-linewidth'}) ? $options{'-linewidth'} : 2;
  my $shifting = ($options{'-shifting'}) ? $options{'-shifting'} : 'center';

  return undef if (!$numfaces or $linewidth < 2);

  my $previous = ($closed) ? $coords->[$numfaces - 1] : undef;
  my $next = $coords->[1];
  $linewidth /= 2 if ($shifting eq 'center');

  for (my $i = 0; $i < $numfaces; $i++) {
    my $pt = $coords->[$i];

    if (!$previous) {
      # extrémité de curve sans raccord -> angle plat
      $previous = [$pt->[0] + ($pt->[0] - $next->[0]), $pt->[1] + ($pt->[1] - $next->[1])];
    }

    my ($angle, $bisecangle) = &vertexAngle($previous, $pt, $next);

    # distance au centre du cercle inscrit : rayon/sinus demi-angle
    my $sin = sin(deg2rad($angle/2));
    my $delta = ($sin) ? abs($linewidth / $sin) : $linewidth;

    if ($shifting eq 'out' or $shifting eq 'in') {
      my $adding = ($shifting eq 'out') ? -90 : 90;
      push (@pts,  &rad_point($pt, $delta, $bisecangle + $adding));
      push (@pts,  @{$pt});

    } else {
      @pts = &rad_point($pt, $delta, $bisecangle+90);
      push (@gopts, \@pts);
      @pts = &rad_point($pt, $delta, $bisecangle-90);
      unshift (@backpts, \@pts);
    }

    if ($i == $numfaces - 2) {
      $next = ($closed) ? $coords->[0] :
	[$coords->[$i+1]->[0] + ($coords->[$i+1]->[0] - $pt->[0]), $coords->[$i+1]->[1] + ($coords->[$i+1]->[1] - $pt->[1])];
    } else {
      $next = $coords->[$i+2];
    }

    $previous = $coords->[$i];
  }

  push(@gopts, @backpts);

  if ($closed) {
    push (@gopts, ($gopts[0], $gopts[1]));
  }

  return \@gopts;
}


#-----------------------------------------------------------------------------------
# Graphics::shiftPathCoords
# retourne les coordonnées d'un décalage de path
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordsList> liste de coordonnées des points du path
# options :
#   -closed : <boolean> ligne fermée
# -shifting : <'out'|'in'> sens de décalage du path (par défaut out)
#    -width : <dimension> largeur de décalage (par défaut 1)
#-----------------------------------------------------------------------------------
sub shiftPathCoords {
  my ($coords, %options) = @_;
  my $numfaces = scalar(@{$coords});

  my $closed = $options{'-closed'};
  my $width = (defined $options{'-width'}) ? $options{'-width'} : 1;
  my $shifting = ($options{'-shifting'}) ? $options{'-shifting'} : 'out';

  return $coords if (!$numfaces or !$width);

  my @pts;

  my $previous = ($closed) ? $coords->[$numfaces - 1] : undef;
  my $next = $coords->[1];

  for (my $i = 0; $i < $numfaces; $i++) {
    my $pt = $coords->[$i];

    if (!$previous) {
      # extrémité de curve sans raccord -> angle plat
      $previous = [$pt->[0] + ($pt->[0] - $next->[0]), $pt->[1] + ($pt->[1] - $next->[1])];
    }

    my ($angle, $bisecangle) = &vertexAngle($previous, $pt, $next);

    # distance au centre du cercle inscrit : rayon/sinus demi-angle
    my $sin = sin(deg2rad($angle/2));
    my $delta = ($sin) ? abs($width / $sin) : $width;

    my $adding = ($shifting eq 'out') ? -90 : 90;
    my ($x, $y) = &rad_point($pt, $delta, $bisecangle + $adding);
    push (@pts,  [$x, $y]);


    if ($i > $numfaces - 3) {
      my $j = $numfaces - 1;
      $next = ($closed) ? $coords->[0] :
	[$pt->[0] + ($pt->[0] - $previous->[0]), $pt->[1] + ($pt->[1] - $previous->[1])];

    } else {
      $next = $coords->[$i+2];
    }

    $previous = $coords->[$i];
  }

  return \@pts;
}

#-----------------------------------------------------------------------------------
# Graphics::perpendicularPoint
# retourne les coordonnées du point perpendiculaire abaissé d'un point sur une ligne
#-----------------------------------------------------------------------------------
# paramètres :
# point : <coords> coordonnées du point de référence
#  line : <coordsList> coordonnées des 2 points de la ligne de référence
#-----------------------------------------------------------------------------------
sub perpendicularPoint {
  my ($point, $line) = @_;
  my ($p1, $p2) = @{$line};

  # cas partiuculier de lignes ortho.
  my $min_dist = .01;
  if (abs($p2->[1] - $p1->[1]) < $min_dist) {
    # la ligne de référence est horizontale
    return ($point->[0], $p1->[1]);

  } elsif (abs($p2->[0] - $p1->[0]) < $min_dist) {
    # la ligne de référence est verticale
    return ($p1->[0], $point->[1]);
  }

  my $a1 = ($p2->[1] - $p1->[1]) / ($p2->[0] - $p1->[0]);
  my $b1 = $p1->[1] - ($a1 * $p1->[0]);

  my $a2 = -1.0 / $a1;
  my $b2 = $point->[1] - ($a2 * $point->[0]);

  my $x = ($b2 - $b1) / ($a1 - $a2);
  my $y = ($a1 * $x) + $b1;

  return ($x, $y);

}


#-----------------------------------------------------------------------------------
# Graphics::lineAngle
# retourne l'angle d'un point par rapport à un centre de référence
#-----------------------------------------------------------------------------------
# paramètres :
# startpoint : <coords> coordonnées du point de départ du segment
#   endpoint : <coords> coordonnées du point d'extremité du segment
#-----------------------------------------------------------------------------------
sub lineAngle {
  my ($startpoint, $endpoint) = @_;
  my $angle = atan2($endpoint->[1] - $startpoint->[1], $endpoint->[0] - $startpoint->[0]);

  $angle += pi/2;
  $angle *= 180/pi;
  $angle += 360  if ($angle < 0);

  return $angle;

}


#-----------------------------------------------------------------------------------
# Graphics::lineNormal
# retourne la valeur d'angle perpendiculaire à une ligne
#-----------------------------------------------------------------------------------
# paramètres :
# startpoint : <coords> coordonnées du point de départ du segment
#   endpoint : <coords> coordonnées du point d'extremité du segment
#-----------------------------------------------------------------------------------
sub lineNormal {
  my ($startpoint, $endpoint) = @_;
  my $angle = &lineAngle($startpoint, $endpoint) + 90;

  $angle -= 360  if ($angle > 360);
  return $angle;

}



#-----------------------------------------------------------------------------------
# Graphics::vertexAngle
# retourne la valeur de l'angle formée par 3 points
# ainsi que l'angle de la bisectrice
#-----------------------------------------------------------------------------------
# paramètres :
# pt0 : <coords> coordonnées du premier point de définition de l'angle
# pt1 : <coords> coordonnées du deuxième point de définition de l'angle
# pt2 : <coords> coordonnées du troisième point de définition de l'angle
#-----------------------------------------------------------------------------------
sub vertexAngle {
  my ($pt0, $pt1, $pt2) = @_;
  my $angle1 = &lineAngle($pt0, $pt1);
  my $angle2 = &lineAngle($pt2, $pt1);

  $angle2 += 360 if $angle2 < $angle1;
  my $alpha = $angle2 - $angle1;
  my $bisectrice = $angle1 + ($alpha/2);

  return ($alpha, $bisectrice);
}


#-----------------------------------------------------------------------------------
# Graphics::arc_pts
# calcul des points constitutif d'un arc
#-----------------------------------------------------------------------------------
# paramètres :
#  center : <coordonnées> centre de l'arc,
#  radius : <dimension> rayon de l'arc,
# options :
#  -angle : <angle> angle de départ en degré de l'arc (par défaut 0)
# -extent : <angle> delta angulaire en degré de l'arc (par défaut 360),
#   -step : <dimension> pas de progresion en degré (par défaut 10)
#-----------------------------------------------------------------------------------
sub arc_pts {
    my ($center, $radius, %options) = @_;
    return unless ($radius);

    $center = [0, 0] if (!defined $center);
    my $angle = (defined $options{'-angle'}) ? $options{'-angle'} : 0;
    my $extent = (defined $options{'-extent'}) ? $options{'-extent'} : 360;
    my $step = (defined $options{'-step'}) ? $options{'-step'} : 10;
    my @pts = ();

    if ($extent > 0) {
	for (my $alpha = $angle; $alpha <= ($angle + $extent); $alpha += $step) {
	    my ($xn, $yn) = &rad_point($center, $radius,$alpha);
	    push (@pts, ([$xn, $yn]));
	}
    } else {
	for (my $alpha = $angle; $alpha >= ($angle + $extent); $alpha += $step) {
	    push (@pts, &rad_point($center, $radius, $alpha));
	}
    }

    return @pts;
}


#-----------------------------------------------------------------------------------
# Graphics::rad_point
# retourne le point circulaire défini par centre-rayon-angle
#-----------------------------------------------------------------------------------
# paramètres :
# center : <coordonnée> coordonnée [x,y] du centre de l'arc,
# radius : <dimension> rayon de l'arc,
#  angle : <angle> angle du point de circonférence avec le centre du cercle
#-----------------------------------------------------------------------------------
sub rad_point {
    my ($center, $radius, $angle) = @_;
    my $alpha = deg2rad($angle);

    my $xpt = $center->[0] + ($radius * cos($alpha));
    my $ypt = $center->[1] + ($radius * sin($alpha));

    return ($xpt, $ypt);
}


#-----------------------------------------------------------------------------------
# Graphics::curveItem2polylineCoords
# Conversion des coordonnées ZnItem curve (multicontours) en coordonnées polyline(s)
#-----------------------------------------------------------------------------------
# paramètres :
# widget : <widget> identifiant du widget zinc
#   item : <tagOrId> identifiant de l'item source
# options :
# -tunits : <integer> nombre pas de division des segments bezier (par défaut 20)
# -adjust : <boolean> ajustement de la courbe de bezier (par défaut 1)
#-----------------------------------------------------------------------------------
sub curveItem2polylineCoords {
  my ($widget, $item, %options) = @_;
  return unless ($widget and $widget->type($item));

  my @coords;
  my $numcontours = $widget->contour($item);
  my $parentgroup = $widget->group($item);

  for (my $contour = 0; $contour < $numcontours; $contour++) {
    my @points = $widget->coords($item, $contour);
    my @contourcoords = &curve2polylineCoords(\@points, %options);

    push(@coords, \@contourcoords);

  }

  return wantarray ? @coords : \@coords;
}

#-----------------------------------------------------------------------------------
# Graphics::curve2polylineCoords
# Conversion curve -> polygone
#-----------------------------------------------------------------------------------
# paramètres :
# points : <coordsList> liste des coordonnées curve à transformer
# options :
# -tunits : <integer> nombre pas de division des segments bezier (par défaut 20)
# -adjust : <boolean> ajustement de la courbe de bezier (par défaut 1)
#-----------------------------------------------------------------------------------
sub curve2polylineCoords {
  my ($points, %options) = @_;

  my $tunits = ($options{'-tunits'}) ? $options{'-tunits'} : 20;
  my $adjust = (defined $options{'-adjust'}) ? $options{'-adjust'} : 1;

  my @poly;
  my $previous;
  my @bseg;
  my $numseg = 0;
  my $prevtype;

  foreach my $point (@{$points}) {
    my ($x, $y, $c) = @{$point};
    if ($c eq 'c') {
      push(@bseg, $previous) if (!@bseg);
      push(@bseg, $point);

    } else {
      if (@bseg) {
	push(@bseg, $point);

	if ($adjust) {
	  my @pts = &bezierCompute(\@bseg, -skipend => 1);
	  shift @pts;
	  shift @pts;
	  push(@poly, @pts);

	} else {
	  my @pts = &bezierSegment(\@bseg, -tunits => $tunits, -skipend => 1);
	  shift @pts;
	  shift @pts;
	  push(@poly, @pts);

	}

	@bseg = ();
	$numseg++;
	$prevtype = 'bseg';

      } else {
	push(@poly, ([$x, $y]));
	$prevtype = 'line';
      }
    }

    $previous = $point;
  }


  return wantarray ? @poly : \@poly;
}


#-----------------------------------------------------------------------------------
# Graphics::buildTabBoxItem
# construit les items de représentations Zinc d'une boite à onglets
#-----------------------------------------------------------------------------------
# paramètres :
#      widget : <widget> identifiant du widget zinc
# parentgroup : <tagOrId> identifiant de l'item group parent
#
#    options :
#     -coords : <coordsList> coordonnées haut-gauche et bas-droite du rectangle
#               englobant du TabBox
#     -params : <hastable> arguments spécifiques des items curve à passer au widget
#    -texture : <imagefile> ajout d'une texture aux items curve
#  -tabtitles : <hashtable> table de hash de définition des titres onglets
#  -pageitems : <hashtable> table de hash de définition des pages internes
#     -relief : <hashtable> table de hash de définition du relief de forme
#
# (options de construction géometrique passées à tabBoxCoords)
#  -numpages : <integer> nombre de pages (onglets) de la boite
#    -anchor : <'n'|'e'|'s'|'w'> ancrage (positionnement) de la ligne d'onglets
# -alignment : <'left'|'center'|'right'> alignement des onglets sur le coté d'ancrage
#  -tabwidth : <'auto'>|<dimension>|<dimensionList> : largeur des onglets
#              'auto' largeur répartie, les largeurs sont auto-ajustée si besoin.
# -tabheight : <'auto'>|<dimension> : hauteur des onglets
#  -tabshift : <'auto'>|<dimension> offset de 'biseau' entre base et haut de l'onglet (défaut auto)
#    -radius : <dimension> rayon des arrondis d'angle
#   -overlap : <'auto'>|<dimension> offset de recouvrement/séparation entre onglets
#   -corners : <booleanList> liste 'spécifique' des raccords de sommets [0|1]
#-----------------------------------------------------------------------------------
sub buildTabBoxItem {
  my ($widget, $parentgroup, %options) = @_;
  my $coords = $options{'-coords'};
  my $params = $options{'-params'};
  my @tags = @{$params->{'-tags'}};
  my $texture;

  if ($options{'-texture'}) {
    $texture = &getTexture($widget, $options{'-texture'});
  }

  my $titlestyle = $options{'-tabtitles'};
  my $titles = ($titlestyle) ? $titlestyle->{'-text'} : undef ;

  return undef if (!$coords);

  my @tabs;
  my ($shapes, $tcoords, $invert) = &tabBoxCoords($coords, %options);
  my $k = ($invert) ? scalar @{$shapes} : -1;
  foreach my $shape (reverse @{$shapes}) {
    $k += ($invert) ? -1 : +1;
    my $group = $widget->add('group', $parentgroup);
    $params->{'-tags'} = [@tags, $k, 'intercalaire'];
    my $form = $widget->add('curve', $group, $shape, %{$params});
    $widget->itemconfigure($form, -tile => $texture) if $texture;

    if ($options{'-relief'}) {
      &graphicItemRelief($widget, $form, %{$options{'-relief'}});
    }

    if ($options{'-page'}) {
      my $page = &buildZincItem($widget, $group, %{$options{'-page'}});
    }	

    if ($titles) {
      my $tindex = ($invert) ? $k : $#{$shapes} - $k;
      $titlestyle->{'-itemtype'} = 'text';
      $titlestyle->{'-coords'} = $tcoords->[$tindex];
      $titlestyle->{'-params'}->{'-text'} = $titles->[$tindex],;
      $titlestyle->{'-params'}->{'-tags'} = [@tags, $tindex, 'titre'];
      &buildZincItem($widget, $group, %{$titlestyle});

    }


  }

  return @tabs;
}


#-----------------------------------------------------------------------------------
# tabBoxCoords
# Calcul des shapes de boites à onglets
#-----------------------------------------------------------------------------------
# paramètres :
# coords : <coordList> coordonnées haut-gauche bas-droite du rectangle englobant 
#          de la tabbox
# options
#  -numpages : <integer> nombre de pages (onglets) de la boite
#    -anchor : <'n'|'e'|'s'|'w'> ancrage (positionnement) de la ligne d'onglets
# -alignment : <'left'|'center'|'right'> alignement des onglets sur le coté d'ancrage
#  -tabwidth : <'auto'>|<dimension>|<dimensionList> : largeur des onglets
#              'auto' largeur répartie, les largeurs sont auto-ajustée si besoin.
# -tabheight : <'auto'>|<dimension> : hauteur des onglets
#  -tabshift : <'auto'>|<dimension> offset de 'biseau' entre base et haut de l'onglet (défaut auto)
#    -radius : <dimension> rayon des arrondis d'angle
#   -overlap : <'auto'>|<dimension> offset de recouvrement/séparation entre onglets
#   -corners : <booleanList> liste 'spécifique' des raccords de sommets [0|1]
#-----------------------------------------------------------------------------------
sub tabBoxCoords {
  my ($coords, %options) = @_;

  my ($x0, $y0, $xn, $yn) = (@{$coords->[0]}, @{$coords->[1]});
  my (@shapes, @titles_coords);
  my $inverse;

  my @options = keys(%options);
  my $numpages = $options{'-numpages'};

  if (!defined $x0 or !defined $y0 or !defined $xn or !defined $yn or !$numpages) {
    print "Vous devez au minimum spécifier le rectangle englobant et le nombre de pages\n";
    return undef;

  }

  my $anchor = ($options{'-anchor'}) ? $options{'-anchor'} : 'n';
  my $alignment = ($options{'-alignment'}) ? $options{'-alignment'} : 'left';
  my $len = ($options{'-tabwidth'}) ? $options{'-tabwidth'} : 'auto';
  my $thick = ($options{'-tabheight'}) ? $options{'-tabheight'} : 'auto';
  my $biso = ($options{'-tabshift'}) ? $options{'-tabshift'} : 'auto';
  my $radius = ($options{'-radius'}) ? $options{'-radius'} : 0;
  my $overlap = ($options{'-overlap'}) ? $options{'-overlap'} : 0;
  my $corners = $options{'-corners'};
  my $orientation = ($anchor eq 'n' or $anchor eq 's') ? 'horizontal' : 'vertical';
  my $maxwidth = ($orientation eq 'horizontal') ? ($xn - $x0) : ($yn - $y0);
  my $tabswidth = 0;
  my $align = 1;

  if ($len eq 'auto') {
    $tabswidth = $maxwidth;
    $len = ($tabswidth + ($overlap * ($numpages - 1)))/$numpages;

  } else {
    if (ref($len) eq 'ARRAY') {
      foreach my $w (@{$len}) {
	$tabswidth += ($w - $overlap);
      }
      $tabswidth += $overlap;
    } else {
      $tabswidth = ($len * $numpages) - ($overlap * ($numpages - 1));
    }

    if ($tabswidth > $maxwidth) {
      $tabswidth = $maxwidth;
      $len = ($tabswidth + ($overlap * ($numpages - 1)))/$numpages;
    }

    $align = 0 if ($alignment eq 'center' and (($maxwidth - $tabswidth) > $radius));
  }


  if ($thick eq 'auto') {
    $thick = ($orientation eq 'horizontal') ? int(($yn - $y0)/10) : int(($xn - $y0)/10);
    $thick = 10 if ($thick < 10);
    $thick = 40 if ($thick > 40);
  }

  if ($biso eq 'auto') {
    $biso = int($thick/2);
  }

  if (($alignment eq 'right' and $anchor ne 'w') or
      ($anchor eq 'w' and $alignment ne 'right')) {

    if (ref($len) eq 'ARRAY') {
      for (my $p = 0; $p < $numpages; $p++) {
	$len->[$p] *= -1;
      }
    } else {
      $len *= -1;
    }
    $biso *= -1;
    $overlap *= -1;
  }

  my ($biso1, $biso2) = ($alignment eq 'center') ? ($biso/2, $biso/2) : (0, $biso);

  my (@cadre, @tabdxy);
  my ($xref, $yref);
  if ($orientation eq 'vertical') {
    $thick *= -1 if ($anchor eq 'w');
    my ($startx, $endx) = ($anchor eq 'w') ? ($x0, $xn) : ($xn, $x0);
    my ($starty, $endy) = (($anchor eq 'w' and $alignment ne 'right') or 
			   ($anchor eq 'e' and $alignment eq 'right')) ? 
			     ($yn, $y0) : ($y0, $yn);

    $xref = $startx - $thick;
    $yref = $starty;
    if  ($alignment eq 'center') {
      my $ratio = ($anchor eq 'w') ? -2 : 2;
      $yref += (($maxwidth - $tabswidth)/$ratio);
    }

    @cadre = ([$xref, $endy], [$endx, $endy], [$endx, $starty], [$xref, $starty]);

    # flag de retournement de la liste des pts de curve si nécessaire -> sens anti-horaire
    $inverse = ($alignment ne 'right');

  } else {
    $thick *= -1 if ($anchor eq 's');
    my ($startx, $endx) = ($alignment eq 'right') ? ($xn, $x0) : ($x0, $xn);
    my ($starty, $endy) = ($anchor eq 's') ? ($yn, $y0) : ($y0, $yn);


    $yref = $starty + $thick;
    $xref = ($alignment eq 'center') ? $x0 + (($maxwidth - $tabswidth)/2) : $startx;

    @cadre = ([$endx, $yref], [$endx, $endy], [$startx, $endy], [$startx, $yref]);

    # flag de retournement de la liste des pts de curve si nécessaire -> sens anti-horaire
    $inverse = (($anchor eq 'n' and $alignment ne 'right') or ($anchor eq 's' and $alignment eq 'right'));
  }

  for (my $i = 0; $i < $numpages; $i++) {
    my @pts = ();

    # décrochage onglet
    #push (@pts, ([$xref, $yref])) if $i > 0;

    # cadre
    push (@pts, @cadre);

    # points onglets
    push (@pts, ([$xref, $yref])) if ($i > 0 or !$align);

    my $tw = (ref($len) eq 'ARRAY') ? $len->[$i] : $len;
    @tabdxy = ($orientation eq 'vertical') ?
      ([$thick, $biso1],[$thick, $tw - $biso2],[0, $tw]) : ([$biso1, -$thick],[$tw - $biso2, -$thick],[$tw, 0]);
    foreach my $dxy (@tabdxy) {
      push (@pts, ([$xref + $dxy->[0], $yref + $dxy->[1]]));
    }

    if ($radius) {
      if (!defined $options{'-corners'}) {
	$corners = ($i > 0 or !$align) ? [0, 1, 1, 0, 0, 1, 1, 0] : [0, 1, 1, 0, 1, 1, 0, 0, 0];
      }
      my $curvepts = &roundedCurveCoords(\@pts, -radius => $radius, -corners => $corners);
      @{$curvepts} = reverse @{$curvepts} if ($inverse);
      push (@shapes, $curvepts);
    } else {
      @pts = reverse @pts if ($inverse);
      push (@shapes, \@pts);
    }

    if ($orientation eq 'horizontal') {
      push (@titles_coords, [$xref + ($tw - ($biso2 - $biso1))/2, $yref - ($thick/2)]);
      $xref += ($tw - $overlap);

    } else {
      push (@titles_coords, [$xref + ($thick/2), $yref + ($len - (($biso2 - $biso1)/2))/2]);
      $yref += ($len - $overlap);
    }

  }

  return (\@shapes, \@titles_coords, $inverse);

}


#-----------------------------------------------------------------------------------
# Graphics::graphicItemRelief
# construit un relief à l'item Zinc en utilisant des items Triangles
#-----------------------------------------------------------------------------------
# paramètres :
#  widget : <widget> identifiant du widget zinc
#    item : <tagOrId> identifiant de l'item zinc
# options : <hash> table d'options
#     -closed : <boolean> le relief assure la fermeture de forme (défaut 1)
#     -profil : <'rounded'|'flat'> type de profil (defaut 'rounded')
#     -relief : <'raised'|'sunken'> (défaut 'raised')
#       -side : <'inside'|'outside'> relief interne ou externe à la forme (défaut 'inside')
#      -color : <color> couleur du relief (défaut couleur de la forme)
#   -smoothed : <boolean> facettes relief lissées ou non (défaut 1)
# -lightangle : <angle> angle d'éclairage (défaut valeur générale widget)
#      -width : <dimension> 'épaisseur' du relief en pixel
#       -fine : <boolean> mode précision courbe de bezier (défaut 0 : auto-ajustée)
#-----------------------------------------------------------------------------------
sub graphicItemRelief {
  my ($widget, $item, %options) = @_;
  my @items;

  # relief d'une liste d'items -> appel récursif
  if (ref($item) eq 'ARRAY') {
    foreach my $part (@{$item}) {
      push(@items, &graphicItemRelief($widget, $part, %options));
    }

  } else {
    my $itemtype = $widget->type($item);

    return unless ($itemtype);

    my $parentgroup = $widget->group($item);
    my $priority = (defined $options{'-priority'}) ? $options{'-priority'} :
      $widget->itemcget($item, -priority)+1;

    # coords transformés (polyline) de l'item
    my $adjust = !$options{'-fine'};
    foreach my $coords (&ZincItem2CurveCoords($widget, $item, -linear => 1,
					      -realcoords => 1,-adjust => $adjust)) {
      my ($pts, $colors) = &polylineReliefParams($widget, $item, $coords, %options);

      push(@items, $widget->add('triangles', $parentgroup, $pts,
				-priority => $priority,
				-colors => $colors));
    }


    # renforcement du contour
    if ($widget->itemcget($item, -linewidth)) {
      push(@items, $widget->clone($item, -filled => 0, -priority => $priority+1));
    }
  }

  return \@items;
}


#-----------------------------------------------------------------------------------
# Graphics::polylineReliefParams
# retourne la liste des points et des couleurs nécessaires à la construction
# de l'item Triangles du relief
#-----------------------------------------------------------------------------------
# paramètres :
#  widget : <widget> identifiant widget Zinc
#    item : <tagOrId> identifiant item Zinc
# options : <hash> table d'options
#     -closed : <boolean> le relief assure la fermeture de forme (défaut 1)
#     -profil : <'rounded'|'flat'> type de profil (defaut 'rounded')
#     -relief : <'raised'|'sunken'> (défaut 'raised')
#       -side : <'inside'|'outside'> relief interne ou externe à la forme (défaut 'inside')
#      -color : <color> couleur du relief (défaut couleur de la forme)
#   -smoothed : <boolean> facettes relief lissées ou non (défaut 1)
# -lightangle : <angle> angle d'éclairage (défaut valeur générale widget)
#      -width : <dimension> 'épaisseur' du relief en pixel
#-----------------------------------------------------------------------------------
sub polylineReliefParams {
  my ($widget, $item, $coords, %options) = @_;

  my $closed = (defined $options{'-closed'}) ? $options{'-closed'} : 1;
  my $profil = ($options{'-profil'}) ? $options{'-profil'} : 'rounded';
  my $relief = ($options{'-relief'}) ? $options{'-relief'} : 'raised';
  my $side = ($options{'-side'}) ? $options{'-side'} : 'inside';
  my $basiccolor = ($options{'-color'}) ? $options{'-color'} : &zincItemPredominantColor($widget, $item);
  my $smoothed = (defined $options{'-smooth'}) ? $options{'-smooth'} : 1;
  my $lightangle = (defined $options{'-lightangle'}) ? $options{'-lightangle'}
    : $widget->cget('-lightangle');

  my $width = $options{'-width'};
  if (!$width or $width < 1) {
    my ($x0, $y0, $x1, $y1) = $widget->bbox($item);
    $width = &_min($x1 -$x0, $y1 - $y0)/10;
    $width = 2 if ($width < 2);
  }

  my $numfaces = scalar(@{$coords});
  my $previous = ($closed) ? $coords->[$numfaces - 1] : undef;
  my $next = $coords->[1];

  my @pts;
  my @colors;
  my $alpha = 100;
  if ($basiccolor =~ /;/) {
    ($basiccolor, $alpha) = split /;/, $basiccolor;

  }

  $alpha /= 2 if (!($options{'-color'} =~ /;/) and $profil eq 'flat');

  my $reliefalphas = ($profil eq 'rounded') ? [0,$alpha] : [$alpha, $alpha];

  for (my $i = 0; $i < $numfaces; $i++) {
    my $pt = $coords->[$i];

    if (!$previous) {
      # extrémité de curve sans raccord -> angle plat
      $previous = [$pt->[0] + ($pt->[0] - $next->[0]), $pt->[1] + ($pt->[1] - $next->[1])];
    }

    my ($angle, $bisecangle) = &vertexAngle($previous, $pt, $next);

    # distance au centre du cercle inscrit : rayon/sinus demi-angle
    my $sin = sin(deg2rad($angle/2));
    my $delta = ($sin) ? abs($width / $sin) : $width;
    my $decal = ($side eq 'outside') ? -90 : 90;

    my @shift_pt = &rad_point($pt, $delta, $bisecangle+$decal);
    push (@pts,  @shift_pt);
    push (@pts,  @{$pt});

    if (!$smoothed and $i) {
      push (@pts, @shift_pt);
      push (@pts,  @{$pt});
    }

    my $faceangle = 360 -(&lineNormal($previous, $next)+90);

    my $light = abs($lightangle - $faceangle);
    $light = 360 - $light if ($light > 180);
    $light = 1 if $light < 1;

    my $lumratio = ($relief eq 'sunken') ? (180-$light)/180 : $light/180;

    if (!$smoothed and $i) {
      push(@colors, ($colors[-2],$colors[-1]));
    }

   if ($basiccolor) {
     # création des couleurs dérivées
     my $shade = &LightingColor($basiccolor, $lumratio);
     my $color0 = $shade.";".$reliefalphas->[0];
     my $color1 = $shade.";".$reliefalphas->[1];
     push(@colors, ($color0, $color1));

   } else {
      my $c = (255*$lumratio);
      my $color0 = &hexaRGBcolor($c, $c, $c, $reliefalphas->[0]);
      my $color1 = &hexaRGBcolor($c, $c, $c, $reliefalphas->[1]);
      push(@colors, ($color0, $color1));
    }

    if ($i == $numfaces - 2) {
      $next = ($closed) ? $coords->[0] :
	[$coords->[$i+1]->[0] + ($coords->[$i+1]->[0] - $pt->[0]), $coords->[$i+1]->[1] + ($coords->[$i+1]->[1] - $pt->[1])];
    } else {
      $next = $coords->[$i+2];
    }

    $previous = $coords->[$i];
  }

  if ($closed) {
    push (@pts, ($pts[0], $pts[1], $pts[2], $pts[3]));
    push (@colors, ($colors[0], $colors[1]));

    if (!$smoothed) {
      push (@pts, ($pts[0], $pts[1], $pts[2], $pts[3]));
      push (@colors, ($colors[0], $colors[1]));
    }

  }


  return (\@pts, \@colors);
}


#-----------------------------------------------------------------------------------
# Graphics::graphicItemShadow
# Création d'une ombre portée à l'item
#-----------------------------------------------------------------------------------
# paramètres :
#  widget : <widget> identifiant widget Zinc
#    item : <tagOrId> identifiant item Zinc
# options : <hash> table d'options
#    -opacity : <percent> opacité de l'ombre (défaut 50)
#     -filled : <boolean> remplissage totale de l'ombre (hors bordure) (defaut 1)
# -lightangle : <angle> angle d'éclairage (défaut valeur générale widget)
#   -distance : <dimension> distance de projection de l'ombre en pixel
#  -enlarging : <dimension> grossi de l'ombre portée en pixels (defaut 0)
#      -width : <dimension> taille de diffusion/diffraction (défaut 4)
#      -color : <color> couleur de l'ombre portée (défaut black)
#-----------------------------------------------------------------------------------
sub graphicItemShadow {
  my ($widget, $item, %options) = @_;
  my @items;

  # relief d'une liste d'items -> appel récursif
  if (ref($item) eq 'ARRAY') {
    foreach my $part (@{$item}) {
      push(@items, &graphicItemShadow($widget, $part, %options));
    }

    return \@items;

  } else {

    my $itemtype = $widget->type($item);

    return unless ($itemtype);

    # création d'un groupe à l'ombre portée
    my $parentgroup = ($options{'-parentgroup'}) ? $options{'-parentgroup'} :
      $widget->group($item);
    my $priority = (defined $options{'-priority'}) ? $options{'-priority'} :
      ($widget->itemcget($item, -priority))-1;
    $priority = 0 if ($priority < 0);

    my $shadow = $widget->add('group', $parentgroup, -priority => $priority);

    if ($itemtype eq 'text') {
      my $opacity = (defined $options{'-opacity'}) ? $options{'-opacity'} : 50;
      my $color = ($options{'-color'}) ? $options{'-color'} : '#000000';

      my $clone = $widget->clone($item, -color => $color.";".$opacity);
      $widget->chggroup($clone, $shadow);

    } else {

      # création des items (de dessin) de l'ombre
      my $filled = (defined $options{'-filled'}) ? $options{'-filled'} : 1;

      # coords transformés (polyline) de l'item
      foreach my $coords (&ZincItem2CurveCoords($widget, $item, -linear => 1, -realcoords => 1)) {
	my ($t_pts, $i_pts, $colors) = &polylineShadowParams($widget, $item, $coords, %options);

	# option filled : remplissage hors bordure de l'ombre portée (item curve)
	if ($filled) {
	  if (@items) {
	    $widget->contour($items[0], 'add', 0, $i_pts);
	
	  } else {
	    push(@items, $widget->add('curve', $shadow, $i_pts,
				      -linewidth => 0,
				      -filled => 1,
				      -fillcolor => $colors->[0],
				     ));
	  }
	}
	
	# bordure de diffusion de l'ombre (item triangles)
	push(@items, $widget->add('triangles', $shadow, $t_pts,
			      -colors => $colors));
      }
    }

    # positionnement de l'ombre portée
    my $distance = (defined $options{'-distance'}) ? $options{'-distance'} : 10;
    my $lightangle = (defined $options{'-lightangle'}) ? $options{'-lightangle'}
      : $widget->cget('-lightangle');

    my ($dx, $dy) = &rad_point([0, 0], $distance, $lightangle+180);
    $widget->translate($shadow, $dx, -$dy);

    return $shadow;

  }

}


#-----------------------------------------------------------------------------------
# Graphics::polylineShadowParams
# retourne les listes des points et de couleurs nécessaires à la construction des
# items triangles (bordure externe) et curve (remplissage interne) de l'ombre portée
#-----------------------------------------------------------------------------------
# paramètres :
#  widget : <widget> identifiant widget Zinc
#    item : <tagOrId> identifiant item Zinc
# options : <hash> table d'options
#    -opacity : <percent> opacité de l'ombre (défaut 50)
# -lightangle : <angle> angle d'éclairage (défaut valeur générale widget)
#   -distance : <dimension> distance de projection de l'ombre en pixel (défaut 10)
#  -enlarging : <dimension> grossi de l'ombre portée en pixels (defaut 2)
#      -width : <dimension> taille de diffusion/diffraction (défaut distance -2)
#      -color : <color> couleur de l'ombre portée (défaut black)
#-----------------------------------------------------------------------------------
sub polylineShadowParams {
  my ($widget, $item, $coords, %options) = @_;

  my $distance = (defined $options{'-distance'}) ? $options{'-distance'} : 10;
  my $width = (defined $options{'-width'}) ? $options{'-width'} : $distance-2;
  my $opacity = (defined $options{'-opacity'}) ? $options{'-opacity'} : 50;
  my $color = ($options{'-color'}) ? $options{'-color'} : '#000000';
  my $enlarging = (defined $options{'-enlarging'}) ? $options{'-enlarging'} : 2;

  if ($enlarging) {
    $coords = &shiftPathCoords($coords, -width => $enlarging, -closed => 1, -shifting => 'out');
  }

  my $numfaces = scalar(@{$coords});
  my $previous = $coords->[$numfaces - 1];
  my $next = $coords->[1];

  my @t_pts;
  my @i_pts;
  my @colors;
  my ($color0, $color1) = ($color.";$opacity", $color.";0");

  for (my $i = 0; $i < $numfaces; $i++) {
    my $pt = $coords->[$i];

    if (!$previous) {
      # extrémité de curve sans raccord -> angle plat
      $previous = [$pt->[0] + ($pt->[0] - $next->[0]), $pt->[1] + ($pt->[1] - $next->[1])];
    }

    my ($angle, $bisecangle) = &vertexAngle($previous, $pt, $next);

    # distance au centre du cercle inscrit : rayon/sinus demi-angle
    my $sin = sin(deg2rad($angle/2));
    my $delta = ($sin) ? abs($width / $sin) : $width;
    my $decal = 90;

    my @shift_pt = &rad_point($pt, $delta, $bisecangle+$decal);
    push (@i_pts,  @shift_pt);
    push (@t_pts,  @shift_pt);
    push (@t_pts,  @{$pt});

    push(@colors, ($color0, $color1));

    if ($i == $numfaces - 2) {
      $next = $coords->[0];
    } else {
      $next = $coords->[$i+2];
    }

    $previous = $coords->[$i];
  }

  # fermeture
  push(@t_pts, ($t_pts[0], $t_pts[1],$t_pts[2],$t_pts[3]));
  push(@i_pts, ($t_pts[0], $t_pts[1]));
  push(@colors, ($color0, $color1,$color0,$color1));

  return (\@t_pts, \@i_pts, \@colors);
}


#-----------------------------------------------------------------------------------
# Graphics::bezierSegment
# Calcul d'une approximation de segment (Quadratique ou Cubique) de bezier
#-----------------------------------------------------------------------------------
# paramètres :
#    points : <[P1, C1, <C1>, P2]> liste des points définissant le segment de bezier
#
# options :
#  -tunits : <integer> nombre pas de division des segments bezier (par défaut 20)
# -skipend : <boolean> : ne pas retourner le dernier point du segment (chainage)
#-----------------------------------------------------------------------------------
sub bezierSegment {
  my ($coords, %options) = @_;
  my $tunits = ($options{'-tunits'}) ? $options{'-tunits'} : 20;
  my $skipendpt = $options{'-skipend'};

  my @pts;

  my $lastpt = ($skipendpt) ? $tunits-1 : $tunits;
  foreach (my $i = 0; $i <= $lastpt; $i++) {
    my $t = ($i) ? ($i/$tunits) : $i;
    push(@pts, &bezierPoint($t, $coords));
  }

  return wantarray ? @pts : \@pts;

}


#-----------------------------------------------------------------------------------
# Graphics::bezierPoint
# calcul d'un point du segment (Quadratique ou Cubique) de bezier
# params :
# t = <n> (représentation du temps : de 0 à 1)
# coords = (P1, C1, <C1>, P2) liste des points définissant le segment de bezier
# P1 et P2 : extémités du segment et pts situés sur la courbe
# C1 <C2> : point(s) de contrôle du segment
#-----------------------------------------------------------------------------------
# courbe bezier niveau 2 sur (P1, P2, P3)
# P(t) = (1-t)²P1 + 2t(1-t)P2 + t²P3
#
# courbe bezier niveau 3 sur (P1, P2, P3, P4)
# P(t) = (1-t)³P1 + 3t(1-t)²P2 + 3t²(1-t)P3 + t³P4
#-----------------------------------------------------------------------------------
sub bezierPoint {
  my ($t, $coords) = @_;
  my ($p1, $c1, $c2, $p2) = @{$coords};

  # quadratique
  if (!defined $p2) {
    $p2 = $c2;
    $c2 = undef;
  }

  # extrémités : points sur la courbe
  return wantarray ? @{$p1} : $p1 if (!$t);
  return wantarray ? @{$p2} : $p2 if ($t >= 1.0);


  my $t2 = $t * $t;
  my $t3 = $t2 * $t;
  my @pt;

  # calcul pour x et y
  foreach my $i (0, 1) {

    if (defined $c2) {
      my $r1 = (1 - (3*$t) + (3*$t2) -    $t3)  * $p1->[$i];
      my $r2 = (    (3*$t) - (6*$t2) + (3*$t3)) * $c1->[$i];
      my $r3 = (             (3*$t2) - (3*$t3)) * $c2->[$i];
      my $r4 = (                          $t3)  * $p2->[$i];

      $pt[$i] = ($r1 + $r2 + $r3 + $r4);

    } else {
      my $r1 = (1 - (2*$t) +    $t2)  * $p1->[$i];
      my $r2 = (    (2*$t) - (2*$t2)) * $c1->[$i];
      my $r3 = (                $t2)  * $p2->[$i];

      $pt[$i] = ($r1 + $r2 + $r3);
    }
  }

  #return wantarray ? @pt : \@pt;
  return \@pt;

}


#-----------------------------------------------------------------------------------
# Graphics::bezierCompute
# Retourne une liste de coordonnées décrivant un segment de bezier
#-----------------------------------------------------------------------------------
# paramètres :
#     coords : <coordsList> liste des points définissant le segment de bezier
#
# options :
# -precision : <dimension> seuil limite du calcul d'approche de la courbe
#   -skipend : <boolean> : ne pas retourner le dernier point du segment (chaînage bezier)
#-----------------------------------------------------------------------------------
sub bezierCompute {
  my ($coords, %options) = @_;
  my $precision = ($options{'-precision'}) ? $options{'-precision'} : $bezierClosenessThreshold;
  my $lastit = [];

  &subdivideBezier($coords, $lastit, $precision);

  push(@{$lastit}, $coords->[3]) if (!$options{'-skipend'});

  return wantarray ? @{$lastit} : $lastit;
}

#------------------------------------------------------------------------------------
# Graphics::smallEnought
# intégration code Stéphane Conversy : calcul points bezier (précision auto ajustée)
#------------------------------------------------------------------------------------
# distance is something like num/den with den=sqrt(something)
# what we want is to test that distance is smaller than precision,
# so we have distance < precision ?  eq. to distance^2 < precision^2 ?
# eq. to (num^2/something) < precision^2 ?
# eq. to num^2 < precision^2*something
# be careful with huge values though (hence 'long long')
# with common values: 9add 9mul
#------------------------------------------------------------------------------------
sub smallEnoughBezier {
  my ($bezier, $precision) = @_;
  my ($x, $y) = (0, 1);
  my ($A, $B) = ($bezier->[0], $bezier->[3]);

  my $den = (($A->[$y]-$B->[$y])*($A->[$y]-$B->[$y])) + (($B->[$x]-$A->[$x])*($B->[$x]-$A->[$x]));
  my $p = $precision*$precision;

  # compute distance between P1|P2 and P0|P3
  my $M = $bezier->[1];
  my $num1 = (($M->[$x]-$A->[$x])*($A->[$y]-$B->[$y])) + (($M->[$y]-$A->[$y])*($B->[$x]-$A->[$x]));

  $M = $bezier->[2];
  my $num2 = (($M->[$x]-$A->[$x])*($A->[$y]-$B->[$y])) + (($M->[$y]-$A->[$y])*($B->[$x]-$A->[$x]));

  # take the max
  $num1 = $num2 if ($num2 > $num1);

  return ($p*$den > ($num1*$num1)) ? 1 : 0;

}

#-----------------------------------------------------------------------------------
# Graphics::subdivideBezier
# subdivision d'une courbe de bezier
#-----------------------------------------------------------------------------------
sub subdivideBezier {
  my ($bezier, $it, $precision, $integeropt) = @_;
  my ($b0, $b1, $b2, $b3) = @{$bezier};

  if (&smallEnoughBezier($bezier, $precision)) {
    push(@{$it}, ([$b0->[0],$b0->[1]]));

  } else {
    my ($left, $right);

    foreach my $i (0, 1) {

      if ($integeropt) {
	# int optimized (6+3=9)add + (5+3=8)shift

	$left->[0][$i] = $b0->[$i];
	$left->[1][$i] = ($b0->[$i] + $b1->[$i]) >> 1;
	$left->[2][$i] = ($b0->[$i] + $b2->[$i] + ($b1->[$i] << 1)) >> 2; # keep precision
	my $tmp = ($b1->[$i] + $b2->[$i]);
	$left->[3][$i] = ($b0->[$i] + $b3->[$i] + ($tmp << 1) + $tmp) >> 3;

	$right->[3][$i] = $b3->[$i];
	$right->[2][$i] = ($b3->[$i] + $b2->[$i]) >> 1;
	$right->[1][$i] = ($b3->[$i] + $b1->[$i] + ($b2->[$i] << 1) ) >> 2; # keep precision
	$right->[0][$i] = $left->[3]->[$i];

      } else {
	# float

	$left->[0][$i] = $b0->[$i];
	$left->[1][$i] = ($b0->[$i] + $b1->[$i]) / 2;
	$left->[2][$i] = ($b0->[$i] + (2*$b1->[$i]) + $b2->[$i]) / 4;
	$left->[3][$i] = ($b0->[$i] + (3*$b1->[$i]) + (3*$b2->[$i]) + $b3->[$i]) / 8;

	$right->[3][$i] = $b3->[$i];
	$right->[2][$i] = ($b3->[$i] + $b2->[$i]) / 2;
	$right->[1][$i] = ($b3->[$i] + (2*$b2->[$i]) + $b1->[$i]) / 4;
	$right->[0][$i] = ($b3->[$i] + (3*$b2->[$i]) + (3*$b1->[$i]) + $b0->[$i]) / 8;

      }
    }

    &subdivideBezier($left, $it, $precision, $integeropt);
    &subdivideBezier($right, $it, $precision, $integeropt);

  }
}



#-----------------------------------------------------------------------------------
# RESOURCES GRAPHIQUES PATTERNS, TEXTURES, IMAGES, GRADIENTS, COULEURS...
#-----------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
# Graphics::getPattern
# retourne la ressource bitmap en l'initialisant si première utilisation
#-----------------------------------------------------------------------------------
# paramètres :
# filename : nom du fichier bitmap pattern
# options
# -storage : <hastable> référence de la table de stockage de patterns
#-----------------------------------------------------------------------------------
sub getPattern {
  my ($filename, %options) = @_;
  my $table = (defined $options{'-storage'} and ref($options{'-storage'}) eq 'HASH') ? 
    $options{'-storage'} : \%bitmaps;

  if (!exists($table->{$filename})) {
    my $bitmap = '@'.Tk::findINC($filename);
    $table->{$filename} = $bitmap if $bitmap;

  }

  return $table->{$filename};
}

#-----------------------------------------------------------------------------------
# Graphics::getTexture
# retourne l'image de texture en l'initialisant si première utilisation
#-----------------------------------------------------------------------------------
# paramètres :
#   widget : <widget> identifiant du widget zinc
# filename : nom du fichier texture
# options
# -storage : <hastable> référence de la table de stockage de textures
#-----------------------------------------------------------------------------------
sub getTexture {
  my ($widget, $filename, %options) = @_;
  my $table = (defined $options{'-storage'} and ref($options{'-storage'}) eq 'HASH') ? 
    $options{'-storage'} : \%textures;

  return &getImage($widget, $filename, -storage => $table);

}

#-----------------------------------------------------------------------------------
# Graphics::getImage
# retourne la ressource image en l'initialisant si première utilisation
#-----------------------------------------------------------------------------------
# paramètres :
#   widget : <widget> identifiant du widget zinc
# filename : nom du fichier image
# options
# -storage : <hastable> référence de la table de stockage d'images
#-----------------------------------------------------------------------------------
sub getImage {
  my ($widget, $filename, %options) = @_;
  my $table = (defined $options{'-storage'} and ref($options{'-storage'}) eq 'HASH') ? 
    $options{'-storage'} : \%images;

  if (!exists($table->{$filename})) {
    my $image;
    if ($filename =~ /.png|.PNG/) {
      $image = $widget->Photo(-format => 'png', -file => Tk::findINC($filename));

    } elsif ($filename =~ /.jpg|.JPG|.jpeg|.JPEG/) {
      $image = $widget->Photo(-format => 'jpeg', -file => Tk::findINC($filename));

    } else {
      $image = $widget->Photo(-file => Tk::findINC($filename));
    }

    $table->{$filename} = $image if $image;

  }

  return $table->{$filename};

}


#-----------------------------------------------------------------------------------
# Graphics::init_pixmaps
# initialise une liste de fichier image
#-----------------------------------------------------------------------------------
# paramètres :
#    widget : <widget> identifiant du widget zinc
# filenames : <filenameList> list des noms des fichier image
# options
#  -storage : <hastable> référence de la table de stockage d'images
#-----------------------------------------------------------------------------------
sub init_pixmaps {
  my ($widget, $filenames, %options) = @_;
  my @imgs = ();

  my @files = (ref($filenames) eq 'ARRAY') ? @{$filenames} : ($filenames);

  foreach (@files) {
    push(@imgs, &getImage($widget, $_, %options));
  }

  return @imgs;
}


#-----------------------------------------------------------------------------------
# Graphics::_min
# retourne la plus petite valeur entre 2 valeurs
#-----------------------------------------------------------------------------------
sub _min {
  my ($n1, $n2) = @_;
  my $mini = ($n1 > $n2) ? $n2 : $n1;
  return $mini;

}

#-----------------------------------------------------------------------------------
# Graphics::_max
# retourne la plus grande valeur entre 2 valeurs
#-----------------------------------------------------------------------------------
sub _max {
  my ($n1, $n2) = @_;
  my $maxi = ($n1 > $n2) ? $n1 : $n2;
  return $maxi;

}

#-----------------------------------------------------------------------------------
# Graphics::_trunc
# fonction interne de troncature des nombres: n = position décimale 
#-----------------------------------------------------------------------------------
sub _trunc {
  my ($val, $n) = @_;
  my $str;
  my $dec;

  ($val) =~ /([0-9]+)\.?([0-9]*)/;
  $str = ($val < 0) ? "-$1" : $1;

  if (($2 ne "") && ($n != 0)) {
    $dec = substr($2, 0, $n);
    if ($dec != 0) {
      $str = $str . "." . $dec;
    }
  }
  return $str;
}

#-----------------------------------------------------------------------------------
# Graphics::setGradients
# création de gradient nommés Zinc
#-----------------------------------------------------------------------------------
# paramètres :
#   widget : <widget> identifiant du widget zinc
#    grads : <hastable> table de hash de définition de couleurs zinc
#-----------------------------------------------------------------------------------
sub setGradients {
  my ($widget, $grads) = @_;

  # initialise les gradients de taches
  unless (@Gradients) {
    while (my ($name, $gradient) = each( %{$grads})) {
      # création des gradients nommés
      $widget->gname($gradient, $name);
      push(@Gradients, $name);
    }
  }
}


#-----------------------------------------------------------------------------------
# Graphics::RGB_dec2hex
# conversion d'une couleur RGB (255,255,255) au format Zinc '#ffffff'
#-----------------------------------------------------------------------------------
# paramètres :
#  rgb : <rgbColorList> liste de couleurs au format RGB
#-----------------------------------------------------------------------------------
sub RGB_dec2hex {
   my (@rgb) = @_;
   return (sprintf("#%04x%04x%04x", @rgb));
}

#-----------------------------------------------------------------------------------
# Graphics::pathGraduate
# création d'un jeu de couleurs dégradées pour item pathLine
#-----------------------------------------------------------------------------------
sub pathGraduate {
  my ($widget, $numcolors, $style) = @_;

  my $type = $style->{'-type'};
  my $triangles_colors;

  if ($type eq 'linear') {
    return &createGraduate($widget, $numcolors, $style->{'-colors'}, 2);

  } elsif ($type eq 'double') {
    my $colors1 = &createGraduate($widget, $numcolors/2+1, $style->{'-colors'}->[0]);
    my $colors2 = &createGraduate($widget, $numcolors/2+1, $style->{'-colors'}->[1]);
    my @colors;
    for (my $i = 0; $i <= $numcolors; $i++) {
      push(@colors, ($colors1->[$i], $colors2->[$i]));
    }

    return \@colors;

  } elsif ($type eq 'transversal') {
    my ($c1, $c2) = @{$style->{'-colors'}};
    my @colors = ($c1, $c2);
    for (my $i = 0; $i < $numcolors; $i++) {
      push(@colors, ($c1, $c2));
    }

    return \@colors;
  }
}

#-----------------------------------------------------------------------------------
# Graphics::createGraduate
# création d'un jeu de couleurs intermédiaires (dégradé) entre n couleurs
#-----------------------------------------------------------------------------------
sub createGraduate {
  my ($widget, $totalsteps, $refcolors, $repeat) = @_;
  my @colors;

  $repeat = 1 if (!$repeat);
  my $numgraduates = scalar @{$refcolors} - 1;

  if ($numgraduates < 1) {
    print "Le dégradé necessite au minimum 2 couleurs de référence...\n";
    return undef;
  }

  my $steps = ($numgraduates > 1) ? $totalsteps/($numgraduates -1) : $totalsteps;

  for (my $c = 0; $c < $numgraduates; $c++) {
    my ($c1, $c2) = ($refcolors->[$c], $refcolors->[$c+1]);

    for (my $i = 0 ; $i < $steps ; $i++) {
      my $color = MedianColor($c1, $c2, $i/($steps-1));
      for (my $k = 0; $k < $repeat; $k++) {
	push (@colors, $color);
      }
    }

    if ($c < $numgraduates - 1) {
      for (my $k = 0; $k < $repeat; $k++) {
	pop @colors;
      }
    }
  }

  return \@colors;
}

#-----------------------------------------------------------------------------------
# Graphics::LightingColor
# modification d'une couleur par sa composante luminosité
#-----------------------------------------------------------------------------------
# paramètres :
#  color : <color> couleur au format zinc
#   newL : <pourcent> (de 0 à 1) nouvelle valeur de luminosité
#-----------------------------------------------------------------------------------
sub LightingColor {
    my ($color, $newL) = @_;
    my ($H, $L, $S);

    if ($color and $newL) {
      my ($RGB) = &hexa2RGB($color);
      ($H, $L, $S) = @{&RGBtoHLS(@{$RGB})};


      $newL = 1 if $newL > 1;		
      my ($nR, $nG, $nB) = @{&HLStoRGB($H, $newL, $S)};
      return &hexaRGBcolor($nR*255, $nG*255, $nB*255);
	
    }

    return undef;
}


#-----------------------------------------------------------------------------------
# Graphics::zincItemPredominantColor
# retourne la couleur dominante d'un item ('barycentre' gradiant fillcolor)
#-----------------------------------------------------------------------------------
# paramètres :
#  widget : <widget> identifiant du widget zinc
#    item : <tagOrId> identifiant de l'item zinc
#-----------------------------------------------------------------------------------
sub zincItemPredominantColor {
  my ($widget, $item) = @_;
  my $type = $widget->type($item);

  if ($type eq 'text' or '$type' eq 'icon') {
    return $widget->itemcget($item, -color);

  } elsif ($type eq 'triangles' or
	   $type eq 'rectangle' or
	   $type eq 'arc' or
	   $type eq 'curve') {

    my @colors;

    if ($type eq 'triangles') {
      @colors =  $widget->itemcget($item, -colors);

    } else {
      my $grad =  $widget->itemcget($item, -fillcolor);
      
      return $grad if (scalar (my @unused = (split / /, $grad)) < 2);
	
      my @colorparts = split /\|/, $grad;
      foreach my $section (@colorparts) {
	if ($section !~ /=/) {
	  my ($color, $director, $position) = split / /, $section;
	  push (@colors, $color);
	}
      }
    }
	

    my ($Rs, $Gs, $Bs, $As, $numcolors) = (0, 0, 0, 0, 0);
    foreach my $color (@colors) {
      my ($r, $g, $b, $a) = ZnColorToRGB($color);
      $Rs += $r;
      $Gs += $g;
      $Bs += $b;
      $As += $a;
      $numcolors++;
    }

    my $newR = int($Rs/$numcolors);
    my $newG = int($Gs/$numcolors);
    my $newB = int($Bs/$numcolors);
    my $newA = int($As/$numcolors);

    my $newcolor = &hexaRGBcolor($newR, $newG, $newB, $newA);

    return $newcolor

  } else {
    return '#777777';
  }
}

#-----------------------------------------------------------------------------------
# Graphics::MedianColor
# calcul d'une couleur intermédiaire défini par un ratio ($rate) entre 2 couleurs
#-----------------------------------------------------------------------------------
# paramètres :
#  color1 : <color> première couleur zinc
#  color2 : <color> seconde couleur zinc
#    rate : <pourcent> (de 0  à 1) position de la couleur intermédiaire
#-----------------------------------------------------------------------------------
sub MedianColor {
  my ($color1, $color2, $rate) = @_;
  $rate = 1 if ($rate > 1);
  $rate = 0 if ($rate < 0);

  my ($r0, $g0, $b0, $a0) = &ZnColorToRGB($color1);
  my ($r1, $g1, $b1, $a1) = &ZnColorToRGB($color2);

  my $r = $r0 + int(($r1 - $r0) * $rate);
  my $g = $g0 + int(($g1 - $g0) * $rate);
  my $b = $b0 + int(($b1 - $b0) * $rate);
  my $a = $a0 + int(($a1 - $a0) * $rate);

  return &hexaRGBcolor($r, $g, $b, $a);
}


#-----------------------------------------------------------------------------------
# Graphics::ZnColorToRGB
# conversion d'une couleur Zinc au format RGBA (255,255,255,100)
#-----------------------------------------------------------------------------------
# paramètres :
#  zncolor : <color> couleur au format hexa zinc (#ffffff ou #ffffffffffff)
#-----------------------------------------------------------------------------------
sub ZnColorToRGB {
  my ($zncolor) = @_;

  my ($color, $alpha) = split /;/, $zncolor;
  my $ndigits = (length($color) > 8) ? 4 : 2;
  my $R = hex(substr($color, 1, $ndigits));
  my $G = hex(substr($color, 1+$ndigits, $ndigits));
  my $B = hex(substr($color, 1+($ndigits*2), $ndigits));

  $alpha = 100 if (!defined $alpha or $alpha eq "");

  return ($R, $G, $B, $alpha);

}

#-----------------------------------------------------------------------------------
# ALGORYTHMES DE CONVERSION ENTRE ESPACES DE COULEURS
#-----------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
# Graphics::RGBtoLCH
# Algorythme de conversion RGB -> CIE LCH°
#-----------------------------------------------------------------------------------
# paramètres :
#  r : <pourcent> (de 0 à 1) valeur de la composante rouge de la couleur RGB
#  g : <pourcent> (de 0 à 1) valeur de la composante verte de la couleur RGB
#  b : <pourcent> (de 0 à 1) valeur de la composante bleue de la couleur RGB
#-----------------------------------------------------------------------------------
sub  RGBtoLCH {
  my ($r, $g, $b) = @_;

  # Conversion RGBtoXYZ
  my $gamma = 2.4;
  my $rgblimit = 0.03928;


  $r = ($r > $rgblimit) ? (($r + 0.055)/1.055)**$gamma : $r / 12.92;
  $g = ($g > $rgblimit) ? (($g + 0.055)/1.055)**$gamma : $g / 12.92;
  $b = ($b > $rgblimit) ? (($b + 0.055)/1.055)**$gamma : $b / 12.92;

  $r *= 100;
  $g *= 100;
  $b *= 100;

  my $X = (0.4124 * $r) + (0.3576 * $g) + (0.1805 * $b);
  my $Y = (0.2126 * $r) + (0.7152 * $g) + (0.0722 * $b);
  my $Z = (0.0193 * $r) + (0.1192 * $g) + (0.9505 * $b);


  # Conversion XYZtoLab
  $gamma = 1/3;
  my ($L, $A, $B);

  if ($Y == 0) {
    ($L, $A, $B) = (0, 0, 0);

  } else {

    my ($Xs, $Ys, $Zs) = ($X/$Xw, $Y/$Yw, $Z/$Zw);
	
    $Xs = ($Xs > 0.008856) ? $Xs**$gamma : (7.787 * $Xs) + (16/116);
    $Ys = ($Ys > 0.008856) ? $Ys**$gamma : (7.787 * $Ys) + (16/116);
    $Zs = ($Zs > 0.008856) ? $Zs**$gamma : (7.787 * $Zs) + (16/116);

    $L = (116.0 * $Ys) - 16.0;

    $A = 500 * ($Xs - $Ys);
    $B = 200 * ($Ys - $Zs);

  }

  # conversion LabtoLCH 
  my ($C, $H);


  if ($A == 0) {
    $H = 0;

  } else {

    $H = atan2($B, $A);
	
    if ($H > 0) {
      $H = ($H / pi) * 180;

    } else {
      $H = 360 - ( abs($H) / pi) * 180
    }
  }


  $C = sqrt($A**2 + $B**2);

  return [$L, $C, $H];

}


#-----------------------------------------------------------------------------------
# Graphics::LCHtoRGB
# Algorythme de conversion CIE L*CH -> RGB
#-----------------------------------------------------------------------------------
# paramètres :
#  L : <pourcent> (de 0 à 1) valeur de la composante luminosité de la couleur CIE LCH
#  C : <pourcent> (de 0 à 1) valeur de la composante saturation de la couleur CIE LCH
#  H : <pourcent> (de 0 à 1) valeur de la composante teinte de la couleur CIE LCH
#-----------------------------------------------------------------------------------
sub LCHtoRGB {
  my ($L, $C, $H) = @_;
  my ($a, $b);

  # Conversion LCHtoLab
  $a = cos( deg2rad($H)) * $C;
  $b = sin( deg2rad($H)) * $C;

  # Conversion LabtoXYZ
  my $gamma = 3;
  my ($X, $Y, $Z);

  my $Ys = ($L + 16.0) / 116.0;
  my $Xs = ($a / 500) + $Ys;
  my $Zs = $Ys - ($b / 200);


  $Ys = (($Ys**$gamma) > 0.008856) ? $Ys**$gamma : ($Ys - 16 / 116) / 7.787;
  $Xs = (($Xs**$gamma) > 0.008856) ? $Xs**$gamma : ($Xs - 16 / 116) / 7.787;
  $Zs = (($Zs**$gamma) > 0.008856) ? $Zs**$gamma : ($Zs - 16 / 116) / 7.787;


  $X = $Xw * $Xs;
  $Y = $Yw * $Ys;
  $Z = $Zw * $Zs;

  # Conversion XYZtoRGB
  $gamma = 1/2.4;
  my $rgblimit = 0.00304;
  my ($R, $G, $B);


  $X /= 100;
  $Y /= 100;
  $Z /= 100;

  $R = (3.2410 * $X) + (-1.5374 * $Y) + (-0.4986 * $Z);
  $G = (-0.9692 * $X) + (1.8760 * $Y) + (0.0416 * $Z);
  $B = (0.0556 * $X) + (-0.2040 * $Y) + (1.0570 * $Z);

  $R = ($R > $rgblimit) ? (1.055 * ($R**$gamma)) - 0.055 : (12.92 * $R);
  $G = ($G > $rgblimit) ? (1.055 * ($G**$gamma)) - 0.055 : (12.92 * $G);
  $B = ($B > $rgblimit) ? (1.055 * ($B**$gamma)) - 0.055 : (12.92 * $B);

  $R = ($R < 0) ? 0 : ($R > 1.0) ? 1.0 : &_trunc($R, 5);
  $G = ($G < 0) ? 0 : ($G > 1.0) ? 1.0 : &_trunc($G, 5);
  $B = ($B < 0) ? 0 : ($B > 1.0) ? 1.0 : &_trunc($B, 5);

  return [$R, $G, $B];

}

#-----------------------------------------------------------------------------------
# Graphics::RGBtoHLS
# Algorythme de conversion RGB -> HLS
#-----------------------------------------------------------------------------------
#  r : <pourcent> (de 0 à 1) valeur de la composante rouge de la couleur RGB
#  g : <pourcent> (de 0 à 1) valeur de la composante verte de la couleur RGB
#  b : <pourcent> (de 0 à 1) valeur de la composante bleue de la couleur RGB
#-----------------------------------------------------------------------------------
sub RGBtoHLS {
  my ($r, $g, $b) = @_;
  my ($H, $L, $S);
  my ($min, $max, $diff);


  $max = &max($r,$g,$b);
  $min = &min($r,$g,$b);

  # calcul de la luminosité
  $L = ($max + $min) / 2;

  # calcul de la saturation
  if ($max == $min) {
    # couleur a-chromatique (gris) $r = $g = $b
    $S = 0;
    $H = undef;

    return [$H, $L, $S];
  }

  # couleurs "Chromatiques" --------------------

  # calcul de la saturation
  if ($L <= 0.5) {
    $S = ($max - $min) / ($max + $min);

  } else {
    $S = ($max - $min) / (2 - $max - $min);

  }

  # calcul de la teinte
  $diff = $max - $min;

  if ($r == $max) {
    # couleur entre jaune et magenta
    $H = ($g - $b) / $diff;

  } elsif ($g == $max) {
    # couleur entre cyan et jaune
    $H = 2 + ($b - $r) / $diff;

  } elsif ($b == $max) {
    # couleur entre magenta et cyan
    $H = 4 + ($r - $g) / $diff;
  }

  # Conversion en degrés
  $H *= 60;

  # pour éviter une valeur négative
  if ($H < 0.0) {
    $H += 360;
  }

  return [$H, $L, $S];

}


#-----------------------------------------------------------------------------------
# Graphics::HLStoRGB
# Algorythme de conversion HLS -> RGB
#-----------------------------------------------------------------------------------
# paramètres :
#  H : <pourcent> (de 0 à 1) valeur de la composante teinte de la couleur HLS
#  L : <pourcent> (de 0 à 1) valeur de la composante luminosité de la couleur HLS
#  S : <pourcent> (de 0 à 1) valeur de la composante saturation de la couleur HLS
#-----------------------------------------------------------------------------------
sub HLStoRGB {
  my ($H, $L, $S) = @_;
  my ($R, $G, $B);
  my ($p1, $p2);


  if ($L <= 0.5) { 
    $p2 = $L + ($L * $S);
	
  } else {
    $p2 = $L + $S - ($L * $S);

  }

  $p1 = 2.0 * $L - $p2;

  if ($S == 0) {
    # couleur a-chromatique (gris)
    # $R = $G = $B = $L
    $R = $L;
    $G = $L;
    $B = $L;

  } else {
    # couleurs "Chromatiques"
    $R = &hlsValue($p1, $p2, $H + 120);
    $G = &hlsValue($p1, $p2, $H);
    $B = &hlsValue($p1, $p2, $H - 120);
	
  }

  return [$R, $G, $B];

}

#-----------------------------------------------------------------------------------
# Graphics::hlsValue (sous fonction interne HLStoRGB)
#-----------------------------------------------------------------------------------
sub hlsValue {
  my ($q1, $q2, $hue) = @_;
  my $value;

  $hue = &r_modp($hue, 360);

  if ($hue < 60) { 
    $value = $q1 + ($q2 - $q1) * $hue / 60;

  } elsif ($hue < 180) { 
    $value = $q2;

  } elsif ($hue < 240) { 
    $value = $q1 + ($q2 - $q1) * (240 - $hue) / 60;

  } else {
    $value = $q1;

  }

  return $value;

}


#-----------------------------------------------------------------------------------
# Graphics::hexaRGBcolor
# conversion d'une couleur RGB (255,255,255) au format Zinc '#ffffff'
#-----------------------------------------------------------------------------------
sub hexaRGBcolor {
   my ($r, $g, $b, $a) = @_;

   if (defined $a) {
     my $hexacolor = sprintf("#%02x%02x%02x", ($r, $g, $b));
     return ($hexacolor.";".$a);
   }

   return (sprintf("#%02x%02x%02x", ($r, $g, $b)));
}



sub hexa2RGB {
  my ($hexastr) = @_;
  my ($r, $g, $b);

  if ($hexastr =~ /(\w\w)(\w\w)(\w\w)/) {
    $r = hex($1);
    $g = hex($2);
    $b = hex($3);

    return [$r/255, $g/255, $b/255] if (defined $r and defined $g and defined $b);

  }

  return undef;
}

#-----------------------------------------------------------------------------------
# Graphics::max
# renvoie la valeur maximum d'une liste de valeurs
#-----------------------------------------------------------------------------------
sub max {
  my (@values) = @_;
  return undef if !scalar(@values);

  my $max = undef;

  foreach my $val (@values) {
    if (!defined $max or $val > $max) {
      $max = $val;
    }
  }

  return $max;
}


#-----------------------------------------------------------------------------------
# Graphics::min
# renvoie la valeur minimum d'une liste de valeurs
#-----------------------------------------------------------------------------------
sub min {
  my (@values) = @_;
  return undef if !scalar(@values);

  my $min = undef;

  foreach my $val (@values) {
    if (!defined $min or $val < $min) {
      $min = $val;
    }
  }

  return $min;
}


#-----------------------------------------------------------------------------------
# Graphics::r_modp
# fonction interne : renvoie le résultat POSITIF du modulo m d'un nombre x
#-----------------------------------------------------------------------------------
sub r_modp {
  my ($x, $m) = @_;

  return undef if $m == 0;

  my $value = $x%$m;

  if ($value < 0.0) {
    $value = $value + abs($m);
  }

  return $value;

}


1;


__END__

Added jni/tkzinc/Perl/Zinc/Graphics.pod.











































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749

=head1 NAME

Graphics : module Perl facilitant la creation d'objets graphiques complexes 
par une description simplifiee.


=head1 SYNOPSIS

use Graphics;

&GraphicsFunction(@params, ?option => value?, ...);

=head1 DESCRIPTION

Z<>

=head2 Fonctions exportées

=head3 1. Création de composants graphiques

=over

=item B<o> buildZincItem(Z<>)

=item B<o> repeatZincItem(Z<>)

=item B<o> buildTabBoxItem(Z<>)

=back

=head3 2. Calculs de formes géométriques complexes

=over

=item B<o> roundedRectangleCoords(Z<>)

=item B<o> hippodromeCoords(Z<>)

=item B<o> ellipseCoords(Z<>)

=item B<o> roundedCurveCoords(Z<>)

=item B<o> polygonCoords(Z<>)

=item B<o> polylineCoords(Z<>)

=item B<o> curveLineCoords>(Z<>)

=item B<o> pathLineCoords(Z<>)

=item B<o> shiftPathCoords(Z<>)

=item B<o> tabBoxCoords(Z<>)

=back

=head3 3. Création de relief et ombre portée

=over

=item B<o> graphicItemRelief(Z<>)

=item B<o> graphicItemShadow(Z<>)

=back

=head3 4. Fonctions géométriques de base

=over

=item B<o> perpendicularPoint(Z<>)

=item B<o> lineAngle(Z<>)

=item B<o> vertexAngle(Z<>)

=item B<o> arc_pts(Z<>)

=item B<o> rad_point(Z<>)

=item B<o> bezierCompute(Z<>)

=item B<o> bezierSegment(Z<>)

=item B<o> bezierPoint(Z<>)

=back

=head3 5. Gestion des ressources images

=over

=item B<o> getPattern(Z<>)

=item B<o> getTexture(Z<>)

=item B<o> getImage(Z<>)

=item B<o> init_pixmaps(Z<>)

=back

=head3 6. Gestion des couleurs

=over

=item B<o> setGradiants(Z<>)

=item B<o> zincItemPredominantColor(Z<>)

=item B<o> ZnColorToRGB(Z<>)

=item B<o> hexaRGBcolor(Z<>)

=item B<o> createGraduate(Z<>)

=item B<o> MedianColor(Z<>)

=item B<o> LightingColor(Z<>)

=item B<o> RGBtoLCH(Z<>)

=item B<o> LCHtoRGB(Z<>)

=item B<o> RGBtoHLS(Z<>)

=item B<o> HLStoRGB(Z<>)

=back

Z<>

=head2 1. Création de composants graphiques


=over

=item B<buildZincItem>(widget, parentgroup, options);

Creation d'items de representations Zinc.
Les objets graphiques generes peuvent etre complexes (geometrie, multi contours, 
operateur de forme, empilage d'items, reliefs, ombre portee, repetition, 
transformations...) mais sont decrits par des 
options geometriques ou de surfacage 2D 1/2 de haut niveau.

=over
    
=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget zinc.

=item B<parentgroup>

<tagOrId> identifiant de l'item group parent.


=back


=item B<Options> :

						      
=over

=item B<-itemtype> => type

Specifie le(s) type(s) d'item(s) souhaite(s). Peut etre celui d'un item
natif zinc (B<group>, B<rectangle>, B<arc>, B<curve>, B<text>, B<icon>),
ou un B<'metatype'> permettant de specifier des curves 'particulieres'. Les sections coniques
de ces metatypes (raccords ou arcs) seront simulees par des segments quadratiques de bezier. Ces metatypes sont :

=over

=item roundedrectangle

decrit par 2 cordonnees (haut-gauche et bas-droite du rectangle) et un rayon de raccord angulaire.
Une liste optionnelle de realisation des raccords [0 = sans raccord|1 = avec raccord] permet de specifier pour chaque angle le type de raccord
(angle ou arc).

=item hippodrome

decrit par 2 cordonnees (haut-gauche et bas-droite du rectangle englobant).
Si l'orientation n'est pas specifiee, le rayon de raccord sera egal a la moitie du plus petit cote .
Une liste optionnelle de realisation des raccords permet de specifier pour chaque angle le type de raccord
(angle ou arc).

=item ellipse

decrit par 2 cordonnees (haut-gauche et bas-droite du rectangle englobant).  
Une liste optionnelle de realisation des raccords permet de specifier pour chaque angle le type de raccord
(angle ou arc).

=item polygone

polygone regulier a n cotes, (triangle equilateral, carre, pentagone, hexagone...)
convexe ou en etoile. Le polygone sera inscrit dans un cercle dont le rayon est passe en parametres 
(un 2eme rayon 'interne' decrira un polygone etoile). Un rayon de raccord et une liste de realisation des raccords permettent 
des variantes interressantes.

=item roundedcurve

curve multicontours a coins arrondis, de rayon raccord unique,
pour specifier une forme quelconque.

=item polyline

curve multicontours a coins arrondis. Le rayon de chaque raccord pouvant etre defini
specifiquement.

=item pathline

creation d'une ligne multisegments 'epaisse',
realisee par 'decalage' par rapport a un path donne (largeur et sens de decalage
 [left|both|right] optionnels). Le contour transforme en surface avec l'item Zinc triangles
permet d'appliquer un degrade de couleurs le long du trace (lineaire, transversal ou double).

=back


=item B<-coords> => \@xy

<coords list> coordonnees geometriques ou de position de l'item.

=item B<-metacoords> => \%metatype_params

<hashtable> calcul des coordonnées de l'item par passage d'un [meta]type d'item
différent de celui décrit par -itemtype. (ex. un pathline défini par un polygone)

<coords list> coordonnees geometriques ou de position de l'item.

=item B<-params> => \%zinc_attr

<hashtable> parametres zinc de l'item.

=item B<-contours> => \@list

<contours list> arguments zinc d'ajout de contours .

=item B<-clip>

<coords list or hashtable> clipping d'un item group.

=item B<-items>

<hashtable> table d'items contenus dans un item group.
provoque un appel récursif de la fonction buildZincItem().

=item B<-texture>

<imagefile> ajout d'une texture a l'item.

=item B<-pattern>

<imagefile> ajout d'un pattern a l'item.

=item B<-relief>

<hash table> creation d'un relief a l'item a l'aide d'item zinc triangles.
Invoque la fonction du module Graphics graphicItemRelief()

=item B<-shadow>

<hash table> creation d'une ombre portee a l'item.
Invoque la fonction du module Graphics graphicItemShadow()

=item B<-repeat>

<hash table> repetition de l'item.
Invoque la fonction du module Graphics repeatZincItem()

=item B<-scale> => scale factor or [xscale, yscale] 

application d'une transformation zinc->scale a l'item

=item B<-translate> => [dx,dy]

 application d'une transformation zinc->translate a l'item

=item B<-rotate> => <angle> (en degré) 

application d'une transformation zinc->rotate a l'item

=item B<-addtags>

<tags list> liste de tags specifiques a ajouter aux parametre item -tags.

=item B<-name>

<string> nom de l'item.

=back
						      
=back

Z<>

=item B<repeatZincItem>(widget, item, options);

Répétition (clonage) d'un objet Zinc de representation.
    
=over

=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget zinc.

=item B<item>

<tagOrId> identifiant de l'item zinc a dupliquer.

=back

=item B<Options> :
						      
=over

=item B<-num> => integer

Nombre de répétitions.

=item B<-dxy> => [dx, dy]

Paramètres de translation a appliquer entre 2 copies.

=item B<-angle> => <angle>

angle de rotation en degré a appliquer entre 2 copies.

=item B<-copytag> => <tag name>

ajout d'un tag indexé pour chaque copie.

=item B<-params> => \%zinc_attr

Paramétrage specialises de chaque copie


=back

=back

Z<>

=item B<buildTabBoxItem>(widget, parentgroup, options);

Construit les items de représentation d'une boîte à onglets multi-pages. 
Le positionnement, la forme et la taille des onglets est définie automatiquement
ou spécifiés par options. L'ajout de titres aux pages est possible. Des tags
de base (intercalaires et titres) permettent de définir des interactions de 
sélection/navigation par bindings. 

=over
    
=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget zinc.

=item B<parentgroup>

<tagOrId> identifiant de l'item group parent.

=back

=item B<Options> :
						      
=over

=item B<-coords> => [[x0,y0],[x1,y1]]

<coords> coordonnées haut-gauche et bas-droite de la BoundingBox du tabBox.  

=item B<-numpages>

<integer> nombre de pages du TabBox.

=item B<-anchor> => 'n'|'e'|'s'|'w' 

ancrage nord, est, sud ou ouest des onglets (par défaut 'n')

=item B<-alignment> => 'left'|'center'|'right' 

alignement gauche, centré ou droit des onglets sur l'ancrage (par défaut left)

=item B<-tabwidth> => 'auto'|<dimension>|<dimensionList> 

longeur des onglets : 'auto' longeur répartie sur le coté, longeur absolue ou liste de longeurs
ces dimensions sont autoajustées si dépassement. (par défaut 'auto').

=item B<-tabheight> => 'auto'|<dimension> 

hauteur des onglets (par défaut 'auto')

=item B<-tabshift> => 'auto'|<dimension> 

offset de biseau entre la base et le haut de l'onglet (par défaut 'auto').

=item B<-overlap> => 'auto'|<dimension> 

offset de décalage entre 2 onglets (par défaut 'auto').

=item B<-radius>

<dimension> rayon des arrondis d'angle des onglets. (par défaut 0)

=item B<-corners> 

<booleanList> liste d'application du raccord aux angles sous forme booleenne 
0 = sans raccord 1 = avec raccord.

=item B<-params> => \%zinc_attr

<hashtable> parametres zinc de l'item.

=item B<-texture>

<imagefile> ajout d'une texture a l'item.

=item B<-relief>

<hash table> creation d'un relief pour les pages du tabBox.
Invoque la fonction du module Graphics graphicItemRelief()

=item B<-tabtitles>

<hashtable> table de hash de définition des titres d'onglets (label, params).

=item B<-pageitems>

<hashtable> table d'items 'complémentaire' à réaliser pour chaque page.
provoque un appel récursif de la fonction buildZincItem().


=back

=back

=back

Z<>

=head2 2. Calculs de formes géométriques complexes

=over

=item B<roundedRectangleCoords>(coords, options);

Retourne les coordonnées (curve) d'un rectangle à coins arrondis

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],[x1,y1]]

<coordList> coordonnées haut-gauche et bas-droite du rectangle.

=back

=item B<Options> :
						      
=over

=item B<-radius>  

<dimension> rayon de raccord circulaire des angles.

=item B<-corners> => \@cornersList

Liste de réalisation des raccords de sommets [0 = pad de raccord (droit)| 1 = raccord circulaire].
(par défaut [1,1,1,1]).

=back

=back

Z<>

=item B<hippodromeCoords>(coords, options);

Retourne les coordonnées (curve) d'un hippodrome

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],[x1,y1]]

<coordList> coordonnées haut-gauche et bas-droite du rectangle exinscrit à l'hippodrome.

=back

=item B<Options> :
						      
=over

=item B<-orientation>  => <horizontal|vertical>

orientation forcée de l'hippodrome (sinon hauteur = plus petit coté).

=item B<-corners> => \@cornersList

Liste de réalisation des raccords de sommets [0 = pad de raccord (droit)| 1 = raccord circulaire].
(par défaut [1,1,1,1]).

=item B<-trunc>  => <left|right|top|bottom|both>

troncatures des cotés circulaires de l'hippodrome.

=back

=back

Z<>

=item B<ellipseCoords>(coords, options);

Retourne les coordonnées (curve) d'une ellipse

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],[x1,y1]]

<coordList> coordonnées haut-gauche et bas-droite du rectangle exinscrit.

=back

=item B<Options> :
						      
=over

=item B<-corners> => \@cornersList

Liste de réalisation des quadrants [0 = angle droit| 1 = raccord d'ellipse].
(par défaut [1,1,1,1]).

=back

=back

Z<>

=item B<roundedCurveCoords>(coords, options);

Retourne les coordonnées d'une curve à coins arrondis.

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],...[xn,yn]]

<coordList> coordonnées de la curve

=back

=item B<Options> :
						      
=over

B<-radius> : <dimension> 
rayon de raccord des angles. par defaut 0

B<-corners> : <booleanList> 
liste d'application du raccord circulaire aux angles sous forme booleenne 
0 = sans raccord 1 = avec raccord. par defaut [1,1,...,1].

=back

=back

Z<>

=item B<polygonCoords>(coords, options);

Retourne les coordonnées d'un polygone régulier à n cotés ou d'une étoile à
n branches. Le polygone sera inscrit dans un cercle de rayon -radius, un 2ème
rayon interne décrira les sommets interne de l'étoile. Raccords circulaires
optionnels des sommets du polygone/étoile

=over

=item B<Parametres> :

=over

=item B<coords> => [x0,y0]

<coords> coordonnées du centre du cercle exinscrit au polygone/étoile

=back

=item B<Options> :
						      
=over

B<-numsides> : <dimension> nombre de cote du polygone ou nombre de branches de l'etoile

B<-radius> : <dimension> rayon du cercle exinscrit au polygone

B<-startangle> : <angle> angle de depart du trace de la figure

B<-inner_radius> : <dimension> rayon du cercle des points 'internes' de l'etoile

B<-corner_radius> : <dimension> rayon des raccords d'angles

B<-corners> : <booleanList> liste d'application du raccord aux angles sous forme booleenne 
0 = sans raccord 1 = avec raccord. par defaut [1,1,1,1].

=back

=back

Z<>

=item B<polylineCoords>(coords, options);

Retourne les coordonnées d'une polyline, ligne 'brisée' multi-segments
avec raccords angulaires optionnels.

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],...[xn,yn]]

<coordList> liste de coordonnées des sommets de la polyline

=back

=item B<Options> :
						      
=over

B<-radius> : <dimension> 
rayon global de raccord des angles. par defaut 0

B<-corners> : <booleanList> 
liste d'application du raccord circulaire aux angles sous forme booleenne 
0 = sans raccord 1 = avec raccord. par defaut [1,1,...,1].

B<-corners_radius> : <dimensionList> 
Liste des rayons de raccord des angles.

=back

=back

Z<>

=item B<curveLineCoords>(coords, options);

ATTENTION FONCTION EN CHANTIER 

Retourne les coordonnées curve (de surface) d'un stroke. la ligne est décrite 
le long d'un chemin et dessinée selon les attributs graphiques classiques 'stroke'
(style d'épaisseur, d'extremité, de jointure, de tiret...)

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],...[xn,yn]]

<coordList> coordonnées de la curve

=back

=item B<Options> :
						      
=over

B<-width> : <dimension> 
épaisseur de la ligne. par defaut 1

B<-linecap> : <'butt'|'round'|'square'> 
Forme des extrémités des tracés ouverts.

B<-linejoin> : <'miter'|'round'|'bevel'> 
Forme des sommets des tracés.

B<-dasharray> : <'none'|motifList> 
Spécification du tireté : none (aucun) ou liste de longueurs tiret,[espace],[tiret]...
permettant de définir le dessin du tireté (par défaut none)

B<-dashoffset> : <dimension> 
distance décalage de départ dans le dessin du tireté (par défaut 0)

=back

=back

Z<>

=item B<pathLineCoords>(coords, %options);

retourne les coordonnées (triangles) d'une ligne multisegments 'epaisse',
realisee par 'décalage' par rapport à un path donné (largeur et sens de décalage
 [out|center|in] optionnels).

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],...[xn,yn]]

<coordList> liste de coordonnées du path

=back

=item B<Options> :
						      
=over

B<-closed> : <boolean> 
fermeture du tracé. par defaut 0

B<-shifting> : <'out'|'center'|'in'> 
sens de décalage de l'épaisseur de contour : 'center' (1/2 décalage de chaque coté du path) 'out' (décalage externe) 'in' (décalage interne) par défaut 'center'.

B<-width> : <dimension> 
Largeur du décalage de ligne (par défaut 2).

=back

=back

Z<>

=item B<shiftPathCoords>(coords, %options);

retourne les coordonnées curve de 'décalage' par rapport à un path donné.

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],...[xn,yn]]

<coordList> liste de coordonnées du path

=back

=item B<Options> :
						      
=over

B<-closed> : <boolean> 
fermeture du tracé. par defaut 0

B<-shifting> : <'out'|'in'> 
sens de décalage du path : 'out' (décalage externe) 'in' (décalage interne) par défaut 'out'.

B<-width> : <dimension> 
Largeur du décalage de ligne (par défaut 1).

=back

=back

Z<>

=item B<tabBoxCoords>(coords, options);

Retourne les coordonnées de construction d'un TabBox (boîte à onglets) : liste de curve décrivant les 'pages' du TabBox et coordonnées de position des titres onglets. 

=over

=item B<Parametres> :

=over

=item B<coords> => [[x0,y0],[x1,y1]]

<coords> coordonnées haut-gauche et bas-droite de la BoundingBox du tabBox.  

=back

=item B<Options> :
						      
=over

B<-numpages> : <integer> nombre de pages du TabBox.

B<-anchor> : <'n'|'e'|'s'|'w'> ancrage nord, est, sud ou ouest des onglets (par défaut 'n')

B<-alignment> : <'left'|'center'|'right'> alignement gauche, centré ou droit des onglets sur l'ancrage (par défaut left)

B<-tabwidth> : 'auto'|<dimension|dimensionList> longeur des onglets : 'auto' longeur répartie sur le coté, longeur absolue ou liste de longeurs
ces dimensions sont autoajustées si dépassement. (par défaut 'auto').

B<-tabheight> : 'auto'|<dimension> hauteur des onglets (par défaut 'auto')

B<-tabshift> : 'auto'<dimension> offset de biseau entre la base et le haut de l'onglet (par défaut 'auto').

B<-overlap> : 'auto'<dimension> offset de décalage entre 2 onglets (par défaut 'auto').

B<-radius> : <dimension> 
rayon des arrondis d'angle des onglets. (par défaut 0)

B<-corners> : <booleanList> liste d'application du raccord aux angles sous forme booleenne 
0 = sans raccord 1 = avec raccord.

=back

=back

=back

Z<>

=head2 3. Création de reliefs et ombre portée

Z<>

=over

=item B<graphicItemRelief>(widget, item, %options);

Construit un relief à l'item géometrique 
(qui peut etre multicontours) en utilisant des items zinc triangles.
Ce relief de type 'embossage' de forme possede un
profil (flat ou rounded) et dérive en luminosite la couleur dominante
de l'item (ou une couleur donnée) suivant l'orientation d'éclairage global zinc
-lighangle (ou un angle de lumière donné).  

=over
    
=item B<Parametres> :

=over

=item B<widget>

identifiant du widget zinc.

=item B<item>

identifiant de l'item zinc à mettre en relief.

=back

=item B<Options> :
						      
=over

B<-closed> : <boolean> fermeture (de forme) du relief (par défaut 1).

B<-profil> : <'flat'|'rounded'> type de profil du relief (par défaut 'rounded').

B<-relief> : <'raised'|'sunken'> sens de l'embossage (par defaut 'raised').

B<-side> : <outside|inside> position externe ou interne du relief (defaut 'inside').

B<-color> : <color> couleur de base du relief (défaut couleur dominante de l'item).

B<-smoothed> : <boolean> lissage des 'facettes' du relief (par defaut 1).

B<-lightangle> : <angle> angle de la lumiere (par defaut attribut -lightangle du widget).

B<-width> : <dimension> largeur du 'contour' relief.

B<-fine> : <boolean> mode precision courbe de bezier (par defaut 0 : auto-ajustee).

=back

=back

Z<>

=item B<graphicItemShadow>(widget, item, %options);

Cree une ombre portee a l'item geometrique 
(qui peut etre multicontours) en utilisant des items zinc triangles et curve.
Cette ombre correspond a une projection de la forme en fonction
d'une distance (par defaut 10) d'une orientation lumineuse (par defaut la valeur
globale -lightangle du widget) et d'un 'grossissement' (par defaut 0).
Une largeur 'width' de perimetre de diffusion/diffraction lumineuse (par defaut 4) 
qui permet de lisser le passage de l'ombre au fond, une couleur (par defaut black) 
et une opacite (par defaut 50) completent la specification.

=over

B<Parametres> : 

=over

B<widget> : <widget> identifiant du widget zinc

B<item> : <tagOrId> identifiant de l'item zinc

=back

B<Options> :

=over

B<-opacity> : <percent> poucentage d'opacite de l'ombre (par defaut 50).

B<-distance> : <dimension> distance de projection de l'ombre (par defaut 10).

B<-enlarging> : <dimension> 'grossissement' cone de projection (defaut 0).

B<-color> : <color> couleur de l'ombre (par defaut black).

B<-lightangle> : <angle> angle de la lumiere (par defaut attribut -lightangle du widget).

B<-width> : <dimension> largeur du perimetre de diffusion/diffraction (par defaut 4).

=back

=back

=back

Z<>

=head2 4. Fonctions géométriques de base

Z<>

=over

=item B<perpendicularPoint>(point, line);

retourne les coordonnées du point perpendiculaire abaissé d'un point sur une ligne.

=over

=item B<Parametres> :

=over

=item B<point> => [x, y]

<coords> coordonnées du point de référence.

=item B<line> => [[x0, y0],[x1, y1]]

<coordsList> liste de coordonnées des deux points de la ligne de référence.

=back

=back

Z<>


=item B<lineAngle>(startpoint, endpoint);

retourne l'angle formée par un vecteur, s'utilise aussi pour connaitre l'angle 'circulaire' 
d'un point par rapport à un centre de référence.

=over

=item B<Parametres> :

=over

=item B<startpoint> => [x, y]

<coords> coordonnées du point de départ du segment (ou centre de référence).

=item B<endpoint> => [x, y]

<coords> coordonnées du point de fin du segment (ou point 'circulaire' de référence).

=back

=back

Z<>

=item B<lineNormal>(startpoint, endpoint);

retourne la valeur d'angle perpendiculaire à un vecteur (utilisée par exemple 
pour mesurer l'incidence de lumière d'une facette). 

=over

=item B<Parametres> :

=over

=item B<startpoint> => [x, y]

<coords> coordonnées du point de départ du segment (ou centre de référence).

=item B<endpoint> => [x, y]

<coords> coordonnées du point de fin du segment (ou point 'circulaire' de référence).

=back

=back

Z<>

=item B<vertexAngle>(point0, point1, point2);

retourne la valeur de l'angle formé par trois points ainsi que la valeur d'angle
de la bisectrice de l'angle (fonction utilisé pour les calculs de décalages de path.

=over

=item B<Parametres> :

=over

=item B<point0> => [x, y]

<coords> coordonnées du premier point de définition de l'angle.

=item B<point1> => [x, y]

<coords> coordonnées du deuxième point de définition de l'angle (sommet).

=item B<point2> => [x, y]

<coords> coordonnées du troisième point de définition de l'angle.


=back

=back

Z<>

=item B<arc_pts>(center, radius, %options);

Calcul des points constitutifs d'un arc

=over 

=item B<Parametres> :

=over

=item B<center> => [x0,y0]

<coords> coordonnées du centre de l'arc.

=item B<radius>  

<dimension> rayon de l'arc.

=back

=item B<Options> :
						      
=over

=item B<-angle>  

<angle> angle de départ (en degré) de l'arc (par défaut 0)

=item B<-extent>  

<angle> delta angulaire (en degré) de l'arc (par défaut 360)

=item B<-step>

<angle> pas de progression angulaire (en degré) de calcul des points (par défaut 10).

=back

=back

Z<>

=item B<rad_point>(center, radius, angle);

Retourne le point circulaire défini par centre-rayon-angle.

=over

=item B<Parametres> :

=over

=item B<center> => [x0,y0]

<coords> coordonnées du centre de l'arc.

=item B<radius>  

<dimension> rayon de l'arc.

=item B<angle>  

<angle> angle (en degré) du point de circonférence avec le centre du cercle.

=back

=back

Z<>

=item B<bezierSegment>(coords, %options);

Calcul d'une approximation de segment (Quadratique ou Cubique) de bezier.

=over 

=item B<Parametres> :

=over

=item B<coords>

<coordsList> Liste de coordonnées des points définissant le segment de bezier.

=back

=item B<Options> :
						      
=over

=item B<-tunits>  

<integer> nombre pas de division des segments bezier (par défaut 20)

=item B<-skipend>  

<boolean> ne pas retourner le dernier point du segment (pour chaînage de segments).

=back

=back

Z<>

=item B<bezierPoint>(t, coords);

Calcul d'un point du segment (Quadratique ou Cubique) de bezier.
t représentation du temps (de 0 à 1). 
coords = (P1, C1, <C1>, P2) liste des points définissant le segment de bezier
P1 et P2 : extémités du segment et pts situés sur la courbe
C1 <C2> : point(s) de contrôle du segment

courbe bezier niveau 2 sur (P1, P2, P3)   P(t) = (1-t)²P1 + 2t(1-t)P2 + t²P3

courbe bezier niveau 3 sur (P1, P2, P3, P4)  P(t) = (1-t)³P1 + 3t(1-t)²P2 + 3t²(1-t)P3 + t³P4

=over 

=item B<Parametres> :

=over

=item B<t>

<pourcent> (de 0 à 1) représentation du temps.

=item B<coords>

<coordsList> Liste de coordonnées des points définissant le segment de bezier.

=back

=back

Z<>


=item B<bezierCompute>(coords, %options);

Calcul d'une approximation auto-ajustée de segment (Quadratique ou Cubique) de bezier.
l'approximation se fait par subdivision successive de la courbe jusqu'à atteindre une
distance avec la courbe théorique <= à la précision passée par option (par défaut 0.2).

=over 

=item B<Parametres> :

=over

=item B<coords>

<coordsList> Liste de coordonnées des points définissant le segment de bezier.

=back

=item B<Options> :
						      
=over

=item B<-precision>  

<dimension> seuil limite du calcul d'approche de la courbe (par défaut .2)

=item B<-skipend>  

<boolean> ne pas retourner le dernier point du segment (pour chaînage de segments).

=back

=back

=back

Z<>

=head2 5. Gestion des ressources images

Z<>

=over

=item B<getPattern>(filename, %options);

retourne et partage la ressource image bitmap en l'initialisant et la stockant si première utilisation.

=over

=item B<Parametres> :

=over

=item B<filename>

<image filename> non du fichier bitmap pattern

=back

=item B<Options> :
						      
=over

=item B<-storage>  

<hashtable> référence de la table de stockage privée des patterns.

=back

=back

Z<>

=item B<getTexture>(widget, filename, %options);

retourne et partage la ressource image texture en l'initialisant et la stockant si première utilisation.

=over

=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget zinc.

=item B<filename>

<imagefile> non du fichier image texture

=back

=item B<Options> :
						      
=over

=item B<-storage>  

<hashtable> référence de la table de stockage privée des textures.

=back

=back

Z<>

=item B<getImage>(widget, filename, %options);

retourne et partage la ressource image en l'initialisant et la stockant si première utilisation.

=over

=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget zinc.

=item B<filename>

<imagefile> non du fichier image

=back

=item B<Options> :
						      
=over

=item B<-storage>  

<hashtable> référence de la table de stockage privée des images.

=back

=back

Z<>

=item B<init_pixmaps>(widget, filenames, %options);

Initialise et stocke un ensemble d'images.

=over

=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget zinc.

=item B<filenames>

<imagefileList> Liste des fichier images à initialiser.

=back

=item B<Options> :
						      
=over

=item B<-storage>  

<hashtable> référence de la table de stockage privée des images.

=back

=back

=back

Z<>

=head2 6. Gestion des couleurs

Z<>

=over

=item B<setGradients>(widget, gradients);

Création de gradiants nommés Zinc

=over

=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget Zinc

=item B<gradients>  

<hashtable> référence de la table de définition des gradiants zinc ('non' => 'zincGradient').

=back

=back

Z<>

=item B<zincItemPredominantColor>(widget, item);

retourne la couleur dominante d'un item ('barycentre' gradiant fillcolor).

=over

=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget Zinc

=item B<item>  

<tagOrId>  identifiant de l'item zinc.

=back

=back

Z<>

=item B<medianColor>(color1, color2, rate);

calcul d'une couleur intermédiaire défini par un ratio ($rate) entre 2 couleurs.

=over

=item B<Parametres> :

=over

=item B<color1>

<color> première couleur

=item B<color2>  

<color> première couleur

=item B<rate>

<pourcent> (de 0 à 1) position de la couleur intermédiaire.

=back

=back

Z<>

=item B<createGraduate>(widget, steps, refcolors, repeat);

création d'un jeu de couleurs intermédiaires (dégradé) entre n couleurs.

=over

=item B<Parametres> :

=over

=item B<widget>

<widget> identifiant du widget Zinc

=item B<steps>  

<integer> nombre totale de couleurs retournées.

=item B<refcolors>  

<colorList> liste de couleurs servant à créer le dégradé.

=item B<repeat>  

<integer> répétition de chaque couleur utilisé par exemple pour triangles path
où la couleur est répétée 2 fois (par défaut 1).

=back

=back

Z<>

=item B<lightingColor>(color, newL);

Modification d'une couleur par sa composante luminosité (exemple relief).

=over

=item B<Parametres> :

=over

=item B<color>

<color> couleur au format zinc.

=item B<newL>

<pourcent> (de 0 à 1) nouvelle valeur de luminosité.

=back

=back

Z<>

=item B<ZnColorToRGB>(zncolor);

conversion d'une couleur Zinc hexa au format RGBA (255,255,255,100).

=over

=item B<Parametres> :

=over

=item B<zncolor>

<color> couleur au format hexa zinc (#ffffff ou #ffffffffffff).

=back

=back

Z<>

=item B<RGBtoLCH>(r, g, b);

conversion d'une couleur de l'espace RGB à l'espace CIE LCH°.

=over

=item B<Parametres> :

=over

=item B<r>

<pourcent> (de 0 à 1) valeur de la composante rouge de la couleur RGB.

=item B<g>

<pourcent> (de 0 à 1) valeur de la composante verte de la couleur RGB.

=item B<b>

<pourcent> (de 0 à 1) valeur de la composante bleue de la couleur RGB.

=back

=back

Z<>

=item B<LCHtoRGB>(L, C, H);

conversion d'une couleur de l'espace CIE LCH° à l'espace RGB.

=over

=item B<Parametres> :

=over

=item B<L>

<pourcent> (de 0 à 1) valeur de la composante luminosité de la couleur CIE LCH.

=item B<C>

C : <pourcent> (de 0 à 1) valeur de la composante saturation de la couleur CIE LCH

=item B<H>

H : <pourcent> (de 0 à 1) valeur de la composante teinte de la couleur CIE LCH

=back

=back

Z<>

=item B<RGBtoHLS>(r, g, b);

conversion d'une couleur de l'espace RGB à l'espace HLS.

=over

=item B<Parametres> :

=over

=item B<r>

<pourcent> (de 0 à 1) valeur de la composante rouge de la couleur RGB.

=item B<g>

<pourcent> (de 0 à 1) valeur de la composante verte de la couleur RGB.

=item B<b>

<pourcent> (de 0 à 1) valeur de la composante bleue de la couleur RGB.

=back

=back

Z<>

=item B<HLStoRGB>(H, L, S);

conversion d'une couleur de l'espace HLS à l'espace RGB.

=over

=item B<Parametres> :

=over

=item B<H>

<pourcent> (de 0 à 1) valeur de la composante teinte de la couleur HLS.

=item B<L>

C : <pourcent> (de 0 à 1) valeur de la composante luminosité de la couleur HLS.

=item B<S>

H : <pourcent> (de 0 à 1) valeur de la composante saturation de la couleur HLS.

=back

=back

Z<>

=item B<hexaRGBcolor>(r, g, b, a);

conversion d'une couleur RGBA (255,255,255,100) au format Zinc '#ffffff'.

=over

=item B<Parametres> :

=over

=item B<r>

<colorComposant> (0 à 255) composante rouge de la couleur rgba.

=item B<g>

<colorComposant> (0 à 255) composante verte de la couleur rgba.

=item B<b>

<colorComposant> (0 à 255) composante bleue de la couleur rgba.

=item B<a>

<colorComposant> (0 à 255) composante alpha de la couleur rgba.

=back

=back

Z<>

=back

Z<>


=head1 EXEMPLE

my %gradset = (
   'gdlens' => '=radial -15 -20|#ffb7b7;70|#bd6622;90',
   'gdstar' => '=radial -15 -20|#ffb7b7;50|#bd6622;90');

my %starstyle => (
       # table hash parametres et options
       -itemtype => 'group',
       -coords => [250, 250],
       -params => {-priority => 90,
                   -tags => ['starlens', 'move'],
                   -sensitive => 1,
                   -atomic => 1,
                   },
       -items => {
           'lens' => {-itemtype => 'hippodrome',
                      -coords => [[-200, -200],
                                  [200, 200]],
                      -params => {-closed => 1,
                                  -filled => 1,
                                  -fillcolor => 'gdlens',
                                  -linewidth => 1.5,
                                  -linecolor => '#440000',
                                  -priority => 10,
                                 },
                      -relief => {-width => 14,
                                  -profil => 'rounded',
                                  -lightangle => 135,
                                  },
                      -shadow => {-distance => 20,
                                  -width => 18,
                                  -lightangle => 135,
                                  -opacity => 40,
                                  -enlarging => 6,
                                 },
                      },
          'star' => {-itemtype => 'polygone',
                     -coords => [0, 0],
                     -numsides => 5,
                     -radius => 180,
                     -inner_radius => 70,
                     -corner_radius => 10,
                     -startangle => 270,
                     -corners => [0,1,0,1,0,1,0,1,0,1],
                     -params => {-filled => 1,
                                 -fillcolor => 'gradstar',
                                 -linewidth => 1,
                                 -linecolor => '#330000',
                                 -priority => 20,
                                },
                     -relief => {-width => 10,
                                 -profil => 'rounded',
                                 -side => 'outside',
                                 -relief => 'sunken',
                                },
                     },
             },
       );


&setGradients($widget, \%gradset);

my $star = &buildZincItem($zinc, $topgroup, \%starstyle);

=head1 AUTEURS

Jean-Luc Vinot <vinot@cena.fr>

Added jni/tkzinc/Perl/Zinc/Logo.pm.





























































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package Tk::Zinc::Logo;

#---------------------------------------------------------------
#
#  Module          : Logo.pm
#  $Id$
#
#  Copyright (C) 2001-2003
#  Centre d'Études de la Navigation Aérienne
#  Authors: Jean-Luc Vinot <vinot@cena.fr>
#
#---------------------------------------------------------------

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use strict;
use Carp;
use Math::Trig;


my @Gradiants;

# paramètres de construction graphique
my %builder = (-gradset => {'logoshape' => '=axial 270 |#ffffff;100 0 28|#66848c;100 96|#7192aa;100 100',
			    'logopoint' => '=radial -20 -20 |#ffffff;100 0|#f70000;100 48|#900000;100 80|#ab0000;100 100',
			    'logoptshad' => '=path 0 0 |#770000;64 0|#770000;70 78|#770000;0 100',
			    },

	       -shape => {-form => {-itemtype => 'curve',
				    -coords => [[0,0],[106,0],[106,58],[122,41],[156,41],[131,69],[153,99],[203,41],
						[155,41],[155,0],[225.71,0],[251.34,0,'c'],[265.17,29.63,'c'],
						[248.71,49.27],[202,105],[246,105],[246,87],[246,59.385,'c'],[268.38,37,'c'],
						[296,37],[323.62,37,'c'],[346,59.385,'c'],[346,87],[346,148],[305,148],
						[305,87],[305,82.58,'c'],[301.42,79,'c'],[297,79],[292.58,79,'c'],
						[289,82.58,'c'],[289,87],[289,150],[251,150],[251,130],[251,125.58,'c'],
						[247.42,122,'c'],[243,122],[243,122],[238.58,122,'c'],[235,125.58,'c'],
						[235,130],[235,150],[168.12,150],[144.7,150,'c'],[132.38,122.57,'c'],
						[147.94,105.06],[148,105],[120,105],[104,81],[104,105],[74,105],[74,41],
						[52,41],[52,105],[20,105],[20,41],[0,41]],

				    -contour => ['add', -1, [[395,78],[395,37],[364.62,37,'c'],[340,61.62,'c'],[340,92],
							    [340,93],[340,123.38,'c'],[364.62,148,'c'],[395,148],[409,148],
							    [409,107],[395,107],[386.72,107,'c'],[380,100.28,'c'],[380,92],
							    [380,93],[380,84.72,'c'],[386.72,78,'c'],[395,78]]],


				    -params => {-closed => 0,
						-filled => 1,
						-visible => 1,
						-fillcolor => 'logoshape',
						-linewidth => 2.5,
						-linecolor => '#000000',
						-priority => 40,
						-fillrule => 'nonzero',
						-tags => ['zinc_shape'],
					       },
				   },

			  -shadow => {-clone => '-form',
				      -translate => [6, 6],
				      -params => {-fillcolor => '#000000;18',
						  -linewidth => 0,
						  -priority => 20,
						 },
				     },
			 },

	       -point => {-coords => [240, 96],
			  -params => {-alpha => 80,
				      -priority => 100,
				     },

			  -form => {-itemtype => 'arc',
				    -coords => [[-20, -20], [20, 20]],
				    -params => {-priority => 50,
						-filled => 1,
						-linewidth => 1,
						-linecolor => '#a10000;100',
						-fillcolor => 'logopoint',
						-closed => 1,
					       },
				   },

			  -shadow => {-clone => '-form',
				      -translate => [5, 5],
				      -params => {-fillcolor => 'logoptshad',
						  -linewidth => 0,
						  -priority => 20,
						 },
				     },
			 },
	      );



sub new {
    my $proto = shift;
    my $type = ref($proto) || $proto;
    my %params = @_;

    my $self = {};
    bless ($self, $type);
    if (exists $params{'-widget'}) {
	$self->{'-widget'} = $params{'-widget'};
    } else {
	croak "in Tk::Zinc::Logo constructor, the -widget attribute must be defined\n";
    }
    $self->{'-parent'} = (exists $params{'-parent'}) ? $params{'-parent'} : 1;
    $self->{'-priority'} = (exists $params{'-priority'}) ? $params{'-priority'} : 500;
    $self->{'-position'} = (exists $params{'-position'}) ? $params{'-position'} : [0, 0];
    $self->{'-scale'} = (exists $params{'-scale'}) ? $params{'-scale'} : [1, 1];

    $self->drawLogo();

    return bless $self, $type;
}



sub drawLogo {
  my ($self) = @_;
  my $zinc = $self->{'-widget'}; 
  my $parent = $self->{'-parent'};
  my $priority = $self->{'-priority'};


  if ($builder{'-gradset'}) {
    while (my ($name, $gradiant) = each( %{$builder{'-gradset'}})) {
      # création des gradiants nommés
      $zinc->gname($gradiant, $name) unless $zinc->gname($name);
      push(@Gradiants, $name);
    }
  }

  # création des groupes logo
  # logogroup : groupe de coordonnées
  my $logogroup =  $self->{'-item'} = $zinc->add('group', $parent, -priority => $priority);
  $zinc->coords($logogroup, $self->{'-position'}) if ($self->{'-position'});

  # group de scaling
  my $group = $self->{'-scaleitem'} = $zinc->add('group', $logogroup);
  $zinc->scale($group,  @{$self->{'-scale'}}) if ($self->{'-scale'});


  # création de l'item shape (Zinc)
  my $formstyle = $builder{'-shape'}->{'-form'};
  $self->ajustLineWidth($formstyle->{'-params'});
  my $shape = $zinc->add('curve', $group,
			$formstyle->{'-coords'},
			%{$formstyle->{'-params'}},
		       );

  $zinc->contour($shape, @{$formstyle->{'-contour'}});

  # ombre portée de la shape
  my $shadstyle = $builder{'-shape'}->{'-shadow'};
  my $shadow = $zinc->clone($shape, %{$shadstyle->{'-params'}});
  $zinc->translate($shadow, @{$shadstyle->{'-translate'}}) if ($shadstyle->{'-translate'});

  # réalisation du point
  my $pointconf = $builder{'-point'};
  my $ptgroup = $zinc->add('group', $group, %{$pointconf->{'-params'}});
  $zinc->coords($ptgroup,  $pointconf->{'-coords'});

  my $pointstyle =  $pointconf->{'-form'};
  my $point = $zinc->add('arc', $ptgroup,
			 $pointstyle->{'-coords'},
			 %{$pointstyle->{'-params'}},
			 );

  my $shadpoint = $zinc->clone($point, %{$shadstyle->{'-params'}});
  $shadstyle = $pointconf->{'-shadow'};
  $zinc->translate($shadpoint, @{$shadstyle->{'-translate'}});

}


sub ajustLineWidth {
  my ($self, $style, $scale) = @_;

  if ($style->{'-linewidth'}) {
    my ($sx, $sy) = @{$self->{'-scale'}};
    my $linewidth = $style->{'-linewidth'};
    if ($linewidth >= 2) {
      my $ratio = ($sx > $sy) ? $sy : $sx;
      $style->{'-linewidth'} = $linewidth * $ratio;
    }
  }
}

1;

__END__

=head1 NAME

Tk::Zinc::Logo - a perl module for drawing the TkZinc logo. 


=head1 SYNOPSIS

 use Tk::Zinc::Logo;
 my $zinc = MainWindow->new()->Zinc()->pack;
 my $logo = $zinc->ZincLogo([options]);



=head1 OPTIONS 

=over

=item B<-parent> => zinc group

Specify the parent group. Default is 1.

=item B<-position> => [x, y]

Specify the relative position of the logo in its parent group. Default is [0, 0].

=item B<-priority> => integer

Specify the priority of the logo in its parent group. Default is 500.

=item B<-scale> => [sx, sy]

Scecify the xscale and yscale factors of the logo. Default is [1, 1].


=back
    

=head1 AUTEUR

Jean-Luc Vinot <vinot@cena.fr>



Added jni/tkzinc/Perl/Zinc/Text.pm.













































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package Tk::Zinc::Text;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);


sub new {
  my $proto = shift;
  my $type = ref($proto) || $proto;
  my ($zinc) = @_;
  my $self = {};

  $zinc->bind('text', '<1>' => sub {startSel($zinc)});
  $zinc->bind('text', '<2>' => sub {pasteSel($zinc)});
  $zinc->bind('text', '<B1-Motion>' => sub {extendSel($zinc)});
  $zinc->bind('text', '<Shift-B1-Motion>' => sub {extendSel($zinc)});
  $zinc->bind('text', '<Shift-1>' => sub {
		my $e = $zinc->XEvent();
		my($x, $y) = ($e->x, $e->y);
		$zinc->select('adjust', 'current', "\@$x,$y"); });
  $zinc->bind('text', '<Left>' => sub {moveCur($zinc, -1);});
  $zinc->bind('text', '<Right>' => sub {moveCur($zinc, 1);});
  $zinc->bind('text', '<Up>' => sub {setCur($zinc, 'up');});
  $zinc->bind('text', '<Down>' => sub {setCur($zinc, 'down');});
  $zinc->bind('text', '<Control-a>' => sub {setCur($zinc, 'bol');});
  $zinc->bind('text', '<Home>' => sub {setCur($zinc, 'bol');});
  $zinc->bind('text', '<Control-e>' => sub {setCur($zinc, 'eol');});
  $zinc->bind('text', '<End>' => sub {setCur($zinc, 'eol');});
  $zinc->bind('text', '<Meta-less>' => sub {setCur($zinc, 0);});
  $zinc->bind('text', '<Meta-greater>' => sub {setCur($zinc, 'end');});
  $zinc->bind('text', '<KeyPress>' => sub {insertKey($zinc);});
  $zinc->bind('text', '<Shift-KeyPress>' => sub {insertKey($zinc);});
  $zinc->bind('text', '<Return>' => sub { insertChar($zinc, chr(10)); });
  $zinc->bind('text', '<BackSpace>' => sub {textDel($zinc, -1)});
  $zinc->bind('text', '<Control-h>' => sub {textDel($zinc, -1)});
  $zinc->bind('text', '<Delete>' => sub {textDel($zinc, 0)});

  bless ($self, $type);
  return $self;
}


sub pasteSel {
  my ($w) = @_;
  my $e = $w->XEvent;
  my($x, $y) = ($e->x(), $e->y());
  my @it = $w->focus();

  if (@it != 0) {
    eval { $w->insert(@it, "\@$x,$y", $w->SelectionGet()); };
  }
}


sub insertChar {
  my ($w, $c) = @_;
  my @it = $w->focus();
  my @selit = $w->select('item');

  if (@it == 0) {
    return;
  }

  if ((scalar(@selit) == scalar(@it)) &&
      ($selit[0] eq $it[0]) && ($selit[1] eq $it[1])) {
    $w->dchars(@it, 'sel.first', 'sel.last');
  }
  $w->insert(@it, 'insert', $c);
}


sub insertKey {
  my ($w) = @_;
  my $c = $w->XEvent->A();

  if ((ord($c) < 32) || (ord($c) == 128)) {
    return;
  }

  insertChar($w, $c);
}


sub setCur {
  my ($w, $where) = @_;
  my @it = $w->focus();

  if (@it != 0) {
    $w->cursor(@it, $where);
  }
}


sub moveCur {
  my ($w, $dir) = @_;
  my @it = $w->focus();
  my $index;

  if (@it != 0) {
    $index = $w->index(@it, 'insert');
    $w->cursor(@it, $index + $dir);
  }
}


sub startSel {
  my($w) = @_;
  my $e = $w->XEvent;
  my($x, $y) = ($e->x(), $e->y());
  my $part = $w->currentpart(1);

  $w->cursor('current', $part, "\@$x,$y");
  $w->focus('current', $part);
  $w->Tk::focus();
  $w->select('from', 'current', $part, "\@$x,$y");
}


sub extendSel {
  my($w) = @_;
  my $e = $w->XEvent;
  my($x, $y) = ($e->x, $e->y);
  my $part = $w->currentpart(1);

  $w->select('to', 'current', $part, "\@$x,$y");
}


sub textDel {
  my($w, $dir) = @_;
  my @it = $w->focus();
  my @selit = $w->select('item');
  my $ind;

  if (@it == 0) {
    return;
  }

  if ((scalar(@selit) == scalar(@it)) &&
      ($selit[0] eq $it[0]) && ($selit[1] eq $it[1])) {
    $w->dchars(@it, 'sel.first', 'sel.last');
  }
  else {
    $ind = $w->index(@it, 'insert') + $dir;
    $w->dchars(@it, $ind, $ind) if ($ind >= 0);
  }
}

1;
__END__

=head1 NAME

Tk::Zinc::Text - Zinc extension for easing text input on text item or on fields

=head1 SYNOPSIS

 use Tk::Zinc::Text;

 $zinc = $mw->Zinc();
 new Tk::Zinc::Text ($zinc);
 ....
 $zinc->addtag('text', 'withtag', $a_text);
 $zinc->addtag('text', 'withtag', $a_track);
 $zinc->addtag('text', 'withtag', $a_waypoint);
 $zinc->addtag('text', 'withtag', $a_tabular);

=head1 DESCRIPTION

This module implements text input with the mouse and keyboard 'a la emacs'.
Text items must have the 'text' tag and must of course be sensitive.
Track, waypoint and tabular items have fields and these fields can
be edited the same way. Only sensitive fields can be edited. the following
interactions are supported:

=over 2

=item B<click 1>

To set the cursor position

=item B<click 2>

To paste the current selection

=item B<drag 1>

To make a selection

=item B<shift drag 1>

To extend the current selection

=item B<shift 1>

To extend the current selection

=item B<left arrow>, B<right arrow>

To move the cursor to the left or to the right

=item B<up arrow>, B<down arrow>

To move the cursor up or down a line

=item B<ctrl+a>, B<home>

To move the cursor at the begining of the line

=item B<ctrl+e>, B<end>

To move the cursor at the end of the line

=item B<meta+<>, B<meta+E<gt>>

To move the cursor at the beginning / end of the text

=item B<BackSpace>, B<ctrl+h>

To delete the char just before the cursor

=item B<Delete>

To delete the char just after the cursor

=item B<Return>

To insert a return char. This does not validate the input!

=back

=head1 BUGS

No known bugs at this time. If you find one, please report them to the authors.

=head1 SEE ALSO

perl(1), Tk(1), Tk::Zinc(3), zinc-demos(1)

=head1 AUTHORS

Patrick Lecoanet <lecoanet@cena.fr>
(and some documentation by Christophe Mertz <mertz@cena.fr>)

=head1 COPYRIGHT

CENA (C) 2002

Tk::Zinc::Text is part of Zinc and has been developed by the CENA (Centres d'Etudes de la Navigation Aérienne)
for its own needs in advanced HMI (Human Machine Interfaces or Interactions). Because we are confident
in the benefit of free software, the CENA delivered this toolkit under the GNU
Library General Public License.

This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MER­CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
General Public License for more details.

=head1 HISTORY

June 2002 : initial release with Zinc-perl 3.2.6

=cut

Added jni/tkzinc/Perl/Zinc/Trace.pm.







































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1995-1999 Nick Ing-Simmons. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself, subject
# to additional disclaimer in Tk/license.terms due to partial
# derivation from Tk8.0 sources.
#
# Copyright (c) 2002 CENA, C.Mertz <mert@cena.fr> to trace all
# Tk::Zinc methods calls as well as the args in a human readable
# form. Updated by D.Etienne.
#
# This package overloads the Tk::Methods function in order to trace
# every Tk::Zinc method call in your application.
#
# This may be very usefull when your application segfaults and
# when you have no idea where this happens in your code.
#
# $Id$
#
# To trap Tk::Zinc errors, use rather the Tk::Zinc::TraceErrors package.
#
# for using this file do some thing like :
# perl -MTk::Zinc::Trace myappli.pl

package Tk::Zinc::Trace;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use vars qw( $ForReplay );

use Tk;
use strict;
use Tk::Zinc::TraceUtils;

my $WidgetMethodfunction;
my %moduleOptions;


BEGIN {
    if (defined $ZincTraceErrors::on && $ZincTraceErrors::on == 1) {
	print STDERR "Tk::Zinc::Trace: incompatible package Tk::Zinc::TraceErrors is already ".
	    "loaded (exit 1)\n";
	exit 1;
    }
    print "## Tk::Zinc::Trace ON\n";
    $ZincTrace::on = 1;
    require Getopt::Long;
    Getopt::Long::Configure('pass_through');
    Getopt::Long::GetOptions(\%moduleOptions, 'code');
    $ForReplay=1 if defined $moduleOptions{code} ;
    select STDOUT; $|=1; ## for flushing the trace output
    # save current Tk::Zinc::InitObject function; it will be invoked in
    # overloaded one (see below)
    use Tk;
    use Tk::Zinc;
    $WidgetMethodfunction = Tk::Zinc->can('WidgetMethod');
    
}

print "## following trace should be very close to a replay-script code\n" if $ForReplay;

my $ZincCounter= "";
my %ZincHash;

#sub Tk::Zinc {
#    print "CREATING Zinc : @_";
#    &$ZincCreationMethodfunction;
#}

sub Tk::Zinc::WidgetMethod {
    my ($zinc, $name, @args) = @_;
    if (defined $Tk::Zinc::Trace::off and $Tk::Zinc::Trace::off > 0) {
	return &$WidgetMethodfunction(@_) if $WidgetMethodfunction;
    }
    my ($package, $filename, $line) = caller(1);
    $package="" unless defined $package;
    $filename="" unless defined $filename;
    $line="" unless defined $line;
    my $widget;
    if (defined $ZincHash{$zinc}) {
	$widget = $ZincHash{$zinc};
    } elsif ($ZincCounter) {
	$ZincHash{$zinc} = '$zinc'.$ZincCounter;
	$widget = '$zinc'.$ZincCounter;
	$ZincCounter++;
    } else {
	$ZincHash{$zinc} = '$zinc';
	$widget = '$zinc';
	$ZincCounter=1; # for the next zinc
    }
    
    if ($ForReplay) {
	print "$widget->$name";
    } else {
	print "TRACE: $filename line $line $name";
    }

    &printList(@args);
    # invoke function possibly overloaded in other modules
    if (wantarray()) {
	my @res = &$WidgetMethodfunction(@_) if $WidgetMethodfunction;
	if ($ForReplay) {
	    print ";\n";
	} else {
	    print "  RETURNS ";
	    &printList (@res);
	    print "\n";
	}
	$zinc->update;
	return @res;
    } else {
	my $res = &$WidgetMethodfunction(@_) if $WidgetMethodfunction;
	if ($ForReplay) {
	    print ";\n";
	} else {
	    print "  RETURNS ";
	    &printItem ($res);
	    print "\n";
	}
	$zinc->update;
	return $res;
    }
}
    
1;


__END__

=head1 NAME

Tk::Zinc::Trace - A module to trace all Tk::Zinc method calls

=head1 SYNOPSIS

use Tk::Zinc::Trace;
$Tk::Zinc::Trace:ForReplay = 1;

or

perl -MTk::Zinc::Trace YourZincBasedScript.pl [--code]

=head1 DESCRIPTION

When loaded, this module overloads a Tk mechanism so that every
Tk::Zinc method call will be traced. Every call will also be followed by a
$zinc->update() so that the method call will be effectively treated.

This module can be very effective for debugging when Tk::Zinc
core dumps and you have no clue which method call can be responsible for. If
you just want to trace Tk::Zinc errors when calling a method you
should rather use the Tk::Zinc::TraceErrors module

The global variable $Tk::Zinc::Trace:off can be used to trace some specific blocks. If set to 1, traces are deactivated, if set to 0, traces are reactivated.
    
If the global variable $Tk::Zinc::Trace:ForReplay is set or if the --code
option is set in the second form, the printout will be very close to re-executable
code, like this:

 ## following trace should be very close to a replay-script code
 $zinc->configure(-relief => 'sunken', -borderwidth => 3,
		  -width => 700, -font => 10x20, -height => 600);
 $zinc->add('rectangle', 1, [10, 10, 100, 50],
	    -fillcolor => 'green', -filled => 1, -linewidth => 10,
	    -relief => 'roundridge', -linecolor => 'darkgreen');
 $zinc->add('text', 1, -font => -adobe-helvetica-bold-r-normal-*-120-*-*-*-*-*-* =>
	    -text => 'A filled rectangle with a "roundridge" relief border of 10 pixels.',
	    -anchor => 'nw', -position => [120, 20]);
 $zinc->add('track', 1, 6,
	    -labelformat => 'x82x60+0+0 x60a0^0^0 x32a0^0>1 a0a0>2>1 x32a0>3>1 a0a0^0>2',
	    -position => [20, 120], -speedvector => [40, -10], -speedvectormark => 1, -speedvectorticks => 1);
 $zinc->coords(4, [20, 120]);

    
If not (the default), the printout will be more informtative, giving
the following information:
    
=over 6

=item * the source filename where the method has been invoked

=item * the line number in the source file

=item * the TkZinc method name

=item * the list of arguments in a human-readable form

=item * the returned value

=back

The trace will look like:

 ## Tk::Zinc::Trace ON
 TRACE: /usr/lib/perl5/Tk/Widget.pm line 196 configure(-relief => 'sunken', -borderwidth => 3, -width => 700, -font => 10x20, -height => 600)  RETURNS undef
 TRACE: Perl/demos/demos/zinc_lib/items.pl line 21 add('rectangle', 1, [10, 10, 100, 50], -fillcolor => 'green', -filled => 1, -linewidth => 10, -relief => 'roundridge', -linecolor => 'darkgreen')  RETURNS 2
 TRACE: Perl/demos/demos/zinc_lib/items.pl line 25 add('text', 1, -font => -adobe-helvetica-bold-r-normal-*-120-*-*-*-*-*-* => -text => 'A filled rectangle with a "roundridge" relief border of 10 pixels.', -anchor => 'nw', -position => [120, 20])  RETURNS 3
 TRACE: Perl/demos/demos/zinc_lib/items.pl line 36 add('track', 1, 6, -labelformat => 'x82x60+0+0 x60a0^0^0 x32a0^0>1 a0a0>2>1 x32a0>3>1 a0a0^0>2', -position => [20, 120], -speedvector => [40, -10], -speedvectormark => 1, -speedvectorticks => 1)  RETURNS 4

=head1 AUTHOR

C.Mertz <mertz@cena.fr> and D.Etienne <etienne@cena.fr>

=head1 CAVEATS and BUGS

This module cannot be used when Tk::Zinc::TraceErrors is already in use.

As every Tk::Zinc method call is followed by an ->update call, this may
dramatically slowdown an application. The trade-off is between application
run-time and developper debug-time.

When using an output "code-like" they are still part of the output which is
not executable code. However, the ouptut could be easily and manually
edited to be executable perl code.

=head1 COPYRIGHT

See Tk::Zinc copyright; BSD

=head1 SEE ALSO

L<Tk::Zinc(3pm)>, L<Tk::Zinc::TraceErrors(3pm)>. L<Tk::Zinc::Debug(3pm)>.

=cut

Added jni/tkzinc/Perl/Zinc/TraceErrors.pm.











































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1995-1999 Nick Ing-Simmons. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself, subject
# to additional disclaimer in Tk/license.terms due to partial
# derivation from Tk8.0 sources.
#
# Copyright (c) 2003 CENA, D.Etienne <etienne@cena.fr> to trace all
# Tk::Zinc errors.
#
# This package overloads the Tk::Zinc::WidgetMethods function in order to
# to trap errors by calling every Tk::Zinc method in an eval() block.
#
# This may be very usefull when your application encounters errors such as
# "error .... at /usr/lib/perl5/Tk.pm line 228". With ZincTraceErrors, the
# module name, the line number and the complete error messages are reported
# for each error.
#
# $Id$
#
# When you have no idea where this happens in your code or when your
# application segfaults, use the Tk::Zinc::Trace package which traces every
# Tk::Zinc method call.
#
# for using this file do some thing like :
# perl -MTk::Zinc::TraceErrors myappli.pl

package Tk::Zinc::TraceErrors;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use strict;
use Tk::Zinc::TraceUtils;

my $WidgetMethodfunction;
my $bold = "";
my $_bold = "";

BEGIN {
    my $bold = "";
    my $_bold = "";
    
    if (defined $ZincTrace::on and $ZincTrace::on == 1) {
	print STDERR $bold."Tk::Zinc::TraceErrors: incompatible package Tk::Zinc::Trace is already ".
	    "loaded".$_bold." (exit 1)\n";
	exit 1;
    }
    print $bold."Tk::Zinc::TraceErrors is ON".$_bold."\n";
    $ZincTraceErrors::on = 1;
    select STDOUT; $|=1; ## for flushing the trace output
    # save current Tk::Zinc::InitObject function; it will be invoked in
    # overloaded one (see below)
    use Tk;
    use Tk::Zinc;
    $WidgetMethodfunction = Tk::Zinc->can('WidgetMethod');
    
}

sub Tk::Zinc::WidgetMethod {
    my ($zinc, $name, @args) = @_;
    my ($package, $filename, $line) = caller(1);
    $package="" unless defined $package;
    $filename="" unless defined $filename;
    $line="" unless defined $line;
    # invoke function possibly overloaded in other modules
    my ($res, @res);
    if (wantarray()) {
	eval {@res = &$WidgetMethodfunction(@_) if $WidgetMethodfunction;};
    } else {
	eval {$res = &$WidgetMethodfunction(@_) if $WidgetMethodfunction;};
    }
    if ($@) {
	print $bold."error:".$_bold." $filename line $line $name";
	&printList (@args);
	my $msg = $@;
	$msg =~ s/at .*//g;
	print " ".$bold."returns".$_bold." $msg\n";
    }
    if (wantarray()) {
	return @res;
    } else {
	return $res;
    }
}
    
    

1;


__END__

=head1 NAME

Tk::Zinc::TraceErrors - A module to trace all Tk::Zinc method calls which generate an error

=head1 SYNOPSIS

use Tk::Zinc::TraceErrors;

or

perl -MTk::Zinc::TraceErrors YourZincBasedScript.pl

=head1 DESCRIPTION

When loaded, this module overloads a Tk mechanism so that every
Tk::Zinc method call will be traced if it provokes an error. The execution
will then continue.

This module can be very effective for debugging and application, specially
when Tk gives an unusuable error message such as ".... errors in Tk.pm line 228"
    
=over 6

=item * the source filename where the method has been invoked

=item * the line number in the source file

=item * the TkZinc method name

=item * the list of arguments in a human-readable form

=item * the error message

=back

=head1 AUTHOR

D.Etienne <etienne@cena.fr> and C.Mertz <mertz@cena.fr>

=head1 CAVEAT

This module cannot be used when Tk::Zinc::Trace is already in use.

=head1 COPYRIGHT

See Tk::Zinc copyright; BSD

=head1 SEE ALSO

L<Tk::Zinc(3pm)>, L<Tk::Zinc::Trace(3pm)>. L<Tk::Zinc::Debug(3pm)>.

=cut

Added jni/tkzinc/Perl/Zinc/TraceUtils.pm.







































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package Tk::Zinc::TraceUtils;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Font;
use Tk::Photo;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(printItem printArray printList Item Array List);

use strict;

sub printItem {
    print &Item (@_);
}

sub printArray {
    print &Array (@_);
}

sub printList {
    print &List (@_);
}


### to print something
sub Item {
    my ($value) = @_;
    my $ref = ref($value);
#    print "VALUE=$value REF=$ref\n";
    if ($ref eq 'ARRAY') {
	return Array ( @{$value} );
    } elsif ($ref eq 'CODE') {
	return "{CODE}";
    } elsif ($ref eq 'Tk::Photo') {
#	print " **** $value ***** ";
	return "Tk::Photo(\"". scalar $value->cget('-file') . "\")";
    } elsif ($ref eq 'Tk::Font') {
	return "'$value'";
    } elsif ($ref eq '') {  # scalar 
	if (defined $value) {
          if ($value =~ /^-[a-zA-Z]([\w])*$/) { # -option1 or -option-1
            return $value;
          } elsif ($value =~ /^-?\d+(\.\d*(e[+-]?\d+)?)?$/) { # -1. or 1.0 or -1.2e+22  or 1.02e+034
            if ($value =~ /(.*[-+]e)0+(\d+)/) {   # removing the 0 after e+ or e-
              return $1.$2;
            } else {
              return $value;
            }
          } elsif ($value eq ''
                   or $value =~ /\s/
                   or $value =~ /^[a-zA-Z]/
                   or $value =~ /^[\W]/
                  ) {
            return "'$value'";
          } else {
            return $value;
          }
	} else {
	    return "_undef";
	}
    } else { # some  class instance
	return $value;
    }
    
} # end Item


### to print a list of something
sub Array {
    my (@values) = @_;
    if (! scalar @values) {
	return "[]";
    }
    else {  # the list is not empty
	my $res = "[";
	while (@values) {
	    my $value = shift @values;
	    $res .= &Item ($value);
	    $res .= ", " if (@values);
	}
	return $res. "]" ;
    }
    
} # end Array


sub List {
    my $res = "(";
    while (@_) {
	my $v = shift @_;
	$res .= Item ($v);
	if (@_ > 0) {
	    ## still some elements
	    if ($v =~ /^-\d+$/) {
		$res .= ", ";
	    } elsif ($v =~ /^-\w+$/) {
		$res .= " => ";
	    } else {
		$res .= ", ";
	    }
	}
    }
    return $res. ")";
    
} # end List


1;



Added jni/tkzinc/Perl/demos/Makefile.PL.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
use ExtUtils::MakeMaker;
WriteMakefile(
	      'EXE_FILES' => ['zinc-demos'],
	      'PMLIBDIRS' => [ qw( Tk/demos/zinc_pm Tk/demos/zinc_contrib_lib
				   Tk/demos/zinc_data Tk/demos/zinc_lib ) ],
      );
 

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_contrib_lib/README.



>
1
This directory is for deposing zinc demos contribs

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_contrib_lib/TripleRotatingWheel.pl.



























































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/usr/bin/perl
# TripleRotatingWheel gambling game contributed by "zentara"

# Idea derived from the wheelOfFortune.pl demo by D. Etienne etienne@cena.fr
# $Id$ 


use Tk; 
use Tk::Zinc;

my @win =(); # an array to store winning wheel values, can range from
             # () to (1,1,1) 

# We create a classical root widget called MainWindow; then we create Zinc 
# widget child with size, color and relief attributes, and we display it using
# the geometry manager called 'pack'.
my $mw = MainWindow->new;
$mw->geometry("700x600");

$mw->resizable(0,0);

my $zinc = $mw->Zinc(-width => 700, -height => 565,
                    -backcolor => 'black',
		     -borderwidth => 3, -relief => 'sunken');
$zinc->pack;

# Then we create a gray filled rectangle, in which we will display explain text.
$zinc->add('rectangle', 1 , [200, 400, 490, 490],
	   -linewidth => 2,
	   -filled => 1,
	   -fillcolor => 'SkyBlue',
	   );
my $text = $zinc->add('text', 1,
		      -position => [350, 445],
		      -anchor => 'center',
		      );

$zinc->add('rectangle', 1 , [250,275,450,325], #(xpos1,ypos1,xpos2,ypos2)
	   -linewidth => 2,
	   -filled => 1,
	   -fillcolor => 'Orange',
	   );

my $wintext = $zinc->add('text', 1,
		      -position => [350, 300],
		      -anchor => 'center',
		      );

#create winning wheel markers
#create first triangle, then clone and translate
my $tr1 = $zinc->add('triangles', 1,
                     [0,20,20,20,10,50],
                     -fan => 1,
                     -colors => 'Orange',
                     -visible => 1,
                     );
my $tr2 = $zinc->clone($tr1);
my $tr3 = $zinc->clone($tr1);
$zinc->translate($tr1,130,0);
$zinc->translate($tr2,340,0);
$zinc->translate($tr3,550,0);



# Create the Wheel object (see Wheel.pm)
my $wheel1 = Wheel->new($zinc, 350, 500,  100); #start xpos,ypos,mag
my $wheel2 = Wheel->new($zinc, 350, 500, 100);
my $wheel3 = Wheel->new($zinc, 350, 500, 100);

# Display comment
&comment("Strike any key to begin");
&wincomment("READY");

# Create Tk binding
$mw->Tk::bind('<Key>', \&openmode);


MainLoop;

# Callback bound to '<Key>' event when wheel is unmapped
sub openmode {
    # set binding to unmap the wheel
    $mw->Tk::bind('<Key>', \&closemode);
    # set binding to rotate the hand
    $zinc->bind($wheel1, '<1>', sub {spin()}); 
    $zinc->bind($wheel2, '<1>', sub {spin()});    
    $zinc->bind($wheel3, '<1>', sub {spin()});    
    # map the wheel
    $wheel1->show(140, 150);
    $wheel2->show(350, 150);
    $wheel3->show(560, 150);
    
    # and then inform user
    &comment("Click on any wheel to play.\n".
	     "Strike any key to hide the wheels.");
}

sub spin {
    return if $wheel1->ismoving;
    return if $wheel2->ismoving;
    return if $wheel3->ismoving;

  @win=();
  &wincomment("PLAYING");
          $wheel1->rotatewheel(int rand(360));
          $wheel2->rotatewheel(int rand(360));
	  $wheel3->rotatewheel(int rand(360));
#  print "\@win->@win\n";
 }    


# Callback bound to '<Key>' event when wheel is already mapped 
sub closemode {
    return if $wheel1->ismoving;
    return if $wheel2->ismoving;
    return if $wheel3->ismoving;

    # set binding to map the wheel
    $mw->Tk::bind('<Key>', \&openmode);
    # unmap the wheel
    $wheel1->hide(350, 400);
    $wheel2->hide(350, 400);
    $wheel3->hide(350, 400);
    # and then inform user
    &comment("Strike any key to show the wheel");
}

# Just display comment 
sub comment {
    my $string = shift;
    $zinc->itemconfigure($text, -text => $string);
}

# display winning comment 
sub wincomment {
    my $string = shift;
    $zinc->itemconfigure($wintext, -text => $string);
}

sub displaywin {
  if($#win == -1){&wincomment("NO WIN")}
  if($#win == 0){&wincomment("SINGLE")}
  if($#win == 1){&wincomment("DOUBLE")}
  if($#win == 2){&wincomment("TRIPLE")}
 
 #restore disabled mouse click for next spin
  $zinc->bind($wheel1, '<1>',  sub {spin()}); 
  $zinc->bind($wheel2, '<1>', sub {spin()});    
  $zinc->bind($wheel3, '<1>', sub {spin()});    
}

#=============================================================================
#                 Wheel  Class
#=============================================================================
package Wheel;

use strict 'vars';
use Carp;
#====================
# Object constructor
#====================
sub new {
    my ($proto, $widget, $x, $y, $radius) = @_;
  
    # object attributes
    my $self = {
	'widget' => $widget,   # widget reference
	'origin' => [$x, $y],  # origin coordinates
	'radius' => $radius,   # wheel radius
	'topgroup' => undef,   # top Group item
	'itemclip' => undef,   # id of item which clips the wheel
	'angle' => 0,          # delta angle
	'stepsnumber' => 20,   # animations parameters
	'afterdelay' => 30,
	'shrinkrate' => 0.8,   # zoom parameters
	'zoomrate' => 1.1,
	   
	};
    bless $self;    
    
    # First, we create a new Group item for the wheel. Why a Group item ?
    # At least two reasons. Wheel object consists of several Zinc items,  
    # we'll see below; it moves when it is mapped or unmapped, grows when  
    # you hit the jackpot. So, it's more easy to apply such transformations 
    # to a structured items set, using Group capability, rather than apply 
    # to each item separately or using canvas-like Tags mechanism.
    # Second reason refers to clipping. When it is mapped or unmapped, wheel 
    # object is drawn inside a circle with variant radius; clipping is a 
    # specific property of Group item

    # That's why we create a Group item in the top group, and set its
    # coordinates.
    $self->{topgroup} = $widget->add('group', 1, -visible => 0);
    $widget->coords($self->{topgroup}, [$x,$y]);
    
#print "  start widget coords-> $x $y\n";    
        
    # All the following items will be created in this group...
    # Create the invisible Arc item used to clip the wheel, centered on the
    # group origin.
    $self->{itemclip} = $widget->add('arc',  $self->{topgroup},
				     [-$radius, -$radius, $radius, $radius],
				     -visible => 0,
				     );
    $widget->itemconfigure($self->{topgroup}, -clip => $self->{itemclip});

    # Create the wheel with 6 filled Arc items centered on the group origin
    my $i = 0;
    for my $color (qw(magenta blue cyan green yellow red)) {
	$widget->add('arc',  $self->{topgroup},
		     [-$radius, -$radius, $radius, $radius],
		     -visible => 1,
		     -filled => 1,
		     -closed => 1,
		     -extent => 60,
		     -pieslice => 1,
		     -fillcolor => $color,
		     -linewidth => 1,
		     -startangle => 60*$i ,
		     -tags => [$self],
		     );
	$i++;
    }
    
    # Create the Text item representing the jackpot.
    $widget->add('text', $self->{topgroup},
		 -position => [0, -$radius+20],
		 -font =>
		 '-adobe-helvetica-bold-o-normal--34-240-100-100-p-182-iso8859-1',
		 -anchor => 'center',
		 -text => "\$",
		 );
    
    
    # Then we unmap the wheel; in fact, Group item is translated and its
    # clipping circle is shrunk to a point.
    $self->_clipAndTranslate($self->{shrinkrate}**$self->{stepsnumber});
    return $self;
}

#================
# Public methods
#================

# Return 1 if wheel is moving (opening or closing animation)
sub ismoving {
    my $self = shift;
    return 1 if $self->{opening} or $self->{closing} or $self->{turning};
}

# Display wheel with animation effect
sub show {
    my ($self, $x, $y) = @_;
    # simple lock management
    return if $self->{opening} or $self->{closing};
    $self->{opening} = 1;
    # start animation 
    $self->_open($x, $y, 0);
}


# Unmap wheel with animation effect
sub hide {
    my ($self, $x, $y) = @_;
    # simple lock management
    return if $self->{opening} or $self->{closing};
    $self->{closing} = 1;
    # start animation
    $self->_close($x, $y, 0);
}


# Just rotate the hand with animation effect.
sub rotatewheel {
    my $self = shift;
    #print "wheel-> $self->{topgroup}";
    my $angle = shift;
#print "  angle->$angle\n";

    return if $self->{turning};

#prevent "double-clicking", so mouse is disabled
#until current play is over
$zinc->bind($wheel1, '<1>', sub {}); 
$zinc->bind($wheel2, '<1>', sub {});    
$zinc->bind($wheel3, '<1>', sub {});    

    $angle = 0  unless $angle;
    my $oldangle = $self->{angle};
    $self->{angle} = $angle;

    if ((330 < $angle)||($angle < 30)) {
    	$self->{fortune} = 1;
        push (@win, $self->{fortune});
    }
    $self->_rotatewheel(2*3.1416*($angle + 1440 - $oldangle)/360); 
    #the 1440 above gives at least 2 full spins each play  
}

#=================
# Private methods
#=================

# Generate opening animation; see below _clipAndTranslate method for
# Zinc specific use.
sub _open {
    my ($self, $x, $y, $cnt) = @_;
    my $widget = $self->{widget};
    my $group = $self->{topgroup};
    # first step of animation
    if ($cnt == 0) {
	$widget->itemconfigure($group, -visible => 1);
	my @pos = $widget->coords($group);
	$x = ($x - $pos[0])/$self->{stepsnumber};
	$y = ($y - $pos[1])/$self->{stepsnumber};
    # last step
    } elsif ($cnt == $self->{stepsnumber}) {
	$self->{opening} = undef;
	return;
    }
    $cnt++;
    # move and grow the wheel
    $self->_clipAndTranslate(1/$self->{shrinkrate}, $x, $y);
    # process the animation using the 'after' Tk defering method
    $widget->after($self->{afterdelay}, sub {$self->_open($x, $y, $cnt)});
}


# Generate closing animation; see below _clipAndTranslate method for
# Zinc specific use.
sub _close {
    my ($self, $x, $y, $cnt) = @_;
    my $widget = $self->{widget};
    my $group = $self->{topgroup};
    # first step of animation
    if ($cnt == 0) {
	my @pos = $widget->coords($group);
	$x = ($x - $pos[0])/$self->{stepsnumber};
	$y = ($y - $pos[1])/$self->{stepsnumber};
    # last step
    } elsif ($cnt == $self->{stepsnumber}) {
	$widget->itemconfigure($group, -visible => 0);
	$self->{closing} = undef;
	return;
    }
    $cnt++;
    # move and shrink the wheel
    $self->_clipAndTranslate($self->{shrinkrate}, $x, $y);
    # process the animation using the 'after' Tk defering method
    $widget->after($self->{afterdelay}, sub {$self->_close($x, $y, $cnt)});

&main::wincomment("READY");
}

# Generate hand rotation animation.
sub _rotatewheel {
    my ($self, $angle, $cnt) = @_;
    my $widget = $self->{widget};
    my $group = $self->{topgroup};

#grab position of widget
my @pos = $widget->coords($group);
my $x = ($pos[0]);
my $y = ($pos[1]);

    $self->{turning} = 1;
    # first step of animation
    if (not $cnt) {
	$angle /= $self->{stepsnumber};
    
    # last step
    } elsif ($cnt == $self->{stepsnumber}) {
	if ($self->{fortune}) {
	    $self->_fortune;
	} else {
	    $self->{turning} = undef;
	}

        &main::displaywin();
	return;
    }
    $cnt++;
    # use 'rotation' Zinc method.

    $widget->rotate($self->{topgroup}, $angle);
# process the animation using the 'after' Tk defering method

#needed to keep wheel stationary while rotating
$widget->coords($self->{topgroup},[$x,$y]);

    $widget->after($self->{afterdelay}, sub {$self->_rotatewheel($angle, $cnt)});

}

# Generate growing animation to notify jackpot
sub _fortune {
    my ($self, $cnt) = @_;
    $cnt = 0 unless $cnt;
    my $zf;
    my $widget = $self->{widget};
    my $group = $self->{topgroup};
    my @pos = $widget->coords($group);
    # last step of animation
    if ($cnt == 6) {
	$self->{fortune} = undef;
	$self->{turning} = undef;
	return;
    # event steps : wheel grows
    } elsif ($cnt == 0 or $cnt % 2 == 0) {
	$zf = $self->{zoomrate};
    # odd steps : wheel is shrunk
    } else {
	$zf = 1/$self->{zoomrate};
    }
    $cnt++;
    
    # Now, we apply scale transformation to the Group item, using the 'scale'
    # Zinc method. Note that we reset group coords before scaling it, in order
    # that the origin of the transformation corresponds to the center of the
    # wheel. When scale is done, we restore previous coords of group.
    $widget->coords($group, [0, 0]);
    $widget->scale($group, $zf, $zf);
    $widget->coords($group, \@pos);
    
    # process the animation using the 'after' Tk defering method
    $widget->after(100, sub {print "\007";$self->_fortune($cnt)});
    &main::displaywin();
}


# Update group clipping and translation, using 'scale' and 'translate'
# Zinc methods.
sub _clipAndTranslate {
    my ($self, $shrinkfactor, $x, $y) = @_;
    $x = 0 unless $x;
    $y = 0 unless $y;
    $self->{widget}->scale($self->{itemclip}, $shrinkfactor, $shrinkfactor);
    if ($Tk::Zinc::VERSION lt "3.297") {
	$self->{widget}->translate($self->{topgroup}, $x, $y);
    } else {
	my ($xc, $yc) = $self->{widget}->coords($self->{topgroup});
	$self->{widget}->coords($self->{topgroup}, [$xc + $x, $yc + $y]);
    }
}
1;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/background_texture.gif.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/hegias_parouest_TE.vid.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/paper-grey.gif.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/paper-grey1.gif.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/paper.gif.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/stripped_texture.gif.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/videomap_orly.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/videomap_paris-w_90_2.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/zinc.gif.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_data/zinc_anti.gif.

cannot compute difference between binary files

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/MagicLens.pl.











































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/bin/perl
#-----------------------------------------------------------------------------------
#
#      MagicLens.pl
#
#      This small demo is based on Zinc::Graphics.pm for creating
#      the graphic items.
#      The magnifyer effect is obtained with the help of clipping,
#      and some glass effect is based on color transparency through
#      a triangles item bordering the magnifier
#
#      Authors: Jean-Luc Vinot <vinot@cena.fr>
#
# $Id$
#-----------------------------------------------------------------------------------

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use Tk::Zinc::Graphics;
use Getopt::Long;
use strict 'vars';

# the original fonts are not available everywhere, even if they are free!
my $font_9b = '7x13bold'; # '-cenapii-bleriot mini-bold-r-normal--9-90-75-75-p-*-iso8859-15';
my $font_8 = '7x13';  #'-cenapii-bleriot mini-book-r-normal--8-80-75-75-p-*-iso8859-15';
my ($dx, $dy);

my @basiccolors = (['Jaune','#fff52a','#f1f1f1','#6a6611'],
		   ["Jaune\nOrangé",'#ffc017','#cfcfcf','#6b510a'],
		   ['Orangé','#ff7500','#a5a5a5','#622d00'],
		   ['Rouge','#ff2501','#8b8b8b','#620e00'],
		   ['Magenta','#ec145d','#828282','#600826'],
		   ["Violet\nRouge",'#a41496','#636363','#020940'],
		   ["Violet\nBleu",'#6a25b6','#555555','#2a0f48'],
		   ['Bleu','#324bde','#646464','#101846'],
		   ['Cyan','#0a74f0','#818181','#064a9a'],
		   ["Bleu\nVert",'#009bb4','#969696','#006474'],
		   ['Vert','#0fa706','#979797','#096604'],
		   ["Jaune\nVert",'#9dd625','#c9c9c9','#496311']);

my $circle_coords = [[0,-30],[-16.569,-30,'c'],[-30,-16.569,'c'],[-30,0],[-30,16.569,'c'],[-16.569,30,'c'],[0,30],
		     [16.569,30,'c'],[30,16.569,'c'],[30,0],[30,-16.569,'c'],[16.569,-30,'c'],[0,-30]];


# MagicLens
my %lensitems = ('back' => {-itemtype => 'arc',
			    -coords => [[-100, -100],[100,100]],
			    -params => {-priority => 10,
					-closed => 1,
					-filled => 1,
					-visible => 0,
					-tags => ['lensback'],
				       },
			   },
 		 'light' => {-itemtype => 'pathline',
 			     -metacoords => {-type => 'polygone',
 					     -coords => [0, 0],
 					     -numsides => 36,
 					     -radius => 100,
 					     -startangle => 240,
 					    },
 			     -linewidth => 10,
 			     -shifting => 'in',
 			     -closed => 1,
 			     -graduate => {-type => 'double',
 					   -colors => [['#ffffff;0', '#6666cc;0', '#ffffff;0'],
 						       ['#ffffff;100', '#333399;50', '#ffffff;100']],
 					  },
 			     -params => {-priority => 50,
 					},
 			    },
 		 'bord' => {-itemtype => 'hippodrome',
 			    -coords => [[-100, -100],[100, 100]],
 			    -params => {-priority => 100,
 					-closed => 1,
 					-filled => 0,
 					-linewidth => 2,
 					-linecolor => '#222266;80'
 				       },

 			   },
		);
				

# creation de la fenetre principale
my $mw = MainWindow->new();
$mw->geometry("1000x900+0+0");
$mw->title('Color Magic Lens');


# creation du widget Zinc
my $zinc = $mw->Zinc(-render => 1,
		     -width => 1000,
		     -height => 900,
		     -borderwidth => 0,
		     -lightangle => 140,
		     -borderwidth => 0,
		     );
$zinc->pack(-fill => 'both', -expand => 1);

my $texture = $zinc->Photo(-file => Tk->findINC('demos/zinc_data/paper-grey1.gif'));
$zinc->configure(-tile => $texture);

# création des 2 vues
my $normview = $zinc->add('group', 1, -priority => 100);
my $lensview = $zinc->add('group', 1, -priority => 200);
my $infoview = $zinc->add('group', $lensview);

my $zoom=1.20;
$zinc->scale($infoview, $zoom, $zoom);

my $lenstexture = $zinc->Photo(-file => Tk->findINC('demos/zinc_data/paper-grey.gif'));
$zinc->add('rectangle', $infoview,
	   [[0,0],[1000,900]],
	   -filled => 1,
	   -fillcolor => '#000000',
	   -tile => $lenstexture,
	   -linewidth => 0,
	   );

my $gradbar;

my $x = 60;
for (my $i = 0; $i < 12; $i++) {

  # ajout d'un groupe dans chacune des les 2 vues
  my $cgroup = $zinc->add('group', $normview);
  $zinc->coords($cgroup, [$x, 60]);
  my $lgroup = $zinc->add('group', $infoview);
  $zinc->coords($lgroup, [$x, 60]);

  # références de la couleur : name, Zncolor saturée, ZnColor désaturée, ZnColor d'ombrage
  my ($colorname, $saturcolor, $greycolor, $shadcolor) = @{$basiccolors[$i]};

  # échantillon référence couleur saturée + relief
  my $refgrad = "=radial -12 -20|#ffffff 0|".$saturcolor." 40|".$shadcolor." 100";
  my $refitem = $zinc->add('curve', $cgroup,
			   $circle_coords,
			   -filled => 1,
			   -fillcolor => $refgrad,
			   -linewidth => 2,
			   -priority => 100
			  );

  # clone dans le group infoview
  my $clone = $zinc->clone($refitem);
  $zinc->chggroup($clone, $lgroup);

  # label couleur (infoview)
  $zinc->add('text', $lgroup,
	     -priority => 200,
	     -position => [0, 0],
	     -text => $colorname,
	     -anchor => 'center',
	     -alignment => 'center',
	     -font => $font_9b,
	     -spacing => 2,
	    );

  # dégradé de la couleur vers le gris de même luminosité
  my $bargrad = "=axial 270|".$saturcolor."|".$greycolor;

  # création des échantillons de couleur (curve multi-contours)
  $gradbar = $zinc->add('curve', $cgroup,
			[],
			-closed => 1,
			-filled => 1,
			-fillcolor => $bargrad,
			-linewidth => 2,
			-priority => 20,
			-fillrule => 'nonzero'
		       );

  # définition des couleurs du dégradé (saturation 100% -> 0%)
  my $zncolors = &createGraduate($zinc, 11, [$saturcolor, $greycolor]);
  # on retire les valeurs alphas
  foreach (@{$zncolors}){ ($_) = split /;/, $_;}

  # réalisation des pas de dégradé (saturation -> désaturation)
  my $c;
  for ($c = 0; $c < 11; $c++) {

    # couleur du pas
    my $color = $zncolors->[$c];

    # item zinc de l'exemple couleur
    my $sample = $zinc->clone($refitem, -fillcolor => $color);
    $zinc->translate($sample, 0, 65*($c+1));

    # ajout à la curve multi-contours
    $zinc->contour($gradbar, 'add', 1, $sample);

    # déplacement vers le groupe info
    $zinc->chggroup($sample, $lgroup);

    # label texte (% saturation + ZnColor)
    my $txtcolor = ((10 - $c)*10)."%\n$color";
    $zinc->add('text', $lgroup,
	       -priority => 200,
	       -position => [0, ($c + 1)* 65],
	       -text => $txtcolor,
	       -anchor => 'center',
	       -alignment => 'center',
	       -font => $font_8,
	       -spacing => 2,
	      );
  }


  $x += 80;
}

# création de la MagicLens
my $lensgroup = $zinc->add('group', 1,
			   -priority => 300,
			   -atomic => 1,
			   -tags => ['lens'],
			  );
$zinc->coords($lensgroup, [300, 110]);
&lensMove(0,0);

# items graphiques
while (my ($name, $style) = each(%lensitems)) {
  &buildZincItem($zinc, $lensgroup, %{$style});
}

# clipping lensview
my $lenszone = $zinc->clone('lensback', -tags => ['lenszone']);
$zinc->chggroup($lenszone, $lensview, 1);
$zinc->itemconfigure($lensview, -clip => $lenszone);

# consigne globale
my $consigne = $zinc->add('text', 1,
			  -position => [30, 840],
			  -text => "<Up>, <Down>, <Left> and <Right> keys or <Mouse Drag>\nMove the Magic Color Lens behind the color gradiants\nto see the ZnColor value of Hue/saturation\n",
			  -font => $font_8,
			  -alignment => 'left',
			  -color => '#ffffff',
			  -spacing => 2,
			 );

my $cclone = $zinc->clone($consigne, -font => $font_9b);
$zinc->chggroup($cclone, $infoview);

&setBindings;


MainLoop;
#----------------------------------------------------------------------- fin de MAIN


sub setBindings {
  $zinc->bind('lens', '<1>', sub {&lensStart();});
  $zinc->bind('lens', '<B1-Motion>', sub {&lensMove();});
  $zinc->bind('lens', '<ButtonRelease>', sub {&lensStop();});

  $mw->Tk::focus();

  # Up, Down, Right, Left : Translate
  $mw->Tk::bind('<KeyPress-Up>', sub {lensTranslate('up');});
  $mw->Tk::bind('<KeyPress-Down>', sub {lensTranslate('down');});
  $mw->Tk::bind('<KeyPress-Left>', sub {lensTranslate('left');});
  $mw->Tk::bind('<KeyPress-Right>', sub {lensTranslate('right');});
}




#-----------------------------------------------------------------------------------
# Callback CATCH de sélection (début de déplacement) de la lentille
#-----------------------------------------------------------------------------------
sub lensStart {
  my $ev = $zinc->XEvent;
  ($dx, $dy) = (0 - $ev->x, 0 - $ev->y);

}


#-----------------------------------------------------------------------------------
# Callback MOVE de déplacement de la lentille
#-----------------------------------------------------------------------------------
sub lensMove {
  my ($tx, $ty) = @_;

  if (defined $tx and defined $ty) {
    # interaction clavier
    $zinc->translate('lens', $tx, $ty);
    $zinc->translate('lenszone', $tx, $ty);

  } else {
    my $ev = $zinc->XEvent;
    $zinc->translate('current', $ev->x + $dx, $ev->y +$dy);
    $zinc->translate('lenszone', $ev->x + $dx, $ev->y +$dy);
    ($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
  }

  my ($lx, $ly) = $zinc->coords('lens');
  $zinc->coords($infoview, [$lx * (1-$zoom), $ly * (1-$zoom)]);

}


#-----------------------------------------------------------------------------------
# Callback RELEASE de relaché (fin de déplacement) de la lentille
#-----------------------------------------------------------------------------------
sub lensStop {
  &lensMove;
}

sub lensTranslate {
  my $way = shift;

  my $dx = ($way eq 'left') ? -10 : ($way eq 'right') ? 10 : 0;
  my $dy = ($way eq 'up') ? -10 : ($way eq 'down') ? 10 : 0;

  &lensMove($dx, $dy);

}



1;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/Zetris.pl.

























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
#!/usr/bin/perl
# Zinc port of TkTetris from Slaven Rezic
#------------------------------------------------------------------------------
#
#  Zetris - A Zinc Toy-Appli based on cool TkTetris from Slaven Rezic
#
#  $Id$
#
#  Copyright (C) 2002 Centre d'Etudes de la Navigation Aérienne
#  Author: Marcellin Buisson <buisson@cena.fr>
#
#  Hacked from Original Code to adapt to Tk::Zinc Widget :
#
#------------------------------------------------------------------------------
#
#  Author: Slaven Rezic
#
#  Copyright (C) 1997, 1999, 2000, 2002 Slaven Rezic. All rights reserved.
#  This program is free software; you can redistribute it and/or
#  modify it under the same terms as Perl itself.
#
#  Mail: slaven.rezic@berlin.de
#  WWW:  http://www.rezic.de/eserte/
#
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
#  What are the differences with the original TkTetris ?
#------------------------------------------------------------------------------
#
#  - This TkTetris-like uses a tk widget similar to the canvas
#    and called "Zinc". Zinc bring to Tk widgets openGL features
#    like transparency, color gradients, scaling.
#    So to use Zetris graphic enhancement, you need openGL capability.
#    Zinc comes with other features like grouping and clipping.
#
#  - A color gradient is used for Zetris background,
#
#  - Zetris balls are filled with transparently color gradients,
#    (transparency is visible when balls fall over TkZinc logo)
#
#  - Zetris balls have a little transparent shadow,
#
#  - The TkZinc logo is animated by rotation and scaling effects,
#
#  - Introducing of groups provided by Zinc for grouping items
#    This feature is particularly useful for applying transformations,
#
#  - The TkZinc logo over background isn't an image but only curves
#    and color gradients (made by <vinot@cena.fr>)
#
#  - Please feel free to provide any feedback to <buisson@cena.fr>
#  
#  - CM: Zetris now works even without openGL. It is just ugly!
#
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# ToDos :
#
#  - Complete this basic version in a full playable game like tktetris.
#  - Review conception through Zinc features.
#    (using groups capabilities for drawing blocks for instance)
#  - Adding special effects when completing a line or changing level.
#
#------------------------------------------------------------------------------
use Tk;
use Tk::Zinc;
use strict;
use Tk::Zinc::Logo;

package main;

use Getopt::Long;

use vars qw($VERSION);

$VERSION = sprintf("%d.%00d", q$Revision$ =~ /(\d+)\.(\d+)/);

my $max_size     = 4;
my $nmbr_blks    = 7;
my $width        = 12;
my $height       = 20;
my $geometry;

my $level;
my $just_started = 1;
my $speed;
my $base_speed = 500;

my $last_resize;
my $fontheight   = 0;

my $basefont
  = sub { sprintf "-*-helvetica-medium-r-normal--%s-*", $_[0] };
my $base2font
  = sub { sprintf "-*-courier-medium-r-normal--%s-*", $_[0] };

my $blocks = 0;
my $lines = 0;
my $mylines = 0;

my $pause = undef;
my $pause_w;
my $freefall = 0;
my $points = 0;
my $flat = 0;
my $moveable_drop = 0;

my $old_win_height;
my $draw_shadow = 1;

# Animation constants
my $afterdelay = 1;
my $stepsnumber = 10;
my $zoomrate = 1.1;

my $active_block    = undef;
my $active_block_nr = undef;
my $active_dir      = undef;
my $next_block      = undef;
my $next_block_nr   = undef;
my $next_dir        = undef;
my $posx = undef;
my $posy = undef;

my $n = 0;

my(%color_dark, %color_very_dark);
my %color_bright =
  (2 => 'red',
   3 => 'green',
   4 => 'blue',
   5 => 'cyan',
   6 => 'yellow',
   7 => 'orange',
   8 => 'pink',
  );

# Blocks matrix
my $block =
  [[[qw(0 0 0 0)],
    [qw(0 2 0 0)],
    [qw(0 2 2 0)],
    [qw(0 2 0 0)]],
   [[qw(0 0 0 0)],
    [qw(3 3 0 0)],
    [qw(0 3 0 0)],
    [qw(0 3 0 0)]],
   [[qw(0 0 0 0)],
    [qw(0 4 4 0)],
    [qw(0 4 0 0)],
    [qw(0 4 0 0)]],
   [[qw(0 0 0 0)],
    [qw(0 5 0 0)],
    [qw(0 5 5 0)],
    [qw(0 0 5 0)]],
   [[qw(0 0 0 0)],
    [qw(0 6 0 0)],
    [qw(6 6 0 0)],
    [qw(6 0 0 0)]],
   [[qw(0 7 0 0)],
    [qw(0 7 0 0)],
    [qw(0 7 0 0)],
    [qw(0 7 0 0)]],
   [[qw(0 0 0 0)],
    [qw(0 0 0 0)],
    [qw(8 8 0 0)],
    [qw(8 8 0 0)]],
  ];

my $playfield;
reset_playfield();

my $step_x = 20;
my $step_y = 20;
my $boxsize_x    = $step_x-2;
my $boxsize_y    = $step_y-2;
my $block_border = int($boxsize_x/10);
my $help_top;

my $top = MainWindow->new();
$top->minsize(181, 83);
$top->title('Zetris');

{
  my $width_height_set = 0;
  if ($geometry)
    {
      if ($geometry =~ /^(=?(\d+)x(\d+))?(([+-]\d+)([+-]\d+))?$/)
	{
	  if (defined $2 and defined $3)
	    {
	      my($width, $height) = ($2, $3);
	      $top->GeometryRequest($width, $height);
	      $width_height_set++;
	    }
	  if (defined $5 and defined $6)
	    {
	      my($x, $y) = ($5, $6);
	      $top->geometry("$x$y");
	    }
	}
      else
	{
	  die "Can't parse geometry: $geometry";
	}
    }
    if (!$width_height_set)
      {
	$top->GeometryRequest($top->screenwidth,
			      $top->screenheight);
      }
}

my $base_level = 1;

$level = level();
$speed = speed();

resize_calc();

while(my($k, $v) = each %color_bright)
  {
    $color_dark{$k} = $top->Darken($v, 80);
    $color_very_dark{$k} = $top->Darken($v, 60);
  }


# Zinc Widget (openGl rendering option set to 1)
my $tetris = $top->Zinc(-width  => $step_x*($width-2),
			-height => $step_y*($height-1),
			-backcolor => '#707070',
			-lightangle => 130,
			-render => 1,
		       )->pack;

# Zetris will no more die if there is no openGL render. I did some minor
# modification (transparency, item priority) to make all needed item
# visible, even without alpha-transparency

my $render = $tetris->cget(-render);

my $shadow_group = $tetris->add('group',1, -visible => 1);

my $pause_group = $tetris->add('group',1, -visible => 1);

my $topgroup = 1;

$tetris->pack(-fill => 'both',
	    -expand=> 1);

$tetris->add('rectangle',
	     1, # Zinc group
	     [0, 0,$step_x*($width-2) ,$step_y*($height-1)] ,
	     -filled => 1,
	     -linewidth => 0,
	     -fillcolor  => $render ? "=axial 90 |black;40|gray80;60" : "grey80",
	     -visible => 1);

my $group = $tetris->add('group', 1, );
my $logo = Tk::Zinc::Logo->new(-widget => $tetris,
			       -parent => $group,
			       -position => [$step_x*($width-2)/2-200,
					     $step_y*($height-1)/2],
			       );

$tetris->lower($group) if $render;

my $score_group = $tetris->add('group',1, -visible => 1);
my $new = $tetris->add('text',$score_group,
		       -text => "    $lines Line\n",
		       #-anchor => 'e',
		       -font => $basefont->($fontheight),
		       -position => [$width-2,10],
		      );
$tetris->add('text',$score_group,
		       -text => "Sorry, without openGL,\nZtetris is just ugly.",
		       #-anchor => 'e',
		       -font => $basefont->($fontheight),
		       -position => [$width-2,100],
	     ) if !$render;

$tetris->lower($score_group) if $render;

my $timer = $top->after(speed(), sub {
			  $old_win_height = $top->height;
			  $just_started = 0;
			  action();
			});

make_key_bindings($top);

print "\n***********************************************\n\n   For help on the game toggle pause with 'p'\n\n***********************************************\n\n";

MainLoop;

#------------------------------------------------------------------------
sub reset_playfield
  {
    my $i;
    # $fake_height: mit negativen Indices können die n-letzten Elemente
    # angesprochen werden...
    my $fake_height = $height+$max_size+1;
    for $i (0 .. $fake_height-1)
      {
	$playfield->[$i][0] = 1;
	my $j;
	for $j (1 .. $width-2)
	  {
	    $playfield->[$i][$j] = 0;
	  }
	$playfield->[$i][$width-1] = 1;
      }
    for $i (0 .. $width-1)
      {
	$playfield->[$height-1][$i] = 1;
      }
  }

sub speed
  {
    my $speed = $base_speed - ($base_speed*$level)/20;
    if ($speed <= 5) { $speed = 5 }
    $speed;
  }

sub level
  {
    int($lines / 10) + 1 + $base_level
  }

sub resize_calc
  {
    $last_resize = time();
    my $win_height;
    if ($just_started)
      {
	$win_height = $top->reqheight;
      }
    else
      {
	$win_height = $top->height;
      }
    $step_x = $step_y = int($win_height/($height+3));
    my $gap = ($step_x > 10 ? 2 : 1);
    $boxsize_x    = $step_x-$gap;
    $boxsize_y    = $step_y-$gap;
    $block_border = int($boxsize_x/10);
    if ($block_border < 1) { $block_border = 1 }
    my @font_height = (10, 11, 12, 14, 17, 18, 20, 24, 25, 34);
    my $req_fontheight = $win_height/30;
    $fontheight = 0;
    foreach (@font_height)
      {
	if ($_ > $req_fontheight)
	  {
	    $fontheight = $_;
	    last;
	  }
      }
    if (!$fontheight) { $fontheight = $font_height[$#font_height] }
    # the following line has been commented out since
    # it modify default font for every application
    # launched by zinc-demos! CM 26/3/02
    # $top->optionAdd("*font" => $basefont->($fontheight));
  }

sub make_key_bindings
  {
    my $top = shift;
#    $top->bind('<Escape>' => \&quit_game);
#    $top->bind('<q>'      => \&quit_game);
#    $top->bind('<Control-c>' => \&quit_game);
    $top->bind('<Left>'   => sub { move('left')  });
    $top->bind('<Right>'  => sub { move('right') });
    $top->bind('<Up>'     => sub { move('antiturn')  });
    $top->bind('<Down>'   => sub { move('turn')  });
    $top->bind('<j>'      => sub { move('left')  });
    $top->bind('<l>'      => sub { move('right') });
    $top->bind('<k>'      => sub { move('turn')  });
    foreach (qw/space KP_Enter/) {
      $top->bind("<$_>"  => sub { move('freefall') });
    }
    $top->bind('<p>'      => sub { toggle_pause() });
    $top->bind('<n>'      => \&stop_and_new_game);
    $top->bind('<h>'      => \&help);
    #$top->bind('all', '<F1>'     => \&help); # don't pause
    $top->bind('all', '<F2>'     => \&lost); 
    #XXX Leave und Enter herausnehmen
    $top->bind('<FocusOut>' => sub { inc_pause(1) });
    #    $top->bind('<Leave>'    => sub { inc_pause(1) });
    $top->bind('<FocusIn>'  => sub { dec_pause(1) });
    #$top->bind('<ButtonRelease>'  => sub {  toggle_pause()});
    #$top->bind('<Key-space>'  => sub {  toggle_pause()});
    #    $top->bind('<Enter>'    => sub { dec_pause(1) });
  }


sub inc_pause
  {
    my $quiet = shift;
    $pause++;
    if (!$quiet && !Tk::Exists($pause_w))
      {
	my $width  = $top->width;
	my $height = $top->height;
	$pause_w = $tetris->add('text',$pause_group,
				   -text => "PAUSE MODE :\n Type p to continue\n
\n\n\nHELP : \n\n- 'p' toggle pause\n\n- Arrow keys to move blocks\n\n- 'n' to start a new game\n\n  ",
				   -font => $basefont->($fontheight),
				   -position => [30,50],
				   -anchor => 'nw',

       );
    }
}

sub dec_pause
  {
    if ($pause)
      {
	$pause--;
	if ($pause < 1)
	  {
	    $tetris->remove($pause_w);
	    undef $pause;
	  }
      }
  }

sub toggle_pause
  {
    my $quiet = shift;
    if ($pause)
      {
	$tetris->remove($pause_w);# if Tk::Exists($pause_w);
	undef $pause;
      }
    else
      {
	
	inc_pause($quiet);
      }
  }


sub action
  {
    if (!$pause)
      {
	if (!defined $active_block_nr)
	  {
	    if (!defined $next_block_nr)
	      {
		get_next_block();
	      }
	    $active_block_nr = $next_block_nr;
	    $blocks++;
	    $active_block = [];
	    copyblock($next_block, $active_block);
	    $active_dir      = $next_dir;
	    get_next_block();
	  }
	if (defined $posx)
	  {
	    # erstes Zeichnen
	    if (testblock($active_block, $posx, $posy+1))
	      {
		drawblock($posx, $posy, 0);
		$posy++;
		drawblock($posx, $posy, 1);
	      }
	    else
	      {
		array_update(($level+1) * int(($height-$posy+5)/5),
			     $posx, $posy);
		return;
	      }
	  }
	else
	  {
	    $posx = int($width / 2) - 1;
	    $posy = -$max_size;
	  }
      }
    $timer = $top->after($freefall ? 1 : speed(), \&action);
  }

sub get_next_block
  {
    $next_block_nr = int(rand()*$nmbr_blks);
    $next_dir      = int(rand()*4);
    $next_block    = $block->[$next_block_nr];
    for (0 .. $next_dir)
      {
	turn($next_block_nr, $next_block);
      }
  }

sub turn
  {
    my($number, $block) = @_;
    my($i, $j, $help_block);
    if ($number != 6)
      {
	if ($number < 5)
	  {
	    for $i (1 .. $max_size-1)
	      {
		for $j (0 .. $max_size-2)
		  {
		    $help_block->[$max_size-1-$j][$i-1] = $block->[$i][$j];
		  }
	      }
	    for $i (1 .. $max_size-1)
	      {
		for $j (0 .. $max_size-2)
		  {
		    $block->[$i][$j] = $help_block->[$i][$j];
		  }
	      }
	  }
	else
	  {
	    for $i (0 .. $max_size-1)
	      {
		for $j (0 .. $max_size-1)
		  {
		    $help_block->[$max_size-1-$j][$i] = $block->[$i][$j];
		  }
	      }
	    copyblock($help_block, $block);
	  }
      }
  }

sub copyblock
  {
    my($from, $to) = @_;
    die if ref $from ne 'ARRAY' || ref $to ne 'ARRAY';
    my($i, $j);
    for $i (0 .. $max_size-1)
      {
	for $j (0 .. $max_size-1)
	  {
	    $to->[$i][$j] = $from->[$i][$j];
	  }
      }
  }
sub rectangle
  {
    my($x, $y, $mode, $zinc) = @_;
    $zinc->remove("$x-$y");         # Zinc command for deleting items
    $zinc->remove("ombre$x-$y");
    if ($mode)
      {
	my($xx, $yy);
	($xx, $yy) = (($x-1)*$step_x, $y*$step_y);
	my $color = $color_bright{$mode};
	# Adding new Zinc item : ball shadow
	my $ombre=$zinc->add(
			     'arc',$shadow_group,[$xx+10,$yy+10,$xx+$boxsize_x+10,$yy+$boxsize_y+10],
			     -visible=>1,
			     -filled=>1,
			     -fillcolor => $render ? "=path 50 50 |black;100 0|black;80 20|black;0 100" : "grey90", # color gradiant
			     -linewidth => 0,
			     -linecolor => 'yellow',
			     -priority => $render ? 6 : 10,
			     -tags => ["ombre$x-$y"]);
	
	$zinc->itemconfigure($shadow_group, -priority => 2);
	
	# Adding new Zinc item : ball
	my $cercle=$zinc->add(
			      'arc',$topgroup,[$xx,$yy,$xx+$boxsize_x,$yy+$boxsize_y],
			      -visible=>1,
			      -filled=>1,
			      -fillcolor => $render ? "=radial -20 -20 |white;90|$color;90" : $color,
			      -linewidth => 1,
			      -priority => 5,
			      -linecolor => "$color;80",
			      -tags => ["$x-$y"]);
      }
  }

sub testblock
  {
    my($active_block, $posx, $posy) = @_;
    for(my $i = 0; $i <= $max_size-1; $i++)
      {
	for(my $j = 0; $j <= $max_size-1; $j++)
	  {
	    if ($active_block->[$i][$j])
	      {
		if ($playfield->[$posy+$i][$posx+$j])
		  {
		    return 0;
		  }
	      }
	  }
      }
    1;
  }

sub drawblock
  {
    my($posx, $posy, $mode, $zinc) = @_;
    my $y = $posy;
    $zinc = $tetris if !$zinc;
    for(my $i = 0; $i <= $max_size-1; $i++)
      {
	my $x = $posx;
	for(my $j = 0; $j <= $max_size-1; $j++)
	  {
	    if ($active_block->[$i][$j])
	      {
		if (!$mode)
		  {
		    rectangle($x, $y, 0, $zinc);
		  }
		else
		  {
		    rectangle($x, $y, $active_block->[$i][$j], $zinc);
		  }
	      }
	    $x++;
	  }
	$y++;
      }
  }



sub new_game {
    reset_playfield();
    renew_field();
    reset_block();
    $next_block_nr = undef;
    reset_game_param();
    action();
}

sub stop_and_new_game {
    stop_game();
    new_game(),
  }

## no more used, because it quits zinc-demos
sub quit_game {

    print "Bye!\n";
    exit;
}

sub lost {
  $top->destroy;
  print "You lost :o( !\n";
  exit;
 }

sub reset_game_param {
    $points = $blocks = $lines = 0;
    $level = level();
    $speed = speed();
    $pause = undef;
}

sub stop_game {
    undef_timer();
    undef $active_block;
}

sub delete_line
  {
    my($y) = @_;
    my $yy = $y*$step_y;
    my $x;
    for $x (1 .. $width-2)
      {
	my $xx = ($x-1)*$step_x;
	$tetris->add
	  ('rectangle',1,
	   [$xx, $yy, $xx+$boxsize_x, $yy+$boxsize_y],
	   -filled => 1,
	   -fillcolor => 'orange;50',
	   -tags => ['delline'],
	  );
      }
    $tetris->idletasks;
    short_sleep(0.05);
    $tetris->remove('delline');
    my $deuxpi = 3.1416;
    my $i = 1;
    my $angle = 360;
    # special effect on TkZinc logo
    rotation($deuxpi*$angle/360);
    $mylines++;
    $tetris->itemconfigure($new,-text => "    $mylines Lines\n", -font => $basefont->($fontheight));
  }

sub rotation
  {
    my ($angle, $cnt) = @_;
    # first step of animation
    if ($cnt == $stepsnumber)
      {
	inflation(); # scaling effect
	return;
      }
    $cnt++;
    # use 'rotation' Zinc method.
    my $stepi = 360/$stepsnumber;
    $angle = $stepi*2*3.1416/360;
    $tetris->rotate($group, $angle, 250, 450 );
    # process the animation using the 'after' Tk defering method
    $tetris->after($afterdelay, sub {rotation($angle, $cnt)});
  }

sub inflation
  {
    my ($cnt) = @_;
    my @pos = $tetris->coords($group);
    my $zf;
    # last step of animation
    if ($cnt == 6)
      {
	return;
	# event steps : wheel grows
      }
    elsif ($cnt % 2 == 0)
      {
	$zf = 4*$zoomrate;
	# odd steps : wheel is shrunk
      }
    else
      {
	$zf = 1/(4*$zoomrate);
      }
    $cnt++;
    # Now, we apply scale transformation to the Group item, using the 'scale'
    # Zinc method. Note that we reset group coords before scaling it, in order
    # that the origin of the transformation corresponds to the center of the
    # wheel. When scale is done, we restore previous coords of group.
    $tetris->coords($group, [0, 0]);
    $tetris->scale($group, $zf, $zf);
    $tetris->coords($group, \@pos);
    # process the animation using the 'after' Tk defering method
    $tetris->after(100, sub {inflation($cnt)});
  }

sub game_over {
  stop_game();
  #    insert_highscore();
  #    show_highscore('Game over');
  #    save_highscore();
  #toggle_pause();
  my $width  = $top->width;
  my $height = $top->height;
  my $new = $tetris->add('text',$pause_group,
			 -font => $basefont->($fontheight),
			 -text => "You lost ! :o)\ntype 'n' to try again !",
			 -position => [20,100],
			);
  $top->update('idletasks');
  short_sleep(1);
  $tetris->remove($new);
 }

sub move {
    my($dir) = @_;
    if (!$active_block || !defined $posx || $pause) {
	$top->bell;
	return;
    }
    if ($dir eq 'right' and testblock($active_block, $posx+1, $posy)) {
	drawblock($posx, $posy, 0);
	$posx++;
	drawblock($posx, $posy, 1);
    } elsif ($dir eq 'left' and testblock($active_block, $posx-1, $posy)) {
	drawblock($posx, $posy, 0);
	$posx--;
	drawblock($posx, $posy, 1);
    } elsif ($dir eq 'turn') {
	my $help_block = [];
	copyblock($active_block, $help_block);
	turn($active_block_nr, $help_block);
	if (testblock($help_block, $posx, $posy)) {
	    drawblock($posx, $posy, 0);
	    copyblock($help_block, $active_block);
	    drawblock($posx, $posy, 1);
	}
    } elsif ($dir eq 'antiturn') {
	my $help_block = [];
	copyblock($active_block, $help_block);
	anti_turn($active_block_nr, $help_block);
	if (testblock($help_block, $posx, $posy)) {
	    drawblock($posx, $posy, 0);
	    copyblock($help_block, $active_block);
	    drawblock($posx, $posy, 1);
	}
    } elsif ($dir eq 'freefall') {
	if ($moveable_drop) {
	    $freefall = 1;
	    undef_timer();
	    action();
	} else {
	    my $free_fall = 0;
	    while (testblock($active_block, $posx, $posy+1)) {
		drawblock($posx, $posy, 0);
		$posy++;
		$free_fall++;
		drawblock($posx, $posy, 1);
		$top->idletasks;
	    }
	    array_update(($level+1)*int(($free_fall+$height-$posy+5)/5),
			 $posx, $posy);
	}
    }
  }

sub array_update
  {
    my($plus, $posx, $posy) = @_;
    my($i, $j);
    undef_timer();
    delete_shadow();
    for $i (0 .. $max_size-1)
      {
	for $j (0 .. $max_size-1) {
	    if ($active_block->[$i][$j] and $posy+$i >= 0) {
		$playfield->[$posy+$i][$posx+$j] = $active_block->[$i][$j];
	    } else {
		if ($active_block->[$i][$j]) {
		    game_over();
		    return;
		}
	    }
	}
    }
    $points += $plus;

    if ($posy >= 0) {
	for $i ($posy .. $height-2) {
	    if (to_del_line($i)) {
		delete_line($i);
		$lines++;
		$points += 10*($level+1);
		for $j (reverse(0 .. $i-1)) {
		    my $k;
		    for $k (1 .. $width-2) {
			$playfield->[$j+1][$k] = $playfield->[$j][$k];
		    }
		}
		renew_field($i);
	    }
	}
    }

    my $oldlevel = $level;
    $level = level();
    if ($oldlevel != $level) {
	my $width  = $top->width;
	my $height = $top->height;
	my $newlevel = $tetris->add('text',$pause_group,
				    -text => 'NEW LEVEL',
				    -font => $basefont->($fontheight),
				    -position => [20,20],
				  );
	$top->update('idletasks');
	short_sleep(0.5);
	$tetris->remove($newlevel);
    }
    
    reset_block();
    action();
}

sub anti_turn
  {
    my($number, $block) = @_;
    for (1 .. 3) { turn($number, $block) }
}

sub undef_timer {
    if ($timer) {
	$timer->cancel;
	undef $timer;
    }
}

sub delete_shadow {
    return if !$draw_shadow;
    for(my $x = 1; $x <= $width-1; $x++) {
#	rectangle($x, 0, 0, $shadow);
    }
}

sub to_del_line {
    my($posy) = @_;
    my $i;
    
    for $i (1 .. $width-2) {
	if ($posy >= 0 and !$playfield->[$posy][$i]) {
	    return 0;
	}
    }
    1;
}
sub reset_block {
    undef $active_block_nr;
    undef $posx;
    $freefall = 0;
}

sub short_sleep {
    my $sleep = shift;
    if ($^O =~ /win/i) {
	$top->Busy;
	my $wait = 0;
	$top->after($sleep*1000, sub { $wait = 1 });
	$top->waitVariable(\$wait);
	$top->Unbusy;
    } else {
	eval { select(undef, undef, undef, $sleep) };
    }
}

sub renew_field {
    my($max_y) = @_;
    $max_y = $height-2 if !defined $max_y;
    my($i, $j);
    for $i (0 .. $max_y) {
	for $j (1 .. $width-2) {
	    if ($playfield->[$i][$j]) {
		rectangle($j, $i, $playfield->[$i][$j], $tetris);
	    } else {
		rectangle($j, $i, 0, $tetris);
	    }
	}
    }
}

sub help
  {
    inc_pause();
    if (defined $help_top and Tk::Exists($help_top))
      {
	$help_top->raise;
	return;
      }
    require Tk::ROText;
    my $firebutton = 'Button';
    eval { require Tk::FireButton; Tk::FireButton->VERSION(1.04); };
    $help_top = $top->Toplevel(-title => 'Tetris Help');
    make_key_bindings($help_top);
    my $ti = "Zetris help :\n  - truc 1\n  - truc 2\n  - truc 3\n \n";
    my $create_but = sub {
	my($t, $command, $fire) = @_;
	my $button = ($fire ? $firebutton : 'Button');
	my $but = $tetris->add('text',$pause_group,
			       -text => $ti,
			       -font => $base2font->(12),
			       -position => [20,20],
				);
    };

    my $cb = $help_top->Button(-text => 'Close',
			       -font => $base2font->(12),
			       -command => sub { $help_top->destroy })->pack;
    $help_top->bind('<Escape>' => sub { $cb->invoke });
}

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/all_options.pl.





















































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/perl -w
# $Id$
# This simple demo has been developped by C. Mertz <mertz@cena.fr>

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use Tk::Pane;

use strict;

my $mw = MainWindow->new();

# The explanation displayed when running this demo
my $label=$mw->Label(-text =>
"Click on one of the following
buttons to get a list of Item
attributes (or zinc options)
with their types.\n",
	   -justify => 'left')->pack(-padx => 10, -pady => 10);


# Creating the zinc widget
my $zinc = $mw->Zinc(-width => 1, -height => 1,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -borderwidth => 0, -relief => 'sunken',
		     )->pack;

# Creating an instance of every item type
my %itemtypes;

# These Items have fields! So the number of fields must be given at creation time
foreach my $type qw(tabular track waypoint) {
    $itemtypes{$type} = $zinc->add($type, 1, 0);
}

# These items needs no specific initial values
foreach my $type qw(group icon map reticle text window) {
    $itemtypes{$type} = $zinc->add($type, 1);
}

# These items needs some coordinates at creation time
# However curves usually needs more than 2 points.
foreach my $type qw(arc curve rectangle) {
    $itemtypes{$type} = $zinc->add($type, 1, [0,0 , 1,1]);
}
# Triangles item needs at least 3 points for the coordinates 
foreach my $type qw(triangles) {
    $itemtypes{$type} = $zinc->add($type, 1, [0,0 , 1,1 , 2,2]);
}


sub showAllOptions {
    my ($type) = @_;

    my $tl = $mw->Toplevel;
    my $title = "All options of an item $type";
    my @options;
    if ($type eq 'zinc') {
	@options = $zinc->configure();
	$title = "All options of zinc widget";
    }
    else {
	@options = $zinc->itemconfigure($itemtypes{$type});
	$title = "All attributes of an item $type";
    }
    $tl->title($title);
    my $frame = $tl->Scrolled('Pane',
			      -scrollbars => 'e',
			      -height => 600,
			      );
    $frame->pack(-padx => 10, -pady => 10,
		 -ipadx => 10,
		 -fill => 'both',
		 -expand => 1,
		 );

    my $fm = $frame->LabFrame(-labelside => 'acrosstop',
			      -label => $title,
			      )->pack(-padx => 10, -pady => 10,
				      -ipadx => 10,
				      -fill => 'both');
    my $bgcolor = 'ivory';
    $fm->Label(-text => 'Option', -background => $bgcolor, -relief => 'ridge')
	->grid(-row => 1, -column => 1, -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => ($type eq 'zinc') ? 'optionClass' : 'Type',
	       -background => $bgcolor, -relief => 'ridge')
	->grid(-row => 1, -column => 2, -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    $fm->Label(-text => ($type eq 'zinc') ? 'defaultValue' : 'ReadOnly',
	       -background => $bgcolor, -relief => 'ridge')
	->grid(-row => 1, -column => 3, -ipady => 10, -ipadx => 5, -sticky => 'nswe');
    my $i = 2;
    my %options; #we used this hastable to sort the options by their names
    
    if ($type eq 'zinc') {
	for my $elem (@options) {
#	    print "$elem @$elem\n";
	    my ($optionName, $optionDatabaseName, $optionClass, $default, $optionValue) = @$elem;
	    $options{$optionName} = [$optionClass, $default, "", $optionValue];
	}
    }
    else {
	for my $elem (@options) {
	    my ($optionName, $optionType, $readOnly, $empty, $optionValue) = @$elem;
	    $options{$optionName} = [$optionType, $readOnly, $empty, $optionValue];
	}
    }
    for my $optionName (sort keys %options) {
	my ($optionType, $readOnly, $empty, $optionValue) = @{$options{$optionName}};
	$fm->Label(-text => $optionName, -relief => 'ridge')
	    ->grid(-row => $i, -column => 1, -ipady => 10, -ipadx => 5, -sticky => 'nswe');
	$fm->Label(-text => $optionType, -relief => 'ridge')
	    ->grid(-row => $i, -column => 2, -ipady => 10, -ipadx => 5, -sticky => 'nswe');

	# $empty is for provision by Zinc
	if ($type ne 'zinc') {
	    if ($readOnly) {$readOnly = "read only"} else { $readOnly = "" }
	}
	$fm->Label(-text => $readOnly, -relief => 'ridge')
	    ->grid(-row => $i, -column => 3, -ipady => 10, -ipadx => 5, -sticky => 'nswe');
	# we do not display $optionValue for these fake items
	$i++;
    }
    $tl->Button(-text => 'Close',
		-command => sub {$tl->destroy})->pack;    

}

my $col = $mw->Frame()->pack();

my $width=0;
foreach my $type (sort keys %itemtypes) {
    if (length ($type) > $width) {
	$width = length ($type);
    }
}

foreach my $type (sort keys %itemtypes) {
    $col->Button(-text => "$type",
		 -width => $width,
		 -command => sub {&showAllOptions ($type);},
		 )->pack(-pady => 4);	   
}
$col->Button(-text => "zinc widget options",
	     -command => sub {&showAllOptions ('zinc');},
	     )->pack(-pady => 4);	   

MainLoop();


1;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/atomic-groups.pl.



























































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/perl
# $Id$
# this simple sample has been developped by C. Mertz mertz@cena.fr

package atomic_groups;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use Tk::Checkbutton;
use Tk::Label;
use strict;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 500, -height => 350,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -borderwidth => 0,
		     )->pack;


my $groups_group_atomicity = 0;
my $red_group_atomicity = 0;
my $green_group_atomicity = 0;

my $display_clipping_item_background = 0;
my $clip = 1;

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text =>
	   "- There are 3 groups: a red group containing 2 redish objects,\n".
	   "a green group containing 2 greenish objects,\n".
	   "and groups_group containing both previous groups.\n".
	   "- You can make some groups atomic or not by depressing \n".
	   "the toggle buttons at the bottom of the window\n".
	   "- Try and then click on some items to observe that callbacks\n".
	   " are then different: they modify either the item, or 2 items of\n".
           " a group or all items",
	   -anchor => 'nw',
	   -position => [10, 10]);


############### creating the top group with its bindings ###############################
my $groups_group = $zinc->add('group', 1, -visible => 1,
			      -atomic => $groups_group_atomicity,
			      -tags => [ 'groups_group' ]);

# the following callbacks will be called only if 'groups_group' IS atomic
$zinc->bind($groups_group, '<1>', \&modify_bitmap_bg);
$zinc->bind($groups_group, '<ButtonRelease-1>', \&modify_bitmap_bg);

############### creating the red_group, with its binding and its content ################
# the red_group may be atomic, that is is makes all children as a single object
# and sensitive to red_group callbacks
my $red_group = $zinc->add('group', $groups_group,
			   -visible => 1,
			   -atomic => $red_group_atomicity,
			   -sensitive => 1,
			   -tags => ['red_group'],
			   );
# the following callbacks will be called only if 'groups_group' IS NOT-atomic
# and if 'red_group' IS atomic
$zinc->bind($red_group, '<1>', sub { &modify_item_lines($red_group)} );
$zinc->bind($red_group, '<ButtonRelease-1>', sub { &modify_item_lines($red_group)} );


my $rc = $zinc->add('arc', $red_group,
		    [100, 200, 140, 240],
		    -filled => 1, -fillcolor => "red2",
		    -linewidth => 3, -linecolor => "white",
		    -tags => [ 'red_circle' ],
		    );

my $rr = $zinc->add('rectangle', $red_group,
		    [300, 200, 400,250],
		    -filled => 1, -fillcolor => "red2",
		    -linewidth => 3, -linecolor => "white",
		    -tags => [ 'red_rectangle' ],
		    );
# the following callbacks will be called only if 'groups_group' IS NOT atomic
# and if 'red_group' IS NOT atomic
$zinc->bind($rc, '<1>', \&toggle_color);
$zinc->bind($rc, '<ButtonRelease-1>', \&toggle_color);
$zinc->bind($rr, '<1>', \&toggle_color);
$zinc->bind($rr, '<ButtonRelease-1>', \&toggle_color);

############### creating the green_group, with its binding and its content ################
# the green_group may be atomic, that is is makes all children as a single object
# and sensitive to green_group callbacks
my $green_group = $zinc->add('group', $groups_group,
			     -visible => 1,
			     -atomic => $green_group_atomicity,
			     -sensitive => 1,
			     -tags => ['green_group'],
			    );
# the following callbacks will be called only if 'groups_group' IS NOT atomic
# and if 'green_group' IS atomic
$zinc->bind($green_group, '<1>', sub { &modify_item_lines($green_group) } );
$zinc->bind($green_group, '<ButtonRelease-1>', sub { &modify_item_lines($green_group) } );

my $gc = $zinc->add('arc', $green_group,
		    [100,270, 140,310],
		    -filled => 1, -fillcolor => "green2",
		    -linewidth => 3, -linecolor => "white",
		    -tags => [ 'green_circle' ],
		    );

my $gr = $zinc->add('rectangle', $green_group,
		    [300,270,  400,320],
		    -filled => 1, -fillcolor => "green2",
		    -linewidth => 3, -linecolor => "white",
		    -tags => [ 'green_rectangle' ],
		    );
# the following callbacks will be called only if 'groups_group' IS NOT atomic
# and if 'green_group' IS NOT atomic
$zinc->bind($gc, '<1>', \&toggle_color);
$zinc->bind($gc, '<ButtonRelease-1>', \&toggle_color);
$zinc->bind($gr, '<1>', \&toggle_color);
$zinc->bind($gr, '<ButtonRelease-1>', \&toggle_color);



my $current_bg = '';
###################### groups_group callback ##############
sub modify_bitmap_bg {
    if ($current_bg eq 'AlphaStipple2') {
	$current_bg = '';
    }
    else {
	$current_bg = 'AlphaStipple2';
    }
    foreach my $item ($rc, $rr, $gc, $gr) {
	$zinc->itemconfigure($item, -fillpattern => $current_bg);
    }
}

#################### red/green_group callback ##############
sub modify_item_lines {
    my ($gr) = @_;
    my @children = $zinc->find('withtag', ".$gr*"); # we are using a pathtag (still undocumented feature of 3.2.6) to get items of an atomic group!
    # we could also temporary modify the groups (make it un-atomic) to get its child

    my $current_linewidth = $zinc->itemcget($children[0], -linewidth);
    if ($current_linewidth == 3) {
	$current_linewidth = 0;
    }
    else {
	$current_linewidth = 3;
    }
    foreach my $item (@children) {
	$zinc->itemconfigure($item, -linewidth => $current_linewidth);
    }
	
}


##################### items callback ######################
sub toggle_color {
    my $item = $zinc->find('withtag', 'current');
    my $fillcolor = $zinc->itemcget($item, -fillcolor);
    my ($color,$num) = $fillcolor =~ /([a-z]+)(\d)/ ;
    if ($num == 2) {
	$num = 4;
    }
    else {
	$num = 2;
    }
    $zinc->itemconfigure($item, -fillcolor => "$color$num");
}


###################### toggle buttons at the bottom #######
my $row = $mw->Frame()->pack();
$row->Checkbutton(-text => 'groups_group is atomic',
		  -variable => \$groups_group_atomicity,
		  -command => sub { &atomic_or_not ($groups_group, \$groups_group_atomicity) },
		  )->pack(-anchor => 'w');	   

$row->Checkbutton(-text => 'red group is atomic   ',
		  -foreground => "red4",
		  -variable => \$red_group_atomicity,
		  -command => sub { &atomic_or_not ($red_group, \$red_group_atomicity) },
		  )->pack(-anchor => 'w');  

$row->Checkbutton(-text => 'green group is atomic ',
		  -foreground => "green4",
		  -variable => \$green_group_atomicity,
		  -command => sub { &atomic_or_not ($green_group, \$green_group_atomicity) },
		  )->pack(-anchor => 'w');
$row->Label()->pack(-anchor => 'w');
$row->Label(-text => "Following command \"\$zinc->find('overlapping', 0,200,500,400)\" returns:")->pack(-anchor => 'w');
my $label = $row->Label(-background => 'gray95')->pack(-anchor => 'w');


sub atomic_or_not {
    my ($gr,$ref_atomic) = @_;
    my $atomic = ${$ref_atomic};
    $zinc->itemconfigure( $gr, -atomic => $atomic);
    &update_found_items;
}

##### to update the list of enclosed items
sub update_found_items {
    $zinc->update;  # to be sure eveyrthing has been updated inside zinc!
    my @found = $zinc->find('overlapping', 0,200,500,400);
    my $str = "";
    foreach my $item (@found) {
	my @tags =   $zinc->itemcget($item, -tags);
	$str .= "  " . $tags[0];
    }
    $label->configure (-text => $str);
}

# to init the list of enclosed items
&update_found_items;

Tk::MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/clipping.pl.













































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/perl
# $Id$
# this simple sample has been developped by C. Mertz mertz@cena.fr

use Tk;
use Tk::Zinc;
use strict;
use Tk::Checkbutton;

package clipping;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 700, -height => 600,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

my $display_clipping_item_background = 0;
my $clip = 1;

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "You can drag and drop the objects.\n".
	   "There are two groups of objects, a \"tan group\" and a \"blue group\".\n".
	   "Try to move them and discover the clipping area which is a curve.\n".
	   "with two contours",
	   -anchor => 'nw',
	   -position => [10, 10]);


my $clipped_group = $zinc->add('group', 1, -visible => 1);

my $clipping_item = $zinc->add('curve', $clipped_group,
			       [10,100, 690,100, 690,590, 520,350,
				350,590, 180,350, 10,590],
			       -closed => 1,
			       -priority => 1,
			       -fillcolor => "tan2",
			       -linewidth => 0,
			       -filled => $display_clipping_item_background);
$zinc->contour($clipping_item, "add", +1, [200,200, 500,200, 500,250, 200,250]);

############### creating the tan_group objects ################
# the tan_group is atomic, that is is makes all children as a single object
# and sensitive to tan_group callbacks
my $tan_group = $zinc->add('group', $clipped_group,
			   -visible => 1,
			   -atomic => 1,
			   -sensitive => 1,
			   );

$zinc->add('arc', $tan_group,
	   [200, 220, 280, 300],
	   -filled => 1,  -linewidth => 1,
	   -startangle => 45, -extent => 270,
	   -pieslice => 1, -closed => 1,
	   -fillcolor => "tan",
	   );

$zinc->add('curve', $tan_group,
	   [400,400, 440,450,  400,500, 500,500, 460,450, 500,400],
	   -filled => 1,  -fillcolor => "tan",
	   -linecolor => "tan",
	   );

############### creating the blue_group objects ################
# the blue_group is atomic too, that is is makes all children as a single object
# and sensitive to blue_group callbacks
my $blue_group = $zinc->add('group', $clipped_group,
			    -visible => 1,
			    -atomic => 1,
			    -sensitive => 1,
			    );

$zinc->add('rectangle', $blue_group,
	   [570,180,  470,280],
	   -filled => 1,  -linewidth => 1,
	   -fillcolor => "blue2",
	   );

$zinc->add('curve', $blue_group,
	   [200,400, 200,500, 300,500, 300,400, 300,300],
	   -filled => 1,  -fillcolor => "blue",
	   -linewidth => 0,
	   );


$zinc->itemconfigure($clipped_group, -clip => $clipping_item);


###################### drag and drop callbacks ############
# for both tan_group and blue_group
$zinc->bind($tan_group, '<ButtonPress-1>' => [\&press, $tan_group, \&motion]);
$zinc->bind($tan_group, '<ButtonRelease-1>' => \&release);
$zinc->bind($blue_group, '<ButtonPress-1>' => [\&press, $blue_group, \&motion]);
$zinc->bind($blue_group, '<ButtonRelease-1>' => \&release);

my ($x_orig, $y_orig);
sub press {
    my ($zinc, $group, $action) = @_;
    my $ev = $zinc->XEvent();
    $x_orig = $ev->x;
    $y_orig = $ev->y;
    $zinc->Tk::bind('<Motion>', [$action, $group]);
}

sub motion {
    my ($zinc, $group) = @_;
    my $ev = $zinc->XEvent();
    my $x = $ev->x;
    my $y = $ev->y;

    $zinc->translate($group, $x-$x_orig, $y-$y_orig);
    $x_orig = $x;
    $y_orig = $y;
}

sub release {
    my ($zinc) = @_;
    $zinc->Tk::bind('<Motion>', '');
}
###################### toggle buttons at the bottom #######
my $row = $mw->Frame()->pack();
$row->Checkbutton(-text => 'Show clipping item',
		 -variable => \$display_clipping_item_background,
		 -command => \&display_clipping_area)->pack;	   

$row->Checkbutton(-text => 'Clip',
		 -variable => \$clip,
		 -command => \&clip)->pack;	   

sub display_clipping_area {
    $zinc->itemconfigure($clipping_item, -filled => $display_clipping_item_background);
}

sub clip {
    if ($clip) {
	$zinc->itemconfigure($clipped_group, -clip => $clipping_item);
    }
    else {
	$zinc->itemconfigure($clipped_group, -clip => undef);
    }
}

Tk::MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/color-circular.pl.























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl
# $Id$
# these simple samples have been developped by C. Mertz mertz@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 700, -height => 600,
		     -borderwidth => 3, -relief => 'sunken',
		     -render => 1, # for activating the openGL render
		     )->pack;

# This demo no more dies if there is no openGL. It simply displays
# a string on the bootom of the window!


$zinc->add('rectangle', 1, [10, 10, 80, 80], -fillcolor => "=radial 50 50 |red |blue", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Radial variation from non-transparent red to non-transparent blue\nin a squarre. The gradient starts from the lower right corner.\n",
	   -anchor => 'nw',
	   -position => [120, 20]);

$zinc->add('arc', 1, [10, 110, 90, 190], -fillcolor => "=radial 0 25 |red;40|blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Radial variation from 40%transparent red to 40% transparent blue\nin a disc. The gradient starts in the middle between\nthe center on the bottom point",
	   -anchor => 'nw',
	   -position => [120, 120]);

$zinc->add('arc', 1, [10, 210, 90, 290], -fillcolor => "=radial 0 0 |red;40|green;40 50|blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A variation from 40%transparent red to 40% transparent blue.\n".
	   "through a 40%green on the middle of the disc. The gradient is centered.",
	   -anchor => 'nw',
	   -position => [120, 220]);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Two overlaping radialy, transparently colored items on a white background",
	   -anchor => 'nw',
	   -position => [20, 320]);

$zinc->add('rectangle', 1, [10, 340, 690, 590], -fillcolor => "white", -filled => 1);

$zinc->add('rectangle', 1, [20, 365, 220, 565], -fillcolor => "=radial 0 0 |red;40|green;40 50|blue;40", -filled => 1);

$zinc->add('arc', 1, [150, 365, 350, 565], -fillcolor => "=radial 0 0 |yellow;40|black;40 50|cyan;40", -filled => 1);

$zinc->add('arc', 1, [280, 365, 480, 565], -fillcolor => "=radial 0 0 |black;100|black;100 20|white;40", -filled => 1, -linewidth => 0);

$zinc->add('arc', 1, [480, 365, 580, 500], -fillcolor => "=radial -10 16 |black;100|white;40", -filled => 1);

$zinc->add('arc', 1, [580, 410, 680, 580], -fillcolor => "=radial -40 -40 |black;70|white;20", -filled => 1);
$zinc->add('arc', 1, [580, 410, 680, 580], -fillcolor => "=radial 40 40 |black;70|white;20", -filled => 1);


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "WITHOUT openGL, NO GRADIENT. SORRY!",
	   -anchor => 'nw',
	   -position => [20, 550]) unless $zinc->cget(-render);

MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/color-path-and-conic.pl.





























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
# $Id$
# these simple samples have been developped by C. Mertz mertz@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 700, -height => 600,
		     -borderwidth => 3, -relief => 'sunken',
		     -render => 1, # for activating the openGL render
		     )->pack;

# This demo no more dies if there is no openGL. It simply displays
# a string on the bootom of the window!


$zinc->add('rectangle', 1, [10, 10, 80, 80], -fillcolor => "=path 0 0 |red |blue", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Path variation from non-transparent red to non-transparent blue\nin a squarre. The gradient start at the middle of the bbox.",
	   -anchor => 'nw',
	   -position => [120, 20]);

$zinc->add('arc', 1, [10, 110, 90, 190], -fillcolor => "=conical 135 |black;40|white;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Conical variation from 40%transparent black to 40% transparent white\nin a disc, center in the middle of the bbox",
	   -anchor => 'nw',
	   -position => [120, 120]);


$zinc->add('arc', 1, [10, 210, 90, 290], -fillcolor => "=path -30 +30 |red;40|green;40 50|blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A path variation from 40%transparent red to 40% transparent blue.\n".
	   "through a 40%green on the middle of the disc. The gradient center\nis toward the SW of the bbox.",
	   -anchor => 'nw',
	   -position => [120, 220]);



$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "overlaping path and conical, transparently colored items on a white background",
	   -anchor => 'nw',
	   -position => [20, 320]);

$zinc->add('rectangle', 1, [10, 340, 690, 590], -fillcolor => "white", -filled => 1);

$zinc->add('rectangle', 1, [20, 365, 220, 565], -fillcolor => "=path -40 -40 |red;40|green;40 50|blue;40", -filled => 1);

$zinc->add('arc', 1, [150, 365, 350, 565], -fillcolor => "=conical 20 -30 45 |yellow;40|black;40 50|cyan;40", -filled => 1);

$zinc->add('arc', 1, [320, 365, 480, 565], -fillcolor => "=path 0 0 |black;100|black;100 20|white;40", -filled => 1, -linewidth => 0);

#$zinc->add('arc', 1, [480, 365, 580, 500], -fillcolor => "=radial -10 16 |black;100|white;40", -filled => 1);

$zinc->add('arc', 1, [580, 410, 680, 580], -fillcolor => "=conical -40 -40 135 |black;70|white;20", -filled => 1);
#$zinc->add('arc', 1, [580, 410, 680, 580], -fillcolor => "=radial 40 40 |black;70|white;20", -filled => 1);


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "WITHOUT openGL, NO GRADIENT. SORRY!",
	   -anchor => 'nw',
	   -position => [20, 550]) unless $zinc->cget(-render);

MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/color-x.pl.





























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl
# $Id$
# these simple samples have been developped by C. Mertz mertz@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 700, -height => 600,
		     -borderwidth => 3, -relief => 'sunken',
		     -render => 1, # for activating the openGL render
		     )->pack;

# This demo no more dies if there is no openGL. It simply displays
# a string on the bootom of the window!

$zinc->add('rectangle', 1, [10,10, 690, 50], -fillcolor => "=axial 0 | red | blue", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A variation from non transparent red to non transparent blue.",
	   -anchor => 'nw',
	   -position => [20, 20]);


$zinc->add('rectangle', 1, [10,60, 690, 100], -fillcolor => "=axial -30 0 30 0 | red | blue", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "The same with a reduced span.",
	   -anchor => 'nw',
	   -position => [20, 70]);


$zinc->add('rectangle', 1, [10,110, 690, 150], -fillcolor => "=axial 0 |red;40|blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A variation from 40%transparent red to 40% transparent blue.",
	   -anchor => 'nw',
	   -position => [20, 120]);


$zinc->add('rectangle', 1, [10,160, 690, 200], -fillcolor => "=axial -30 0 30 0 |red;40|blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "The same with a reduced span.",
	   -anchor => 'nw',
	   -position => [20, 170]);


# we are using here the X explicit notation for rgb color
# we could also have used CIE encoding. If interested,
# please read the X man pages
my $gradient = ($^O eq 'linux') ? "=axial 0 | rgb:ffff/0/0;40 | rgb:0/ffff/0;40 50 | rgb:0/0/ffff;40" 
  : "=axial 0 | #ff0000;40 | #00ff00;40 50 | #0000ff;40";

$zinc->add('rectangle', 1, [10, 210, 690, 300], -fillcolor => "=axial 0 | rgb:ffff/0/0;40 | rgb:0/ffff/0;40 50 | rgb:0/0/ffff;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A variation from 40%transparent red to 40% transparent blue.\n".
	   "through a 40%green on the middle",
	   -anchor => 'nw',
	   -position => [20, 220]);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Two overlaping transparently colored rectangles on a white background",
	   -anchor => 'nw',
	   -position => [20, 320]);

$zinc->add('rectangle', 1, [10, 340, 690, 590], -fillcolor => "white", -filled => 1);
$zinc->add('rectangle', 1, [200, 350, 500, 580], -fillcolor => "red;40|green;40 50|blue;40", -filled => 1);

$zinc->add('rectangle', 1, [10, 400, 690, 500], -fillcolor => "=axial 0 |yellow;40|black;40 50|cyan;40", -filled => 1);


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "WITHOUT openGL, NO GRADIENT. SORRY!",
	   -anchor => 'nw',
	   -position => [20, 550]) unless $zinc->cget(-render);



MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/color-y.pl.























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl
# $Id$
# these simple samples have been developped by C. Mertz mertz@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 700, -height => 600,
		     -borderwidth => 3, -relief => 'sunken',
		     -render => 1, # for activating the openGL render
		     )->pack;

# This demo no more dies if there is no openGL. It simply displays
# a string on the bootom of the window!


$zinc->add('rectangle', 1, [10, 10, 340, 100], -fillcolor => "=axial 90 |red |blue", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A variation from non transparent red\n to non transparent blue.",
	   -anchor => 'nw',
	   -position => [20, 20]);


$zinc->add('rectangle', 1, [360, 10, 690, 100], -fillcolor => "=axial 0 30 0 -30 |red |blue", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "The same with a reduced span.",
	   -anchor => 'nw',
	   -position => [370, 20]);



$zinc->add('rectangle', 1, [10,110, 330, 200], -fillcolor => "=axial 90|red;40 |blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A variation from 40%transparent red\nto 40% transparent blue.",
	   -anchor => 'nw',
	   -position => [20, 120]);


$zinc->add('rectangle', 1, [360,110, 690, 200], -fillcolor => "=axial 0 30 0 -30|red;40 |blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "The same with a reduced span.",
	   -anchor => 'nw',
	   -position => [370, 120]);


$zinc->add('rectangle', 1, [10, 210, 690, 300], -fillcolor => "=axial 90 |red;40|green;40 50|blue;40", -filled => 1);

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A variation from 40%transparent red to 40% transparent blue.\n".
	   "through a 40%green on the middle",
	   -anchor => 'nw',
	   -position => [20, 220]);


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Two overlaping transparently colored rectangles on a white background",
	   -anchor => 'nw',
	   -position => [20, 320]);

$zinc->add('rectangle', 1, [10, 340, 690, 590], -fillcolor => "white", -filled => 1);
$zinc->add('rectangle', 1, [200, 350, 500, 580], -fillcolor => "=axial 90 |red;40|green;40 50|blue;40", -filled => 1);

$zinc->add('rectangle', 1, [10, 400, 690, 500], -fillcolor => "=axial 90 |yellow;40|black;40 50|cyan;40", -filled => 1);


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "WITHOUT openGL, NO GRADIENT. SORRY!",
	   -anchor => 'nw',
	   -position => [20, 550]) unless $zinc->cget(-render);



MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/contours.pl.





















































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/perl -w
# $Id$
# This simple demo has been developped by C. Mertz <mertz@cena.fr>

package contours; # for avoiding symbol collision between different demos

use Tk;
use Tk::Zinc;

use strict;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

my $mw = MainWindow->new();

# The explanation displayed when running this demo
my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2,
		     -setgrid => 'true', -height => 9);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
'All visibles items are made by combining 2 items using contours:
 - the firebrick curve1 has been holed using a addhole with a circle,
 - the lightblue curve2 has been "mickey-moused" by adding two circles,
 - the yellow curve3 is the union with a disjoint circle,
 - the grey curve4 is combined with 7 circles, with \'positive\' -fillrule.
The following operations are possible:
 - "Mouse Button 1" for dragging objects.
 - "Mouse Button 1" for dragging the black handle and
    modifying the grey curve contour.');

# Creating the zinc widget
my $zinc = $mw->Zinc(-width => 600, -height => 500,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;


# Creation of 2 items NOT visible, but used for creating visible
# curves[1-5] with more than one contours.
# The center of these 2 items is 200,100
my $curve0 = $zinc->add('curve', 1, [ [300,0], [400,100, 'c'], [300,200], [200,300,'c'], [100,200], [0,100,'c'], [100,0],  ],
			-closed => 1, -visible => 0, -filled => 1,
			);
my $cercle100 = $zinc->add('arc', 1, [130,30, 280,180],
			  -visible => 0,
			  );

# cloning curve0 as curve1 and moving it
my $curve1 = $zinc->clone($curve0, -visible => 1, -fillcolor => "firebrick1");
# adding a 'difference' contour to the curve1
$zinc->contour($curve1, 'add', +1, $cercle100);


# cloning curve0 as curve2 and moving it
# creating a curve without contour to control contour clockwise/counterclockwise
my $curve2 = $zinc->add('curve', 1, [], -closed => 1, -filled => 1,
			-visible => 1, -fillcolor => "lightblue2", -fillrule => 'positive');
$zinc->contour($curve2, 'add', -1, $curve0); ## why must the flag be -1 and not -1 !?
# adding the left ear of mickey mouse!
$zinc->translate($curve2,100,90);
# adding the right ear of mickey mouse!
$zinc->contour($curve2, 'add', +1, $cercle100);

$zinc->translate($curve2,-200,0);
# adding an 'intersection' contour to the curve2
$zinc->contour($curve2, 'add', +1, $cercle100);

# ... translate to make it more visible
$zinc->translate($curve2, 320,20);


# cloning curve0 as curve3 and moving it
my $curve3 = $zinc->clone($curve0, -visible => 1, -fillcolor => "yellow3");
$zinc->translate($curve3,0,290);
# adding an 'union' contour to the curve3
$zinc->contour($curve3, 'add', +1, $cercle100);
# ... translate to make it more visible
$zinc->translate($curve3, -130,00);

    


# cloning curve0 as curve4 and moving it slightly
my $curve4 = $zinc->clone($curve0, -visible => 1, -fillcolor => "grey50",
			  -tags => ["grouped"],
			  -fillrule => 'positive',
                          # the tag "grouped" is used for both curve4 and
			  # a handle (see just below)
			  # It is used for translating both easily
			  );

my $index = 2; ## index of the vertex associated to the handle
my ($x,$y) = $zinc->coords($curve4,0,$index);
my $handle = $zinc->add('rectangle', 1, [$x-5,$y-5,$x+5,$y+5],
			-fillcolor => 'black', -filled => 1,
			  -tags => ["grouped"],
			);

# adding a 'difference' contour to the curve4
$zinc->contour($curve4, 'add', +1, $cercle100);
$zinc->translate('grouped',110,0);
$zinc->contour($curve4, 'add', +1, $cercle100);
$zinc->translate('grouped',-220,0);
$zinc->contour($curve4, 'add', +1, $cercle100);
$zinc->translate('grouped',110,80);
$zinc->contour($curve4, 'add', -1, $cercle100);
$zinc->translate('grouped',0,-160);
$zinc->contour($curve4, 'add', +1, $cercle100);

$zinc->translate('grouped',200,80);
$zinc->contour($curve4, 'add', +1, $cercle100);
$zinc->translate('grouped',-350,0);
$zinc->contour($curve4, 'add', +1, $cercle100);

$zinc->translate('grouped',350,250);
#$zinc->lower('grouped');

# Deleting no more usefull items: curve0 and cercle100:
$zinc->remove($curve0, $cercle100);

$zinc->raise($curve1);

# adding drag and drop callback to each visible curve!
foreach my $item ($curve1, $curve2, $curve3, $curve4) {
    # Some bindings for dragging the items
    $zinc->bind($item, '<ButtonPress-1>' => [\&press, $item, \&motion]);
    $zinc->bind($item, '<ButtonRelease-1>' => \&release);
}

# adding drag and drop on curve4 which also moves handle
$zinc->bind($curve4, '<ButtonPress-1>' => [\&press, $curve4, \&motionWithHandle]);
$zinc->bind($curve4, '<ButtonRelease-1>' => \&release);

# adding drag and drop on handle which also modify curve4
$zinc->bind($handle, '<ButtonPress-1>' => [\&press, $handle, \&moveHandle]);
$zinc->bind($handle, '<ButtonRelease-1>' => \&release);

# callback for starting a drag
my ($x_orig, $y_orig);
sub press {
    my ($zinc, $item, $action) = @_;
    my $ev = $zinc->XEvent();
    $x_orig = $ev->x;
    $y_orig = $ev->y;
    $zinc->Tk::bind('<Motion>', [$action, $item]);
}

# Callback for moving an item
sub motion {
    my ($zinc, $item) = @_;
    my $ev = $zinc->XEvent();
    my $x = $ev->x;
    my $y = $ev->y;

    $zinc->translate($item, $x-$x_orig, $y-$y_orig);
    $x_orig = $x;
    $y_orig = $y;
}

# Callback for moving an item and its handle
sub motionWithHandle {
    my ($zinc, $item) = @_;
    my $ev = $zinc->XEvent();
    my $x = $ev->x;
    my $y = $ev->y;

    my ($tag) = $zinc->itemcget($item, -tags);
    $zinc->translate($tag, $x-$x_orig, $y-$y_orig);
    $x_orig = $x;
    $y_orig = $y;
}

# Callback for moving the handle and modifying curve4
# this code is far from being generic. Only for demonstrating how we can
# modify a contour with a unique handle!
sub moveHandle {
    my ($zinc, $handle) = @_;
    my $ev = $zinc->XEvent();
    my $x = $ev->x;
    my $y = $ev->y;

    $zinc->translate($handle, $x-$x_orig, $y-$y_orig);

    my ($vertxX,$vertxY) = $zinc->coords($curve4,0,$index);
    $zinc->coords($curve4,0,$index, [$vertxX+($x-$x_orig), $vertxY+($y-$y_orig)]);
    $x_orig = $x;
    $y_orig = $y;
}

# Callback when releasing the mouse button. It removes any motion callback
sub release {
    my ($zinc) = @_;
    $zinc->Tk::bind('<Motion>', '');
}

Tk::MainLoop();


1;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/counter.pl.

















































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/usr/bin/perl
# This simple demo has been developped by C. Schlienger <celine@intuilab.com>

package counter; # for avoiding symbol collision between different demos

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;
use constant;

my constant $PI=3.1416;

my $boldfont = '-adobe-helvetica-bold-r-normal--20-240-100-100-p-182-iso8859-1';

my $mw = MainWindow->new();

###################################################
# Zinc
###################################################

my $zinc = $mw->Zinc(-width => 700, -height => 400,
		     -font => "10x20", 
		     -borderwidth => 3, 
		     -relief => 'sunken',
		     -render => 1,
		    )->pack;

if ($zinc->cget(-render)) {
    $zinc->add('rectangle', 1,
	       [0,0,700,400],
	       -filled => 1,  -linewidth => 0,
	       -fillcolor => "=axial 90 |red;40|green;40 50|blue;40"
	       );
} else { ## no openGL rendering!
    # creating a curve in the background to demonstrate the clipping
    # of the hole in the counter
    $zinc->add('curve', 1, [30,30, 350,150, 670,30, 400,200, 670,370, 350,250, 30,370, 300,200, 30,30],
	       -filled => 1,
	       -fillcolor => "tan",
	       );
}

# The explanation displayed when running this demo
$zinc->add('text', 1,
	   -position=> [10,10],
	   -text => 'This toy-appli shows a simple counter. It is made thanks
to clipping and contours : this is the only way to do this.
You can drag the counter. Observe that the color of the background
of the counter is the same as the one of the window (use of clips)',
	   -font => "10x20",
	   );

###################################################
# Les positions
###################################################

#--------------------------------
# Carre dans lequel sera inscrit le cercle du compteur
#---------------------------------

my $x0=250;
my $y0=100;
my $x1=$x0+200;
my $y1=$y0+200;

#--------------------------------
# Rectangle dans lequel defileront les chiffres
#---------------------------------

my $x2=$x0+50;
my $y2=$y0+130;
my $x3=$x1-50;
my $y3=$y1-50;


###################################################
# Chiffres clippes
###################################################

my $general_group = $zinc->add('group',1, -visible => 1);

my $clipped_group1 = $zinc->add('group',$general_group, -visible => 1);

#--------------------------------
# Clipping items
#---------------------------------

my $clipping_item1 = $zinc->add('curve', $clipped_group1,
			       [$x2,$y2,$x3,$y2,$x3,$y3,$x2,$y3,$x2,$y2]
			      );

#--------------------------------
# Clipped items
#---------------------------------

my $group1=$zinc->add('group',$clipped_group1);

my $ecart=17;

# Il y a deux listes de chifres pour centaines, dizaines, unites,
# pour assurer l'enchainement des chiffres quand le temps passe
# (cf. : actions automatiques)

#--------------------------------
# Centaines
#---------------------------------

my $cent = $zinc->add('group',$group1, -visible => 1,);
my $xc=$x2+20;
my $yc=$y2;


my $nbc1=$zinc->add('text', $cent,
	   -font => $boldfont,
	   -text => "0
1
2
3
4
5
6
7
8
9",
	   -anchor => 'nw',
	   -position => [$xc, $yc],
);
my $nbc2=$zinc->add('text', $cent,
	   -font => $boldfont,
	   -text => "0
1
2
3
4
5
6
7
8
9",
	   -anchor => 'nw',
	   -position => [$xc, $yc+210],
);
#--------------------------------
# Dixaines
#---------------------------------

my $dix = $zinc->add('group',$group1, -visible => 1);

my $xd=$xc+30;
my $yd=$y2;
my $nbd1=$zinc->add('text', $dix,
	   -font => $boldfont,
	   -text => "0
1
2
3
4
5
6
7
8
9",
	   -anchor => 'nw',
	   -position => [$xd,$yd]);

my $nbd2=$zinc->add('text', $dix,
	   -font => $boldfont,
	   -text => "0
1
2
3
4
5
6
7
8
9",
	   -anchor => 'nw',
	   -position => [$xd,$yd+210]);
#--------------------------------
# Unites
#---------------------------------

my $unit = $zinc->add('group',$group1, -visible => 1);
my $xu=$xd+30;
my $yu=$y2;
my $nbu1=$zinc->add('text', $unit,
		    -font => $boldfont,
		    -text => "0
1
2
3
4
5
6
7
8
9",
		    -anchor => 'nw',
		    -position => [$xu, $yu]);

my $nbu2=$zinc->add('text', $unit,
		    -font => $boldfont,
		    -text => "0
1
2
3
4
5
6
7
8
9",
		    -anchor => 'nw',
		    -position => [$xu, $yu+210]);

#--------------------------------
# Clip
#---------------------------------

$zinc->itemconfigure($clipped_group1, -clip => $clipping_item1);


###################################################
# Cadran clippe
###################################################

my $clipped_group2 = $zinc->add('group',$general_group, -visible => 1);

#--------------------------------
# Clipping items
#---------------------------------

my $clipping_item2 = $zinc->add('curve', $clipped_group2,
			       [0,0,700,0,700,700,0,700,0,0],
				-linewidth=>0,
			      );

$zinc->contour($clipping_item2,"add",0,[$x2,$y2,$x3,$y2,$x3,$y3,$x2,$y3,$x2,$y2]);

#--------------------------------
# Clipped items
#---------------------------------

my $group2=$zinc->add('group',$clipped_group2);

my $cercle=$zinc->add('arc',$group2,[$x0,$y0,$x1,$y1],
			 -visible=>1,
			 -filled=>1,
			 -fillcolor=>"yellow",);

my $fleche=$zinc-> add('curve', $group2, [$x0+40,$y0+40,$x1-100,$y1-25],
		       -firstend => [10, 10, 10],
		       -linewidth => 7,
		       -linecolor=>"red",
	    );

#--------------------------------
# Clip
#---------------------------------

$zinc->itemconfigure($clipped_group2, -clip => $clipping_item2);

# this translation if for having an "interesting" background in the counter hole
# when we do not have openGL and a gradient in the background
$zinc->translate($general_group,0,21); 

###################################################
# Actions automatiques
###################################################

#--------------------------------
# Variables
#---------------------------------
# Pour le timer
my $repeat=10;

# Pour la rotation
my @centre=($x1-100,$y1-25);
my $pas=40;
my $angle=+$PI/$pas;
my $nb_tot=12;
my $nb=0;

# Pour la translation des centaines
my @c_c1=$zinc->itemcget($nbc1,-position);
my @c_c2=$zinc->itemcget($nbc2,-position);
my $nbtour_cent=2;

# Pour la translation des dizaines
my @c_d1=$zinc->itemcget($nbd1,-position);
my @c_d2=$zinc->itemcget($nbd2,-position);
my $nbtour_dix=2;

# Pour la translation des unites
my @c_u1=$zinc->itemcget($nbu1,-position);
my @c_u2=$zinc->itemcget($nbu2,-position);
my $nbtour_unit=2;


#--------------------------------
# Timer
#---------------------------------
my $timer = $zinc->repeat($repeat, [\&refresh]);

$mw->OnDestroy(\&destroyTimersub );

my $timerIsDead = 0;
sub destroyTimersub {
    $timerIsDead = 1;
    $mw->afterCancel($timer);
    # the timer is not really cancelled when using zinc-demos! 
}

#--------------------------------
# Actions
#---------------------------------
sub refresh {
  #--------------------------------
  # Rotation de la fleche
  #---------------------------------
  return if $timerIsDead;   # the timer is still running when using zinc-demos!
  $zinc->rotate($fleche,$angle,$centre[0],$centre[1]);
  $nb+=1;
  if (($nb==$nb_tot)&&($angle==$PI/$pas))
    {
      $nb=0;
      $angle=-$PI/$pas;
    } 
  else{
    if(($nb==$nb_tot)&&($angle==-$PI/$pas)){
      $nb=0;
      $angle=+$PI/$pas;
    }
  }
  #--------------------------------
  # Deplacement du texte
  #---------------------------------

  #--------------------------------
  # Centaines
  #---------------------------------
  $zinc->translate($cent,0,-0.01);

  my @coords_c1=$zinc->transform($cent,$group1,[$c_c1[0],$c_c1[1]]);
  if(int($coords_c1[1])==$yc-210){
    $zinc->itemconfigure($nbc1,-position=>[$xc,$yc+($nbtour_cent*210)]);
    $nbtour_cent+=1;
    @c_c1=$zinc->itemcget($nbc1,-position);
  }

  my @coords_c2=$zinc->transform($cent,$group1,[$c_c2[0],$c_c2[1]]);
  if($coords_c2[1]==$yc-210){
    $zinc->itemconfigure($nbc2,-position=>[$xc,$yc+($nbtour_cent*210)]);
    $nbtour_cent+=1;
    @c_c2=$zinc->itemcget($nbc2,-position);
  }

  #-------------------------------- 
  #Dixaines
  #---------------------------------
  $zinc->translate($dix,0,-0.1);

  my @coords_d1=$zinc->transform($dix,$group1,[$c_d1[0],$c_d1[1]]);
  if(int($coords_d1[1])==$yd-210){
    $zinc->itemconfigure($nbd1,-position=>[$xd,$yd+($nbtour_dix*210)]);
    $nbtour_dix+=1;
    @c_d1=$zinc->itemcget($nbd1,-position);
  }

  my @coords_d2=$zinc->transform($dix,$group1,[$c_d2[0],$c_d2[1]]);
  if($coords_d2[1]==$yd-210){
    $zinc->itemconfigure($nbd2,-position=>[$xd,$yd+($nbtour_dix*210)]);
    $nbtour_dix+=1;
    @c_d2=$zinc->itemcget($nbd2,-position);
  }


  #--------------------------------
  # Unites
  #---------------------------------
  $zinc->translate($unit,0,-1);

  my @coords_u1=$zinc->transform($unit,$group1,[$c_u1[0],$c_u1[1]]);
  if($coords_u1[1]==$yu-210){
    $zinc->itemconfigure($nbu1,-position=>[$xu,$yu+($nbtour_unit*210)]);
    $nbtour_unit+=1;
    @c_u1=$zinc->itemcget($nbu1,-position);
  }

  my @coords_u2=$zinc->transform($unit,$group1,[$c_u2[0],$c_u2[1]]);
  if($coords_u2[1]==$yu-210){
    $zinc->itemconfigure($nbu2,-position=>[$xu,$yu+($nbtour_unit*210)]);
    $nbtour_unit+=1;
    @c_u2=$zinc->itemcget($nbu2,-position);
  }

}

###################################################
# Actions manuelles
###################################################

#---------------------------------------------
# Drag and drop the counter
#---------------------------------------------

my ($prev_x, $prev_y);
$zinc -> bind($cercle,'<ButtonPress-1>'=>[\&move_on] ); 


#"move_on" state#
sub move_on{
    $prev_x=$zinc->XEvent()->x;
    $prev_y=$zinc->XEvent()->y;
    # move the counter
    $zinc -> bind($cercle,'<Motion>'=> [\&move]);
    $zinc -> bind($cercle,'<ButtonRelease-1>'=> [\&move_off]); #"move_off" state
}


#"move_off" state#
sub move_off{
  $zinc -> bind($cercle,'<Motion>'=>""); 
  $zinc -> bind($cercle,'<ButtonRelease-1>'=>"");
}

#move the counter#
sub move{
  my $x=$zinc->XEvent()->x,
  my $y=$zinc->XEvent()->y;
  $zinc->translate($clipped_group1,$x-$prev_x,$y-$prev_y);
  $zinc->translate($clipped_group2,$x-$prev_x,$y-$prev_y);
  ($prev_x,$prev_y) = ($x,$y);
}
 
Tk::MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl.



























































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/perl -w
# $Id$
# This simple demo has been developped by C. Mertz <mertz@cena.fr>

####### This file has been initially inspired from svg examples

package curveBezier;

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk::Zinc;


my $mw = MainWindow->new();
$mw->title('example of curves with cubic control points');

my $text = $mw->Text (-relief => 'sunken', -borderwidth => 2,
		      -setgrid => 'true',  -height =>3);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
'6 examples of curves containing control points are displayed, 
 with the list of control points written just below.
You can move the handles to modify the bezier curves');


my $zinc = $mw->Zinc(-width => 700, -height => 650,
		     -font => "10x20",
		     -font => "9x15",
		     -borderwidth => 0,
                     -backcolor => "white",
		     -forecolor => "grey80",
		     -render => 1, # this demo also works without openGL
		     # with openGL, antialiasing makes the curves nicer
		      )->pack;

my $group = $zinc->add('group', 1);

$zinc->add('text',$group, -position => [50,20], -anchor => 'w',
	   -text => "Examples of curve items using cubic bezier control points",
	   -color => "grey20");

## Please note: much of the following items below could be computed
$zinc->add('text',$group, -position => [25,270], -anchor => 'w', -tags => ['bezier1'], -color => "grey20");
$zinc->add('curve',$group,[100, 200, 100, 100], -tags => ['line1', 'l1-2'], -linecolor => "#888888", -filled => 0, -linewidth => 2);
$zinc->add('curve',$group,[400, 100, 400, 200], -tags => ['line1', 'l3-4'], -linecolor => "#888888", -filled => 0, -linewidth => 2);
$zinc->add('curve',$group,[[100, 200], [100, 100, 'c'], [400, 100, 'c'], [400, 200]],
	   -tags => ['bezier1'], -closed => 0, -linecolor => "red", -linewidth => 5);
$zinc->add('arc',$group,[90, 190, 110, 210], -tags => ['handle1',"p1"], -filled => 1, -fillcolor => "#BBBBBB");
$zinc->add('arc',$group,[90, 90, 110, 110], -tags => ['handle1',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1);
$zinc->add('arc',$group,[390, 90, 410, 110], -tags => ['handle1',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1);
$zinc->add('arc',$group,[390, 190, 410, 210], -tags => ['handle1',"p4"], -filled => 1, -fillcolor => "#BBBBBB");

$zinc->add('text',$group, -position => [570,270], -anchor => 'w', -tags => ['bezier2'], -color => "grey20");
$zinc->add('curve',$group,[600, 200, 675, 100], -tags => ['line2', 'l1-2'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[975, 100, 900, 200], -tags => ['line2', 'l3-4'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[[600, 200], [675, 100, 'c'], [975, 100, 'c'], [900, 200]],
	   -tags => ['bezier2'], -closed => 0, -linecolor => "red", -linewidth => 5);
$zinc->add('arc',$group,[590, 190, 610, 210], -tags => ['handle2',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2);
$zinc->add('arc',$group,[665, 90, 685, 110], -tags => ['handle2',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80");
$zinc->add('arc',$group,[965, 90, 985, 110], -tags => ['handle2',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80");
$zinc->add('arc',$group,[890, 190, 910, 210], -tags => ['handle2',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2);

$zinc->add('text',$group, -position => [25,570], -anchor => 'w', -tags => ['bezier3'], -color => "grey20");
$zinc->add('curve',$group,[100, 500, 25, 400], -tags => ['line3', 'l1-2'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[475, 400, 400, 500], -tags => ['line3', 'l3-4'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[[100, 500], [25, 400, 'c'], [475, 400, 'c'], [400, 500]],
	   -tags => ['bezier3'], -closed => 0, -linecolor => "red", -linewidth => 5);
$zinc->add('arc',$group,[90, 490, 110, 510], -tags => ['handle3',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2);
$zinc->add('arc',$group,[15, 390, 35, 410], -tags => ['handle3',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", );
$zinc->add('arc',$group,[465, 390, 485, 410], -tags => ['handle3',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", );
$zinc->add('arc',$group,[390, 490, 410, 510], -tags => ['handle3',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2);

$zinc->add('text',$group, -position => [570,570], -anchor => 'w', -tags => ['bezier4'], -color => "grey20");
$zinc->add('curve',$group,[600, 500, 600, 350], -tags => ['line4', 'l1-2'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[900, 650, 900, 500], -tags => ['line4', 'l3-4'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[[600, 500], [600, 350, 'c'], [900, 650, 'c'], [900, 500]], -tags => ['bezier4'], -closed => 0, -linecolor => "red", -linewidth => 5);
$zinc->add('arc',$group,[590, 490, 610, 510], -tags => ['handle4',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2);
$zinc->add('arc',$group,[590, 340, 610, 360], -tags => ['handle4',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80");
$zinc->add('arc',$group,[890, 640, 910, 660], -tags => ['handle4',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80");
$zinc->add('arc',$group,[890, 490, 910, 510], -tags => ['handle4',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2);

$zinc->add('text',$group, -position => [25,870], -anchor => 'w', -tags => ['bezier5'], -color => "grey20");
$zinc->add('curve',$group,[100, 800, 175, 700], -tags => ['line5', 'l1-2'], -linecolor => "#888888", -filled => 0, -linewidth => 2);
$zinc->add('curve',$group,[325, 700, 400, 800], -tags => ['line5', 'l3-4'], -linecolor => "#888888", -filled => 0, -linewidth => 2);
$zinc->add('curve',$group,[[100, 800], [175, 700, 'c'], [325, 700, 'c'], [400, 800]],
	   -tags => ['bezier5'], -closed => 0, -linecolor => "red", -linewidth => 5);
$zinc->add('arc',$group,[90, 790, 110, 810], -tags => ['handle5',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2);
$zinc->add('arc',$group,[165, 690, 185, 710], -tags => ['handle5',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1);
$zinc->add('arc',$group,[315, 690, 335, 710], -tags => ['handle5',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1);
$zinc->add('arc',$group,[390, 790, 410, 810], -tags => ['handle5',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2);

$zinc->add('text',$group, -position => [570,980], -anchor => 'w', -tags => ['bezier6'], -color => "grey20");
$zinc->add('curve',$group,[600, 800, 625, 700], -tags => ['line6', 'l1-2'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[725, 700, 750, 800], -tags => ['line6', 'l3-4'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[750, 800, 775, 900], -tags => ['line6', 'l4-5'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[875, 900, 900, 800], -tags => ['line6', 'l6-7'], -linecolor => "#888888", -linewidth => 2);
$zinc->add('curve',$group,[[600, 800], [625, 700, 'c'], [725, 700, 'c'], [750, 800], [775, 900, 'c'], [875, 900, 'c'], [900, 800]],
	   -tags => ['bezier6'], -filled => 0, -closed => 0, -linecolor => "red", -linewidth => 5);
$zinc->add('arc',$group,[590, 790, 610, 810], -tags => ['handle6',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2);
$zinc->add('arc',$group,[615, 690, 635, 710], -tags => ['handle6',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80");
$zinc->add('arc',$group,[715, 690, 735, 710], -tags => ['handle6',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80");
$zinc->add('arc',$group,[740, 790, 760, 810], -tags => ['handle6',"p4"], -filled => 1, -linecolor => "blue",-fillcolor => "blue", -linewidth => 2);
$zinc->add('arc',$group,[766, 891, 784, 909], -tags => ['handle6',"p5"], -filled => 1, -linecolor => "grey80", -linewidth => 4);
$zinc->add('arc',$group,[865, 890, 885, 910], -tags => ['handle6',"p6"], -filled => 1, -linewidth => 0, -fillcolor => "grey80");
$zinc->add('arc',$group,[890, 790, 910, 810], -tags => ['handle6',"p7"], -filled => 1, -linecolor => "grey80", -linewidth => 2);

$zinc->scale($group, 0.6, 0.6);

## Set the text of the text item with a tag "tag"
## to a human-readable form of the coords of the
## corresponding curve with the same tag "tag"
sub setText {
    my ($tag) = @_;
    my $textItem = $zinc->find("withtype", 'text', $tag);
    my $curveItem = $zinc->find("withtype", 'curve', $tag);
    my @coords = $zinc->coords($curveItem);
    my $count = 0;
    my $text = "[ ";
    while (@coords) {
	$refXYc = pop @coords;
	my $x=sprintf "%i", $refXYc->[0];
	my $y=sprintf "%i", $refXYc->[1];
	my $t=$refXYc->[2];
	$t = (defined $t) ? ", '".$t."'" : "" ;
	$text .= "[$x, $y$t]";
	if (@coords) { $text .= ", "; }
	if ($count and @coords) {
	    $text .= "\n   ";
	    $count =0;
	} else {
	    $count++;
	}
    }
    $text .= " ]";
    $zinc->itemconfigure($textItem, -text => $text);
}

foreach my $bezierCount (1..6) {
    &setText ("bezier".$bezierCount);
    my $curveItem = $zinc->find("withtype", 'curve', "bezier".$bezierCount);
    my @coords = $zinc->coords($curveItem);
#    print "$bezierCount : ", scalar @coords, "\n";
    $zinc->bind("handle$bezierCount", '<ButtonPress-1>', [\&press, \&motion]);
    $zinc->bind("handle$bezierCount", '<ButtonRelease-1>', [\&release]);
}



&Tk::MainLoop;


##### bindings for moving the handles
my ($cur_x, $cur_y,$item, $bezierNum, $ptNum);
sub press {
    my ($zinc, $action) = @_;
    my $ev = $zinc->XEvent();
    $cur_x = $ev->x;
    $cur_y = $ev->y;
    $item = $zinc->find('withtag', 'current');
    $zinc->bind($item, '<Motion>', [$action]);
    foreach ( $zinc->gettags($item) ) {
	## looking for the tag "handlei"
	if ( /^handle(\d+)$/ ) {
	    $bezierNum = $1;
	}
	## looking for the tag "pj"
	if ( /^p(\d+)$/ ) {
	    $ptNum = $1;
	}
    }
#    print "bezierNum=$bezierNum ptNum=$ptNum\n";
}

sub motion {
    my ($zinc) = @_;
    my $ev = $zinc->XEvent();
    my $lx = $ev->x;
    my $ly = $ev->y;
    my ($dx,$dy) = $zinc->transform($group, [$lx-$cur_x, $ly-$cur_y]);
    &moveHandle($item,$dx,$dy);
    my ($pt1,$pt2) = $zinc->coords($item);
#    print "coords=",@{$pt1}, " ",@{$pt2},"\n";
    $cur_x = $lx;
    $cur_y = $ly;
}

sub release {
    my ($zinc) = @_;
    $zinc->bind($item,'<Motion>', '');
    $item = "";
}

sub moveHandle {
    my ($item,$dx,$dy) = @_;
    my ($pt1,$pt2) = $zinc->coords($item);
    ## modifying the handle coords
    $zinc->coords($item, [ $pt1->[0]+$dx, $pt1->[1]+$dy, $pt2->[0]+$dx, $pt2->[1]+$dy]);
    my $prevPtNum = $ptNum-1;
    # there should only be one such item!
    my $lineA = $zinc->find("withtag", "line$bezierNum && l$prevPtNum-$ptNum");
    if (defined $lineA) {
	my ($x,$y) = $zinc->coords($lineA,0,1); # to get the 2nd point coords
	$zinc->coords($lineA, 0,1, [ $x+$dx, $y+$dy ]);
    }

    my $nextPtNum = $ptNum+1;
    # there should only be one such item:
    my ($lineB) = $zinc->find("withtag", "line$bezierNum && l$ptNum-$nextPtNum");
    if (defined $lineB) {
	my ($x,$y) = $zinc->coords($lineB,0,0); # to get the 1st point coords
	$zinc->coords($lineB, 0,0, [ $x+$dx, $y+$dy ] );
    }

    my ($x,$y,$control) = $zinc->coords("bezier$bezierNum", 0,$ptNum-1);
    $zinc->coords("bezier$bezierNum", 0,$ptNum-1, [ [$x+$dx, $y+$dy, $control] ] );
    &setText ("bezier$bezierNum");
	
}
    

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/fillrule.pl.











































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/perl -w
# $Id$
# This simple demo has been developped by C. Mertz <mertz@cena.fr>

####### This file has been largely inspired from figure 11-3
####### of "The OpenGL Programming Guide 3rd Edition, The 
####### Official Guide to Learning OpenGL Version 1.2",  ISBN 0201604582

####### it illustrates the use of :
#######   -fillrule attribute of curves
#######   contour, coords and clone method

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk::Zinc;


my $mw = MainWindow->new();
$mw->title('example of multiple contours and fillrule usage');

my $zinc = $mw->Zinc(-width => 510, -height => 630,
		     -font => "10x20",
		     -font => "9x15",
		     -borderwidth => 0,
                     -backcolor => "white",
		      )->pack;

$zinc->add('text', 1, -position => [20,8], -text => "This (still static) example reproduces figure 11-3
of \"The OpenGL Programming Guide 3rd Edition\" V 1.2");

my $group = $zinc->add('group', 1);

my $g1 = $zinc->add('group', $group);
my $curve1 = $zinc->add('curve',$g1, []);
$zinc->contour($curve1, "add", +1, [ 0,0, 0,120, 120,120, 120,0, 0,0]);
$zinc->contour($curve1, "add", +1, [ 20,20, 20,100, 100,100, 100,20, 20,20]);
$zinc->contour($curve1, "add", +1, [ 40,40, 40,80, 80,80, 80,40, 40,40]);
$zinc->translate($g1, 40,40);


my $g2 = $zinc->add('group', $group);
my $curve2 = $zinc->add('curve',$g2, []);
$zinc->contour($curve2, "add", +1, [ 0,0, 0,120, 120,120, 120,0, 0,0]);
$zinc->contour($curve2, "add", -1, [ 20,20, 20,100, 100,100, 100,20, 20,20]);
$zinc->contour($curve2, "add", -1, [ 40,40, 40,80, 80,80, 80,40, 40,40]);
$zinc->translate($g2, 200,40);


my $g3 = $zinc->add('group', $group);
my $curve3 = $zinc->add('curve',$g3, []);
$zinc->contour($curve3, "add", +1, [ 20,0, 20,120, 100,120, 100,0, 20,0]);
$zinc->contour($curve3, "add", +1, [ 40,20, 60,120, 80,20, 40,20]);
$zinc->contour($curve3, "add", +1, [ 0,60, 0,80, 120,80, 120,60, 0,60]);
$zinc->translate($g3, 360,40);

my $g4 = $zinc->add('group', $group);
my $curve4 = $zinc->add('curve',$g4, []);
$zinc->contour($curve4, "add", +1, [ 0,0, 0,140, 140,140,  140,60,  60,60,  60,80, 80,80, 80,40, 40,40,
				     40,100, 100,100, 100,20, 20,20,
				     20,120, 120,120, 120,0, 0,0]);
$zinc->translate($g4, 520,40);

$zinc->scale($group, 0.6, 0.6);
$zinc->translate($group, 80,20);

$zinc->add('text',$group, -position => [-110, 40], -text => "contours\nand\nwinding\nnumbers");
$zinc->add('text',$group, -position => [-110, 170], -text => "winding\nrules");
my $dy = 0;
foreach my $fillrule ('odd', 'nonzero', 'positive', 'negative', 'abs_geq_2') {
    $dy += 160;
    $zinc->add('text',$group, -position => [-110, 100+$dy], -text => $fillrule eq 'odd' ? "odd\n(default)" : $fillrule);
    foreach my $item ($curve1, $curve2, $curve3, $curve4) {
	my $clone = $zinc->clone($item, -fillrule => $fillrule, -filled => 1);
	$zinc->translate($clone, 0,$dy);
    }
}

# creating simple lines with arrows under each curves
foreach my $item ($curve1, $curve2, $curve3, $curve4) {
    my $contour_number = $zinc->contour($item);
#    print "$item => contour_number=$contour_number\n";
    foreach my $n (0..$contour_number-1) {
	my @points = $zinc->coords($item,$n);
#	print "   ",$#points,"points\n";
	foreach my $i (0 .. $#points-1) {
#	    print "    line $i ",$i+1,"\n";
	    $firstpoint = $points[$i];
	    $lastpoint = $points[$i+1];
	    $middlepoint = [$firstpoint->[0]+($lastpoint->[0]-$firstpoint->[0])/1.5,
			    $firstpoint->[1]+($lastpoint->[1]-$firstpoint->[1])/1.5];
	    $zinc->add("curve", $zinc->group($item),
		       [ $firstpoint, $middlepoint],
		       -lastend => [7,10,4]);
	}
    }
}
&Tk::MainLoop;


    

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/groups_in_ATC_strips.pl.





























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
#!/usr/bin/perl -w
#-----------------------------------------------------------------------------------
#
#      Copyright (C) 2002
#      Centre d'Études de la Navigation Aérienne
#
#      Authors: Jean-Luc Vinot <vinot@cena.fr> for whole graphic design and coding
#               Christophe Mertz <mertz@cena.fr> for adding simple animations
#                                                and integration in zinc-demos
#                 This integration is still not perfect and requires an extension in zinc
#                 We must know if a neamed gradient already exists, when launching
#                 many time the same demo in the same process!
#
# $Id$
#-----------------------------------------------------------------------------------
#      This small application illustrates both the use of groups in combination
#         of -composescale attributes and an implementation of kind of air traffic
#         control electronic strips.
#      However it is only a simplified example given as is, without any immediate usage!
#
#      3 strips formats are accessible through "+" / "-" buttons on the right side
#
#      1.   small-format: with 2 lines of info, and reduced length
#
#      2.   normal-format: with 3 lines of info, full length
#
#      3.  extended-format: with 3 lines of infos, full length
#                           the 3 lines are zoomed
#                           an additionnel 4th lone is displayed
#
#      An additionnal 4th format (micro-format) is available when double-clicking somewhere...
#
#      Strips can be moved around by drag&drop from the callsign
#
#      When changing size, strips are animated. The animation is a very simple one,
#        which should be enhanced.... You can change the animation parameters, by modifyng
#        $delay and $steps.
#
#-----------------------------------------------------------------------------------

package groups_in_ATC_strips; # for avoiding symbol collision between different demos

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

$| = 1;


my @stripGradiants;
my %stripFontset;
my %textures;

my $oldfkey;
my ($dx, $dy);

my $delay = 50; # ms between each animation steps
my $steps = 6;  # number of steps for the animation
my %scales;     # this hash just memorizes the current x and y scaling ratio
                # In a real appli, this should be memorized in strip objects

#----------------------
# configuration data
#----------------------
my $fnb10 = 'cenapii-digistrips-b10';
my $fnb10c = 'cenapii-digistrips-b10c';
my $fnb11 = 'cenapii-digistrips-b11';
my $fnb12 = 'cenapii-digistrips-b12';
my $fnb15 = 'cenapii-radar-b15';
my $fnm20 = 'cenapii-radar-m20';
my $fne18 = 'cenapii-radar-m18';

my @ratio2fontset = ([1.2, 'normal'],
		     [10, 'large']);

my $mwidth = 700;
my $mheight = 500;

my %stripstyle = (-gradset => {'idnt' => '=axial 90 |#ffffff 0|#ffeedd 30|#e9d1ca 90|#e9a89a',
			       'back' => '=axial 0 |#c1daff|#8aaaff',
			       ## the following shadow gradient is sub-optimal
			       'shad' => '=path -40 -40 |#000000;50 0|#000000;50 92|#000000;0 100',
			       'btn_outside' => '=axial 0 |#ffeedd|#8a9acc', 
			       'btn_inside' => '=axial 180 |#ffeedd|#8a9acc',
			       'ch1' => '=axial 0 |#8aaaff|#5B76ED',
			   },
		  
		  -fontset => {'normal' => {'callsign' => $fnb15,
					    'type1' => $fnb12,
					    'type2' => $fnb10,
					    'type3' => $fnb10c,
					},
			       
			       'large' => {'callsign' => $fnm20,
					   'type1' => $fne18,
					   'type2' => $fnb15,
					   'type3' => $fnb12,
				       },
			   },
		  
		  -width => 340,
		  -height => 86,
		  -shadowcoords => [8, 8, 374, 94],
		  -shadowcolor => 'shad',

		  -strip => {-linewidth => 3,
			     -linecolor => '#aaccff',
			     -fillcolor => 'back',
			     -relief => 'roundraised',
			 },

		  -buttons => {-coords => [340, 0],
			       -clipcoords => [0, 0, 90, 83],
			       -zone => {-coords => [0, 0, 26, 85],
					 -fillcolor => 'btn_outside',
					 -linewidth => 0,
				     },
			    
			       -btns => {'btnup' => {-coords => [0, 0, 26, 43],
						     -arrow => [14, 2, 24, 40,
								1, 40, 14, 2],
						     -linewidth => 1,
						     -linecolor => '#aabadd',
						     -fillcolor => 'btn_inside',
						     -label => {-coords => [13, 27],
								-text => "+",
								-font => $fnm20,
								-color => '#ffffff',
								-anchor => 'center',
							    },
						 },
					 
					 'btndn' => {-coords => [0, 43, 26, 86],
						     -arrow => [14, 83, 24, 43,
								1, 43, 14, 83],
						     -linewidth => 1,
						     -linecolor => '#aabadd',
						     -fillcolor => 'btn_inside',
						     -label => {-coords => [13, 56],
								-text => "-",
								-font => $fnm20,
								-color => '#ffffff',
								-anchor => 'center',
							    },
						 },
				     },
			   },
		  
		  -clipcoords => [3, 3, 332, 80],
		  -zones => {'ident' => {-coords => [3, 3, 90, 50],
					 -atomic => 1,
					 -priority => 200,
					 -sensitive => 1,
					 -tags => "move",
					 -linewidth => 1,
					 -filled => 1,
					 -relief => 'sunken',
					 -linecolor => '#ffeedd',
					 -fillcolor => 'idnt',
					 -fields => {-callsign => {-coords => [10, 18],
								   -font => 'callsign',
								   -text => 'EWG361',
								   -anchor => 'w',
								   -color => '#000000',
							       },
						     -company => {-coords => [10, 34],
								  -font => 'type2',
								  -text => 'Eurowing',
								  -anchor => 'w',
								  -color => '#444444',
							      },
						 },
				     },
			     'input' => {-coords => [3, 3, 334, 82],
					 -atomic => 1,
					 -priority => 100,
					 -sensitive => 1,
					 -tags => "scale",
					 -linewidth => 0,
					 -filled => 1,
					 -relief => 'flat',
					 -linecolor => 'white',
					 -fillcolor => 'back', #'#afb2cc',
					 -fields => {-type => {-coords => [100, 18],
							       -font => 'type1',
							       -text => 'TYPA',
							       -anchor => 'w',
							       -color => '#444444',
							   },
						     -cfmu => {-coords => [200, 18],
							       -font => 'type1',
							       -text => '08:26',
							       -anchor => 'e',
							       -color => '#444444',
							   },
						     -ptsid => {-coords => [100, 40],
							       -font => 'type2',
							       -text => 'NIPOR',
							       -anchor => 'w',
							       -color => '#444444',
							   },
						     -confsid => {-coords => [158, 40],
							       -font => 'type2',
							       -text => '8G',
							       -anchor => 'center',
							       -color => '#444444',
							   },
						     -park => {-coords => [200, 40],
							       -font => 'type2',
							       -text => 'G23',
							       -anchor => 'e',
							       -color => '#444444',
							   },
						     
						     -dest => {-coords => [10, 66],
							       -font => 'type2',
							       -text => 'DEST',
							       -anchor => 'w',
							       -color => '#555555',
							   },
						     -champ1 => {-type => 'rect',
								 -coords => [45, 56,
									     135, 76],
								 -filled => 1,
								 -fillcolor => 'ch1',
								 -linecolor => 'white',
								 -linewidth => 0,
							   },
						     -bret => {-coords => [200, 66],
							       -font => 'type2',
							       -text => 'Bret.',
							       -anchor => 'e',
							       -color => '#444444',
							   },
						 },
				     },
			     
			     'zreco' => {-coords => [210, 3, 346, 82],
					 -atomic => 1,
					 -priority => 200,
					 -texture => "stripped_texture.gif",
					 -sensitive => 1,
					 -tags => "edit",
					 -linewidth => 2,
					 -filled => 1,
					 -relief => 'sunken',
					 -linecolor => '#deecff',
					 -fillcolor => '#d3e5ff',
				     },

			     
			 },
		  
		  -zinfo => {-coords => [0, 86],
			     -rectcoords => [0, 0, 340, 20],
			     -shadowcoords => [8, 8, 348, 28],
			     -shadowcolor => 'shad',
			     -atomic => 1,
			     -priority => 200,
			     -sensitive => 1,
			     -tags => "edit2",
			     -linewidth => 2,
			     -linecolor => '#aaccff',
			     -fillcolor => 'back',
			     -relief => 'roundraised',
			     -fields => {-ssr => {-coords => [4, 10],
						  -font => 'type3',
						  -text => '7656',
						  -anchor => 'w',
						  -color => '#444444',
					      },
					 -pdep => {-coords => [47, 10],
						  -font => 'type3',
						  -text => 'G23',
						  -anchor => 'center',
						  -color => '#444444',
					      },
					 -qfu => {-coords => [73, 10],
						  -font => 'type3',
						  -text => '09R',
						  -anchor => 'center',
						  -color => '#444444',
					      },
					 -slabel => {-coords => [105, 10],
						  -font => 'type3',
						  -text => 'vit:',
						  -anchor => 'e',
						  -color => '#444444',
					      },
					 -speed => {-coords => [106, 10],
						    -font => 'type3',
						    -text => '260',
						    -anchor => 'w',
						    -color => '#444444',
					      },
					 -pper => {-coords => [142, 10],
						  -font => 'type3',
						  -text => 'EPL',
						  -anchor => 'center',
						  -color => '#444444',
					      },
					 -rfl => {-coords => [166, 10],
						  -font => 'type3',
						  -text => '210',
						  -anchor => 'center',
						  -color => '#444444',
					      },
					 -cautra => {-coords => [183, 10],
						  -font => 'type3',
						  -text => '8350',
						  -anchor => 'w',
						  -color => '#444444',
					      },
					 -nsect => {-coords => [219, 10],
						  -font => 'type3',
						  -text => 'MOD',
						  -anchor => 'w',
						  -color => '#444444',
					      },
					 -day => {-coords => [297, 10],
						  -font => 'type3',
						  -text => '21/05/02',
						  -anchor => 'e',
						  -color => '#444444',
					      },
					 -hour => {-coords => [332, 10],
						  -font => 'type3',
						  -text => '13:50',
						  -anchor => 'e',
						  -color => '#444444',
					      },
			     },
					 
			  },
		  );

# creation de la fenetre principale
my $mw;
$mw = MainWindow->new();

# The explanation displayed when running this demo
my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2,
		     -setgrid => 'true', -height =>7);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
'These fake air Traffic Control electronic strips illustrates
 the use of groups for an advanced graphic design.
The following interactions are possible:
   "drag&drop button1" on the callsign.
   "button 1" triangle buttons on the right side of the strips
    to modify strips size
   "double click 1" on the blueish zone to fully reduce size');

$mw->title('ATC strips using groups');


#------------------------
# creation du widget Zinc
my $zinc = $mw->Zinc(-render => 1,
		     -width => $mwidth,
		     -height => $mheight,
		     -borderwidth => 0,
		     -lightangle => 130,
		     );
		     
$zinc->pack(-fill => 'both', -expand => 1);

my $texture = $zinc->Photo('background_texture.gif',
			   -file => Tk->findINC('demos/zinc_data/background_texture.gif'));
$zinc->configure(-tile => $texture) if $texture;



my ($xn, $yn) = (10, 30);

# test Strips
for (my $index = 0; $index < 4 ; $index++) {
    
    &createStrip($index, $xn, $yn, \%stripstyle);

    $xn += 50;
    $yn += 120;

}


&initBindings('move', 'scale');


	 

Tk::MainLoop;

#----------------------------------------------------------------------- fin de MAIN


# Création du Strip
sub createStrip {
    my ($index, $x, $y, $style) = @_;

    # initialise les gradiants
    unless (@stripGradiants) {
	my %gradiants = %{$style->{'-gradset'}};
	my ($name, $gradiant);
	while (($name, $gradiant) = each(%gradiants)) {
	    # création des gradients nommés
	    $zinc->gname($gradiant, $name) unless $zinc->gname($gradiant);
	    # the previous test is usefull only
	    # when this script is executed many time in the same process
	    # (it is typically the case in zinc-demos)

	    push(@stripGradiants, $name);
	}  
    }
  
    # initialise les jeux de fontes 
    unless (%stripFontset) {
	%stripFontset = %{$style->{'-fontset'}};
    }

    # création du groupe de base : coords
    my $g1 = $zinc->add('group', 1, -priority => 100, -tags => ["base".$index]);
    $zinc->coords($g1, [$x, $y]);

    # group de transfo 1 : scaling (à partir du coin haut droit)
    my $g2 = $zinc->add('group', $g1, -tags => ["scaling".$index]);


    #-------------------------------------------------------------
    # réalisation du strip lui même (papier support + ombre portée
    #-------------------------------------------------------------
    
    # params strip
    my $stripw = $style->{'-width'};
    my $striph = $style->{'-height'};
    
    # ombre portée
    $zinc->add('rectangle', $g2,
	       $style->{'-shadowcoords'},
	       -filled => 1,
	       -linewidth => 0,
	       -fillcolor => $style->{'-shadowcolor'},
	       -priority => 10,
	       -tags => ["shadow".$index],
	       );


    # strip
    my $sstyle = $style->{'-strip'};    
    my $strip = $zinc->add('rectangle', $g2,
			   [0, 0, $stripw, $striph],
			   -filled => 1,
			   -linewidth => $sstyle->{'-linewidth'},
			   -linecolor => $sstyle->{'-linecolor'},
			   -fillcolor => $sstyle->{'-fillcolor'},
			   -relief => $sstyle->{'-relief'},
			   -priority => 20,
			   -tags => ["strip".$index],
			   );

    if ($sstyle->{'-texture'}) {
	if (!exists($textures{'-strip'})) {
	    my $texture = $zinc->Photo($sstyle->{'-texture'}, 
                                       -file => Tk->findINC("demos/zinc_data/".$sstyle->{-texture}));
	    $textures{'-strip'} = $texture;
	}
	    
	$zinc->itemconfigure($strip, -tile => $textures{'-strip'});
    }
    

    #-------------------------------------------------
    # ajout de la zone des boutons (à droite du strip)
    #-------------------------------------------------
    if ($style->{'-buttons'}) {
	my $bstyle = $style->{'-buttons'};

	# le groupe de la zone bouton
	my $btngroup = $zinc->add('group', $g2, -priority => 40);
	$zinc->coords($btngroup, $bstyle->{'-coords'});

	# sa zone de clipping
	my $btnclip = $zinc->add('rectangle', $btngroup,
				 $bstyle->{'-clipcoords'},
				 -filled => 0,
				 -visible => 0,
				 );
	
	# le clipping du groupe bouton
	$zinc->itemconfigure($btngroup, -clip => $btnclip);
	
	# zone bouton
	$zinc->add('rectangle', $btngroup,
		   $bstyle->{'-zone'}->{'-coords'},
		   -filled => 1,
		   -linewidth => $bstyle->{'-zone'}->{'-linewidth'},
		   -fillcolor => $bstyle->{'-zone'}->{'-fillcolor'},
		   -composescale => 0,
		   -tags => ["content".$index],
		   );
	

	my %btns = %{$bstyle->{'-btns'}};
	my ($name, $btnstyle);
	while (($name, $btnstyle) = each(%btns)) {
#	    print "bouton $name $btnstyle\n";

	    my $sgroup = $zinc->add('group', $btngroup,
				    -atomic => 1,
				    -sensitive => 1,
				    -composescale => 0,
				    -tags => [$name.$index, "content".$index],
				    );

	    $zinc->add('rectangle', $sgroup,
		       $btnstyle->{'-coords'},
		       -filled => 1,
		       -visible => 0,
		       -priority => 100,
		       );
	
	    $zinc->add('curve', $sgroup,
		       $btnstyle->{'-arrow'},
		       -closed => 1,
		       -filled => 1,
		       -linewidth => $btnstyle->{'-linewidth'},
		       -linecolor => $btnstyle->{'-linecolor'},
		       -fillcolor => $btnstyle->{'-fillcolor'},
		       -priority => 50,
		       );

	    $zinc->add('text', $sgroup,
		       -position => $btnstyle->{'-label'}->{'-coords'},
		       -text => $btnstyle->{'-label'}->{'-text'},
		       -font => $btnstyle->{'-label'}->{'-font'},
		       -color => $btnstyle->{'-label'}->{'-color'},
		       -anchor => $btnstyle->{'-label'}->{'-anchor'},
		       -priority => 60,
		       );
	}

	# bindings boutons Up et Down du Strip
	$zinc->bind('btnup'.$index, '<1>', \&extendedStrip);
	$zinc->bind('btndn'.$index, '<1>', \&smallStrip);
	
    }

    # construction du contenu du strip
    &buildContent($index, $g2, 100, $style);

    # et de la barre d'extension info (extended format)
    &buildExtent($index, $g2, $style->{'-zinfo'});

}


# Construction des zones internes du Strips
sub buildContent {
    my ($index, $parent, $priority, $style) = @_;
    
    # group content
    my $g3 = $zinc->add('group', $parent, -priority => $priority);

    # zone de clipping
    my $clip = $zinc->add('rectangle', $g3,
			  $style->{'-clipcoords'},
			  -filled => 0,
			  -visible => 0,
			  );
    
    # clipping du groupe content
    $zinc->itemconfigure($g3, -clip => $clip);

    # création d'un group intermédiaire pour bloquer le scaling
    my $g4 = $zinc->add('group', $g3,
			-composescale => 0,
			-tags => ["content".$index],
			);
    
    # création des zones
    my %zones = %{$style->{'-zones'}};
    my ($name, $zonestyle);
    while (($name, $zonestyle) = each(%zones)) {
	# group de zone
	my $gz = $zinc->add('group', $g4);

	if ($zonestyle->{'-atomic'}) {
	    $zinc->itemconfigure($gz, -atomic => 1,
				 -sensitive => $zonestyle->{'-sensitive'},
				 -priority => $zonestyle->{'-priority'},
				 -tags => [$name.$index, $zonestyle->{'-tags'}],
				 );
	}
	
	my $rectzone = $zinc->add('rectangle', $gz,
				  $zonestyle->{'-coords'},
				  -filled => $zonestyle->{'-filled'},
				  -linewidth => $zonestyle->{'-linewidth'},
				  -linecolor => $zonestyle->{'-linecolor'},
				  -fillcolor => $zonestyle->{'-fillcolor'},
				  -relief => $zonestyle->{'-relief'},
				  -priority => 10,
				  -tags => [$name.$index],
				  );

	if ($zonestyle->{'-texture'}) {
	    if (!exists($textures{$name})) {
		my $texture = $zinc->Photo($zonestyle->{'-texture'}, 
                                           -file => Tk->findINC("demos/zinc_data/".$zonestyle->{-texture}));
		$textures{$name} = $texture;
	    }

	    $zinc->itemconfigure($rectzone, -tile => $textures{$name});
	}


	my %fields;
	%fields = %{$zonestyle->{'-fields'}} if (defined $zonestyle->{'-fields'}) ;
	my ($field, $fieldstyle);
	my $fontsty = $stripFontset{'normal'};
	while ( ($field, $fieldstyle) = each(%fields) ) {
	    if ($fieldstyle->{'-type'} and $fieldstyle->{'-type'} eq 'rect') {
		$zinc->add('rectangle', $gz,
			   $fieldstyle->{'-coords'},
			   -filled => $fieldstyle->{'-filled'},
			   -fillcolor => $fieldstyle->{'-fillcolor'},
			   -linewidth => $fieldstyle->{'-linewidth'},
			   -linecolor => $fieldstyle->{'-linecolor'},
			   -priority => 20,
			   );
		} else {
		
		    my $font = $fieldstyle->{'-font'};
#		    print "buildContent field:$field font:$font\n";
		    $zinc->add('text', $gz,
			       -position => $fieldstyle->{'-coords'},
			       -text => $fieldstyle->{'-text'},
			       -font => $fontsty->{$font},
			       -color => $fieldstyle->{'-color'},
			       -anchor => $fieldstyle->{'-anchor'},
			       -priority => 30,
			       -tags => [$font.$index],
			       );
		}
		
	}

    }
}


# Construction de la barre d'extension info du Strip
sub buildExtent {
    my ($index, $parent, $infostyle) = @_;
    
    # group content
    my $extgroup = $zinc->add('group', $parent);
    $zinc->coords($extgroup, $infostyle->{'-coords'});

    $zinc->itemconfigure($extgroup,
			 -atomic => $infostyle->{'-atomic'},
			 -sensitive => $infostyle->{'-sensitive'},
			 -priority => $infostyle->{'-priority'},
			 -visible => 0,
			 -tags => ["zinfo".$index, $infostyle->{'-tags'}],
			 );

    # ombre portée
    $zinc->add('rectangle', $extgroup,
	       $infostyle->{'-shadowcoords'},
	       -filled => 1,
	       -linewidth => 0,
	       -fillcolor => $infostyle->{'-shadowcolor'},
	       -priority => 10,
	       -tags => ["shadow".$index],
	       );
    
    my $rectzone = $zinc->add('rectangle', $extgroup,
  			      $infostyle->{'-rectcoords'},
  			      -filled => 1,
  			      -linewidth => $infostyle->{'-linewidth'},
  			      -linecolor => $infostyle->{'-linecolor'},
  			      -fillcolor => $infostyle->{'-fillcolor'},
  			      -relief => $infostyle->{'-relief'},
  			      -priority => 20,
  			      );

    if ($infostyle->{'-texture'}) {
  	if (!exists($textures{'-zinfo'})) {
  	    my $texture = $zinc->Photo($infostyle->{'-texture'}, 
                                       -file => Tk->findINC("demos/zinc_data/".$infostyle->{-texture}));
  	    $textures{'-zinfo'} = $texture;
  	}
  	$zinc->itemconfigure($rectzone, -tile => $textures{'-zinfo'});
	
    }

    my %fields = %{$infostyle->{'-fields'}};
    my ($field, $fieldstyle);
    my $fontsty = $stripFontset{'normal'};
    while (($field, $fieldstyle) = each(%fields)) {
	if ($fieldstyle->{'-type'} and $fieldstyle->{'-type'} eq 'rect') {
	    $zinc->add('rectangle', $extgroup,
		       $fieldstyle->{'-coords'},
		       -filled => $fieldstyle->{'-filled'},
		       -fillcolor => $fieldstyle->{'-fillcolor'},
		       -linewidth => $fieldstyle->{'-linewidth'},
		       -linecolor => $fieldstyle->{'-linecolor'},
		       -priority => 40,
		       );
	} else {
	    
	    my $font = $fieldstyle->{'-font'};
#	    print "buildContent field:$field font:$font\n";
	    $zinc->add('text', $extgroup,
		       -position => $fieldstyle->{'-coords'},
		       -text => $fieldstyle->{'-text'},
		       -font => $fontsty->{$font},
		       -color => $fieldstyle->{'-color'},
		       -anchor => $fieldstyle->{'-anchor'},
		       -priority => 50,
		       -tags => [$font.$index],
		       );
	}
	
    }
    
}

# initialisation des bindings généraux dy Strip
sub initBindings {
    my ($movetag, $scaletag) = @_;

    $zinc->bind($movetag, '<1>', \&catchStrip);
    $zinc->bind($movetag, '<ButtonRelease>', \&releaseStrip);
    $zinc->bind($movetag, '<B1-Motion>', \&motionStrip);

    $zinc->bind($scaletag, '<Double-Button-1>', \&microStrip);

}
    
# Callback CATCH de début de déplacement du Strip
sub catchStrip {
    my $index = substr(($zinc->itemcget('current', -tags))[0], 5);

    my ($x, $y) = $zinc->coords("base".$index);
    my $ev = $zinc->XEvent;
    ($dx, $dy) = ($x - $ev->x, $y - $ev->y);

    $zinc->itemconfigure("base".$index, -priority => 200);

}

# Callback MOVE de fin de déplacement du Strip
sub motionStrip {
    my $index = substr(($zinc->itemcget('current', -tags))[0], 5);
    my $ev = $zinc->XEvent;
    $zinc->coords("base".$index, [$ev->x + $dx, $ev->y + $dy]);
    
}

# Callback RELEASE de fin de déplacement du Strip
sub releaseStrip {
    my $index = substr(($zinc->itemcget('current', -tags))[0], 5);
    $zinc->itemconfigure("base".$index, -priority => 100);
}

# Zoom Strip : normal format
sub normalStrip {
    my $index = substr(($zinc->itemcget('current', -tags))[0], 5);

    $zinc->itemconfigure("input".$index, -sensitive => 1);

    &displayRecoZone($index, 1);
    &displayExtentZone($index, 0);
    &configButtons($index, \&extendedStrip, \&smallStrip);
    &changeStripFormat($index, 1, 1, 0, 1);
}

# Zoom Strip : small format (lignes 1 et 2)
sub smallStrip {
    my $index = substr(($zinc->itemcget('current', -tags))[0], 5);

    &displayRecoZone($index, 0);
    &configButtons($index, \&normalStrip, 0);
    &changeStripFormat($index, 1, .63, 0, 1);
}

# Zoom Strip : micro format (zone ident)
sub microStrip {
    my $index = substr(($zinc->itemcget('current', -tags))[0], 5);
    
    &configButtons($index, \&normalStrip, 0);
    &changeStripFormat($index, .28, .63, 0, 1);
    
}

# Zoom Strip : extendedFormat
sub extendedStrip {
    my $index = substr(($zinc->itemcget('current', -tags))[0],5);

    $zinc->itemconfigure("input".$index, -sensitive => 0);
    $zinc->itemconfigure("base".$index, -priority => 150);
    &displayRecoZone($index, 0);
    &displayExtentZone($index, 1);
    &configButtons($index, 0, \&normalStrip);
    &changeStripFormat($index, 1.3, 1.3, 1, 1.3);
}


# affiche/masque la zone Reco
sub displayRecoZone {
    my ($index, $state) = @_;
    my $priority = ($state) ? 200 : 0;
    $zinc->itemconfigure("zreco".$index, -priority => $priority);
}


# affiche/masque la zone Extent
sub displayExtentZone {
    my ($index, $state) = @_;

    $zinc->itemconfigure("zinfo".$index,
			 -visible => $state,
			 -sensitive => $state);
}

# Configure affichage et callbacks des boutons du Strip
sub configButtons {
    my ($index, $funcUp, $funcDown) = @_;

    # button Up
    $zinc->itemconfigure("btnup".$index, -visible => $funcUp);
    $zinc->bind('btnup'.$index, '<1>', $funcUp) if $funcUp;

    # button Down
    $zinc->itemconfigure("btndn".$index, -visible => $funcDown);
    $zinc->bind('btndn'.$index, '<1>', $funcDown) if $funcDown;

}

    
# this function has been hacked to provide the user with an animation
# The animation is (too) simple but provide a better feedback than without
sub changeStripFormat {
    my ($index, $xratio, $yratio, $composeflag, $fontratio) = @_;

    # réinitialisation du groupe scaling
    $zinc->treset("scaling".$index);

    # configure le blocage de transformation du format des champs
    $zinc->itemconfigure("content".$index, -composescale => $composeflag);

    # applique le nouveau scaling
    $scales{$index} = [1,1] unless defined $scales{$index};
    my ($oldXratio,$oldYratio) = @{$scales{$index}};
    $scales{$index}=[$xratio, $yratio];
    my $dx = ($xratio - $oldXratio) / $steps;
    my $dy = ($yratio - $oldYratio) / $steps;
    &_resize($index, $delay, $oldXratio+$dx, $oldYratio+$dy, $dx, $dy, $steps);
}

sub _resize {
    my ($index, $delay, $newXratio, $newYratio, $dx, $dy, $steps) = @_;
    $zinc->treset("scaling".$index);
    $zinc->scale("scaling".$index, $newXratio, $newYratio);
    # jeu de fontes
    &setFontes($index, $newYratio);
    $steps--;
    $zinc->after($delay, sub {&_resize ($index, $delay, $newXratio+$dx, $newYratio+$dy, $dx, $dy, $steps)})
	if $steps > 0;
}

sub getFKey {
    my ($ratio) = @_;
    my $newfkey;
   
    foreach my $param (@ratio2fontset) {
	my ($maxratio, $fkey) = @{$param};
	$newfkey = $fkey;
	if ($ratio < $maxratio) {
	    return $newfkey;
	}
    }
	
    return $newfkey;
}


sub setFontes {
    my ($index, $ratio) = @_;
    my $newfkey = &getFKey($ratio);
    
    if (!$oldfkey or $oldfkey ne $newfkey) {
	my $fontsty = $stripFontset{$newfkey};
#	print "setFontes $oldfkey -> $newfkey\n";
	if ($fontsty) {
	    foreach my $type ('callsign', 'type1', 'type2', 'type3') {
		$zinc->itemconfigure($type.$index, -font => $fontsty->{$type});
	    }
	}
	
	$oldfkey = $newfkey;
    }
}

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/groups_priority.pl.











































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/perl -w
# $Id$
# This simple demo has been developped by C. Mertz <mertz@cena.fr>

package groups_priority;  # for avoiding symbol sharing between different demos

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;

use strict;

my $mw = MainWindow->new();

# The explanation displayed when running this demo
my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2,
		     -height => 12);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
'There are two groups (a red one and a green one) each containing
 4 rectangles. Those rectangles display their current priority.
The following operations are possible:
   "Mouse Button 1" for dragging objects.
   "Mouse Button 2" for dragging a colored group.
   "Key +" on a rectangle to raise it inside its group.
   "Key -" on a rectangle to lower it inside its group.
   "Key l" on a rectangle to lower its colored group.
   "Key r" on a rectangle to raise its colored group.
   "Key t" on a rectangle to change its group (but not its color!).
   "Key [0-9] on a rectangle to set the priority to [0-9]
Raising or lowering an item inside a group modify its priority if necessary');

# Creating the zinc widget
my $zinc = $mw->Zinc(-width => 600, -height => 500,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

#########################################################################"
# Creating the redish group
my $group1 = $zinc->add('group', 1, -visible => 1);

my $counter=0;
# Adding 4 rectangles with text to redish group
foreach my $data ( [200,100, 'red'], [210,210,'red1'],
		   [390,110,'red2'], [395,215,'red3'] ) {
    $counter += 2;
    my ($centerx,$centery,$color) = @{$data};
    # this small group is for merging together :
    #   the rectangle and the text showing its name
    my $g = $zinc->add('group', $group1,
		       -visible => 1,
		       -atomic => 1,
		       -sensitive => 1,
		       -priority => $counter,
		       );
    my $rec = $zinc->add('rectangle', $g, [$centerx-100,$centery-60,
					   $centerx+100, $centery+60],
			  -fillcolor => $color, -filled => 1,
			  );
    my $txt = $zinc->add('text', $g,
			 -position => [$centerx,$centery],
			 -text => "pri=$counter",
			 -anchor => 'center',
			 );
    # Some bindings for dragging the rectangle or the full group
    $zinc->bind($g, '<ButtonPress-1>' => [\&press, $g, \&motion]);
    $zinc->bind($g, '<ButtonRelease-1>' => \&release);
    $zinc->bind($g, '<ButtonPress-2>' => [\&press, $g, \&groupMotion]);
    $zinc->bind($g, '<ButtonRelease-2>' => \&release);
}

#########################################################################"
# Creating the greenish group
my $group2 = $zinc->add('group', 1, -visible => 1);
$counter=0;

# Adding 4 rectangles with text to greenish group
foreach my $data ( [200,300,'green1'], [210,410,'green2'],
		   [390,310,'green3'], [395,415,'green4'] ) {
    $counter++;
    my ($centerx,$centery,$color) = @{$data};
    # this small group is for merging together a rectangle
    # and the text showing its priority
    my $g = $zinc->add('group', $group2,
		       -atomic => 1,
		       -sensitive => 1,
		       -priority => $counter,
		       );
    my $rec = $zinc->add('rectangle', $g, [$centerx-100,$centery-60,
					   $centerx+100, $centery+60],
			  -fillcolor => $color, -filled => 1,
			  );
    my $txt = $zinc->add('text', $g,
			 -position => [$centerx,$centery],
			 -text => "pri=$counter",
			 -anchor => 'center',
			 );
    # Some bindings for dragging the rectangle or the full group
    $zinc->bind($g, '<ButtonPress-1>' => [\&press, $g, \&motion]);
    $zinc->bind($g, '<ButtonRelease-1>' => \&release);
    $zinc->bind($g, '<ButtonPress-2>' => [\&press, $g, \&groupMotion]);
    $zinc->bind($g, '<ButtonRelease-2>' => \&release);
}


#########################################################################"
# adding the key bindings

# the focus on the widget is ABSOLUTELY necessary for key bindings!
$zinc->Tk::focus(); 

$zinc->Tk::bind('<KeyPress-r>' => \&raiseGroup);
$zinc->Tk::bind('<KeyPress-l>' => \&lowerGroup);
$zinc->Tk::bind('<KeyPress-plus>' => \&raise);
$zinc->Tk::bind('<KeyPress-KP_Add>' => \&raise);
$zinc->Tk::bind('<KeyPress-minus>' => \&lower);
$zinc->Tk::bind('<KeyPress-KP_Subtract>' => \&lower);
$zinc->Tk::bind('<KeyPress-t>' => \&toggleItemGroup);

my @KP_MAPPINGS = qw (Insert End Down Next Left Begin Right Home Up Prior);

for my $i (0..9) {
    $zinc->Tk::bind("<KeyPress-$i>" => [\&setPriorrity, $i]);
    my $code = $KP_MAPPINGS[$i];
    $zinc->Tk::bind("<KeyPress-KP_$code>" => [\&setPriorrity, $i]);
}

# The following binding is currently not possible; only text items
# with focus can get a KeyPress or KeyRelease event
#    $zinc->bind($g, '<KeyPress>' => [\&raise, $g]);

#########################################################################"
# Definition of all callbacks

sub updateLabel {
    my ($group) = @_;
    my $priority = $zinc->itemcget($group, -priority);
    # we get the text item from this group:
    my $textitem = $zinc->find('withtype', 'text', ".$group.");
    $zinc->itemconfigure($textitem, -text => "pri=$priority");
}

sub setPriorrity {
    my ($zinc, $priority) = @_;
    my $item = $zinc->find('withtag', 'current');
    return unless $item;
    $zinc->itemconfigure ($item, -priority => $priority);
    &updateLabel($item);
}
    

# Callback to lower a small group of a rectangle and a text
sub lower {
    my ($zinc) = @_;
    # to get the item under the cursor!
    my $item = $zinc->find('withtag', 'current');
    return unless $item;
    $zinc->lower($item);
    &updateLabel($item);
}

# Callback to raise a small group of a rectangle and a text
sub raise {
    my ($zinc) = @_;
    # to get the item under the cursor!
    my $item = $zinc->find('withtag', 'current');
    return unless $item;
    $zinc->raise($item);
    &updateLabel($item);
}

# Callback to raise the group of groups of a rectangle and a text
sub lowerGroup {
    my ($zinc) = @_;
    # to get the item under the cursor!
    my $item = $zinc->find('withtag', 'current');
    return unless $item;
    my $coloredGroup = $zinc->group($item);
    $zinc->lower($coloredGroup);
}

# Callback to raise the group of groups of a rectangle and a text
sub raiseGroup {
    my ($zinc) = @_;
    # to get the item under the cursor!
    my $item = $zinc->find('withtag', 'current');
    return unless $item;
    my $coloredGroup = $zinc->group($item);
    $zinc->raise($coloredGroup);
    &updateLabel($item);
}

# Callback to change the group of groups of a rectangle and a text
sub toggleItemGroup {
    my ($zinc) = @_;
    # to get the item under the cursor!
    my $item = $zinc->find('withtag', 'current');
    return unless $item;
    my $newgroup;
    if ($group1 == $zinc->group($item)) {
	$newgroup = $group2;
    }
    else {
	$newgroup = $group1;
    }
    
    $zinc->chggroup($item,$newgroup,1); ## the lats argument is true for mainting $item' position
    &updateLabel($item);
}

# callback for starting a drag
my ($x_orig, $y_orig);
sub press {
    my ($zinc, $group, $action) = @_;
    my $ev = $zinc->XEvent();
    $x_orig = $ev->x;
    $y_orig = $ev->y;
    $zinc->Tk::bind('<Motion>', [$action, $group]);
}

# Callback for moving a small group of a rectangle and a text
sub motion {
    my ($zinc, $group) = @_;
    my $ev = $zinc->XEvent();
    my $x = $ev->x;
    my $y = $ev->y;

    $zinc->translate($group, $x-$x_orig, $y-$y_orig);
    $x_orig = $x;
    $y_orig = $y;
}

# Callback for moving a group of groups of a rectangle and a text
sub groupMotion {
    my ($zinc, $group) = @_;
    my $ev = $zinc->XEvent();
    my $x = $ev->x;
    my $y = $ev->y;

    my $coloredGroup = $zinc->group($group);
    $zinc->translate($coloredGroup, $x-$x_orig, $y-$y_orig);
    $x_orig = $x;
    $y_orig = $y;
}

# Callback when releasing the mouse button. It removes any motion callback
sub release {
    my ($zinc) = @_;
    $zinc->Tk::bind('<Motion>', '');
}


Tk::MainLoop();


1;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/icon_zoom_resize.pl.



























































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/perl
# $Id$
# this simple demo has been developped by C. Mertz <mertz@cena.fr>

package icon_zoom__resize; # for avoiding symbol re-use between different demos

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;


my $defaultfont = '-adobe-helvetica-bold-r-normal--*-140-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $text = $mw->Scrolled(qw/Text -relief sunken -borderwidth 2 -setgrid true
	      -height 7 -scrollbars ''/);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
	      'This demo needs openGL for rescaling/rotating the icon
   You can transform this earth gif image with your mouse:
     Drag-Button 1 for zooming the earth,
     Drag-Button 2 for rotating the earth,
     Drag-Button 3 for moving the earth,
     Shift-Drag-Button 1 for modifying the earth transparency'
	      );

my $zinc = $mw->Zinc(-width => 350, -height => 250,
		     -render => 1,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

my $earth_group = $zinc->add('group', 1, );

# the following image is included in Perl/Tk distrib
my $image = $zinc->Photo('earth.gif', -file => Tk->findINC('demos/images/earth.gif'));

my $earth = $zinc->add('icon', $earth_group,
		      -image => $image,
		      -composescale => 1,
		      -composerotation => 1,
		      );
$zinc->add('text', $earth_group,
           -position => [30,30],
#	   -connecteditem => $earth,
	   -text => "try to zoom/resize the earth!\nWorks even without openGL!!",
	   -color => "white",
	   -composescale => 1,
	   -composerotation => 1,
	   );

$zinc->Tk::bind('<ButtonPress-1>', [\&press, \&zoom]);
$zinc->Tk::bind('<ButtonRelease-1>', [\&release]);

$zinc->Tk::bind('<ButtonPress-2>', [\&press, \&rotate]);
$zinc->Tk::bind('<ButtonRelease-2>', [\&release]);

$zinc->Tk::bind('<ButtonPress-3>', [\&press, \&motion]);
$zinc->Tk::bind('<ButtonRelease-3>', [\&release]);
    

$zinc->Tk::bind('<Shift-ButtonPress-1>', [\&press, \&modifyAlpha]);
$zinc->Tk::bind('<Shift-ButtonRelease-1>', [\&release]);



#
# Controls for the window transform.
#
my ($cur_x, $cur_y, $cur_angle);
sub press {
    my ($zinc, $action) = @_;
    my $ev = $zinc->XEvent();
    $cur_x = $ev->x;
    $cur_y = $ev->y;
    $cur_angle = atan2($cur_y, $cur_x);
    $zinc->Tk::bind('<Motion>', [$action]);
}

sub modifyAlpha {
    my ($zinc) = @_;
    my $ev = $zinc->XEvent();
    my $lx = $ev->x;
    my $xrate = $lx /  $zinc->cget(-width);

    $xrate = 0 if $xrate < 0;
    $xrate = 1 if $xrate > 1;

    my $alpha = $xrate * 100;
    
    $zinc->itemconfigure($earth_group, -alpha => $alpha);
}


sub motion {
    my ($zinc) = @_;
    my $ev = $zinc->XEvent();
    my $lx = $ev->x;
    my $ly = $ev->y;
    my @res;
    
    @res = $zinc->transform($earth_group, [$lx, $ly, $cur_x, $cur_y]);
    $zinc->translate($earth_group, $res[0] - $res[2], $res[1] - $res[3]);
    $cur_x = $lx;
    $cur_y = $ly;
}

sub zoom {
    my ($zinc, $self) = @_;
    my $ev = $zinc->XEvent();
    my $lx = $ev->x;
    my $ly = $ev->y;
    my $maxx;
    my $maxy;
    my $sx;
    my $sy;
    
    if ($lx > $cur_x) {
	$maxx = $lx;
    } else {
	$maxx = $cur_x;
    }
    if ($ly > $cur_y) {
	$maxy = $ly
    } else {
	$maxy = $cur_y;
    }
    return if ($maxx == 0 || $maxy == 0);
    $sx = 1.0 + ($lx - $cur_x)/$maxx;
    $sy = 1.0 + ($ly - $cur_y)/$maxy;
    $cur_x = $lx;
    $cur_y = $ly;
    $zinc->scale($earth_group, $sx, $sy);
}

sub rotate {
    my ($zinc) = @_;
    my $ev = $zinc->XEvent();
    my $lx = $ev->x;
    my $ly = $ev->y;
    my $langle;
    
    $langle = atan2($ly, $lx);
    $zinc->rotate($earth_group, -($langle - $cur_angle));
    $cur_angle = $langle;
}

sub release {
    my ($zinc) = @_;
    $zinc->Tk::bind('<Motion>', '');
}

Tk::MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/items.pl.























































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/perl -w
# $Id$
# these simple samples have been developped by C. Mertz mertz@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Scrolled('Zinc', -width => 700, -height => 600,
			 -font => '10x20', -borderwidth => 3,
			 -relief => 'sunken', -scrollbars => 'se',
			 -scrollregion => [-100, 0, 1000, 1000]);
$zinc->pack(-expand => 'yes', -fill => 'both');

$zinc->add('rectangle', 1, [10,10, 100, 50], -fillcolor => "green", -filled => 1,
	    -linewidth => 10, -relief => "roundridge", -linecolor => "darkgreen");


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A filled rectangle with a \"roundridge\" relief border of 10 pixels.",
	   -anchor => 'nw',
	   -position => [120, 20]);


my $labelformat = "x82x60+0+0 x60a0^0^0 x32a0^0>1 a0a0>2>1 x32a0>3>1 a0a0^0>2";

my $x=20;
my $y=120;
my $track=$zinc->add('track', 1, 6, # 6 is the number of fields in the flightlabel
		     -labelformat => $labelformat,
		     -position => [$x, $y],
		     -speedvector => [40, -10],
		     -speedvectormark =>  1, # currently works only with openGL
		     -speedvectorticks => 1, # currently works only with openGL
		     );
# moving the track, to display past positions
foreach my $i (0..5) {  $zinc->coords("$track",[$x+$i*10,$y-$i*2]); }

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A flight track for a radar display. (A waypoint looks similar,\n".
	   "but has no speedvector neither past positions)",
	   -anchor => 'nw',
	   -position => [200, 80],
	   );

$zinc->itemconfigure($track, 0,
		     -filled => 0,
		     -bordercolor => 'DarkGreen',
		     -border => "contour",
		     );
$zinc->itemconfigure($track, 1,
		     -filled => 1,
		     -backcolor => 'gray60',
		     -text => "AFR001");
$zinc->itemconfigure($track, 2,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "360");
$zinc->itemconfigure($track, 3,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "/");
$zinc->itemconfigure($track, 4,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "410");
$zinc->itemconfigure($track, 5,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "Beacon");





$zinc->add('arc', 1, [150, 140, 450, 240], -fillcolor => "gray20",
	   -filled => 0,  -linewidth => 1,
	   -startangle => 45, -extent => 270);
$zinc->add('arc', 1, [260, 150, 340, 230], -fillcolor => "gray20",
	   -filled => 0,  -linewidth => 1,
	   -startangle => 45, -extent => 270,
	   -pieslice => 1, -closed => 1,
	   -linestyle => 'mixed', -linewidth => 3,
	   );

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "Two arcs, starting at 45° with an extent of 270°.",
	   -anchor => 'nw',
	   -position => [320, 180]);


$zinc->add('curve', 1, [10, 324, 24, 300, 45, 432, 247, 356, 128, 401],
	   -filled => 0, -relief => 'roundgroove',
           # -linewidth => 10, ## BUG with zinc 3.2.3g 
	   );
$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "An open curve.",
	   -anchor => 'nw',
	   -position => [50, 350]);


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A waypoint",
	   -anchor => 'nw',
	   -position => [10, 480],
	   );
my $waypoint = $zinc->add('waypoint', 1, 6, -position => [100,520],
			  -labelformat => $labelformat,
			  -symbol => "AtcSymbol2",
			  -labeldistance => 30);  

foreach my $fieldId (1..5) {
    $zinc->itemconfigure($waypoint, $fieldId,
			 -filled => 0,
			 -bordercolor => 'DarkGreen',
			 -border => "contour",  # does not work with openGL (zinc-perl v3.2.3e)
			 -text => "field$fieldId",
			 );
}


$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "3 tabulars of 2 fields,\nattached together.",
	   -anchor => 'nw',
	   -position => [510, 380],
	   );

my $labelformat2 = "x72x40 x72a0^0^0 x34a0^0>1";

my $tabular1 = $zinc->add('tabular', 1, 6, -position => [570,250],
			  -labelformat => $labelformat2,
			  );
my $tabular2 = $zinc->add('tabular', 1, 6, -connecteditem => $tabular1,
			  -labelformat => $labelformat2,
			  );
my $tabular3 = $zinc->add('tabular', 1, 6, -connecteditem => $tabular2,
			  -labelformat => $labelformat2,
			  );
my $count=1;
foreach my $tab ($tabular1, $tabular2, $tabular3) {
    $zinc->itemconfigure($tab, 1, -filled => 0,
			 -bordercolor => 'DarkGreen',
			 -border => "contour", -text => "tabular",
			 );
    $zinc->itemconfigure($tab, 2, -filled => 0,
			 -bordercolor => 'DarkGreen',
			 -border => "contour", -text => "n°$count",
			 );
    $count++;
}


$zinc->add('reticle', 1, -position => [530,550],
	   -firstradius => 20, -numcircles => 6,
	   -period => 2, -stepsize => 20,
	   -brightlinestyle => 'dashed', -brightlinecolor => 'darkred', 
	   );

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "a reticle of 6 circles.",
	   -anchor => 'nw',
	   -position => [530, 540]);



$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "maps, triangles and groups items\nare not demonstrated here.",
	   -anchor => 'nw',
	   -position => [10, 550]);



MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/labelformat.pl.































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/perl -w
# $Id$
# This simple demo has been developped by C. Mertz <mertz@cena.fr>

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

my $mw = MainWindow->new();


###########################################
# Text zone
###########################################

my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2,
		     -height => 4);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
'This toy-appli demonstrates the use of labelformat for tabular items.
The fieldPos (please, refer to the "labelformat type" description 
in the "Zinc reference manual") of each field as described in
the labelformat is displayed inside the field.');


###########################################
# Zinc
##########################################
my $zinc = $mw->Zinc(-width => 600, -height => 500,
		     -font => "10x20",
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

###########################################
# Tabulars
###########################################

### first labelformat and tabular
my $labelformat1 = "300x300 x100x20+0+0 x100x20+100+0 x100x20+0+20 x100x20+100+20 x100x20+50+55";

my $tabular1 = $zinc->add('tabular',1, 5,
		    -position => [10,10],
		    -labelformat => $labelformat1,
		   );

&setLabelContent ($tabular1,$labelformat1);

$zinc->add('text', 1, -position => [10,100], -text =>
	   "All fields positions
are given in pixels");


### second labelformat and tabular
my $labelformat2 = "300x300 x110x20+100+30 x80x20<0<0 x80x20<0>0 x80x20>0>0 x80x20>0<0";

my $tabular2 = $zinc->add('tabular',1, 5,
                    -position => [270,10],
		    -labelformat => $labelformat2,
		    );
&setLabelContent ($tabular2,$labelformat2);

$zinc->add('text', 1, -position => [260,100], -text =>
	   "All fields positions are given
relatively to field 0.
They are either on the left/right
and up/down the field 0.");


### third labelformat and tabular
my $labelformat3 = "400x300 x200x70+100+70 x80x26^0<0 x80x26^0>0 x80x29\$0\$0 x80x32\$0^0 x90x20\<1^1 x90x20<2\$2 x90x20^4<4 x90x20^3>3";

my $tabular3 = $zinc->add('tabular',1, 9,
                    -position => [150,180],
                    -labelformat => $labelformat3,
                    );
&setLabelContent ($tabular3,$labelformat3);

$zinc->add('text', 1, -position => [40,360], -text =>
	   "Fields 1-4 are positionned relatively to field 0.
Field 5 is positionned relatively to field 1,
Field 6 is positionned relatively to field 2..."
);


### this function displays in each field, the corresponding <fieldPos>
### part of the labelformat
sub setLabelContent {
  my ($item,$labelformat) = @_;

  my @fieldsSpec = split (/ / , $labelformat);
  shift @fieldsSpec;

  my $i=0;
  foreach my $fieldSpec (@fieldsSpec) {
    my ($posSpec) = $fieldSpec =~ /^.\d+.\d+(.*)/ ;
#    print "$fieldSpec\t$i\t$posSpec\n";
    $zinc->itemconfigure ($item,$i,
                          -text => "$i: $posSpec",
  			  -border => "contour",
			  );
    $i++;
  }
}



MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/lines.pl.

































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl
# $Id$
# these simple samples have been developped by C. Mertz mertz@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 700, -height => 600,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

$zinc->add('text', 1,
	   -font => $defaultfont,
	   -text => "A set of lines with different styles of lines and termination\n".
	   "NB: some attributes such as line styles are not necessarily\n".
	   "  available with an openGL rendering system" ,
	   -anchor => 'nw',
	   -position => [20, 20]);

$zinc-> add('curve', 1, [20, 100, 320, 100]); # default options
$zinc-> add('curve', 1, [20, 120, 320, 120],
	    -linewidth => 20,
	    );
$zinc-> add('curve', 1, [20, 160, 320, 160],
	    -linewidth => 20,
	    -capstyle => "butt",
	    );
$zinc-> add('curve', 1, [20, 200, 320, 200],
	    -linewidth => 20,
	    -capstyle => "projecting",
	    );
$zinc-> add('curve', 1, [20, 240, 320, 240],
	    -linewidth => 20,
	    -linepattern => "AlphaStipple7",
	    -linecolor => "red",
	    );

# right column
$zinc-> add('curve', 1, [340, 100, 680, 100],
	    -firstend => [10, 10, 10],
	    -lastend => [10, 25, 45],
	    );
$zinc-> add('curve', 1, [340, 140, 680, 140],
	    -linewidth => 2,
	    -linestyle => 'dashed',
	    );
$zinc-> add('curve', 1, [340, 180, 680, 180],
	    -linewidth => 4,
	    -linestyle => 'mixed',
	    );
$zinc-> add('curve', 1, [340, 220, 680, 220],
	    -linewidth => 2,
	    -linestyle => 'dotted',
	    );

$zinc->add('curve', 1, [20, 300, 140, 360, 320, 300, 180, 260],
	   -closed => 1,
	   -filled => 1,
	   -fillpattern => "Tk",
	   -fillcolor => "grey60",
	   -linecolor => "red",
	   -marker => "AtcSymbol7",
	   -markercolor => "blue",

	   );


$zinc->add('curve', 1, [340, 300, 440, 360, 620, 300, 480, 260],
	   -closed => 1,
	   -linewidth => 10,
	   -joinstyle => "miter", #"round", # "bevel" | "miter"
	   -linecolor => "red",
	   );
$zinc->add('curve', 1, [400, 300, 440, 330, 560, 300, 480, 280],
	   -closed => 1,
	   -linewidth => 10,
	   -joinstyle => "round", # "bevel" | "miter"
	   -tile => Tk::findINC("Xcamel.gif"),
	   -fillcolor => "grey60",
	   -filled => 1,
	   -linecolor => "red",
	   );

#	   -tile => Tk::findINC("Xcamel.gif"),

MainLoop;


Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/mapinfo.pl.





































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl
# $Id$
# This simple demo has been developped by C. Schlienger <celine@intuilab.com>

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;


my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();

###########################################
# Text zone
###########################################

my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2,
		     -height => 4);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
	      'This toy-appli shows zoom actions on map item.
The following operations are possible:
   Click "-" to zoom out
   Click "+" to zoom in ' );

###########################################
# Zinc
###########################################
my $zinc_width=600;
my $zinc_height=500;
my $zinc = $mw->Zinc(-width => $zinc_width, -height => $zinc_height,
		     -font => "10x20",
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

###########################################
# Waypoints and sector
###########################################

my $mapinfo=$mw->mapinfo("mapinfo","create"); #creation of mapinfo

#--------------------------------
# Waypoints
#--------------------------------
$mw->mapinfo("mapinfo","add","symbol",200,100,0);
$mw->mapinfo("mapinfo","add","symbol",300,150,0);
$mw->mapinfo("mapinfo","add","symbol",400,50,0);
$mw->mapinfo("mapinfo","add","symbol",350,450,0);
$mw->mapinfo("mapinfo","add","symbol",300,250,0);
$mw->mapinfo("mapinfo","add","symbol",170,240,0);
$mw->mapinfo("mapinfo","add","symbol",550,200,0);

#--------------------------------
# Waypoints names
#--------------------------------
$mw->mapinfo("mapinfo","add","text","normal","simple",170,100,"DO");
$mw->mapinfo("mapinfo","add","text","normal","simple",270,160,"RE");
$mw->mapinfo("mapinfo","add","text","normal","simple",410,50,"MI");
$mw->mapinfo("mapinfo","add","text","normal","simple",345,470,"FA");
$mw->mapinfo("mapinfo","add","text","normal","simple",280,265,"SOL");
$mw->mapinfo("mapinfo","add","text","normal","simple",150,240,"LA");
$mw->mapinfo("mapinfo","add","text","normal","simple",555,200,"SI");

#--------------------------------
# Routes
#--------------------------------

$mw->mapinfo("mapinfo","add","line","simple",1,200,100,300,150);
$mw->mapinfo("mapinfo","add","line","simple",1,300,150,400,50);
$mw->mapinfo("mapinfo","add","line","simple",1,300,150,350,450);
$mw->mapinfo("mapinfo","add","line","simple",1,300,250,170,240);
$mw->mapinfo("mapinfo","add","line","simple",1,300,250,550,200);

#--------------------------------
# Sectors
#---------------------------------
$mw->mapinfo("mapinfo","add","line","simple",1,300,0,400,50);
$mw->mapinfo("mapinfo","add","line","simple",1,400,50,500,100);
$mw->mapinfo("mapinfo","add","line","simple",1,500,100,550,200);
$mw->mapinfo("mapinfo","add","line","simple",1,550,200,550,400);
$mw->mapinfo("mapinfo","add","line","simple",1,550,400,350,450);
$mw->mapinfo("mapinfo","add","line","simple",1,350,450,170,240);
$mw->mapinfo("mapinfo","add","line","simple",1,170,240,200,100);
$mw->mapinfo("mapinfo","add","line","simple",1,200,100,300,0);

#--------------------------------
# Sectors
#---------------------------------
my $gpe = $zinc ->add('group',1);
my $map = $zinc ->add('map',$gpe,#creation of the map object which has 'mapinfo' information
		      -mapinfo=>"mapinfo",
		      -symbols=>['AtcSymbol15']);


###################################################
# control panel
###################################################
my $rc = $mw->Frame()->pack();

#the reference of the scale function is top-left corner of the zinc object
#so we first translate the group to zoom in order to put its center on top-left corner
#change the scale of the group
#translate the group to put it back at the center of the zinc object 

my $minus=$rc->Button(-width => 2, 
		      -height => 2,
		      -text => '-',
		      -command=>sub{
			$zinc->translate($gpe,-$zinc_width/2,-$zinc_height/2);
			$zinc->scale($gpe,0.8,0.8);
			$zinc->translate($gpe, $zinc_width/2,$zinc_height/2);
		      })->pack(-side=>'left');


my $plus=$rc->Button(-width => 2, 
		     -height => 2,
		     -text => '+',
		     -command=>sub{
		       $zinc->translate($gpe, -$zinc_width/2,-$zinc_height/2);
		       $zinc->scale($gpe,1.2,1.2);
		       $zinc->translate($gpe,$zinc_width/2,$zinc_height/2);
		     })->pack(-side => 'right');



MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/path_tags.pl.











































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/perl -w
# $Id$
# this pathtatg demo have been developped by C. Mertz mertz@cena.fr
# with the help of Daniel Etienne etienne@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;

#This demo only works with Tk::Zinc > "3.2.5b";

## this demo demonstrates the use of path tags to address one or more items
## belonging to a hierarchy of groups.
## This hierarchy is described just below, gr_xxx designates a group
## (with a tag xxx) and i_yyy designates an non-group item (with a tag yyy).

#  gr_top --- gr_a --- gr_aa --- gr_aaa --- gr_aaaa --- i_aaaaa
#          |       |         |          |-- i_aaab  |-- i_aaaab
#          |       |         -- i_aab
#          |       |-- i_ab
#          |       |
#          |       ---gr_ac --- i_aca
#          |                |
#          |-- i_b          --- i_acb
#          |
#          --- gr_c --- gr_ca --- i_caa
#                   |         |
#                   |         --- i_cab
#                   |-- i_cb
#                   |
#                   ---gr_cc --- i_cca
#                            |
#                            --- i_ccb
#the same objects are cloned and put in an other hierarchy where
#gr_top is replaced by gr_other_top

my $defaultForecolor = "grey80";
my $selectedColor = "yellow";
my $mw = MainWindow->new();

###########################################
# Text zone
###########################################

my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2,
		     -height => 5, -font => "10x20");
$text->pack(-expand => 'yes', -fill => 'both');

$text->insert('0.0',
'This represents a group hierarchy:
  - groups are represented by a rectangle and an underlined title.
  - non-group items are represented by a text.
Select a pathTag or a tag with one of the radio-button
or experiment your own tags in the input field');

###########################################
# Zinc creation
###########################################

my $zinc = $mw->Zinc(-width => 850, -height => 360, -font => "10x20",
		     -borderwidth => 0, -backcolor => "black",
		     -forecolor => $defaultForecolor,
		     )->pack;

###########################################
# Creation of a bunch of radiobutton and a text input
###########################################

my $tagsfm = $mw->Frame()->pack();
my $pathtag;

my @pl = qw/-side left -expand 1 -padx .5c -pady .2c/;
my $left = $tagsfm->Frame->pack(@pl);
my $middle = $tagsfm->Frame->pack(@pl);
my $right = $tagsfm->Frame->pack(@pl);
my $rtop = $right->Frame->pack(-side => 'top');
my $rbottom = $right->Frame->pack(-side => 'top');
my $rbot_left = $rbottom->Frame->pack(-side => 'left');
my $rbot_right = $rbottom->Frame->pack(-side => 'left');

my $resultfm = $mw->Frame()->pack();
$resultfm->Label(-font => "10x20",
	     -relief => 'flat',
	     -text => 'explanation:',
	     )->pack(-side => 'left');
my $explan_txt = $resultfm->Label(-font => "10x20",
				  -relief => 'flat',
				  -width => 70,
				  -height => 3.5,
				  -text => '...',
				  -justify => 'left',
				  -wraplength => '16c',
				  )->pack(-side => 'left');


@pl = qw/-side top -pady 2 -anchor w/;
my @tags_explan;
@tags_explan = ("top" => "a simple tag for the top group",
		".top" => "all items in the root group with the tag 'top'",
		".top." => "direct children of a group in the root group with the tag 'top'",
		".top*" => "descendance of ONE group in the root group with the tag 'top'",
		".top*cca" => "items with a tag 'cca' in ONE direct group of root group with tag 'top'",
		".5." => "direct content of THE group with id 5");
while (@tags_explan) {
    my $tag = shift @tags_explan;
    my $explan = shift @tags_explan;
    $left->Radiobutton(-text     => $tag,
		       -font => "10x20",
		       -command => sub { &displayPathtag ($explan)},
		       -variable => \$pathtag,
		       -relief   => 'flat',
		       -value    => $tag,
		       )->pack(@pl);
}
@tags_explan = (".top*aa" => "items with a tag 'aa' in a direct group of root group with tag 'top'",
		".top*aa." => "direct children of ONE group with a tag 'aa', descending from a direct group of root group with tag 'top'",
		".top*aa*" => "descendance of ONE group with a tag 'aa', descending from a direct group of root group with tag 'top'",
		".top.a" => "items with a tag 'a' in a direct group of root group with tag 'top'",
		".top.a." => "direct children of ONE group with a tag 'a' in a direct group of root group with tag 'top'",
		".5*" => "descendance of THE group with id 5",
		);
while (@tags_explan) {
    my $tag = shift @tags_explan;
    my $explan = shift @tags_explan;
    $middle->Radiobutton(-text     => $tag,
			 -font => "10x20",
			 -command => sub { &displayPathtag ($explan)},
			 -variable => \$pathtag,
			 -relief   => 'flat',
			 -value    => $tag,
			 )->pack(@pl);
}


$rtop->Label(-font => "10x20",
	     -relief => 'flat',
	     -text => 'your own tag :',
	     )->pack(-side => 'left');
$rtop->Entry(-font => "10x20", -width => 15)
    ->pack(-side => 'left')->bind('<Key-Return>', sub {$pathtag = $_[0]->get();
						       &displayPathtag("sorry, I am not smart enough to explain your pathTag ;-)")});


@tags_explan =  (".top*aa*aaa" => "all items with a tag 'aaa' descending from ONE group with a tag 'aa' descending from ONE group with a tag 'top' child of the root group",
		 ".top*aa*aaa." => "children of ONE group with a tag 'aaa' descending from ONE group with a tag 'aa' descending from ONE group with a tag 'top' child of the root group",
		 ".top*aa*aaa*" => "descendance of ONE group with a tag 'aaa' descending from ONE group with a tag 'aa' descending from ONE group with a tag 'top' child of the root group",
		 ".other_top*aa*" => "descendance of ONE group with a tag 'aa' descending from ONE group with a tag 'other_top' child of the root group",
		 ".5*ca*" => "descendance of ONE group with a tag 'ca' descending from THE group with id 5",
		 );
while (@tags_explan) {
    my $tag = shift @tags_explan;
    my $explan = shift @tags_explan;
    $rbot_left->Radiobutton(-text     => $tag,
			    -font => "10x20",
			    -command => sub { &displayPathtag ($explan)},
			    -variable => \$pathtag,
			    -relief   => 'flat',
			    -value    => $tag,
			    )->pack(@pl);
}

@tags_explan = ("*aa*aaaa" => "all items with a tag 'aaaa' descending from a group with a tag 'aa'",
		"*aaa" => "all items with a tag 'aaa'",
		"aa || ca" => "items with tag 'aa' or tag 'ca'",
		"none" => "no items, as none has the tag 'none'",
		"all" => "all items",
		);
while (@tags_explan) {
    my $tag = shift @tags_explan;
    my $explan = shift @tags_explan;
    $rbot_right->Radiobutton(-text     => $tag,
			     -font => "10x20",
			     -command => sub { &displayPathtag ($explan)},
			     -command => \&displayPathtag,
			     -variable => \$pathtag,
			     -relief   => 'flat',
			     -value    => $tag,
			     )->pack(@pl);
}

# creating the item hierarchy
$zinc ->add('group', 1, -tags => ['top']);
&createSubHierarchy ('top');

# creating a parallel hierarchy
$zinc ->add('group', 1, -tags => ['other_top']);
&createSubHierarchy ('other_top');

### Here we create the genuine hierarchy of groups and items
### Later we will create graphical objects to display groups
sub createSubHierarchy {
    my ($gr) = @_;
    $zinc->add('group', $gr, -tags => ['a']);
    $zinc->add('text',  $gr, -tags => ['b', 'text'], -text => 'b',
	       -position => [270,150]);
    $zinc->add('group', $gr, -tags => ['c']);
    
    $zinc->add('group', 'a', -tags => ['aa']);
    $zinc->add('text',  'a', -tags => ['ab', 'text'], -text => 'ab'
	       , -position => [60,220]);
    $zinc->add('group', 'a', -tags => ['ac']);
    
    $zinc->add('group', 'aa', -tags => ['aaa']);
    $zinc->add('text',  'aa', -tags => ['aab', 'text'], -text => 'aab', 
	       -position => [90,190]);
    $zinc->add('group', 'aaa', -tags => ['aaaa']);
    $zinc->add('text',  'aaaa', -tags => ['aaaaa', 'text'], -text => 'aaaaa', 
	       -position => [150,110]);
    $zinc->add('text',  'aaaa', -tags => ['aaaab', 'text'], -text => 'aaaab',
	       -position => [150,130]);
    $zinc->add('text',  'aaa', -tags => ['aaab', 'text'], -text => 'aaab',
	       -position => [120,160]);
    
    $zinc->add('text', 'ac', -tags => ['aca'], -text => 'aca',
	       -position => [90,260]);
    $zinc->add('text',  'ac', -tags => ['acb', 'text'], -text => 'acb',
	       -position => [90,290]);
    
    $zinc->add('group', 'c', -tags => ['ca']);
    $zinc->add('text',  'c', -tags => ['cb', 'text'], -text => 'cb',
	       -position => [330,160]);
    $zinc->add('group', 'c', -tags => ['cc']);
    
    $zinc->add('text',  'ca', -tags => ['caa', 'text'], -text => 'caa',
	       -position => [360,110]);
    $zinc->add('text',  'ca', -tags => ['cab', 'text'], -text => 'cab',
	       -position => [360,130]);

    $zinc->add('text',  'cc', -tags => ['cca', 'text'], -text => 'cca',
	       -position => [360,200]);
    $zinc->add('text',  'cc', -tags => ['ccb', 'text'], -text => 'ccb',
	       -position => [360,220]);
}

## modifying the priority so that all rectangles and text will be visible
map { $_, $zinc->itemconfigure($_,-priority => 20)} ($zinc->find('withtype', 'text', ".top*"));
map { $_, $zinc->itemconfigure($_,-priority => 20)} ($zinc->find('withtype', 'text', ".other_top*"));
map { $_, $zinc->itemconfigure($_,-priority => 20)} ($zinc->find('withtype', 'group', ".top*"));
map { $_, $zinc->itemconfigure($_,-priority => 20)} ($zinc->find('withtype', 'group', ".other_top*"));

# converts a list of items ids in a list of sorted tags (the first tag of each item)
sub items2tags {
    my @items = @_;
    my @selected_tags;
    foreach my $item (@items) {
	my @tags = $zinc->itemcget ($item, -tags);
	next if $tags[0] =~ /frame|title/  ;    # to remove group titles frame
	push @selected_tags, $tags[0];
    }
    return sort @selected_tags;
}

### drawing :
####   a rectangle item for showing the bounding box of each group, 
###    a text item for the group name (i.e. its first tag)

## backgrounds used to fill rectangles representing groups
my @backgrounds = qw(grey25 grey35 grey43 grey50 grey55);

sub drawHierarchy {
    my ($group,$level) = @_;
    my @tags = $zinc->gettags($group);
#    print "level=$level (", $tags[0],")\n";
    foreach my $g ($zinc->find('withtype', 'group', ".$group.")) {
	&drawHierarchy ($g,$level+1);
    }
    my ($x,$y,$x2,$y2) = $zinc->bbox($group);
    $zinc->add('text',$group, -position => [$x-5,$y-4],
	       -text => $tags[0], -anchor => "w", -alignment => "left",
	       -underlined => 1,
	       -priority => 20,
	       -tags => ["title_".$tags[0], 'group_title'],
	       );
    ($x,$y,$x2,$y2) = $zinc->bbox($group);
    if (defined $x) {
	my $background  = $backgrounds[$level];
	$zinc->add('rectangle', $group, [$x+0,$y+5,$x2+5,$y2+2],
		   -filled => 1,
		   -fillcolor => $background,
		   -priority => $level,
		   -tags => ["frame_".$tags[0], 'group_frame'],
		   );
    } else {
	print "undefined bbox for $group : @tags\n";
    }
}

### this sub extracts out of groups both text and frame representing
### each group. This is necessary to avoid unexpected selection of
### rectangles and titles inside groups
sub extractTextAndFrames {
    foreach my $group_title ($zinc->find('withtag', 'group_title || group_frame')) {
	my @ancestors = $zinc->find('ancestor',$group_title);
#	print "$group_title, @ancestors\n";
	my $grandFather = $ancestors[1];
	$zinc->chggroup($group_title,$grandFather,1);
    }
}

## this sub modifies the color/line color of texts and rectangles
## representing selected items. 
sub displayPathtag {
#    print "var=@_ $pathtag\n";
    my $explanation = shift;
    my @selected = $zinc->find('withtag', $pathtag);
    my @tags = &items2tags(@selected);
#    print "selected: @tags\n";
    $explan_txt->configure(-text => $explanation ? "$explanation\n" : "");
	
    ## unselecting all items 
    foreach my $item ($zinc->find('withtype', 'text')) {
	$zinc->itemconfigure($item, -color => $defaultForecolor);
    }
    foreach my $item ($zinc->find('withtype', 'rectangle')) {
	$zinc->itemconfigure($item, -linecolor => $defaultForecolor);
    }

    ## highlighting selected items
    foreach my $item (@selected) {
	my $type = $zinc->type($item);
#	print $item, " ", $zinc->type($item), " ", join (",",$zinc->gettags($item)), "\n";
	if ($type eq 'text') {
	    $zinc->itemconfigure($item, -color => $selectedColor);
	} elsif ($type eq 'rectangle') {
	    $zinc->itemconfigure($item, -linecolor => $selectedColor);
	} elsif ($type eq 'group') {
	    my $tag = ($zinc->gettags($item))[0];
	    ## as there is 2 // hierachy, we must refine the tag used
	    ## to restrict to the proper hierarchy
	    ## NB: this is due to differences between the group hierarchy
	    ##     and the graphical object hierarchy used for this demo
	    if ($zinc->find('ancestors',$item,'top')) {
		$zinc->itemconfigure(".top*frame_$tag", -linecolor => $selectedColor);
		$zinc->itemconfigure(".top*title_$tag", -color => $selectedColor);
	    } elsif ($zinc->find('ancestors',$item,'other_top')) {
		$zinc->itemconfigure(".other_top*frame_$tag", -linecolor => $selectedColor);
		$zinc->itemconfigure(".other_top*title_$tag", -color => $selectedColor);
	    } else {
		$zinc->itemconfigure("frame_$tag", -linecolor => $selectedColor);
		$zinc->itemconfigure("title_$tag", -color => $selectedColor);
	    }
	}
    }
}

&drawHierarchy('top',0);
&drawHierarchy('other_top',0);
$zinc->translate('other_top', 400,0);
&extractTextAndFrames;



MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/rotation.pl.

























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl
# $Id$
# This simple demo has been developped by C. Schlienger <celine@intuilab.com>

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);


use Tk;
use Tk::Zinc;
use strict;
use constant;

my constant $PI=3.1416;

my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();


###########################################
# Text zone
###########################################

my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2, -height => 4);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
	      'This toy-appli shows rotations on waypoint items.
The following operations are possible:
   Click "<-" for negative rotation
   Click "->" for positive rotation' );


###########################################
# Zinc
###########################################
my $zinc_width=600;
my $zinc_height=500;
my $zinc = $mw->Zinc(-width => $zinc_width, -height => $zinc_height,
		     -font => "10x20",
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

###########################################
# Waypoints
###########################################

my $wp_group = $zinc->add('group', 1, -visible => 1);

my $p1=[200, 200];
my $wp1 = $zinc->add('waypoint',$wp_group, 1,
		    -position => $p1,
		    -connectioncolor => 'green',
		    -symbolcolor => 'blue',
		    -labelformat => 'x20x18+0+0',
		    -leaderwidth=>'0',
		    -labeldx=>'-20'
		   );
$zinc->itemconfigure($wp1, 0,
		     -text => "DO",
		    );

my $p2=[300, 300];
my $wp2 = $zinc->add('waypoint',$wp_group, 1,
		     -position => $p2,
		     -connecteditem => $wp1,
		     -connectioncolor => 'blue',
		     -symbolcolor => 'blue',
		     -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldx=>'-20',
		     #-labeldy=>'30'
		    );

$zinc->itemconfigure($wp2, 0,
		     -text => "RE",
		    );

my $p3=[400, 150];
my $wp3 = $zinc->add('waypoint', $wp_group, 2,
		     -position => $p3,
		     -connecteditem => $wp2,
		     -connectioncolor => 'blue',
		     -symbolcolor => 'blue',
		     -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldx=>'20',
		     -labeldy=>'+10'
		    );
$zinc->itemconfigure($wp3, 0,
		     -text => "MI",
		    );

###################################################
# control panel
###################################################
my $rc = $mw->Frame()->pack();

my $left=$rc->Button(-width => 2, 
		     -height => 2,
		     -text => '<-',
		     -command=>sub{
		       #--------------------------------
		       # Negative rotation
		       #--------------------------------
		       my @centre=$zinc->coords("$wp2"); #the center of the rotation is $wp2
		       $zinc->rotate("$wp_group",-$PI/6,$centre[0],$centre[1]); 
		     })->pack(-side => 'left');

my $right=$rc->Button(-width => 2, 
		      -height => 2,
		      -text => '->',
		      -command=>sub{
			#--------------------------------
			# Positive rotation
			#--------------------------------
			my @centre=$zinc->coords("$wp2");#the center of the rotation is $wp2
			$zinc->rotate("$wp_group",+$PI/6,$centre[0],$centre[1]); 
		      })->pack(-side=>'right');




MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl.



























































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/perl
# $Id$
# This simple demo has been developped by C. Schlienger <celine@intuilab.com>

package simple_interaction_track; # for avoiding symbol collision between different demos

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);


use Tk;
use Tk::Zinc;
use strict;

my $mw = MainWindow->new();



###########################################
# Zinc
###########################################
my $zinc_width=600;
my $zinc_height=500;
my $zinc = $mw->Zinc(-width => $zinc_width, -height => $zinc_height,
		     -font => "10x20",
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

# The explanation displayed when running this demo
$zinc->add('text', 1,
	   -position=> [10,10],
	   -text => 'This toy-appli shows some interactions on different parts
of a flight track item. The following operations are possible:
 - Drag Button 1 on the track to move it.
      Please Note the position history (past positions)
 - Enter/Leave flight label fields
 - Enter/Leave the speedvector, symbol (i.e. current position),
     label, or leader',
	   -font => "9x15",
	   );

###########################################
# Track
###########################################

#the label format (6 formats for 6 fields)#
my $labelformat = "x80x60+0+0 x60a0^0^0 x30a0^0>1 a0a0>2>1 x30a0>3>1 a0a0^0>2";

#the track#
my $x=250;
my $y=200;
my $track=$zinc->add('track', 1, 6, # 6 is the number of field in the flightlabel
		     -labelformat => $labelformat,
		     -position => [$x, $y],#position of the marker
		     -speedvector => [30, -15],#ccords of the speed vector
		     -markersize => 10,
		     );
# moving the track, to display past positions
foreach my $i (0..5) {  $zinc->coords($track,[$x+$i*10,$y-$i*5]); }

#fields of the label#
$zinc->itemconfigure($track, 0,#configuration of field 0 of the label
		     -filled => 0,
		     -bordercolor => 'DarkGreen',
		     -border => "contour",
		    );
$zinc->itemconfigure($track, 1,
		     -filled => 1,
		     -backcolor => 'gray60',
		     -text => "AFR6128");
$zinc->itemconfigure($track, 2,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "390");
$zinc->itemconfigure($track, 3,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "/");
$zinc->itemconfigure($track, 4,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "350");
$zinc->itemconfigure($track, 5,
		     -filled => 0,
		     -backcolor => 'gray65',
		     -text => "TUR");



###########################################
# Events on the track
###########################################
#---------------------------------------------
# Enter/Leave a field of the label of the track
#---------------------------------------------

foreach my $field (0..5) {
  #Entering the field $field higlights it#
  $zinc->bind("$track:$field", 
	      '<Enter>',
	      sub {
		if ($field==0){ 
		  higlight_label_on();
#		  print "CP=", $zinc->currentpart, "\n";
		}
		else{
		  highlight_fields_on($field);
#		  print "CP=", $zinc->currentpart, "\n";
		}
		
	      });
  #Leaving the field cancels the highlight of $field#
  $zinc->bind("$track:$field", 
	      '<Leave>',
	      sub {
		if($field==0){
		  higlight_label_off();
		}
		else{
		  if ($field==1){
		    highlight_field1_off();
		  }
		  else{
		    highlight_other_fields_off($field);
		  }
		}
	      });
}

#fonction#
sub higlight_label_on{
   $zinc->itemconfigure('current', 0,
			-filled => 0,
			-bordercolor => 'red',
			-border => "contour",
		    );
  
}
sub higlight_label_off{
   $zinc->itemconfigure('current', 0,
			-filled => 0,
			-bordercolor => 'DarkGreen',
			-border => "contour",
		    );
  
  
}

sub highlight_fields_on{
  my $field=$_[0];
  $zinc->itemconfigure('current', $field,
		       -border => 'contour',
		       -filled => 1,
		       -color => 'white'
		      );
  
}
sub highlight_field1_off{
    $zinc->itemconfigure('current', 1,
			 -border => '',
			 -filled => 1,
			 -color => 'black',
			 -backcolor => 'gray60'
			);
  
}

sub highlight_other_fields_off{
  my $field=$_[0];
  $zinc->itemconfigure('current', $field,
		       -border => '',
		       -filled => 0,
		       -color => 'black',
		       -backcolor => 'gray65'
		      );
}
#---------------------------------------------
# Enter/Leave other parts of the track
#---------------------------------------------
$zinc->bind("$track:position", 
	      '<Enter>',
	      sub {  $zinc->itemconfigure($track,
					  -symbolcolor=>"red",
					  );
#		  print "CP=", $zinc->currentpart, "\n";
		 });
$zinc->bind("$track:position", 
	      '<Leave>',
	      sub {  $zinc->itemconfigure($track,
					  -symbolcolor=>"black",
					  );
		 });

$zinc->bind("$track:speedvector", 
	      '<Enter>',
	      sub {  $zinc->itemconfigure($track,
					  -speedvectorcolor=>"red",
					  );
		 });
$zinc->bind("$track:speedvector", '<Leave>',
    sub {  $zinc->itemconfigure($track,
				-speedvectorcolor=>"black",
				);
       });

$zinc->bind("$track:leader", '<Enter>',
    sub {  $zinc->itemconfigure($track,
				-leadercolor=>"red",
				);
       });

$zinc->bind("$track:leader", '<Leave>',
    sub {  $zinc->itemconfigure($track,
				-leadercolor=>"black",
				);
       });

#---------------------------------------------
# Drag and drop the track
#---------------------------------------------
#Binding to ButtonPress event -> "move_on" state#
$zinc -> bind($track,'<ButtonPress-1>'=>[ sub { &select_color_on(); #change the color
						&move_on($_[1],$_[2]); #"move_on" state
					    }, Tk::Ev('x'),Tk::Ev('y') ]); 

#Binding to ButtonRelease event -> "move_off" state#
$zinc -> bind($track,'<ButtonRelease-1>'=>sub{&select_color_off(); #change the color
					      &move_off();}); #"move_off" state

#"move_on" state#
sub move_on{
    my ($xi,$yi)=@_;
    #Binding to Motion event -> move the track#
    $zinc -> bind($track,'<Motion>'=>
		  [sub{move($xi,$yi,$_[1],$_[2]); #move the track
		       $xi=$_[1];
		       $yi=$_[2];
		   },Tk::Ev('x'),Tk::Ev('y')]); 
}

#"move_off" state#
sub move_off{
    #Motion event not allowed on track
    $zinc -> bind($track,'<Motion>'=>""); 
}

#move the track#
sub move{
    my ($xi,$yi,$x,$y)=@_;
    select_color_on();
    my @coords=$zinc->coords($track);
    $zinc->coords($track,[$coords[0]+$x-$xi,$coords[1]+$y-$yi]);
}


sub select_color_on{
    $zinc->itemconfigure($track,
			 -speedvectorcolor=>"white",
			 -markercolor=>"white",
			 -leadercolor=>"white" );
}

sub select_color_off{
  $zinc->itemconfigure($track,
		       -speedvectorcolor=>"black",
		       -markercolor=>"black",
		       -leadercolor=>"black" );
}
 Tk::MainLoop;

Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/simpleradar.pl.



































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
#!/usr/bin/perl -w
# $Id$
# This simple radar has been initially developped by P. Lecoanet <lecoanet@cena.fr>
# It has been adapted by C. Mertz <mertz@cena.fr> for demo purpose.

package simpleradar; # for avoiding symbol collision between different demos

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);


use Tk;
use Tk::Zinc;

use strict;

# to find the SimpleRadarControls module
require Tk->findINC('demos/zinc_pm/SimpleRadarControls.pm');

my $mw = MainWindow->new();

my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2,
		     -height => 11);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
	      'This a very simple radar display, where you can see flight tracks,
   a so-called ministrip (green) and and extend flight label (tan background).
   The following operations are possible:
     Shift-Button 1 for using a squarre lasso (result in the terminal).
     Click Button 2 for identifiying the closest item (result in the terminal).
     Button 3 for dragging most items, but not the ministrip (not in the same group).
     Shift-Button 3 for zooming independently on X and Y axis.
     Ctrl-Button 3 for rotationg graphic objects.
     Enter/Leave in flight label fields, speed vector, position and leader,
       and in the ministrip fields.
     Click Button 1 on flight track to display a route.');



###################################################
# creation zinc
###################################################
my $top = 1;
my $scale = 1.0;
my $center_x = 0.0;
my $center_y = 0.0;
my $zinc_width = 800;
my $zinc_height = 500;
my $delay = 2000;
my $rate = 0.3;
my %tracks = ();

my $pause = 0; # if true the flight are no more moving
my $zinc = $mw->Zinc(-render => 1,
                     -enablerotation => 1,
                     -backcolor => 'gray65',
		     -relief => 'sunken',
		     -font => "10x20");
$zinc->pack(-expand => 1, -fill => 'both');
$zinc->configure(-width => $zinc_width, -height => $zinc_height);
#$radar = $top;
my $radar = $zinc->add('group', $top, -tags => ['controls', 'radar']);
$zinc->configure(-overlapmanager => $radar);

my $rotation = 0;
$zinc->Tk::bind('<Alt-1>', sub { $rotation += 10; $zinc->configure(-screenrotation => $rotation); });
$zinc->Tk::bind('<Alt-3>', sub { $rotation -= 10; $zinc->configure(-screenrotation => $rotation); });

###################################################
# creation panneau controle
###################################################
my $rc = $mw->Frame()->pack();
$rc->Button(-text => 'Up',
	    -command => sub { $center_y -= 30.0;
			      update_transform($zinc); })->grid(-row => 0,
								-column => 2,
								-sticky, 'ew');
$rc->Button(-text => 'Down',
	    -command => sub { $center_y += 30.0;
			      update_transform($zinc); })->grid(-row => 2,
								-column => 2,
								-sticky, 'ew');
$rc->Button(-text => 'Left',
	    -command => sub { $center_x += 30.0;
			      update_transform($zinc); })->grid(-row => 1,
								-column => 1);
$rc->Button(-text => 'Right',
	    -command => sub { $center_x -= 30.0;
			      update_transform($zinc); })->grid(-row => 1,
								-column => 3);
$rc->Button(-text => 'Expand',
	    -command => sub { $scale *= 1.1;
			      update_transform($zinc); })->grid(-row => 1,
								-column => 4);
$rc->Button(-text => 'Shrink',
	    -command => sub { $scale *= 0.9;
			      update_transform($zinc); })->grid(-row => 1,
								-column => 0);
$rc->Button(-text => 'Reset',
	    -command => sub { $scale = 1.0;
			      $center_x = $center_y = 0.0;
			      update_transform($zinc); })->grid(-row => 1,
								-column => 2,
								-sticky, 'ew');

$rc->Button(-text => 'Pause',
	    -command => sub { $pause = ! $pause;
			  })->grid(-row => 0,
				   -column => 6);

###################################################
# Code de reconfiguration lors d'un
# redimensionnement.
###################################################
$zinc->Tk::bind('<Configure>', [\&resize]);

sub resize {
    my ($zinc) = @_;
    my $ev = $zinc->XEvent();
    my $width = $ev->w;
    my $height = $ev->h;
    my $bw = $zinc->cget(-borderwidth);
    $zinc_width = $width - 2*$bw;
    $zinc_height = $height - 2*$bw;
    update_transform($zinc);
}

sub update_transform {
    my ($zinc) = @_;
    $zinc->treset($top);
    $zinc->translate($top, -$center_x, -$center_y);
    $zinc->scale($top, $scale, $scale);
    $zinc->scale($top, 1, -1);
    my $virtualSize = sqrt($zinc_width*$zinc_width + $zinc_height*$zinc_height);
    my $hVirtualSize = $virtualSize/2;
    $zinc->translate($top, $hVirtualSize, $hVirtualSize);
    #$zinc->translate($top, $zinc_width/2, $zinc_height/2);
}


###################################################
# Creation de pistes.
###################################################
my $one_of_track_item;
sub create_tracks {
    my $i = 20;
    my $j;
    my $track;
    my $x;
    my $y;
    my $w = $zinc_width / $scale;
    my $h = $zinc_height / $scale;
    my $d;
    my $item;
    
    for ( ; $i > 0; $i--) {
	$track = {};
	$track->{'item'} = $item = $zinc->add('track', $radar, 6);
	$one_of_track_item = $item;
	$tracks{$item} = $track;
	$track->{'x'} = rand($w) - $w/2 + $center_x;
	$track->{'y'} = rand($h) - $h/2 + $center_y;
	$d = (rand() > 0.5) ? 1 : -1;
	$track->{'vx'} =  (8.0 + rand(10.0)) * $d;
	$d = (rand() > 0.5) ? 1 : -1;
	$track->{'vy'} =  (8.0 + rand(10.0)) * $d;
	$zinc->itemconfigure($item,
			     -position => [$track->{'x'}, $track->{'y'}],
			     -speedvector => [$track->{'vx'}, $track->{'vy'}],
			     -speedvectorsensitive => 1,
			     -labeldistance => 30,
			     -markersize => 20,
			     -historycolor => 'gray30',
			     -filledhistory => 0,
			     -circlehistory => 1,
			     -labelformat => "x80x60+0+0 x63a0^0^0 x33a0^0>1 a0a0>2>1 x33a0>3>1 a0a0^0>2");
	$zinc->itemconfigure($item, 0,
			     -filled => 0,
			     -backcolor => 'gray60',
#			     -border => "contour",
			     -sensitive => 1
			     );
	$zinc->itemconfigure($item, 1,
			     -filled => 1,
			     -backcolor => 'gray55',
			     -text => sprintf ("AFR%03i",$i));
	$zinc->itemconfigure($item, 2,
			     -filled => 0,
			     -backcolor => 'gray65',
			     -text => "360");
	$zinc->itemconfigure($item, 3,
			     -filled => 0,
			     -backcolor => 'gray65',
			     -text => "/");
	$zinc->itemconfigure($item, 4,
			     -filled => 0,
			     -backcolor => 'gray65',
			     -text => "410");
	$zinc->itemconfigure($item, 5,
			     -filled => 0,
			     -backcolor => 'gray65',
			     -text => "Balise");
	my $b_on = sub { $zinc->itemconfigure('current', $zinc->currentpart(),
					      -border => 'contour')};
	my $b_off = sub { $zinc->itemconfigure('current', $zinc->currentpart(),
					       -border => 'noborder')};
	my $tog_b = sub { my $current = $zinc->find('withtag', 'current');
			  my $curpart = $zinc->currentpart();
			  if ($curpart =~ '[0-9]+') {
			      my $on_off = $zinc->itemcget($current, $curpart, -sensitive);
			      $zinc->itemconfigure($current, $curpart,
						   -sensitive => !$on_off);
			  }
		      };
	for ($j = 0; $j < 6; $j++) {
	    $zinc->bind($item.":$j", '<Enter>', $b_on);
            $zinc->bind($item.":$j", '<Leave>', $b_off);
            $zinc->bind($item, '<1>', $tog_b);
            $zinc->bind($item, '<Shift-1>', sub {});
        }
	$zinc->bind($item, '<Enter>',
		    sub {$zinc->itemconfigure('current',
					      -historycolor => 'red3',
					      -symbolcolor => 'red3',
					      -markercolor => 'red3',
					      -leaderwidth => 2,
					      -leadercolor => 'red3',
					      -speedvectorwidth => 2,
					      -speedvectorcolor => 'red3')});
        $zinc->bind($item, '<Leave>',
                    sub {$zinc->itemconfigure('current',
					      -historycolor => 'black',
					      -symbolcolor => 'black',
					      -markercolor => 'black',
					      -leaderwidth => 1,
					      -leadercolor => 'black',
					      -speedvectorwidth => 1,
					      -speedvectorcolor => 'black')});
        $zinc->bind($item.':position', '<1>', [\&create_route]);
        $zinc->bind($item.':position', '<Shift-1>', sub { });
        $track->{'route'} = 0;
    }
}

create_tracks();

###################################################
# creation way point
###################################################
sub create_route {
    my ($zinc) = @_;
    my $wp;
    my $connected;
    my $x;
    my $y;
    my $i = 4;
    my $track = $tracks{$zinc->find('withtag', 'current')};
    
    if ($track->{'route'} == 0) {
	$x = $track->{'x'} + 8.0 * $track->{'vx'};
	$y = $track->{'y'} + 8.0 * $track->{'vy'};
	$connected = $track->{'item'};
	for ( ; $i > 0; $i--) {
	    $wp = $zinc->add('waypoint', 'radar', 2,
			     -position => [$x, $y],
			     -connecteditem => $connected,
			     -connectioncolor => 'green',
			     -symbolcolor => 'green',
			     -labelformat => 'x20x18+0+0');
	    $zinc->lower($wp, $connected);
	    $zinc->bind($wp.':0', '<Enter>',
			sub {$zinc->itemconfigure('current', 0, -border => 'contour')});
	    $zinc->bind($wp.':position', '<Enter>',
			sub {$zinc->itemconfigure('current', -symbolcolor => 'red')});
	    $zinc->bind($wp.':leader', '<Enter>',
			sub {$zinc->itemconfigure('current', -leadercolor => 'red')});
	    $zinc->bind($wp.':connection', '<Enter>',
			sub {$zinc->itemconfigure('current', -connectioncolor => 'red')});
	    $zinc->bind($wp.':0', '<Leave>',
			sub {$zinc->itemconfigure('current', 0, -border => '')});
	    $zinc->bind($wp.':position', '<Leave>',
			sub {$zinc->itemconfigure('current', -symbolcolor => 'green')});
	    $zinc->bind($wp.':leader', '<Leave>',
			sub {$zinc->itemconfigure('current', -leadercolor => 'black')});
	    $zinc->bind($wp.':connection', '<Leave>',
			sub {$zinc->itemconfigure('current', -connectioncolor => 'green')});
	    $zinc->itemconfigure($wp, 0,
				 -text => "$i",
				 -filled => 1,
                                 -backcolor => 'gray55');
	    $zinc->bind($wp.':position', '<1>', [\&del_way_point]);
	    $x += (2.0 + rand(8.0)) * $track->{'vx'};
	    $y += (2.0 + rand(8.0)) * $track->{'vy'};
	    $connected = $wp;
	}
	$track->{'route'} = $wp;
    }
    else {
	$wp = $track->{'route'};
	while ($wp != $track->{'item'}) {
	    $track->{'route'} = $zinc->itemcget($wp, -connecteditem);
	    $zinc->bind($wp.':position', '<1>', '');
	    $zinc->bind($wp.':position', '<Enter>', '');
	    $zinc->bind($wp.':position', '<Leave>', '');
	    $zinc->bind($wp.':leader', '<Enter>', '');
            $zinc->bind($wp.':leader', '<Leave>', '');
            $zinc->bind($wp.':connection', '<Enter>', '');
            $zinc->bind($wp.':connection', '<Leave>', '');
            $zinc->bind($wp.':0', '<Enter>', '');
            $zinc->bind($wp.':0', '<Leave>', '');
            $zinc->remove($wp);
	    $wp = $track->{'route'};
	}
	$track->{'route'} = 0;
    }
}

###################################################
# suppression waypoint intermediaire
###################################################
sub find_track {
    my ($zinc, $wp) = @_;
    my $connected = $wp;
    
    while ($zinc->type($connected) ne 'track') {
	$connected = $zinc->itemcget($connected, -connecteditem);
    }
    return $connected;
}

sub del_way_point {
    my ($zinc) = @_;
    my $wp = $zinc->find('withtag', 'current');
    my $track = $tracks{find_track($zinc, $wp)};
    my $next = $zinc->itemcget($wp, -connecteditem);
    my $prev;
    my $prevnext;

    $prev = $track->{'route'};
    if ($prev != $wp) {
	$prevnext = $zinc->itemcget($prev, -connecteditem);
	while ($prevnext != $wp) {
	    $prev = $prevnext;
	    $prevnext = $zinc->itemcget($prev, -connecteditem);
	}
    }
    $zinc->itemconfigure($prev, -connecteditem => $next);
    $zinc->bind($wp.':position', '<1>', '');
    $zinc->remove($wp);
    if ($wp == $track->{'route'}) {
	if ($next == $track->{'item'}) {
	    $track->{'route'} = 0;
	}
	else {
	    $track->{'route'} = $next;
	}
    }
}


###################################################
# creation macro
###################################################
my $macro = $zinc->add("tabular", $radar, 10,
    -labelformat => "x73x20+0+0 x20x20+0+0 x53x20+20+0"
    );
$zinc->itemconfigure($macro, 0, -backcolor => "tan1", -filled => 1,
		     -fillpattern => "AlphaStipple7",
		     -bordercolor => "red3");
$zinc->itemconfigure($macro, 1 , -text => "a");
$zinc->itemconfigure($macro, 2, -text => "macro");

$zinc->itemconfigure($macro, -connecteditem => $one_of_track_item);
foreach my $part (0..2) {
    $zinc->bind("$macro:$part", "<Enter>", [ \&borders, "on"]);
    $zinc->bind("$macro:$part", "<Leave>", [ \&borders, "off"]);
}
###################################################
# creation ministrip
###################################################
my $ministrip = $zinc->add("tabular", 1, 10,
			   -labelformat => "x153x80^0^0 x93x20^0^0 x63a0^0>1 a0a0>2>1 x33a0>3>1 a0a0^0>2",
			   -position => [100, 10]);
$zinc->itemconfigure($ministrip, 0 ,
		     -filled => 1,
		     -backcolor => "grey70",
		     -border => "contour",
		     -bordercolor => "green",
		     );
$zinc->itemconfigure($ministrip, 1 ,
		     -text => 'ministrip', -color => "darkgreen",
		     -backcolor => "grey40", 
		     );
$zinc->itemconfigure($ministrip, 2 ,
		     -text => 'field1', -color => "darkgreen",
		     -backcolor => "grey40",
		     );
$zinc->itemconfigure($ministrip, 3 ,
		     -text => 'field2', -color => "darkgreen",
		     -backcolor => "grey40",
		     );
$zinc->itemconfigure($ministrip, 4 ,
		     -text => 'f3', -color => "darkgreen",
		     -backcolor => "grey40",
		     );
$zinc->itemconfigure($ministrip, 5 ,
		     -text => 'field4', -color => "darkgreen",
		     -backcolor => "grey40",
		     );

foreach my $field (1..5) {
    $zinc->bind("$ministrip:$field", '<Enter>',
		sub {
		    $zinc->itemconfigure('current', $field,
					 -border => 'contour',
					 -filled => 1,
					 -color => 'white'
					 )
		    });
$zinc->bind("$ministrip:$field", '<Leave>',
    sub {$zinc->itemconfigure('current', $field,
			      -border => '',
			      -filled => 0,
			      -color => 'darkgreen'
			      )});
}

###################################################
# creation map
###################################################
$mw->videomap("load", Tk->findINC("demos/zinc_data/videomap_paris-w_90_2"), 0, "paris-w");
$mw->videomap("load", Tk->findINC("demos/zinc_data/videomap_orly"), 17, "orly");
$mw->videomap("load", Tk->findINC("demos/zinc_data/hegias_parouest_TE.vid"), 0, "paris-ouest");

my $map = $zinc->add("map", $radar,
		     -color => 'gray80');
$zinc->itemconfigure($map,
		     -mapinfo => 'orly');

my $map2 = $zinc->add("map", $radar,
		      -color => 'gray60',
		      -filled => 1,
		      -priority => 0,
		      -fillpattern => "AlphaStipple6");
$zinc->itemconfigure($map2,
		     -mapinfo => 'paris-ouest');

my $map3 = $zinc->add("map", $radar,
		      -color => 'gray50');
$zinc->itemconfigure($map3,
		     -mapinfo => "paris-w");


###################################################
# Création fonctions de contrôle à la souris
###################################################
new SimpleRadarControls($zinc);

###################################################
# Rafraichissement des pistes
###################################################
my $timer = $zinc->repeat($delay, [\&refresh, $zinc]);
$mw->OnDestroy(\&destroyTimersub ); # this is 

my $timerIsDead = 0;
sub destroyTimersub {
    $timerIsDead = 1;
    $mw->afterCancel($timer);
    # the timer is not really cancelled when using zinc-demos! 
}

sub refresh {
    my ($zinc) = @_;

    return if $pause;
    return if $timerIsDead;
    foreach my $t (values(%tracks)) {
	$t->{'x'} += $t->{'vx'} * $rate;
	$t->{'y'} += $t->{'vy'} * $rate;
	$zinc->itemconfigure($t->{'item'},
			     -position => [$t->{'x'}, $t->{'y'}]);
    }
}

sub borders {
    my($widget, $onoff) = @_;
    $onoff = "on" unless $onoff;
    my $contour = "noborder";
    $contour = "contour" if ($onoff eq 'on');
    $zinc->itemconfigure('current', 0, -border => $contour);
}


Tk::MainLoop();


Added jni/tkzinc/Perl/demos/Tk/demos/zinc_lib/testGraphics.pl.











































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
#!/usr/bin/perl
#-----------------------------------------------------------------------------------
#
#      testGraphics.pl
#      Fichier test du module Graphics
#
#      Authors: Jean-Luc Vinot <vinot@cena.fr>
#
# $Id$
#-----------------------------------------------------------------------------------

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use Tk::Zinc::Graphics;
use Math::Trig;
use Getopt::Long;
use strict 'vars';


my $currenttransfo;
my $previousangle = 0;
my $rotate_angle = .1;
my $zoomfactor = .1;
my $curview;
my ($dx, $dy);

my $tabanchor = 'n';
my $tabalign = 'left';

my $font_9b = '7x13bold';
# the original font is not standard, even if it is fully free:
# my $font_9b = '-cenapii-bleriot mini-bold-r-normal--9-90-75-75-p-75-iso8859-15';

my %gradset = (# gradients zinc
	       'boitonglet' => '=axial 0|#ff7777|#ffff99',
	       'roundrect1' => '=axial 270|#a7ffa7;70 0|#ffffff;90 5|#00bd00;80 8|#b7ffb7;50 80|#ffffff;70 91|#00ac00;70 95|#006700;60 100',
	       'roundrect2' => '=axial 270|#00bd00;80 |#d7ffd7;60',
	       'roundrect3' => '=axial 270|#00bd00;100 0|#ffffff;100 14|#ffffff;100 16|#00bd00;90 25|#b7ffb7;60 100',
	       'roundrect4' => '=axial 0|#00bd00;100 0|#ffffff;100 20|#00bd00;50 30|#00bd00;90 80|#b7ffb7;60 100',
	       'roundrect4ed' => '=path 48 48|#e7ffe7;20 0 70|#007900;20',
	       'roundcurve2' => '=axial 270|#d7ffd7;60|#7777ff;80',
	       'roundcurve1' => '=axial 270|#2222ff;80 |#d7ffd7;60',
	       'roundcurve' => '=axial 270|#7777ff;80 |#d7ffd7;60',
	       'roundpolyg' => '=radial -15 -20|#ffb7b7;50|#bd6622;90',
	       'rpolyline' => '=axial 90|#ffff77;80 |#ff7700;60',
	       'pushbtn1' => '=axial 0|#cccccc;100 0|#ffffff;100 10|#5a5a6a;100 80|#aaaadd;100 100',
	       'pushbtn2' => '=axial 270|#ccccff;100 0|#ffffff;100 10|#5a5a7a;100 80|#bbbbee;100 100',
	       'pushbtn3' => '=radial -15 -15|#ffffff;100 0|#333344;100 100',
	       'pushbtn4' => '=axial 270|#ccccff;100 0|#ffffff;100 10|#7a7a9a;100 80|#bbbbee;100 100',
	       'conical_edge' => '=conical 0 0 -45|#ffffff;100 0|#888899;100 30|#555566;100 50|#888899;100 70|#ffffff;100 100',
	       'conical_ext' => '=conical 0 0 135|#ffffff;100 0|#777788;100 30|#444455;100 50|#777788;100 70|#ffffff;100 100',
	       'pushbtn_edge' => '=axial 140|#ffffff;100 0|#555566;100 100',
	       'pushbtn_edge2' => '=axial 92|#ffffff;100 0|#555566;100 100',
	       'logoshape2' => '=axial 270|#ffffff|#7192aa',
	       'logopoint2' => '=radial -20 -20|#ffffff 0|#f70000 48|#900000 80|#ab0000 100',
	       'logoptshad2' => '=path 0 0|#770000;64 0|#770000;70 78|#770000;0 100',
	      );


# contenu des pages exemples
my %pagesconf = ('Rectangle' => {'consigne' => {-itemtype => 'text',
						 -coords => [-285, 155],
						 -params => {-font => $font_9b,
							     -text => "Mouse button 1 drag objects,\nEscape key reset transfos.",
							     -color => '#2222cc',
							    },
					      },
				  # roudedrectangle simple + radius 20
				  'rr1' => {-itemtype => 'roundedrectangle',
					    -coords => [[-200, 30], [50, 130]],
					    -radius => 20,
					    -params => {-closed => 1,
							-filled => 1,
							-fillcolor => 'roundrect2',
							-linewidth => 2,
							-linecolor => '#000000',
							-priority => 20,
							-tags => ['move'],
						       },
					   },

				  # roudedrectangle 'carré' (radius automatique)
				  'rr2' => {-itemtype => 'roundedrectangle',
					    -coords => [[-250, -100], [-90, 60]],
					    -params => {-closed => 1,
							-filled => 1,
							-fillcolor => 'roundrect1',
							-linewidth => 3,
							-linecolor => '#000000',
							-priority => 30,
							-tags => ['move'],
						       },
					   },
				  # cas particulier -> hippodrome (radius = h/2)
				  'rr3' => {-itemtype => 'roundedrectangle',
						  -coords => [[-30, 80], [130, 160]],
						  -radius => 40,
						  -params => {-closed => 1,
							      -filled => 1,
							      -fillcolor => 'roundrect3',
							      -linewidth => 4,
							      -linecolor => '#000000',
							      -priority => 30,
							      -tags => ['move'],
							     },
					   },

				  # utilisation de l'option -corners (pétales de fleur)
				  'rr4a' => {-itemtype => 'roundedrectangle',
					     -coords => [[-30, -60], [110, 10]],
					     -radius => 40,
					     -params => {-closed => 1,
							 -filled => 1,
							 -fillcolor => 'roundrect3',
							 -linewidth => 3,
							 -linecolor => '#000000',
							 -priority => 30,
							 -tags => ['move'],
							},
					     -corners => [1, 0, 1, 0],
					    },
				  'rr4b' => {-itemtype => 'roundedrectangle',
					     -coords => [[118, -68], [220, -132]],
					     -radius => 40,
					     -params => {-closed => 1,
							 -filled => 1,
							 -fillcolor => 'roundrect3',
							 -linewidth => 3,
							 -linecolor => '#000000',
							 -priority => 30,
							 -tags => ['move'],
							},
					     -corners => [1, 0, 1, 0],
					    },
				  'rr4c' => {-itemtype => 'roundedrectangle',
					     -coords => [[118, -60], [190, 30]],
					     -radius => 40,
					     -params => {-closed => 1,
							 -filled => 1,
							 -fillcolor => 'roundrect3',
							 -linewidth => 3,
							 -linecolor => '#000000',
							 -priority => 30,
							 -tags => ['move'],
							},
					     -corners => [0, 1, 0, 1],
					    },
				  'rr4d' => {-itemtype => 'roundedrectangle',
					     -coords => [[40, -152], [110, -68]],
					     -radius => 40,
					     -params => {-closed => 1,
							 -filled => 1,
							 -fillcolor => 'roundrect3',
							 -linewidth => 3,
							 -linecolor => '#000000',
							 -priority => 30,
							 -tags => ['move'],
							},
					     -corners => [0, 1, 0, 1],
					    },

				  # groupe de 2 boutons avec bordure externe
				  'gr8' => {-itemtype => 'group',
					    -coords => [0, 0],
					    -params => {-priority => 10,
							-tags => ['move'],
							-atomic => 1,
						       },
					    -items => {'edge' => {-itemtype => 'roundedrectangle',
								  -coords => [[174, -36],[266, 146]],
								  -radius => 26,
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'roundrect4ed',
									      -linewidth => 1,
									      -linecolor => '#ffffff',
									      -priority => 20,
									     },
								 },
						       'top' => {-itemtype => 'roundedrectangle',
								    -coords => [[180, -30], [260, 53]],
								    -parentgroup => 'gr8',
								    -radius => 20,
								    -params => {-closed => 1,
										-filled => 1,
										-fillcolor => 'roundrect4',
										-linewidth => 2.5,
										-linecolor => '#000000',
										-priority => 30,
									       },
								    -corners => [1, 0, 0, 1],
								   },
						       'topico' => {-itemtype => 'curve',
								    -parentgroup => 'gr8',
								    -coords => [[220, -10],[200, 30],[240, 30]],
								    -params => {-closed => 1,
										-filled => 1,
										-fillcolor => '#ffff00;80',
										-linewidth => 1,
										-linecolor => '#007900;80',
										-priority => 50,
									       },
								   },
						       'bottom' => {-itemtype => 'roundedrectangle',
								    -parentgroup => 'gr8',
								    -coords => [[180, 57], [260, 140]],
								    -radius => 20,
								    -params => {-closed => 1,
										-filled => 1,
										-fillcolor => 'roundrect4',
										-linewidth => 2.5,
										-linecolor => '#000000',
										-priority => 30,
									       },
								    -corners => [0, 1, 1, 0],
								   },
						       'bottomico' => {-itemtype => 'curve',
								       -parentgroup => 'gr8',
								       -coords => [[220, 120],[240, 80],[200, 80]],
								       -params => {-closed => 1,
										   -filled => 1,
										   -fillcolor => '#ffff00;80',
										   -linewidth => 1,
										   -linecolor => '#007900;80',
										   -priority => 50,
										  },
								      },
						      },
					   },
				 },
		 'Hippodrome' => {'consigne' => {-itemtype => 'text',
						 -coords => [-285, 165],
						 -params => {-font => $font_9b,
							     -text => "Click hippo Buttons with mouse button 1.\n",
							     -color => '#2222cc',
							    },
						},
				  'hp1' => {-itemtype => 'group',
					    -coords => [-163, -40],
					    -params => {-priority => 40,
						       },
					    -items => {'edge' => {-itemtype => 'hippodrome',
								  -coords => [[-46, -86], [46, 86]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn_edge',
									      -linewidth => 1,
									      -linecolor => '#ffffff',
									      -priority => 10,
									     },
								 },
						       'form' => {-itemtype => 'hippodrome',
								  -coords => [[-40, -80], [40, 80]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn1',
									      -linewidth => 3,
									      -linecolor => '#000000',
									      -priority => 20,
									      -tags => ['b1','pushbtn'],
									     },
								 },
						       },
					   },

				   'hp2' => {-itemtype => 'group',
					     -coords => [-40, -40],
					     -params => {-priority => 40,
							},
					    -items => {'edge' => {-itemtype => 'hippodrome',
								  -coords => [[-46, -86], [46, 86]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn_edge',
									      -linewidth => 1,
									      -linecolor => '#ffffff',
									      -priority => 10,
									     },
								 },
						       'formT' => {-itemtype => 'hippodrome',
								   -coords => [[-40, -80], [40, -28]],
								   -params => {-closed => 1,
									       -filled => 1,
									       -fillcolor => 'pushbtn1',
									       -linewidth => 3,
									       -linecolor => '#000000',
									       -priority => 20,
									       -tags => ['b2t','pushbtn'],
									      },
								   -orientation => 'vertical',
								   -trunc => 'bottom',
								  },
						       'formC' => {-itemtype => 'hippodrome',
								   -coords => [[-40, -26.5], [40, 26.5]],
								   -params => {-closed => 1,
									       -filled => 1,
									       -fillcolor => 'pushbtn1',
									       -linewidth => 3,
									       -linecolor => '#000000',
									       -priority => 20,
									       -tags => ['b2c','pushbtn'],
									      },
								   -trunc => 'both',
								  },
						       'formB' => {-itemtype => 'hippodrome',
								   -coords => [[-40, 28], [40, 80]],
								   -params => {-closed => 1,
									       -filled => 1,
									       -fillcolor => 'pushbtn1',
									       -linewidth => 3,
									       -linecolor => '#000000',
									       -priority => 20,
									       -tags => ['b2b','pushbtn'],
									      },
								   -orientation => 'vertical',
								   -trunc => 'top',
								  },
						      },
					     },
				   'hp3edge' => {-itemtype => 'hippodrome',
						 -coords => [[-204, 96], [204, 144]],
						 -params => {-closed => 1,
							     -filled => 1,
							     -fillcolor => 'pushbtn_edge2',
							     -linewidth => 1,
							     -linecolor => '#ffffff',
							     -priority => 10,
							    },
						},
				  'hp3g' => {-itemtype => 'group',
					     -coords => [-160, 120],
					     -params => {-priority => 40,
							},
					    -items => {'form' => {-itemtype => 'hippodrome',
								  -coords => [[-40, -20], [40, 20]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn2',
									      -linewidth => 2,
									      -linecolor => '#000000',
									      -priority => 20,
									      -tags => ['b3g','pushbtn'],
									     },
								  -trunc => 'right',
								 },
						       'ico' => {-itemtype => 'curve',
								 -coords => [[-20, 0],[-4, 8],[-4, -8]],
								 -params => {-closed => 1,
									     -filled => 1,
									     -fillcolor => '#000000',
									     -linewidth => 1,
									     -linecolor => '#aaaaaa',
									     -relief => 'raised',
									     -priority => 30,
									     -tags => ['b3g','pushbtn','ico'],
									    },
								 -contours =>  [['add',-1,[[0, 0],[16, 8],[16, -8]]]],
								},
						      },
					     },
				  'hp3c1' => {-itemtype => 'group',
					      -coords => [-80, 120],
					      -params => {-priority => 40,
							 },
					    -items => {'form' => {-itemtype => 'hippodrome',
								  -coords => [[-38, -20], [39, 20]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn2',
									      -linewidth => 2,
									      -linecolor => '#000000',
									      -priority => 20,
									      -tags => ['b3c1','pushbtn'],
									     },
								  -trunc => 'both',
								 },
						       'ico' => {-itemtype => 'curve',
								 -coords => [[-8, 0],[8, 8],[8, -8]],
								 -params => {-closed => 1,
									     -filled => 1,
									     -fillcolor => '#000000',
									     -linewidth => 1,
									     -linecolor => '#aaaaaa',
									     -priority => 30,
									     -relief => 'raised',
									     -tags => ['b3c1','pushbtn','ico'],
									    },
								},
						       },
					      },
				  'hp3c2' => {-itemtype => 'group',
					      -coords => [0, 120],
					      -params => {-priority => 40,
							 },
					      -items => {'form' => {-itemtype => 'hippodrome',
								  -coords => [[-39, -20], [39, 20]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn2',
									      -linewidth => 2,
									      -linecolor => '#000000',
									      -priority => 20,
									      -tags => ['b3c2','pushbtn'],
									     },
								  -trunc => 'both',
								 },
						       'ico' => {-itemtype => 'rectangle',
								 -coords => [[-6, -6],[6, 6]],
								 -params => {-filled => 1,
									     -fillcolor => '#000000',
									     -linewidth => 1,
									     -linecolor => '#aaaaaa',
									     -priority => 30,
									     -tags => ['b3c2','pushbtn','ico'],
									    },
								},
						       },
					      },
				  'hp3C3' => {-itemtype => 'group',
					      -coords => [80, 120],
					      -params => {-priority => 40,
							 },
					      -items => {'form' => {-itemtype => 'hippodrome',
								    -coords => [[-39, -20], [39, 20]],
								    -params => {-closed => 1,
										-filled => 1,
										-fillcolor => 'pushbtn2',
										-linewidth => 2,
										-linecolor => '#000000',
										-priority => 20,
										-tags => ['b3c3','pushbtn'],
									       },
								    -trunc => 'both',
								   },
							 'ico' => {-itemtype => 'curve',
								   -coords => [[8, 0],[-8, -8],[-8, 8]],
								   -params => {-closed => 1,
									       -filled => 1,
									       -fillcolor => '#000000',
									       -linewidth => 1,
									       -linecolor => '#aaaaaa',
									       -priority => 30,
									       -relief => 'raised',
									       -tags => ['b3c3','pushbtn','ico'],
									      },
								  },
							},
					     },

				  'hp3D' => {-itemtype => 'group',
					     -coords => [160, 120],
					     -params => {-priority => 40,
							 },
					     -items => {'form' => {-itemtype => 'hippodrome',
								   -coords => [[-40, -20], [40, 20]],
								   -params => {-closed => 1,
									       -filled => 1,
									       -fillcolor => 'pushbtn2',
									       -linewidth => 2,
									       -linecolor => '#000000',
									       -priority => 20,
									       -tags => ['b3d','pushbtn'],
									      },
								   -trunc => 'left',
								  },
							'ico' => {-itemtype => 'curve',
								  -coords => [[20, 0],[4, -8],[4, 8]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => '#000000',
									      -linewidth => 1,
									      -linecolor => '#aaaaaa',
									      -priority => 30,
									      -relief => 'raised',
									      -tags => ['b3d','pushbtn','ico'],
									     },
								  -contours =>  [['add',-1,[[0,0],[-16, -8],[-16, 8]]]],
								 },
						       },
					    },

				  'hp4a' => {-itemtype => 'group',
					     -coords => [48, -97],
					     -params => {-priority => 40,
							},
					     -repeat => {-num => 2,
							 -dxy => [0, 64],
							},
					    -items => {'edge' => {-itemtype => 'hippodrome',
								  -coords => [[-29, -29], [29, 29]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn_edge',
									      -linewidth => 1,
									      -linecolor => '#ffffff',
									      -priority => 0,
									     },
								 },
						       'form' => {-itemtype => 'hippodrome',
								  -coords => [[-24, -24], [24, 24]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn3',
									      -linewidth => 3,
									      -linecolor => '#000000',
									      -priority => 30,
									      -tags => ['b4a','pushbtn'],
									     },
								 },
						      },
					    },

				  'hp4b' => {-itemtype => 'group',
					     -coords => [145, -65],
					     -params => {-priority => 40,
							},
					    -items => {'edge' => {-itemtype => 'hippodrome',
								  -coords => [[-60, -60], [60, 60]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'conical_edge',
									      -linewidth => 1,
									      -linecolor => '#ffffff',
									      -priority => 0,
									     },
								 },
						       'ext' => {-itemtype => 'hippodrome',
								 -coords => [[-53, -53], [53, 53]],
								 -params => {-closed => 1,
									     -filled => 1,
									     -fillcolor => 'conical_ext',
									     -linewidth => 3,
									     -linecolor => '#000000',
									     -priority => 10,
									     -tags => ['b4b','pushbtn'],
									    },
								},
						       'int' => {-itemtype => 'hippodrome',
								 -coords => [[-41, -41], [40, 40]],
								 -params => {-closed => 1,
									     -filled => 1,
									     -fillcolor => '=path 10 10|#ffffff 0|#ccccd0 50|#99999f 80|#99999f;0 100',
									     -linewidth => 0,
									     -linecolor => '#cccccc;80',
									     -priority => 30,
									     -tags => ['b4b','pushbtn'],
									    },
								},
						      },
					    },

				  'hp5' => {-itemtype => 'group',
					    -coords => [60, 25],
					    -params => {-priority => 40,
						       },
					    -rotate => 30,
					    -repeat => {-num => 4,
							-dxy => [45, 0],
						       },
					    -items => {'edge' => {-itemtype => 'hippodrome',
								  -coords => [[-19, -34], [19, 34]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn_edge',
									      -linewidth => 1,
									      -linecolor => '#ffffff',
									      -priority => 10,
									     },
								 },
						       'form' => {-itemtype => 'hippodrome',
								  -coords => [[-15, -30], [15, 30]],
								  -params => {-closed => 1,
									      -filled => 1,
									      -fillcolor => 'pushbtn1',
									      -linewidth => 2,
									      -linecolor => '#000000',
									      -priority => 20,
									      -tags => ['b5','pushbtn'],
									     },
								 },
						       },
					   },
				 },

		 'Polygone' => {'consigne' => {-itemtype => 'text',
						 -coords => [-285, 160],
						 -params => {-font => $font_9b,
							     -text => "Click and Drag inside Polygons for rotate them\nEscape key reset transfos.",
							     -color => '#2222cc',
							    },
					      },
				'triangle' => {-itemtype => 'group',
					       -coords => [-215, -95],
					       -items => {'form' => {-itemtype => 'polygone',
								     -coords => [0, 0],
								     -numsides => 3,
								     -radius => 78,
								     -corner_radius => 10,
								     -startangle => 90,
								     -params => {-closed => 1,
										 -filled => 1,
										 -fillcolor => 'roundpolyg',
										 -linewidth => 2,
										 -linecolor => '#330000',
										 -priority => 20,
										 -tags => ['p1', 'poly'],
										},
								    },
							  'text' => {-itemtype => 'text',
								     -coords => [0, -6],
								     -params => {-font => $font_9b,
										 -text => "Triangle",
										 -anchor => 'n',
										 -alignment => 'center',
										 -color => '#660000',
										 -priority => 50,
										},
								    },
							 },
					      },

				 'carre' => {-itemtype => 'group',
					     -coords => [-80, -75],
					     -items => {'form' => {-itemtype => 'polygone',
								   -coords => [0, 0],
								   -numsides => 4,
								   -radius => 70,
								   -corner_radius => 10,
								   -startangle => 90,
								   -params => {-closed => 1,
									       -filled => 1,
									       -fillcolor => 'roundpolyg',
									       -linewidth => 2,
									       -linecolor => '#330000',
									       -priority => 20,
									       -tags => ['p2', 'poly'],
									      },
								  },
							'text' => {-itemtype => 'text',
								   -coords => [0, -6],
								   -params => {-font => $font_9b,
									       -text => "Carré",
									       -anchor => 'n',
									       -alignment => 'center',
									       -color => '#660000',
									       -priority => 50,
									      },
								  },
						       },
					    },

				'pentagone' => {-itemtype => 'group',
						-coords => [65, -75],
						-items => {'form' => {-itemtype => 'polygone',
								      -coords => [0, 0],
								      -numsides => 5,
								      -radius => 70,
								      -corner_radius => 10,
								      -startangle => 270,
								      -params => {-closed => 1,
										  -filled => 1,
										  -fillcolor => 'roundpolyg',
										  -linewidth => 2,
										  -linecolor => '#330000',
										  -priority => 20,
										  -tags => ['p3', 'poly'],
										 },
								     },
							   'text' => {-itemtype => 'text',
								      -coords => [0, -6],
								      -params => {-font => $font_9b,
										  -text => "Pentagone",
										  -anchor => 'n',
										  -alignment => 'center',
										  -color => '#660000',
										  -priority => 50,
										 },
								     },
							  },
					       },

				'hexagone' => {-itemtype => 'group',
					       -coords => [210, -75],
					       -items => {'form' => {-itemtype => 'polygone',
								     -coords => [0, 0],
								     -numsides => 6,
								     -radius => 68,
								     -corner_radius => 10,
								     -params => {-closed => 1,
										 -filled => 1,
										 -fillcolor => 'roundpolyg',
										 -linewidth => 2,
										 -linecolor => '#330000',
										 -priority => 20,
										 -tags => ['p4', 'poly'],
										},
								    },
							  'text' => {-itemtype => 'text',
								     -coords => [0, -6],
								     -params => {-font => $font_9b,
										 -text => "Hexagone",
										 -anchor => 'n',
										 -alignment => 'center',
										 -color => '#660000',
										 -priority => 50,
										},
								    },
							 },
					      },

				'heptagone' => {-itemtype => 'group',
						-coords => [-215, 85],
						-items => {'form' => {-itemtype => 'polygone',
								      -coords => [0, 0],
								      -numsides => 7,
								      -radius => 64,
								      -corner_radius => 10,
								      -params => {-closed => 1,
										  -filled => 1,
										  -fillcolor => 'roundpolyg',
										  -linewidth => 2,
										  -linecolor => '#330000',
										  -priority => 20,
										  -tags => ['p5', 'poly'],
										 },
								     },
							   'text' => {-itemtype => 'text',
								      -coords => [0, -6],
								      -params => {-font => $font_9b,
										  -text => "Heptagone",
										  -anchor => 'n',
										  -alignment => 'center',
										  -color => '#660000',
										  -priority => 50,
										 },
								     },
							  },
					       },
				

				'octogone' => {-itemtype => 'group',
					       -coords => [-76, 85],
					       -items => {'form' => {-itemtype => 'polygone',
								     -coords => [0, 0],
								     -numsides => 8,
								     -radius => 64,
								     -corner_radius => 10,
								     -params => {-closed => 1,
										 -filled => 1,
										 -fillcolor => 'roundpolyg',
										 -linewidth => 2,
										 -linecolor => '#330000',
										 -priority => 20,
										 -tags => ['p6', 'poly'],
										},
								    },
							  'text' => {-itemtype => 'text',
								     -coords => [0, -6],
								     -params => {-font => $font_9b,
										 -text => "Octogone",
										 -anchor => 'n',
										 -alignment => 'center',
										 -color => '#660000',
										 -priority => 50,
										},
								    },
							 },
					      },

				'petagone' => {-itemtype => 'group',
					       -coords => [66, 85],
					       -items => {'form' => {-itemtype => 'polygone',
								     -coords => [0, 0],
								     -numsides => 32,
								     -radius => 64,
								     -corner_radius => 10,
								     -params => {-closed => 1,
										 -filled => 1,
										 -fillcolor => 'roundpolyg',
										 -linewidth => 2,
										 -linecolor => '#330000',
										 -priority => 20,
										 -tags => ['p7', 'poly'],
										},
								    },
							  'text' => {-itemtype => 'text',
								     -coords => [0, -6],
								     -params => {-font => $font_9b,
										 -text => "32 cotés...",
										 -anchor => 'n',
										 -alignment => 'center',
										 -color => '#660000',
										 -priority => 50,
										},
								    },
							 },
					      },

				'etoile' => {-itemtype => 'group',
					     -coords => [210, 85],
					     -items => {'form' => {-itemtype => 'polygone',
								   -coords => [0, 0],
								   -numsides => 5,
								   -radius => 92,
								   -inner_radius => 36,
								   -corner_radius => 10,
								   -startangle => 270,
								   -corners => [0,1,0,1,0,1,0,1,0,1],
								   -params => {-closed => 1,
									       -filled => 1,
									       -fillcolor => 'roundpolyg',
									       -linewidth => 2,
									       -linecolor => '#330000',
									       -priority => 20,
									       -tags => ['p8', 'poly'],
									      },
								  },
							'text' => {-itemtype => 'text',
								   -coords => [0, -6],
								   -params => {-font => $font_9b,
									       -text => "Etoile",
									       -anchor => 'n',
									       -alignment => 'center',
									       -color => '#660000',
									       -priority => 50,
									      },
								  },
						       },
					    },
			       },

		 'Polyline' => {'consigne' => {-itemtype => 'text',
						 -coords => [-285, 155],
						 -params => {-font => $font_9b,
							     -text => "Mouse button 1 drag objects,\nEscape key reset transfos.",
							     -color => '#2222cc',
							    },
					      },
				 'a' => {-itemtype => 'polyline',
					 -coords => [[-200, -115],[-200, -100],[-218, -115],[-280, -115],[-280, -16],
						     [-218, -16],[-200, -31],[-200, -17.5],[-150, -17.5],[-150,-115]],
					 -corners_radius => [0, 0, 42, 47, 47, 42, 0, 0, 0, 0, 0, 0],
					 -params => {-closed => 1,
						     -filled => 1,
						     -visible => 1,
						     -fillcolor => 'rpolyline',
						     -linewidth => 2,
						     -linecolor => '#000000',
						     -priority => 50,
						     -tags => ['move'],
						    },
					 -contours => [['add', -1, [[-230, -80],[-230, -50],[-200, -50],[-200, -80]],15]],
					 },
				 'b' => {-itemtype => 'polyline',
					 -coords => [[-138, -150],[-138, -17.5],[-88, -17.5],[-88, -31],[-70, -16],
						     [-8, -16],[-8, -115],[-70, -115],[-88, -100],[-88, -150]],
					 -corners_radius => [0, 0, 0, 0, 42, 47, 47, 42, 0, 0, 0, 0, 0, 0],
					 -params => {-closed => 1,
						     -filled => 1,
						     -visible => 1,
						     -fillcolor => 'rpolyline',
						     -linewidth => 2,
						     -linecolor => '#000000',
						     -priority => 50,
						     -tags => ['move'],
						    },
					 -contours => [['add', -1, [[-88, -80],[-88, -50],[-58, -50],[-58, -80]],15]],
					},
				 'c' => {-itemtype => 'polyline',
					 -coords => [[80, -76],[80, -110],[60, -115],[0, -115],[0, -16],
						     [60, -16],[80, -21],[80, -57],[50, -47],[50, -86]],
					 -corners_radius => [0, 0, 70, 47, 47, 70, 0, 0, 14, 14, 0, 0, 0,0 ],
					 -params => {-closed => 1,
						     -filled => 1,
						     -visible => 1,
						     -fillcolor => 'rpolyline',
						     -linewidth => 2,
						     -linecolor => '#000000',
						     -priority => 50,
						     -tags => ['move'],
						    },
					},
				 'spirale' => {-itemtype => 'polyline',
					      -coords => [[215, -144],[139, -144],[139, 0],[268, 0],[268, -116],
							   [162.5, -116],[162.5, -21],[248, -21],[248, -96],[183, -96],
							  [183, -40],[231,-40],[231, -80],[199, -80],[199, -55],[215, -55]],
					       -corners_radius => [0, 76, 68, 61, 55, 50, 45, 40, 35, 30, 26, 22, 18, 14, 11],
					       -params => {-closed => 1,
							   -filled => 1,
							   -visible => 1,
							   -fillcolor => 'rpolyline',
							   -linewidth => 2,
							   -linecolor => '#000000',
							   -priority => 50,
							   -tags => ['move'],
							  },
					      },
				 'logo' => {-itemtype => 'group',
					    -coords => [0, 0],
					    -params => {-priority => 30,
							-atomic => 1,
							-tags => ['move'],
							},
					    -items => {'tkzinc' => {-itemtype => 'polyline',
								    -coords => [[-150,10],[-44,10],[-44,68],[-28,51],[6,51],
										[-19,79],[3,109],[53,51],[5,51],[5,10],[140,10],
										[52,115],[96,115],[96,47],[196,47],[196,158],
										[155,158],[155,89],[139,89],[139,160],[101, 160],
										[101,132],[85,132],[85,160],[-42,160],[-2,115],
										[-30,115],[-46,91],[-46,115],[-76,115],[-76,51],
										[-98,51],[-98,115],[-130,115],[-130,51],[-150, 51]],
								    -corners_radius => [0,0,0,0,0,0,0,0,0,0,30,0,0,50,50,
											0,0,8,8,0,0,8,8,0,27],
								    -params => {-closed => 1,
										-filled => 1,
										-visible => 1,
										-fillcolor => 'logoshape2',
										-linewidth => 2.5,
										-linecolor => '#000000',
										-priority => 10,
										-fillrule => 'nonzero',
									       },

								    -contours => [['add', 1, [[245,88],[245,47],[190,47],[190,158],
											       [259,158],[259,117],[230,117],[230,88]],
										   5, undef, [0,0,55,55,0,0,15,15]]],
								   },
						       'shad' => {-itemtype => 'arc',
								   -coords => [[75, 91],[115,131]],
								   -params => {-priority => 20,
									       -filled => 1,
									       -linewidth => 0,
									       -fillcolor => 'logoptshad2',
									       -closed => 1,
									      },
								  },
						       'point' => {-itemtype => 'arc',
								   -coords => [[70, 86],[110,126]],
								   -params => {-priority => 50,
									       -filled => 1,
									       -linewidth => 1,
									       -linecolor => '#a10000',
									       -fillcolor => 'logopoint2',
									       -closed => 1,
									      },
								  },
						      },
					    },
				 },

		 'MultiContours' => {'consigne' => {-itemtype => 'text',
						 -coords => [-285, 155],
						 -params => {-font => $font_9b,
							     -text => "Mouse button 1 drag objects,\nEscape key reset transfos.",
							     -color => '#2222cc',
							    },
					      },
				     'mc1' => {-itemtype => 'roundedcurve',
					      -coords => [[-30, -170], [-130, 0],[70, 0]],
					      -radius => 14,
					      -params => {-closed => 1,
							  -filled => 1,
							  -fillcolor => 'roundcurve2',
							  -linewidth => 1,
							  -linecolor => '#000000',
							  -priority => 20,
							  -tags => ['move'],
							  -fillrule => 'odd',
							 },
					       -contours => [['add',1,[[-30,-138],[-100,-18],[40,-18]],8],
							     ['add',1,[[-30,-130],[ -92,-22],[32,-22]],5],
							     ['add',1,[[-30,-100],[ -68,-36],[8,-36]],5],
							     ['add',1,[[-30, -92],[ -60,-40],[0,-40]],3],],
					     },
				    'mc2' => {-itemtype => 'polyline',
					      -coords => [[-250,-80], [-240,-10],[-285,-10],[-285,80],
							  [-250, 80],[-250, 40],[-170, 40],[-170,80],
							  [-100,80],[-100,40],[-20,40],[-20,80],[30,80],
							  [-10, 0],[-74, -10],[-110, -80]],
					      -corners_radius => [24,4, 40, 20, 0, 40, 40, 0, 0, 40, 40, 0, 30, 75, 0, 104],
					      -params => {-closed => 1,
							  -filled => 1,
							  -fillcolor => 'roundcurve1',
							  -linewidth => 2,
							  -linecolor => '#000000',
							  -priority => 30,
							  -tags => ['move'],
							  },
					      -contours => [['add',-1,[[-240,-72],[-230,0],[-169,0],[-185, -72]],
							     0, undef, [16, 16, 0, 0]],
							    ['add', -1, [[-175,-72],[-159,0],[-78,0],[-116, -72]],
							     0, undef, [0, 0, 8, 88]],
							    ['add', 1, [[-245,45],[-245,115],[-175,115],[-175, 45]],
							     35],
							    ['add', -1, [[-225,65],[-225,95],[-195,95],[-195, 65]],
							     15],
							    ['add', 1, [[-95,45],[-95,115],[-25,115],[-25, 45]],
							     35],
							    ['add', -1, [[-75,65],[-75,95],[-45,95],[-45, 65]],
							     15],
							   ],
					     },
				    'mc3' => {-itemtype => 'roundedcurve',
					      -coords => [[-10, 170], [256, 170],[312, 60],[48, 60]],
					      -radius => 34,
					      -params => {-closed => 1,
							  -filled => 1,
							  -fillcolor => 'roundcurve2',
							  -linewidth => 2.5,
							  -linecolor => '#000000',
							  -priority => 40,
							  -tags => ['move'],
							 },
					      -contours => [['add', -1, [[58, 62],[12, 144],[60, 172],[104, 88]],27],
							    ['add', 1, [[48, 77],[48, 119],[90, 119],[90, 77]],21],
							    ['add', -1, [[244, 58],[198, 140],[246, 168],[290, 84]],27],
							    ['add', 1, [[213, 110],[213, 152],[255, 152],[255, 110]],21],
							    ['add', -1, [[150, 60],[150, 170],[160, 170],[160, 60]],0]],
					      },
				     'mc4' => {-itemtype => 'roundedcurve',
					      -coords => [[222, -150],[138, -150],[180, -50],[138, -150],
							  [80, -92],[180, -50],[80, -92],[80, -8],
							  [180, -50],[80, -8],[138, 50],[180, -50],
							  [138, 50],[222, 50],[179.8, -50],[222, 50],
							  [280, -8],[180, -50],[280, -8],[280, -92],
							  [180, -50],[280, -92],[222,-150],[180,-50]],
					      -radius => 28,
					      -params => {-closed => 1,
							  -filled => 1,
							  -fillcolor => 'roundcurve',
							  -linewidth => 2,
							  -linecolor => '#000000',
							  -priority => 30,
							  -tags => ['move'],
							 },
					      -contours => [['add', -1, [[160, -70],[160, -30],[200, -30],[200, -70]],20]],
					      },
				    },

		 'TabBox' => {'consigne' => {-itemtype => 'text',
					     -coords => [-285, 160],
					     -params => {-font => $font_9b,
							 -text => "Click on thumbnail to select page\nChange anchor or alignment tabs options with radio buttons.\n",
							 -color => '#2222cc',
							},
					    },

			      'exemple' => {-itemtype => 'text',
					    -coords => [-165, -105],
					    -params => {-font => $font_9b,
							-text => "",
							-alignment => 'left',
							-anchor => 'nw',
							-color => '#000000',
							-priority => 500,
							-width => 350,
							-tags => ['div2', 'fontname'],
						       },
					    },

			      'bo1' => {-itemtype => 'tabbox',
					-coords => [[-240, -160], [240, 100]],
					-radius => 8,
					-tabwidth => 72,
					-tabheight => 28,
					-numpages => 8,
					-anchor => 'n',
					-alignment => 'left',
					-overlap => 3,
					-params => {-closed => 1,
						    -priority => 100,
						    -filled => 1,
						    -fillcolor => '#ffffff',
						    -linewidth => 1.2,
						    -linecolor => '#000000',
						    -tags => ['div2', 'divider'],
						   },
					-tabtitles => {-text => ['A', 'B', 'C', 'D', 'E', 'F','G','H'],
						       -params => {-text => 'titre',
								   -color => '#2222cc',
								   -font => $font_9b,
								   -anchor => 'center',
								   -alignment => 'center',
								   -priority => 400,
								   -visible => 1,
								  },
						      },
				       },

			       'back' => {-itemtype => 'roundedrectangle',
					  -coords => [[-242, -162], [242, 102]],
					  -radius => 10,
					  -params => {-closed => 1,
						      -filled => 1,
						      -fillcolor => '#777777;80',
						      -linewidth => 1,
						      -linecolor => '#777777;80',
						     },
					 },

			       'anchor' => {-itemtype => 'text',
					    -coords => [-120, 115],
					    -params => {-text => 'tabs anchor',
							-color => '#2222cc',
							-font => $font_9b,
							-anchor => 'center',
							-alignment => 'center',
							-priority => 40,
						       },
					   },

			       'anchorN' => {-itemtype => 'hippodrome',
					     -coords => [[-210, 125], [-165, 151]],
					     -params => {-closed =>