aboutsummaryrefslogtreecommitdiff
path: root/demos/items.tcl
blob: 8468f6a0dba2113e8501deac6c52329db096af33 (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
# $Id: items.tcl 1465 2004-05-07 10:51:56Z lecoanet $
# tcl version by Jean-Paul Imbert imbert@cena.fr

if {![info exists zincDemo]} {
    error "This script should be run from the zinc-widget demo."
}

namespace eval allItems {
    variable w .items
    catch {destroy $w}
    toplevel $w
    wm title $w "Zinc Item Demonstration"
    wm iconname $w Items
    
    variable defaultfont [font create -family Helvetica -size 10 -weight bold]
    
    grid [button $w.dismiss -text Dismiss -command "destroy $w"] -row 2 -column 0 -pady 10
    grid [button $w.code -text "See Code" -command "showCode $w"] -row 2 -column 1 -pady 10

    scrollbar $w.vscroll -command "$w.zinc yview"
    grid $w.vscroll -row 0 -column 2 -sticky ns
    scrollbar $w.hscroll -orient horiz -command "$w.zinc xview"
    grid $w.hscroll -row 1 -column 0 -columnspan 2 -sticky we

    zinc $w.zinc -width 700 -height 600 -scrollregion {-100 0 1000 1000} \
	-xscrollcommand "$w.hscroll set" \
	-yscrollcommand "$w.vscroll set" \
	-font 10x20 -borderwidth 3 -relief sunken
    grid $w.zinc -row 0 -column 0 -columnspan 2 -sticky news
    grid columnconfigure $w 0 -weight 1
    grid columnconfigure $w 1 -weight 1
    grid rowconfigure $w 0 -weight 2

    $w.zinc add rectangle 1 {10 10 100 50} -fillcolor green -filled 1 -linewidth 10 \
	-relief roundridge -linecolor darkgreen


    $w.zinc add text 1 -font $defaultfont -anchor nw -position {120 20} \
	-text {A filled rectangle with a "roundridge" relief border of 10 pixels.}

    variable labelformat {x82x60+0+0 x60a0^0^0 x32a0^0>1 a0a0>2>1 x32a0>3>1 a0a0^0>2};

    variable x 20;
    variable y 120;
    variable track [$w.zinc add track 1 6 -labelformat $labelformat -position "$x $y" \
		   -speedvector {40 -10} -speedvectormark 1 -speedvectorticks 1]

    # moving the track, to display past positions
    for {set i 0} {$i<=5} {incr i} { 
	set x1 [expr $x+$i*10]
	set y1 [expr $y-$i*2]
	$w.zinc coords "$track" "$x1 $y1" 
    }

    $w.zinc add text 1 -font $defaultfont -anchor nw -position {200 80} \
	-text "A flight track for a radar display. A waypoint looks similar,
but has no speed vector and no past positions."

    $w.zinc itemconfigure $track 0 -filled 0 -bordercolor DarkGreen -border contour

    $w.zinc itemconfigure $track 1 -filled 1 -backcolor gray60 -text AFR001
    $w.zinc itemconfigure $track 2 -filled 0 -backcolor gray65 -text 360
    $w.zinc itemconfigure $track 3 -filled 0 -backcolor gray65 -text /
    $w.zinc itemconfigure $track 4 -filled 0 -backcolor gray65 -text 410
    $w.zinc itemconfigure $track 5 -filled 0 -backcolor gray65 -text Beacon


    $w.zinc add arc 1 {150 140 450 240} -fillcolor gray20 -filled 0 -linewidth 1 \
	-startangle 45 -extent 270
    $w.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

    $w.zinc add text 1 -font $defaultfont -anchor nw -position {320 180} \
	-text {Two arcs, starting at 45° with an extent of 270°}


    $w.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 

    $w.zinc add text 1 -font $defaultfont -text {An open curve} -anchor nw -position {50 350}

    $w.zinc add text 1 -font $defaultfont -text {A waypoint} -anchor nw -position {10 480}

    variable waypoint [$w.zinc add waypoint 1 6 -position {100 520} -labelformat $labelformat \
		      -symbol AtcSymbol2 -labeldistance 30] 

    for {set fieldId 1} {$fieldId<=5} {incr fieldId} {
	$w.zinc itemconfigure $waypoint $fieldId -filled 0 -bordercolor DarkGreen \
	    -border contour -text "field$fieldId"
    }


    $w.zinc add text 1 -font $defaultfont -anchor nw -position {510 380} \
	-text "3 tabulars of 2 fields,\nattached together."

    variable labelformat2 {x72x40 x72a0^0^0 x34a0^0>1}

    variable tabular1 [$w.zinc add tabular 1 6 -position {570 250} -labelformat $labelformat2]
    variable tabular2 [$w.zinc add tabular 1 6 -connecteditem $tabular1 -labelformat $labelformat2]
    variable tabular3 [$w.zinc add tabular 1 6 -connecteditem $tabular2 -labelformat $labelformat2]

    variable count 1

    foreach tab "$tabular1 $tabular2 $tabular3" {
	$w.zinc itemconfigure $tab 1 -filled 0 -bordercolor DarkGreen -border contour -text tabular
	$w.zinc itemconfigure $tab 2 -filled 0 -bordercolor DarkGreen -border contour -text "n°$count"
	incr count
    }


    $w.zinc add reticle 1 -position {530 550} -firstradius 20 -numcircles 6 \
	-period 2 -stepsize 20 -brightlinestyle dashed -brightlinecolor darkred

    $w.zinc add text 1 -font $defaultfont -text {a reticle with 6 circles} \
	-anchor nw -position {530 540}

    bind $w.zinc <ButtonPress-1> "::allItems::press $w.zinc motion %x %y"
    bind $w.zinc <ButtonRelease-1> "::allItems::release $w.zinc"

    variable curX 0
    variable curY 0

    proc press {z action x y} {
	variable curX
	variable curY

	set curX $x
	set curY $y
	bind $z <Motion> "::allItems::$action $z %x %y"
    }

    proc motion {z x y} {
	variable curX
	variable curY

	$z translate current [expr $x - $curX] [expr $y - $curY]
	set curX $x
	set curY $y
    }

    proc release {z} {
	bind $z <Motion> {}
    }
}