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