OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [demos/] [samples/] [ArrowBtn.tcl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Tix Demostration Program
2
#
3
# This sample program is structured in such a way so that it can be
4
# executed from the Tix demo program "widget": it must have a
5
# procedure called "RunSample". It should also have the "if" statment
6
# at the end of this file so that it can be run as a standalone
7
# program using tixwish.
8
 
9
# This file demonstrates how to write a new Tix widget class.
10
#
11
 
12
# ArrowBtn.tcl --
13
#
14
#       Arrow Button: a sample Tix widget.
15
#
16
set arrow(n) [image create bitmap -data {
17
    #define up_width 15
18
    #define up_height 15
19
    static unsigned char up_bits[] = {
20
        0x80, 0x00, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x1f,
21
        0xfe, 0x3f, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
22
        0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
23
}]
24
set arrow(w) [image create bitmap -data {
25
    #define left_width 15
26
    #define left_height 15
27
    static unsigned char left_bits[] = {
28
        0x00, 0x00, 0x40, 0x00, 0x60, 0x00, 0x70, 0x00, 0x78, 0x00, 0x7c, 0x00,
29
        0xfe, 0x3f, 0xff, 0x3f, 0xfe, 0x3f, 0x7c, 0x00, 0x78, 0x00, 0x70, 0x00,
30
        0x60, 0x00, 0x40, 0x00, 0x00, 0x00};
31
}]
32
set arrow(s) [image create bitmap -data {
33
    #define down_width 15
34
    #define down_height 15
35
    static unsigned char down_bits[] = {
36
        0x00, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
37
        0xc0, 0x01, 0xc0, 0x01, 0xfe, 0x3f, 0xfc, 0x1f, 0xf8, 0x0f, 0xf0, 0x07,
38
        0xe0, 0x03, 0xc0, 0x01, 0x80, 0x00};
39
}]
40
set arrow(e) [image create bitmap -data {
41
    #define right_width 15
42
    #define right_height 15
43
    static unsigned char right_bits[] = {
44
        0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f,
45
        0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0x3f, 0x00, 0x1f, 0x00, 0x0f, 0x00, 0x07,
46
        0x00, 0x03, 0x00, 0x01, 0x00, 0x00};
47
}]
48
 
49
tixWidgetClass tixArrowButton {
50
    -classname  TixArrowButton
51
    -superclass tixPrimitive
52
    -method {
53
        flash invoke invert
54
    }
55
    -flag {
56
        -direction -state
57
    }
58
    -configspec {
59
        {-direction direction Direction e tixArrowButton:CheckDirection}
60
        {-state state State normal}
61
    }
62
    -alias {
63
        {-dir -direction}
64
    }
65
}
66
 
67
proc tixArrowButton:InitWidgetRec {w} {
68
    upvar #0 $w data
69
 
70
    tixChainMethod $w InitWidgetRec
71
    set data(count) 0
72
}
73
 
74
proc tixArrowButton:ConstructWidget {w} {
75
    upvar #0 $w data
76
    global arrow
77
 
78
    tixChainMethod $w ConstructWidget
79
 
80
    set data(w:button) [button $w.button -image $arrow($data(-direction))]
81
    pack $data(w:button) -expand yes -fill both
82
}
83
 
84
proc tixArrowButton:SetBindings {w} {
85
    upvar #0 $w data
86
 
87
    tixChainMethod $w SetBindings
88
 
89
    bind $data(w:button) <1> "tixArrowButton:IncrCount $w"
90
}
91
 
92
proc tixArrowButton:IncrCount {w} {
93
    upvar #0 $w data
94
 
95
    incr data(count)
96
}
97
 
98
proc tixArrowButton:CheckDirection {dir} {
99
    if {[lsearch {n w s e} $dir] != -1} {
100
        return $dir
101
    } else {
102
        error "wrong direction value \"$dir\""
103
    }
104
}
105
 
106
proc tixArrowButton:flash {w} {
107
    upvar #0 $w data
108
 
109
    $data(w:button) flash
110
}
111
 
112
proc tixArrowButton:invoke {w} {
113
    upvar #0 $w data
114
 
115
    $data(w:button) invoke
116
}
117
 
118
proc tixArrowButton:invert {w} {
119
    upvar #0 $w data
120
 
121
    set curDirection $data(-direction)
122
    case $curDirection {
123
        n {
124
            set newDirection s
125
        }
126
        s {
127
            set newDirection n
128
        }
129
        e {
130
            set newDirection w
131
        }
132
        w {
133
            set newDirection e
134
        }
135
    }
136
    $w config -direction $newDirection
137
}
138
 
139
proc tixArrowButton:config-direction {w value} {
140
    upvar #0 $w data
141
    global arrow
142
 
143
    $data(w:button) configure -image $arrow($value)
144
}
145
 
146
proc tixArrowButton:config-state {w value} {
147
    upvar #0 $w data
148
    global arrow
149
 
150
    $data(w:button) configure -state $value
151
}
152
 
153
#----------------------------------------------------------------------
154
#
155
# Instantiate several widgets of the tixArrowButton class
156
#
157
#----------------------------------------------------------------------
158
 
159
proc RunSample {w} {
160
    set top [frame $w.top -border 1 -relief raised]
161
    tixArrowButton $top.a -dir w
162
    tixArrowButton $top.b -dir e
163
 
164
    pack $top.a $top.b -side left -expand yes -fill both -padx 50 -pady 10
165
 
166
    tixButtonBox $w.box -orientation horizontal
167
    $w.box add ok     -text Ok     -underline 0 -command "destroy $w" \
168
        -width 6
169
 
170
    pack $w.box -side bottom -fill x
171
    pack $w.top -side top -fill both -expand yes
172
}
173
 
174
# This "if" statement makes it possible to run this script file inside or
175
# outside of the main demo program "widget".
176
#
177
if {![info exists tix_demo_running]} {
178
    wm withdraw .
179
    set w .demo
180
    toplevel $w
181
    RunSample $w
182
    bind .demo <Destroy> "exit"
183
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.