add window management
|
1 |
var pageClass = { |
2 |
new : func (d) { |
|
3 |
var m = { parents : [pageClass] }; |
|
4 |
m.page = d.display.screen; |
|
5 |
m.window = {}; |
|
6 |
m.state = {}; |
|
7 |
m.selected = ''; |
|
8 |
return m; |
|
9 |
}, |
|
10 | ||
11 |
del : func (id = nil) { |
|
12 |
if (id != nil and typeof(v) == 'scalar') { |
|
13 |
delete(me.state, id); |
|
14 |
id = [ id ]; |
|
15 |
} |
|
16 |
else { |
|
17 |
foreach (var s; keys(me.state)) |
|
18 |
delete(me.state, s); |
|
19 |
id = keys(me.window); |
|
20 |
} |
|
21 |
foreach (var w; id) { |
|
22 |
me.window[w] |
|
23 |
.hide() |
|
24 |
.del(); |
|
25 |
delete(me.window, w); |
|
26 |
} |
|
27 |
}, |
|
28 | ||
29 |
_selected_text : func (id, text, x, y) { |
|
30 |
me.selected = id; |
|
31 |
me.window[id] |
|
32 |
.setFontSize(16) |
|
33 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
34 |
.setTranslation(x, y) |
|
35 |
.setDrawMode(0x01 + 0x04) |
|
36 |
.setText(text) |
|
37 |
.setColorFill(0,1,1) |
|
38 |
.setColor(0,0,0); |
|
39 |
}, |
|
40 | ||
41 |
_editable_text : func (id, text, x, y) { |
|
42 |
me.window[id] |
|
43 |
.setFontSize(16) |
|
44 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
45 |
.setTranslation(x, y) |
|
46 |
.setText(text) |
|
47 |
.setColorFill(0,0,0) |
|
48 |
.setColor(0,1,1); |
|
49 |
}, |
|
50 | ||
51 |
_normal_text : func (id, text, x, y) { |
|
52 |
me.window[id] |
|
53 |
.setFontSize(16) |
|
54 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
55 |
.setTranslation(x, y) |
|
56 |
.setText(text) |
|
57 |
.setColorFill(0,0,0) |
|
58 |
.setColor(1,1,1); |
|
59 |
}, |
|
60 | ||
61 |
_title_text : func (id, text, x, y) { |
|
62 |
me.window[id] |
|
63 |
.setFontSize(16) |
|
64 |
.setFont('LiberationFonts/LiberationMono-Regular.ttf') |
|
65 |
.setTranslation(x, y) |
|
66 |
.setAlignment('center-center') |
|
67 |
.setText(text) |
|
68 |
.setColorFill(0,0,0) |
|
69 |
.setColor(0,1,1); |
|
70 |
}, |
|
71 | ||
changes about how to fill wi...
|
72 |
fill : func (id, scroll = nil) { |
add window management
|
73 |
var state = me.state[id]; |
changes about how to fill wi...
|
74 |
state.scroll = { |
75 |
offset : 0, # offset between canvas element and state element |
|
76 |
last : 9999, # last scrollgroup |
|
77 |
begin: -9999, # first canvas element of the scrolling area |
|
78 |
end: 9999, # last canvas element of the scrolling area |
|
79 |
upper: -9999, # group printed on the top of the scrolling area |
|
80 |
lower: 9999, # group printed at the bottom of the scrolling area |
|
81 |
lines : scroll.lines, # number of lines for the scrolling area |
|
82 |
columns : scroll.columns, # number of objects on each scrolling lines |
|
83 |
}; |
|
84 |
var scrollgroup = {}; |
|
85 |
forindex (var line; state.objects) { |
|
86 |
if (find('separator', state.objects[line].type) > -1) { |
|
87 |
me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('path') |
|
add window management
|
88 |
.setStrokeLineWidth(1) |
89 |
.moveTo(state.x_base, state.geometry.y - 12) |
|
90 |
.horiz(state.geometry.w - 20) |
|
91 |
.setColor(1,1,1); |
|
92 |
state.geometry.x = state.x_base; |
|
93 |
state.geometry.y += 8; |
|
94 |
} |
|
95 |
else { |
|
changes about how to fill wi...
|
96 |
if (contains(state.objects[line], 'scrollgroup')) { |
97 |
state.scroll.last = state.objects[line].scrollgroup; |
|
98 |
scrollgroup[state.objects[line].scrollgroup] = 1; |
|
99 |
if (state.scroll.begin == -9999) { |
|
100 |
state.scroll.begin = line; |
|
101 |
state.scroll.upper = state.objects[line].scrollgroup; |
|
102 |
} |
|
103 |
if (size(keys(scrollgroup)) > state.scroll.lines) { |
|
104 |
if (state.scroll.end == 9999) { |
|
105 |
state.scroll.end = line - 1; |
|
106 |
state.scroll.lower = state.objects[line - 1].scrollgroup; |
|
107 |
} |
|
108 |
else |
|
109 |
state.scroll.last = state.objects[line].scrollgroup; |
|
110 |
state.scroll.offset += 1; |
|
111 |
continue; |
|
112 |
} |
|
113 |
} |
|
114 |
me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('text'); |
|
115 |
if (find('normal', state.objects[line].type) > -1) |
|
add window management
|
116 |
me._normal_text( |
changes about how to fill wi...
|
117 |
id ~ '-' ~ (line - state.scroll.offset), |
118 |
state.objects[line].text, |
|
add window management
|
119 |
state.geometry.x, |
120 |
state.geometry.y, |
|
121 |
); |
|
122 | ||
changes about how to fill wi...
|
123 |
elsif (find('selected', state.objects[line].type) > -1) |
add window management
|
124 |
me._selected_text( |
changes about how to fill wi...
|
125 |
id ~ '-' ~ (line - state.scroll.offset), |
126 |
state.objects[line].text, |
|
add window management
|
127 |
state.geometry.x, |
128 |
state.geometry.y, |
|
129 |
); |
|
130 | ||
changes about how to fill wi...
|
131 |
elsif (find('editable', state.objects[line].type) > -1) |
add window management
|
132 |
me._editable_text( |
changes about how to fill wi...
|
133 |
id ~ '-' ~ (line - state.scroll.offset), |
134 |
state.objects[line].text, |
|
add window management
|
135 |
state.geometry.x, |
136 |
state.geometry.y, |
|
137 |
); |
|
138 | ||
changes about how to fill wi...
|
139 |
elsif (find('title', state.objects[line].type) > -1) |
add window management
|
140 |
me._title_text( |
changes about how to fill wi...
|
141 |
id ~ '-' ~ (line - state.scroll.offset), |
142 |
state.objects[line].text, |
|
add window management
|
143 |
state.x_base - 10 + state.geometry.w / 2, |
144 |
state.geometry.y |
|
145 |
); |
|
146 | ||
changes about how to fill wi...
|
147 |
if (find('end-of-line', state.objects[line].type) > -1 |
148 |
or find('title', state.objects[line].type) > -1) { |
|
add window management
|
149 |
state.geometry.x = state.x_base; |
150 |
state.geometry.y += 24; |
|
151 |
} |
|
152 |
else |
|
changes about how to fill wi...
|
153 |
state.geometry.x += size(state.objects[line].text) * 10 + 8; |
add window management
|
154 |
} |
155 |
} |
|
changes about how to fill wi...
|
156 |
# reset the scrolling offset before the first move |
157 |
state.scroll.offset = 0; |
|
add window management
|
158 |
}, |
159 |
|
|
changes about how to fill wi...
|
160 |
draw : func (id, geometry, objects, scroll = nil) { |
add window management
|
161 |
if (contains(me.window, id ~ '-bg')) { |
162 |
printlog('debug', 'objet ' ~ id ~ ' already exists'); |
|
163 |
return; |
|
164 |
} |
|
165 |
if (!contains(geometry, 'h') and !contains(geometry, 'l')) { |
|
166 |
printlog('debug', 'missing parameter l or h'); |
|
167 |
return; |
|
168 |
} |
|
169 |
me.state[id] = { |
|
changes about how to fill wi...
|
170 |
objects: objects, |
add window management
|
171 |
geometry: geometry, |
172 |
x_base : geometry.x + 10, |
|
173 |
h_max : contains(geometry, 'h') ? h : geometry.l * 24 + 8 + geometry.sep * 16, |
|
174 |
}; |
|
175 |
me.state[id].y_max = me.state[id].h_max + me.state[id].geometry.y; |
|
176 |
me.window[id ~ '-bg'] = me.page.createChild('path'); |
|
177 |
me.window[id ~ '-bg'] |
|
178 |
.rect(geometry.x, geometry.y, |
|
179 |
geometry.w, me.state[id].h_max) |
|
180 |
.setColor(1,1,1) |
|
181 |
.setColorFill(0,0,0); |
|
182 |
me.state[id].geometry.x += 10; |
|
183 |
me.state[id].geometry.y += 16; |
|
changes about how to fill wi...
|
184 |
me.fill(id, scroll); |
add window management
|
185 |
}, |
186 |
}; |