aboutsummaryrefslogtreecommitdiff
path: root/sandbox/zinc.tcl
blob: a798e3b8f779b039a028a8614bd1a7aa4807b347 (plain)
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
lappend auto_path .

package require Tkzinc
package require Img

set top 1

#memory info
#memory trace on
#memory validate on

image create photo logo -file logo.gif
image create photo logosmall -file logo.gif
#image create photo bois -file texture-bois1.xpm

#set r [zinc .r -backcolor gray -relief sunken -tile bois]
set r [zinc .r -backcolor gray -relief sunken]
pack .r -expand t -fill both
set scale 1.0
set centerX 0.0
set centerY 0.0
set zincWidth 800
set zincHeight 500
#.r configure -width $zincWidth -height $zincHeight
#.r configure -drawbboxes t
set view [.r add group $top -tags "controls"]

frame .rc
button .rc.up -text "Up" \
	-command {set centerY [expr $centerY+30.0]; updateTransform .r}
button .rc.down -text "Down" \
	-command {set centerY [expr $centerY-30.0]; updateTransform .r}
button .rc.left -text "Left" \
	-command {set centerX [expr $centerX+30.0]; updateTransform .r}
button .rc.right -text "Right" \
	-command {set centerX [expr $centerX-30.0]; updateTransform .r}
button .rc.expand -text "Expand" \
	-command {set scale [expr $scale*1.1]; updateTransform .r}
button .rc.shrink -text "Shrink" \
	-command {set scale [expr $scale*0.9]; updateTransform .r}
button .rc.reset -text "Reset" \
	-command {set scale 1.0; set centerX 0.0; set centerY 0.0; \
	updateTransform .r}
button .rc.quit -text "Quit" -command "exit"
grid .rc.up -row 0 -column 2 -sticky ew
grid .rc.down -row 2 -column 2 -sticky ew
grid .rc.left -row 1 -column 1
grid .rc.right -row 1 -column 3
grid .rc.expand -row 1 -column 4
grid .rc.shrink -row 1 -column 0
grid .rc.reset -row 1 -column 2 -sticky ew
grid .rc.quit -row 3 -column 2
pack .rc

bind .r <Configure> "ZincStyleConfig %W %w %h"

proc ZincStyleConfig {zinc w h} {
    global zincWidth zincHeight
    
    set bw [$zinc cget -borderwidth]
    set zincWidth [expr $w - 2*$bw]
    set zincHeight [expr $h - 2*$bw]
    updateTransform $zinc
}

proc updateTransform {zinc} {
    global zincWidth zincHeight
    global scale centerX centerY
    global top
    
    $zinc treset $top
    $zinc translate $top [expr -$centerX] [expr -$centerY]
    $zinc scale $top $scale $scale
    $zinc scale $top 1 -1
    $zinc translate $top [expr $zincWidth/2] [expr $zincHeight/2]
}

#
# TRACKS
#
set track [.r add track $view 6 -tags track -leaderanchors "|0|0"]
.r itemconfigure $track -position "1 1"
.r itemconfigure $track -position "10 10"
.r itemconfigure $track -position "20 20"
.r itemconfigure $track -position "30 30"
.r itemconfigure $track -position "40 40"
.r itemconfigure $track -position "50 50"
.r itemconfigure $track -position "55 60"
.r itemconfigure $track -position "60 70"
.r itemconfigure $track -speedvector "20 0"
.r itemconfigure $track -symbolcolor salmon -speedvectorcolor salmon -leadercolor salmon \
	 -labeldistance 20
.r itemconfigure $track -markersize 20 \
	 -filledmarker 1 \
	 -markerfillpattern AlphaStipple4 \
	 -markercolor salmon
.r itemconfigure $track -labelformat "120x40 l0l0+0+0 x80x20+0+0 x40x20+80+0 x40x20+0+20 x20x20>3>2 x60x20>1>1"
.r itemconfigure $track 0 -filled 1 -backcolor gray -bordercolor gray -relief groove
.r itemconfigure $track 1 -filled 1 -backcolor tan -bordercolor tan -relief groove \
	 -font "cenapii-etiquette-m17" -text "AFR451"
.r itemconfigure $track 2 -text "WPY" \
	 -font "cenapii-etiquette-m17"
.r itemconfigure $track 3 -text "400" -filled 1 -backcolor wheat \
	 -font "cenapii-etiquette-m17"
.r itemconfigure $track 4 -text "-" -filled 1 -backcolor wheat \
	 -font "cenapii-etiquette-m17"
.r itemconfigure $track 5 -text "450" -font "cenapii-etiquette-m17"

.r bind $track:speedvector <Enter> ".r itemconfigure $track -speedvectorcolor red"
.r bind $track:speedvector <Leave> ".r itemconfigure $track -speedvectorcolor salmon"

set track2 [.r add track $view 4 -speedvector "-20 0" \
	 -symbolcolor salmon  -speedvectorcolor salmon -leadercolor salmon \
	 -labeldx -20 -labeldy 20 -leaderanchors "%30x30" \
	 -historycolor MistyRose -lastasfirst t ]
.r itemconfigure $track2 -labelformat "a3f110+0+0 a3f110>0^0 a3f110^0>0 a3f110>2>0"
.r itemconfigure $track2 0 -filled 1 -backcolor tan -text "BAW452"
.r itemconfigure $track2 1 -filled 1 -backcolor wheat -text "450"
.r itemconfigure $track2 2 -filled 1 -backcolor wheat -text "KMC"
#.r itemconfigure $track2 3 -filled 1 -backcolor wheat -text ""
.r itemconfigure $track2 -connecteditem $track -connectioncolor green
.r itemconfigure $track2 -position "10 0"
.r itemconfigure $track2 -position "-20 10"
.r itemconfigure $track2 -position "-30 20"
.r itemconfigure $track2 -position "-40 30"
.r itemconfigure $track2 -position "-50 40"
.r itemconfigure $track2 -position "-60 50"
.r itemconfigure $track2 -position "-70 50"
.r itemconfigure $track2 -position "-80 50"
.r itemconfigure $track2 -position "-90 50"

#
# WAY POINTS
#
puts "creating way points"
set wp [.r add waypoint $view 1 -tags borders]
.r itemconfigure $wp -symbolcolor bisque -leadercolor bisque  -position "-100 120" \
	 -labelformat "40x20"
.r itemconfigure $wp 0 -bordercolor bisque -text "NCY" -tile logo -filled t
set wp2 [.r add waypoint $view 1 -tags borders]
.r itemconfigure $wp2 -symbolcolor bisque \
    -leadercolor bisque  \
    -position "50 160" \
    -labelformat "40x20" \
    -connectioncolor bisque \
    -connecteditem $wp
.r itemconfigure $wp2 0 -bordercolor bisque -text "MPW"
set wp3 [.r add waypoint $view 1 -tags borders]
.r itemconfigure $wp3 -symbolcolor bisque \
    -leadercolor bisque \
    -position "200 140" \
    -labelformat "40x20" \
    -connectioncolor bisque \
    -connecteditem $wp2
.r itemconfigure $wp3 0 -bordercolor bisque -text "ART"

#
# MACROS
#
puts "creating macros"
set macro [.r add tabular $view 10 -labelformat "x40x20+0+0 x40x20+40+0" \
	       -tags f0borders -connecteditem $track]
.r itemconfigure $macro 0 -text une
.r itemconfigure $macro 1 -text macro

#
# MINISTRIPS
#
puts "creating ministrips"
set ministrip [.r add tabular $view 1 \
	-labelformat "60x20" -position "10 10"]
.r itemconfigure $ministrip 0 -text "ministrip" -sensitive f
set ministrip2 [.r add tabular $view 1 \
	-labelformat "60x20" -connecteditem $ministrip]
.r itemconfigure $ministrip2 0 -text "ministrip2" -sensitive f
set ministrip3 [.r add tabular $view 1 \
	-labelformat "60x20" -connecteditem $ministrip2]
.r itemconfigure $ministrip3 0 -text "ministrip3" -sensitive f

#
# MAPS
#
puts "creating maps"
videomap load "/usr/share/toccata/maps/videomap_paris-w_90_2" 0 paris-w
videomap load "/usr/share/toccata/maps/videomap_orly" 17 orly
videomap load "/usr/share/toccata/maps/hegias_parouest_TE.vid" 0 paris-ouest

set map [.r add map $view -color darkblue]
.r itemconfigure $map -mapinfo orly

set map2 [.r add map $view -color darkblue -filled 1 -priority 0 -fillpattern AlphaStipple1]
.r itemconfigure $map2 -mapinfo paris-ouest

set map3 [.r add map $view -color orange]

mapinfo mpessai create
mapinfo mpessai add text normal simple 0 200 "Et voilà"
mapinfo mpessai add line simple 5 0 0 100 100
mapinfo mpessai add line simple 0 100 100 0 200
mapinfo mpessai add line simple 2  -100 100 0 0
.r itemconfigure $map3 -mapinfo mpessai

#
# Clip
#
puts "crée les clips"
set clip [.r add rectangle $view "-100 -100 300 200" -filled t \
	      -linewidth 0 -fillcolor darkgray -visible f]
#.r rotate $clip [expr 3.14159 / 4]
.r lower $clip
#.r itemconfigure $view -clip $clip

.r add rectangle $top "-5 -5 5 5"  -filled t -fillcolor red
set topclip [.r add rectangle $top "-400 -400 400 400" \
		 -filled t -fillcolor lightgray -linewidth 0 -visible t]
.r lower $topclip
#.r rotate $topclip [expr 3.14159 / 4]
#.r itemconfigure $top -clip $topclip

#
# CONTROLS
#
proc borders {onoff} {
    set part [.r currentpart]
    puts "part $part $onoff"
    set contour noborder
    if { $onoff == "on" } {
	set contour "contour oblique"
    }
    if { [regexp {^[0-9]+$} $part] } {
	.r itemconfigure current $part -border $contour
    }
}

.r bind borders <Enter> "borders on"
.r bind borders <Leave> "borders off"
.r bind f0borders:0 <Enter> "borders on"
.r bind f0borders:0 <Leave> "borders off"
.r bind track <Enter> {puts "Entre dans item"}
.r bind track <Leave> {puts "Sort d'item"}
.r bind track:0 <Enter> {puts "Entre dans champ 0"}
.r bind track:0 <Leave> {puts "Sort de champ 0"}
.r bind track:1 <Enter> {puts "Entre dans champ 1"}
.r bind track:1 <Leave> {puts "Sort de champ 1"}
.r bind track:2 <Enter> {puts "Entre dans champ 2"}
.r bind track:2 <Leave> {puts "Sort de champ 2"}
.r bind track:3 <Enter> {puts "Entre dans champ 3"}
.r bind track:3 <Leave> {puts "Sort de champ 3"}

bind .r <2> {puts "%x@%y, item: [.r find atpoint %x %y]"}

proc finditems {cornerx cornery} {
    global origx origy

    puts "--- enclosed ---"
    puts "++ [.r find enclosed $origx $origy $cornerx $cornery] ++"
    puts "--- overlapping ---"
    puts "++ [.r find overlapping $origx $origy $cornerx $cornery] ++"
    puts ""
}

bind .r <ButtonPress-1> "set origx %x; set origy %y"
bind .r <ButtonRelease-1> "finditems %x %y"

.r bind all <1> { if {! [catch {.r find withtag current} item] } { \
	puts "<1> in $item" } else { puts "None" } }

#
#for {set j 0} {$j < 20} {incr j} {
#    memory info
#    for {set i 0} {$i < 10} {incr i} {
#	 set a($i) [.r add icon 1 -image logo]
#	 set b($i) [.r add rectangle 1 "10 10 1000 1000" -filled t -tile logosmall]
#	 set c($i) [.r add curve 1 "10 10 10 100 100 100" -filled t -tile logosmall]
#    }
#    for {set i 0} {$i < 10} {incr i} {
#	 .r remove $a($i)
#	 .r remove $b($i)
#	 .r remove $c($i)
#    }
#}
    
source "controls.tcl"