add window management
|
1 |
var pageClass = { |
2 |
new : func (d) { |
|
3 |
var m = { parents : [pageClass] }; |
|
fix issue #2
|
4 |
m.page = d.display.display.createGroup().set('z-index', 100); |
add window management
|
5 |
m.window = {}; |
6 |
m.state = {}; |
|
7 |
m.selected = ''; |
|
8 |
return m; |
|
9 |
}, |
|
10 | ||
11 |
del : func (id = nil) { |
|
fixes some bugs in windows
|
12 |
if (id != nil and typeof(id) == 'scalar') { |
add window management
|
13 |
delete(me.state, id); |
fix deletion of specific win...
|
14 |
var _id = id ~ '-'; |
15 |
id = []; |
|
16 |
foreach (var w; keys(me.window)) |
|
17 |
if (find(_id, w) == 0) |
|
18 |
append(id, w); |
|
add window management
|
19 |
} |
20 |
else { |
|
21 |
foreach (var s; keys(me.state)) |
|
22 |
delete(me.state, s); |
|
23 |
id = keys(me.window); |
|
24 |
} |
|
25 |
foreach (var w; id) { |
|
26 |
me.window[w] |
|
27 |
.hide() |
|
28 |
.del(); |
|
29 |
delete(me.window, w); |
|
30 |
} |
|
31 |
}, |
|
32 | ||
33 |
_selected_text : func (id, text, x, y) { |
|
34 |
me.selected = id; |
|
35 |
me.window[id] |
|
36 |
.setFontSize(16) |
|
37 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
38 |
.setTranslation(x, y) |
|
inverted color... the come b...
|
39 |
.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX) |
add window management
|
40 |
.setText(text) |
inverted color... the come b...
|
41 |
.setColorFill(0,1,1) |
42 |
.setColor(0,0,0); |
|
add window management
|
43 |
}, |
44 | ||
45 |
_editable_text : func (id, text, x, y) { |
|
46 |
me.window[id] |
|
47 |
.setFontSize(16) |
|
48 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
49 |
.setTranslation(x, y) |
|
inverted color... the come b...
|
50 |
.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX) |
add window management
|
51 |
.setText(text) |
52 |
.setColorFill(0,0,0) |
|
53 |
.setColor(0,1,1); |
|
54 |
}, |
|
55 | ||
56 |
_normal_text : func (id, text, x, y) { |
|
57 |
me.window[id] |
|
58 |
.setFontSize(16) |
|
59 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
60 |
.setTranslation(x, y) |
|
61 |
.setText(text) |
|
62 |
.setColorFill(0,0,0) |
|
63 |
.setColor(1,1,1); |
|
64 |
}, |
|
65 | ||
66 |
_title_text : func (id, text, x, y) { |
|
67 |
me.window[id] |
|
68 |
.setFontSize(16) |
|
69 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
70 |
.setTranslation(x, y) |
|
71 |
.setAlignment('center-center') |
|
72 |
.setText(text) |
|
73 |
.setColorFill(0,0,0) |
|
74 |
.setColor(0,1,1); |
|
75 |
}, |
|
76 | ||
changes about how to fill wi...
|
77 |
fill : func (id, scroll = nil) { |
add window management
|
78 |
var state = me.state[id]; |
changes about how to fill wi...
|
79 |
state.scroll = { |
80 |
offset : 0, # offset between canvas element and state element |
|
81 |
last : 9999, # last scrollgroup |
|
82 |
begin: -9999, # first canvas element of the scrolling area |
|
83 |
end: 9999, # last canvas element of the scrolling area |
|
84 |
upper: -9999, # group printed on the top of the scrolling area |
|
85 |
lower: 9999, # group printed at the bottom of the scrolling area |
|
fixes some bugs in windows
|
86 |
lines : scroll != nil ? scroll.lines : 0, # number of lines for the scrolling area |
87 |
columns : scroll != nil ? scroll.columns : 0, # number of objects on each scrolling lines |
|
changes about how to fill wi...
|
88 |
}; |
89 |
var scrollgroup = {}; |
|
90 |
forindex (var line; state.objects) { |
|
91 |
if (find('separator', state.objects[line].type) > -1) { |
|
92 |
me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('path') |
|
add window management
|
93 |
.setStrokeLineWidth(1) |
94 |
.moveTo(state.x_base, state.geometry.y - 12) |
|
95 |
.horiz(state.geometry.w - 20) |
|
96 |
.setColor(1,1,1); |
|
97 |
state.geometry.x = state.x_base; |
|
98 |
state.geometry.y += 8; |
|
99 |
} |
|
100 |
else { |
|
changes about how to fill wi...
|
101 |
if (contains(state.objects[line], 'scrollgroup')) { |
102 |
state.scroll.last = state.objects[line].scrollgroup; |
|
103 |
scrollgroup[state.objects[line].scrollgroup] = 1; |
|
104 |
if (state.scroll.begin == -9999) { |
|
105 |
state.scroll.begin = line; |
|
106 |
state.scroll.upper = state.objects[line].scrollgroup; |
|
107 |
} |
|
108 |
if (size(keys(scrollgroup)) > state.scroll.lines) { |
|
109 |
if (state.scroll.end == 9999) { |
|
110 |
state.scroll.end = line - 1; |
|
111 |
state.scroll.lower = state.objects[line - 1].scrollgroup; |
|
112 |
} |
|
113 |
else |
|
114 |
state.scroll.last = state.objects[line].scrollgroup; |
|
115 |
state.scroll.offset += 1; |
|
116 |
continue; |
|
117 |
} |
|
118 |
} |
|
119 |
me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('text'); |
|
type normal for text is defa...
|
120 |
if (find('selected', state.objects[line].type) > -1) |
add window management
|
121 |
me._selected_text( |
changes about how to fill wi...
|
122 |
id ~ '-' ~ (line - state.scroll.offset), |
123 |
state.objects[line].text, |
|
add window management
|
124 |
state.geometry.x, |
125 |
state.geometry.y, |
|
126 |
); |
|
127 | ||
adds type highlighted
|
128 |
elsif (find('editable', state.objects[line].type) > -1 |
129 |
or find('highlighted', state.objects[line].type) > -1) |
|
add window management
|
130 |
me._editable_text( |
changes about how to fill wi...
|
131 |
id ~ '-' ~ (line - state.scroll.offset), |
132 |
state.objects[line].text, |
|
add window management
|
133 |
state.geometry.x, |
134 |
state.geometry.y, |
|
135 |
); |
|
136 | ||
changes about how to fill wi...
|
137 |
elsif (find('title', state.objects[line].type) > -1) |
add window management
|
138 |
me._title_text( |
changes about how to fill wi...
|
139 |
id ~ '-' ~ (line - state.scroll.offset), |
140 |
state.objects[line].text, |
|
add window management
|
141 |
state.x_base - 10 + state.geometry.w / 2, |
142 |
state.geometry.y |
|
143 |
); |
|
144 | ||
type normal for text is defa...
|
145 |
else |
146 |
me._normal_text( |
|
147 |
id ~ '-' ~ (line - state.scroll.offset), |
|
148 |
state.objects[line].text, |
|
149 |
state.geometry.x, |
|
150 |
state.geometry.y, |
|
151 |
); |
|
152 | ||
153 | ||
changes about how to fill wi...
|
154 |
if (find('end-of-line', state.objects[line].type) > -1 |
155 |
or find('title', state.objects[line].type) > -1) { |
|
add window management
|
156 |
state.geometry.x = state.x_base; |
157 |
state.geometry.y += 24; |
|
158 |
} |
|
159 |
else |
|
changes about how to fill wi...
|
160 |
state.geometry.x += size(state.objects[line].text) * 10 + 8; |
add window management
|
161 |
} |
162 |
} |
|
changes about how to fill wi...
|
163 |
# reset the scrolling offset before the first move |
164 |
state.scroll.offset = 0; |
|
add window management
|
165 |
}, |
166 |
|
|
simplifies draw call
|
167 |
draw : func (id, geometry, objects = nil, scroll = nil) { |
168 |
if (typeof(geometry) == 'vector') { |
|
169 |
if (typeof(objects) == 'hash') |
|
170 |
scroll = objects; |
|
171 |
objects = geometry; |
|
172 |
geometry = {autogeom: 1}; |
|
173 |
} |
|
174 | ||
add window management
|
175 |
if (contains(me.window, id ~ '-bg')) { |
printlog deprecated + consta...
|
176 |
logprint(LOG_DEBUG, 'objet ' ~ id ~ ' already exists'); |
add window management
|
177 |
return; |
178 |
} |
|
add auto config geometry for...
|
179 |
if (!contains(geometry, 'sep')) |
180 |
geometry.sep = 0; |
|
181 |
if (contains(geometry, 'autogeom') and geometry.autogeom) { |
|
182 |
# 1024x768 display |
|
183 |
# - let 10 from the border |
|
184 |
# - plus other 10 from the window border and the text |
|
185 |
# - font size tends to be 10x24 |
|
186 |
# - let 8+8 around the separator |
|
fix count of lines
|
187 |
var textWidth = 0; |
add auto config geometry for...
|
188 |
var lines = 0; |
fix count of lines
|
189 |
var _textWidth = 0; |
add auto config geometry for...
|
190 |
forindex (var o; objects) { |
fix count of lines
|
191 |
if (find('end-of-line', objects[o].type) > -1) { |
improve autogeom
|
192 |
if (scroll != nil and contains(scroll, 'lines')) { |
fix count of lines
|
193 |
if (contains(objects[o], 'scrollgroup')) { |
improve autogeom
|
194 |
if (objects[o].scrollgroup < scroll.lines) |
195 |
lines += 1; |
|
fix count of lines
|
196 |
_textWidth += size(objects[o].text) * 10; |
197 |
if (_textWidth > textWidth) textWidth = _textWidth; |
|
198 |
_textWidth = 0; |
|
199 |
} |
|
200 |
else { |
|
201 |
lines += 1; |
|
202 |
_textWidth += size(objects[o].text) * 10; |
|
203 |
if (_textWidth > textWidth) textWidth = _textWidth; |
|
204 |
_textWidth = 0; |
|
205 |
} |
|
improve autogeom
|
206 |
} |
fix count of lines
|
207 |
else { |
improve autogeom
|
208 |
lines += 1; |
fix count of lines
|
209 |
_textWidth += size(objects[o].text) * 10; |
210 |
if (_textWidth > textWidth) textWidth = _textWidth; |
|
211 |
_textWidth = 0; |
|
212 |
} |
|
add auto config geometry for...
|
213 |
} |
fix count of lines
|
214 |
elsif (objects[o].type == 'title') { |
215 |
lines += 1; |
|
216 |
_textWidth = size(objects[o].text) * 10; |
|
217 |
if (_textWidth > textWidth) textWidth = _textWidth; |
|
218 |
_textWidth = 0; |
|
219 |
} |
|
220 |
elsif (objects[o].type != 'separator') { |
|
221 |
_textWidth += size(objects[o].text) * 10; |
|
222 |
} |
|
223 | ||
add auto config geometry for...
|
224 |
if (contains(objects[o], 'type') and objects[o].type == 'separator') |
225 |
geometry.sep += 1; |
|
226 |
} |
|
fix count of lines
|
227 |
if (!contains(geometry, 'l')) geometry.l = lines; |
228 |
if (!contains(geometry, 'x')) geometry.x = 1014 - textWidth; |
|
229 |
if (!contains(geometry, 'y')) geometry.y = 758 - (lines * 24) - 72; # 72 = offset from bottom to let softkeys display and margin |
|
add auto config geometry for...
|
230 |
if (!contains(geometry, 'w')) geometry.w = textWidth; |
231 |
} |
|
add window management
|
232 |
if (!contains(geometry, 'h') and !contains(geometry, 'l')) { |
printlog deprecated + consta...
|
233 |
logprint(LOG_DEBUG, 'missing parameter l or h'); |
add window management
|
234 |
return; |
235 |
} |
|
add auto config geometry for...
|
236 | |
fixes some bugs in windows
|
237 |
var save_x = geometry.x; |
238 |
var save_y = geometry.y; |
|
add auto config geometry for...
|
239 |
if (!geometry.sep) |
240 |
geometry.sep = 1; |
|
add window management
|
241 |
me.state[id] = { |
changes about how to fill wi...
|
242 |
objects: objects, |
add window management
|
243 |
geometry: geometry, |
244 |
x_base : geometry.x + 10, |
|
245 |
h_max : contains(geometry, 'h') ? h : geometry.l * 24 + 8 + geometry.sep * 16, |
|
246 |
}; |
|
add auto config geometry for...
|
247 | |
248 |
logprint(LOG_DEBUG, sprintf('geom id: %s, x: %d, y: %d, w: %d, h: %d, l: %d, sep: %d', |
|
249 |
id, geometry.x, geometry.y, geometry.w, me.state[id].h_max, geometry.l, geometry.sep)); |
|
add window management
|
250 |
me.state[id].y_max = me.state[id].h_max + me.state[id].geometry.y; |
251 |
me.window[id ~ '-bg'] = me.page.createChild('path'); |
|
252 |
me.window[id ~ '-bg'] |
|
253 |
.rect(geometry.x, geometry.y, |
|
254 |
geometry.w, me.state[id].h_max) |
|
255 |
.setColor(1,1,1) |
|
256 |
.setColorFill(0,0,0); |
|
257 |
me.state[id].geometry.x += 10; |
|
258 |
me.state[id].geometry.y += 16; |
|
changes about how to fill wi...
|
259 |
me.fill(id, scroll); |
fixes some bugs in windows
|
260 |
geometry.x = save_x; |
261 |
geometry.y = save_y; |
|
add window management
|
262 |
}, |
263 |
}; |