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
|
############################################################################
#
# File: vstyle.icn
#
# Subject: Procedures for drawing buttons
#
# Authors: Jon Lipp and Gregg M. Townsend
#
# Date: August 14, 1996
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# Utility procedures in this file:
# Vset_style()
#
############################################################################
link imscolor
procedure Vset_style (vid, style)
style := integer(style) | case style of {
&null: V_RECT
"regular": V_RECT
"regularno": V_RECT_NO
"check": V_CHECK
"checkno": V_CHECK_NO
"circle": V_CIRCLE
"circleno": V_CIRCLE_NO
"diamond": V_DIAMOND
"diamondno": V_DIAMOND_NO
"xbox": V_XBOX
"xboxno": V_XBOX_NO
"image": V_IMAGE
"imageno": V_IMAGE_NO
default: _Vbomb("invalid style parameter")
}
vid.style := style
case style of {
V_RECT :
vid.D := Vstd_draw(draw_off_rect, draw_on_rect, init_rect)
V_CHECK :
vid.D := Vstd_draw(draw_off_check, draw_on_check, init_check)
V_CIRCLE :
vid.D := Vstd_draw(draw_off_circle, draw_on_circle, init_circle)
V_DIAMOND:
vid.D := Vstd_draw(draw_off_diamond, draw_on_diamond, init_diamond)
V_XBOX :
vid.D := Vstd_draw(draw_off_xbox, draw_on_xbox, init_xbox)
V_IMAGE :
vid.D := Vstd_draw(draw_off_image, draw_on_image, init_image)
V_RECT_NO : {
vid.D := Vstd_draw(draw_off_rect, draw_on_rect, init_rect)
vid.D.outline := 1
}
V_CHECK_NO : {
vid.D := Vstd_draw(draw_off_check, draw_on_check, init_check)
vid.D.outline := 1
}
V_CIRCLE_NO : {
vid.D := Vstd_draw(draw_off_circle, draw_on_circle, init_circle)
vid.D.outline := 1
}
V_DIAMOND_NO: {
vid.D := Vstd_draw(draw_off_diamond, draw_on_diamond, init_diamond)
vid.D.outline := 1
}
V_XBOX_NO : {
vid.D := Vstd_draw(draw_off_xbox, draw_on_xbox, init_xbox)
vid.D.outline := 1
}
V_IMAGE_NO : {
vid.D := Vstd_draw(draw_off_image, draw_on_image, init_image)
vid.D.outline := 1
}
default: _Vbomb("invalid style parameter")
}
end
procedure init_xbox(s)
# nothing to do
end
procedure draw_off_xbox(s)
if /s.D.outline then {
EraseArea(s.win, s.ax + 2, s.ay + 2, s.aw - 4, s.ah - 4)
BevelRectangle(s.win, s.ax, s.ay, s.aw, s.ah, 2)
}
else
EraseArea(s.win, s.ax, s.ay, s.aw, s.ah)
end
procedure draw_on_xbox(s)
WAttrib(s.win, "linewidth=2")
DrawSegment(s.win, s.ax + 4, s.ay + 4, s.ax + s.aw - 4, s.ay + s.ah - 4,
s.ax + s.aw - 4, s.ay + 4, s.ax + 4, s.ay + s.ah - 4)
WAttrib(s.win, "linewidth=1")
if /s.D.outline then
BevelRectangle(s.win, s.ax, s.ay, s.aw, s.ah, -2)
end
procedure init_rect(s)
local TW, FH, ascent, descent
/s.s := ""
TW := TextWidth(s.win, s.s)
ascent := WAttrib(s.win, "ascent")
descent := WAttrib(s.win, "descent")
FH := ascent + descent
/s.aw := TW + 8
/s.ah := FH + 8
s.aw := 0 < s.aw | 1
s.ah := 0 < s.ah | 1
s.D.basex := (s.aw - TW - 1) / 2
s.D.basey := (s.ah - FH) / 2 + ascent
end
procedure draw_off_rect(s)
EraseArea(s.win, s.ax, s.ay, s.aw, s.ah)
GotoXY(s.win, s.ax+s.D.basex, s.ay+s.D.basey)
writes(s.win, s.s)
if /s.D.outline then
BevelRectangle(s.win, s.ax, s.ay, s.aw, s.ah, 2)
end
procedure draw_on_rect(s)
FillRectangle(s.win, s.ax, s.ay, s.aw, s.ah)
WAttrib(s.win, "reverse=on")
GotoXY(s.win, s.ax+s.D.basex, s.ay+s.D.basey)
writes(s.win, s.s)
WAttrib(s.win, "reverse=off")
if /s.D.outline then
BevelRectangle(s.win, s.ax, s.ay, s.aw, s.ah, -2)
end
procedure init_check(s)
local FH, ascent, descent
/s.s := ""
s.D.space := 4
ascent := WAttrib(s.win, "ascent")
descent := WAttrib(s.win, "descent")
FH := ascent + descent
/s.ah := FH + 8
/s.aw := TextWidth(s.win, s.s) + FH + 3*s.D.space
s.aw := 0 < s.aw | 1
s.ah := 0 < s.ah | 1
s.D.basex := FH + 2*s.D.space
s.D.basey := (s.ah - FH)/2 + ascent
s.D.CS := FH
s.D.CP := (s.ah-s.D.CS)/2
end
procedure draw_off_check(s)
local sp, cp, cs, ax, ay
sp := s.D.space; cp := s.D.CP; cs := s.D.CS
ax := s.ax; ay := s.ay
BevelRectangle(s.win, ax+sp, ay+cp, cs, cs, 2)
EraseArea(s.win, ax+sp+2, ay+cp+2, cs-4, cs-4)
GotoXY(s.win, ax+s.D.basex, ay+s.D.basey)
writes(s.win, s.s)
if /s.D.outline then
GrooveRectangle(s.win, s.ax, s.ay, s.aw, s.ah)
end
procedure draw_on_check(s)
local sp, cs, cp, ax, ay
sp := s.D.space; cp := s.D.CP; cs := s.D.CS
ax := s.ax; ay := s.ay
BevelRectangle(s.win, ax+sp, ay+cp, cs, cs, -2)
FillRectangle(s.win, ax+sp+2, ay+cp+2, cs-4, cs-4)
GotoXY(s.win, ax+s.D.basex, ay+s.D.basey)
writes(s.win, s.s)
if /s.D.outline then
GrooveRectangle(s.win, s.ax, s.ay, s.aw, s.ah)
end
procedure init_circle(s)
local FH, ascent, descent
/s.s := ""
s.D.space := 4
ascent := WAttrib(s.win, "ascent")
descent := WAttrib(s.win, "descent")
FH := ascent + descent
/s.ah := FH + 8
/s.aw := TextWidth(s.win, s.s) + FH + 3*s.D.space
s.aw := 0 < s.aw | 1
s.ah := 0 < s.ah | 1
s.D.basex := FH + 2*s.D.space
s.D.basey := (s.ah -FH)/2 + ascent
s.D.CS := FH + 1
s.D.CP := (s.ah-s.D.CS)/2
end
procedure draw_off_circle(s)
local da, ax, ay, r
da := s.D
r := da.CS / 2 - 1
ax := s.ax
ay := s.ay
EraseArea(s.win, ax+da.space, ay+da.CP, da.CS, da.CS)
BevelCircle(s.win, ax+da.space+r, ay+da.CP+r, r, 2)
GotoXY(s.win, ax+da.basex, ay+da.basey)
writes(s.win, s.s)
if /da.outline then
GrooveRectangle(s.win, s.ax, s.ay, s.aw, s.ah)
end
procedure draw_on_circle(s)
local da, ax, ay, r
da := s.D
da := s.D
r := da.CS / 2 - 1
ax := s.ax
ay := s.ay
FillCircle(s.win, ax+da.space+r, ay+da.CP+r, r - 1)
BevelCircle(s.win, ax+da.space+r, ay+da.CP+r, r, -2)
GotoXY(s.win, ax+da.basex, ay+da.basey)
writes(s.win, s.s)
if /da.outline then
GrooveRectangle(s.win, s.ax, s.ay, s.aw, s.ah)
end
procedure init_diamond(s)
local FH, ascent, descent
/s.s := ""
s.D.space := 4
ascent := WAttrib(s.win, "ascent")
descent := WAttrib(s.win, "descent")
FH := ascent + descent
/s.ah := FH + 8
/s.aw := TextWidth(s.win, s.s) + FH + 3*s.D.space
s.aw := 0 < s.aw | 1
s.ah := 0 < s.ah | 1
s.D.basex := FH + 2*s.D.space
s.D.basey := (s.ah - FH)/2 + ascent
s.D.CS := FH + 1
s.D.CP := (s.ah-s.D.CS)/2
end
procedure draw_off_diamond(s)
local sp, cp, cs, ax, ay, r
sp := s.D.space; cp := s.D.CP; cs := s.D.CS
ax := s.ax; ay := s.ay
r := cs / 2
EraseArea(s.win, ax+sp, ay+cp, cs, cs)
BevelDiamond(s.win, ax+sp+r, ay+cp+r, r, 2)
GotoXY(s.win, ax+s.D.basex, ay+s.D.basey)
writes(s.win, s.s)
if /s.D.outline then
GrooveRectangle(s.win, s.ax, s.ay, s.aw, s.ah)
end
procedure draw_on_diamond(s)
local sp, cs, cp, ax, ay, r
sp := s.D.space; cp := s.D.CP; cs := s.D.CS
ax := s.ax; ay := s.ay
r := cs / 2
BevelDiamond(s.win, ax+sp+r, ay+cp+r, r, -2)
FillDiamond(s.win, ax+sp+r, ay+cp+r, r - 2)
GotoXY(s.win, ax+s.D.basex, ay+s.D.basey)
writes(s.win, s.s)
if /s.D.outline then
GrooveRectangle(s.win, s.ax, s.ay, s.aw, s.ah)
end
# undocumented image button code from Lorne Foss & Clint Jeffery, UTSA
#
# If type = V_IMAGE | V_IMAGE_NO, button string is used as image source.
# If it contains a comma, it's a DrawImage string.
# If not, it's the name of a GIF file in the current directory.
# Size is determined by the GIF or DrawImage image.
procedure init_image(s)
local imagefile
imagefile := s.s
if string(s.s) then {
if not find(",", s.s) then {
s.s := WOpen("canvas=hidden","image="||imagefile) |
_Vbomb("can't initialize button image from file " || s.s)
s.aw := WAttrib(s.s,"width")
s.ah := WAttrib(s.s,"height")
}
else {
s.aw := imswidth(s.s)
s.ah := imsheight(s.s)
if /s.aw | /s.ah then
_Vbomb("illegal DrawImage string for button")
}
if /s.D.outline then {
s.aw +:= 4
s.ah +:= 4
}
}
end
procedure draw_on_image(s)
draw_image_helper(s, -2, FillRectangle)
end
procedure draw_off_image(s)
draw_image_helper(s, 2, EraseArea)
end
procedure draw_image_helper(s, bevel, bgproc)
local b
static type
initial type := proc("type", 0) # protect attractive name
if /s.D.outline then {
BevelRectangle(s.win, s.ax, s.ay, s.aw, s.ah, bevel)
b := abs(bevel)
}
else
b := 0
if type(s.s) == "window" then
CopyArea(s.s, s.win, 0, 0, s.aw, s.ah, s.ax + b, s.ay + b)
else {
bgproc(s.win, s.ax + b, s.ay + b, s.aw - 2 * b, s.ah - 2 * b)
DrawImage(s.win, s.ax + b, s.ay + b, s.s)
}
end
|