-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreen.spin2
179 lines (138 loc) · 4.05 KB
/
Screen.spin2
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
{Screen Object}
CON
MAX_WIDGETS = 10 'Max buttons per window (9 windows total)
VAR
'Attributes
long bg_color 'background color
long fg_color 'foreground color
long ol_color 'outline = border
word xtop
word ytop
word xbot
word ybot
byte border_width
byte invert_border
long event_coordinates 'word[0]=x word[1]=y
long my_event_handler
byte id
byte enabled
long background_image_pointer
'Widgets method pointers
LONG widget_enable_method[MAX_WIDGETS]
LONG widget_draw_method[MAX_WIDGETS]
LONG widget_check_event_method[MAX_WIDGETS]
LONG widget_counter
OBJ
util : "Utilities"
graphics : "Graphics"
background_image : "Image"
PUB null()
''+--------------------------------------------------------------------+
'' WIDGET INTERFACE METHODS
''+--------------------------------------------------------------------+
PUB set_enable(e):w
if e
enabled := true
else
enabled := false
{
Commented because when screen is not enabled, it doesn't pass the event
to its children. Hence there is no need to enable or disable all at once
since it prevents individual manipulation of children widgets.
if widget_counter > 0
repeat w from 0 to widget_counter-1
widget_enable_method[w](enabled)
}
{
Uncommented, because besides the event handling, there is the issue of
when a contained widget is updating it could draw over a different
screen.
}
if widget_counter > 0
repeat w from 0 to widget_counter-1
widget_enable_method[w](enabled)
PUB draw()| w
if enabled
if background_image_pointer
graphics.send_image(background_image_pointer,xtop,ytop,xbot-xtop,ybot-ytop)
else
graphics.fill_rectangle(xtop,ytop,xbot,ybot,bg_color)
'BORDER
util.draw_border(xtop,ytop,xbot,ybot,ol_color,border_width,invert_border)
if widget_counter > 0
repeat w from 0 to widget_counter-1
widget_draw_method[w]()
PUB check_event(coord):is_mine | x, y, i
if enabled
x := coord.WORD[0]
y := coord.WORD[1]
'debug("Screen pre-coords", udec(x), udec(y))
if (x >= xtop AND x <= xbot) AND (y >= ytop AND y <= ybot)
is_mine := true
event_coordinates := coord
'debug("Screen ", udec(x), udec(y))
if widget_counter > 0
repeat i from 0 to widget_counter-1
if widget_check_event_method[i](event_coordinates):1
quit
PUB set_background_image(imagePtr)
background_image_pointer := imagePtr
''+--------------------------------------------------------------------+
'' CONFIGURATION METHODS
''+--------------------------------------------------------------------+
PUB configure(s, xt, yt, w, h, bg, fg, ol)
id := s
xtop := xt
ytop := yt
xbot := w + xt 'xb
ybot := h + yt 'yb
bg_color := bg
fg_color := fg
ol_color := ol
background_image.set_image(background_image_pointer, w, h)
background_image.configure(0,xt,yt,bg_color,fg_color,ol_color)
border_width := 1
invert_border := false
PUB set_id(i)
id := i
PUB is_enabled():e
e := enabled
PUB set_bg_color(color)
bg_color := color
PUB set_fg_color(color)
fg_color := color
PUB set_ol_color(color)
ol_color := color
PUB get_bg_color():bg
bg := bg_color
PUB get_fg_color():fg
fg := fg_color
PUB get_ol_color():ol
ol := ol_color
PUB set_ys(yt,yb)
ytop := yt
ybot := yb
PUB set_xs(xt,xb)
xtop := xt
xbot := xb
PUB set_coordinates(xt, yt, xb, yb)
xtop := xt
ytop := yt
xbot := xb
ybot := yb
PUB get_coordinates() : xt, yt, xb, yb
xt := xtop
yt := ytop
xb := xbot
yb := ybot
PUB set_border_width(bw)
border_width := bw
''+--------------------------------------------------------------------+
'' CONTAINER INTERFACE METHODS
''+--------------------------------------------------------------------+
PUB add_widget(enable_pointer, draw_pointer, check_event_pointer)
if widget_counter <= MAX_WIDGETS-1
widget_enable_method[widget_counter] := enable_pointer
widget_draw_method[widget_counter] := draw_pointer
widget_check_event_method[widget_counter] := check_event_pointer
widget_counter++