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