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
|
############################################################################
#
# vibline.icn -- procedures for defining a line object
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
$include "vibdefn.icn"
##########################################################################
# line_obj:
# proc : name of user callback procedure
# v : vidget used for drawing line
# id : unique means of identifying instance
# x,y,w,h : bounding box
# x1,y1 : one endpoint
# y1,y2 : other endpoint
# focus : should focus lines be drawn around this object?
##########################################################################
record line_obj(v, proc, id, x, y, w, h, x1, y1, x2, y2, focus)
##########################################################################
# create_line() creates a line instance and draws the line if
# it is a first class object.
##########################################################################
procedure create_line(x1, y1, x2, y2)
local r, id
id := next_id("line")
r := line_obj(, "", "line" || id, , , , , x1, y1, x2, y2, 0)
r.v := Vline(APPWIN, x1, y1, x2, y2)
VInsert(ROOT, r.v, x1, y1)
VRemove(ROOT, r.v, 1)
update_line_bb(r)
return r
end
##########################################################################
# update_line_bb() updates various attributes of the line that
# change when the button is resized, etc.
##########################################################################
procedure update_line_bb(object)
if object.x1 < 0 then {
object.x2 -:= object.x1
object.x1 := 0
}
if object.x2 < 0 then {
object.x1 -:= object.x2
object.x2 := 0
}
if object.y1 < CANVASY then {
object.y2 -:= (object.y1 - CANVASY)
object.y1 := CANVASY
}
if object.y2 < CANVASY then {
object.y1 -:= (object.y2 - CANVASY)
object.y2 := CANVASY
}
object.x := minimum(object.x1, object.x2) - 2
object.y := minimum(object.y1, object.y2) - 2
object.w := abs(object.x1 - object.x2) + 4
object.h := abs(object.y1 - object.y2) + 4
end
##########################################################################
# draw_line() draws the given line object.
##########################################################################
procedure draw_line(r)
r.v.ax1 := r.x1
r.v.ay1 := r.y1
r.v.ax2 := r.x2
r.v.ay2 := r.y2
VDraw(r.v)
return r
end
##########################################################################
# outline_line() draws an outline for the given line. Outlines are
# used when the object is moved or resized.
##########################################################################
procedure outline_line(r)
DrawLine(XORWIN, r.x1, r.y1, r.x2, r.y2)
end
##########################################################################
# drag_line() is a special procedure for dragging line objects.
##########################################################################
procedure drag_line(r)
local xoff, yoff, x1, y1, dx, dy
x1 := r.x1
y1 := r.y1
dx := r.x2 - x1
dy := r.y2 - y1
xoff := x1 - &x
yoff := y1 - &y
DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
until Event(XORWIN) === (&lrelease | &mrelease | &rrelease) do {
DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
x1 := &x + xoff
y1 := &y + yoff
DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
}
DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
&x := r.x + x1 - r.x1
&y := r.y + y1 - r.y1
end
##########################################################################
# load_line() restores a line object from session code.
##########################################################################
procedure load_line(r, o)
r.x1 := o.x
r.y1 := o.y + CANVASY
r.x2 := o.w
r.y2 := o.h + CANVASY
r.v := Vline(APPWIN, r.x1, r.y1, r.x2, r.y2)
VInsert(ROOT, r.v, r.x1, r.y1)
VRemove(ROOT, r.v, 1)
end
##########################################################################
# save_line() augments the record for saving a line object.
##########################################################################
procedure save_line(r, o)
r.typ := "Line"
r.x := o.x1
r.y := o.y1 - CANVASY
r.w := o.x2
r.h := o.y2 - CANVASY
r.proc := &null
return
end
##########################################################################
# display_line_atts() displays the attribute sheet with the current
# attributes for the given line instance.
##########################################################################
procedure display_line_atts(object)
local t, dx, dy
t := table()
t["a_id"] := object.id
t["c_x1"] := object.x1
t["d_y1"] := object.y1 - CANVASY
t["e_x2"] := object.x2
t["f_y2"] := object.y2 - CANVASY
repeat {
if line_dialog(t) == "Cancel" then
fail
if illegal(t["a_id"], "ID", "s") |
illegal(t["c_x1"], "X1", "i") |
illegal(t["d_y1"], "Y1", "i") |
illegal(t["e_x2"], "X2", "i") |
illegal(t["f_y2"], "Y2", "i")
then
next
unfocus_object(object)
erase_object(object)
object.id := t["a_id"]
object.x1 := t["c_x1"]
object.y1 := t["d_y1"] + CANVASY
object.x2 := t["e_x2"]
object.y2 := t["f_y2"] + CANVASY
# can't just do a move_object() here: doesn't work for line changes
update_line_bb(object)
draw_canvas()
focus_object(object)
DIRTY := 1
break
}
end
#===<<vib:begin>>=== modify using vib; do not remove this marker line
procedure line_dialog(win, deftbl)
static dstate
initial dstate := dsetup(win,
["line_dialog:Sizer::1:0,0,350,138:",],
["_cancel:Button:regular::192,87,50,30:Cancel",],
["_okay:Button:regular:-1:127,86,50,30:Okay",],
["a_id:Text::40:13,14,318,19:ID: \\=",],
["c_x1:Text::3:13,42,59,19:x1: \\=",],
["d_y1:Text::3:81,42,59,19:y1: \\=",],
["e_x2:Text::3:204,42,59,19:x2: \\=",],
["f_y2:Text::3:272,42,59,19:y2: \\=",],
)
return dpopup(win, deftbl, dstate)
end
#===<<vib:end>>=== end of section maintained by vib
|