-
Notifications
You must be signed in to change notification settings - Fork 2
/
GAUGE.SC
204 lines (173 loc) · 3.57 KB
/
GAUGE.SC
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
;;;;
;;;; GAUGE.SC
;;;; (c) Sierra On-Line, Inc, 1988
;;;;
;;;; Author: Jeff Stephenson
;;;;
;;;; A class to display a thermometer-like gauge in a Dialog, allowing
;;;; the user to set a value.
;;;;
;;;; Classes:
;;;; Gauge
(script# GAUGE)
(define BLOCKON 6)
(define BLOCKOFF 7)
(local
textI
upI
downI
gaugeI
okI
normalI
noI
[str 40]
)
(class Gauge kindof Dialog
(properties
description 0 ;text to tell the user what to do
higher {up} ;text for the 'increase value' button
lower {down} ;text for the 'decrease value' button
normal 7 ;default value of quantity being set
minimum 0 ;minimum value of quantity being set
maximum 15 ;maximum value of quantity being set
)
(methods
update ;private -- used to update the display
)
(method (init value &tmp dx dy)
;; Set up the Gauge Dialog.
; give ourself the class SysWindow as our window
(= window SysWindow)
(self update:value)
((= downI (DButton new:))
text: lower,
moveTo: MARGIN MARGIN,
setSize:
)
(self add:downI, setSize:)
((= gaugeI (DText new:))
text:@str,
moveTo:(+ (downI nsRight?) MARGIN) MARGIN,
font:SYSFONT,
setSize:
)
(self add:gaugeI, setSize:)
((= upI (DButton new:))
text: higher,
moveTo:(+ (gaugeI nsRight?) MARGIN) MARGIN,
setSize:
)
(self add:upI, setSize:)
(+= nsBottom (* 2 MARGIN))
((= okI (DButton new:))
text: {OK},
setSize:,
moveTo: MARGIN nsBottom
)
((= normalI (DButton new:))
text: {Normal},
setSize:,
moveTo: (+ (okI nsRight?) MARGIN) nsBottom
)
((= noI (DButton new:))
text: {Cancel},
setSize:,
moveTo: (+ (normalI nsRight?) MARGIN) nsBottom
)
(self add:okI normalI noI, setSize:)
(= dx (- (- nsRight (noI nsRight?)) MARGIN))
((= textI (DText new:))
text: description,
font: smallFont,
setSize: (- nsRight (* 2 MARGIN)),
moveTo: MARGIN MARGIN
)
(= dy (+ (textI nsBottom?) MARGIN))
(self add:textI)
(upI move: 0 dy)
(downI move: 0 dy)
(gaugeI move: 0 dy)
(okI move: dx dy)
(normalI move: dx dy)
(noI move: dx dy)
(self setSize:, center:, open: wTitled 15)
)
(method (doit value &tmp i ret)
;; Display the Gauge and let the user set the value.
(self init:value)
(= ret value)
(repeat
(self update:ret)
(gaugeI draw:)
(= i (super doit: okI))
(cond
((== i upI)
;User wants to increase the value.
(if (< ret maximum)
(++ ret)
)
)
((== i downI)
;User wants to decrease the value.
(if (> ret minimum)
(-- ret)
)
)
((== i okI)
;Value is set. Return.
(break)
)
((== i normalI)
;Reset to value which is considered 'normal'.
(= ret normal)
)
((or (== i 0) (== i noI))
;Bail out, setting the value back to that which was in
;effect on entry.
(= ret value)
(break)
)
)
)
(self dispose:)
(return ret)
)
(method (update value &tmp i range)
;; Update the string which is the thermometer to reflect 'value'.
(= range (- maximum minimum))
(for ((= i 0))
(< i range)
((++ i))
(StrAt @str i (if (< i value) BLOCKON else BLOCKOFF))
)
)
(method (handleEvent event)
(switch (event type?)
(keyDown
(switch (event message?)
(LEFTARROW
(event claimed:TRUE)
(return downI)
)
(RIGHTARROW
(event claimed:TRUE)
(return upI)
)
)
)
(direction
(switch (event message?)
(dirW
(event claimed:TRUE)
(return downI)
)
(dirE
(event claimed:TRUE)
(return upI)
)
)
)
)
(return (super handleEvent:event))
)
)