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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
#include <stdlib.h>
#include <string.h>
#include "eve.h"
#include "eve_kbd.h"
#include "eve_font.h"
#include "window.h"
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
void eve_window_init(EVEWindow *window, EVERect *g, EVEWindow *parent, char *name) {
memset(window, 0, sizeof(EVEWindow));
if (g) window->g = *g;
window->root = parent ? parent->root : NULL;
window->parent = parent;
window->name = name;
}
void eve_window_init_root(EVEWindowRoot *root, EVERect *g, char *name, EVEFont *font) {
EVEWindow *_window = &root->w;
eve_window_init(_window, g, NULL, name);
_window->root = root;
root->mem_next = EVE_RAM_G;
root->font = font;
root->win_kbd = NULL;
root->win_scroll = NULL;
root->tag_scroll = EVE_NOTAG;
eve_touch_set_handler(eve_window_root_touch, root);
}
static uint8_t kbd_draw(EVEView *view, uint8_t tag0) {
EVEKbd *kbd = view->param;
tag0 = eve_view_clear(view, tag0, 0);
eve_kbd_draw(kbd);
return tag0;
}
static int kbd_touch(EVEView *view, EVETouch *touch, uint16_t evt) {
EVEKbd *kbd = view->param;
return eve_kbd_touch(kbd, touch, evt);
}
void eve_window_init_kbd(EVEWindowKbd *win_kbd, EVERect *g, EVEWindowRoot *root, char *name, EVEKbd *kbd) {
EVEWindow *_window = &win_kbd->w;
eve_window_init(_window, g, NULL, name);
_window->root = root;
win_kbd->kbd = kbd;
root->win_kbd = win_kbd;
eve_view_init(&win_kbd->v, _window, kbd_draw, kbd_touch, NULL, kbd);
eve_view_attach(&win_kbd->v, _window, NULL);
}
void eve_window_set_parent(EVEWindow *window, EVEWindow *parent) {
window->parent = parent;
window->root = parent->root;
}
void eve_window_attach_view(EVEWindow *window, EVEView *view, void *view_id) {
if (window->view) window->dirty = 1;
window->view = view;
window->view_id = view_id;
}
void eve_window_detach_view(EVEWindow *window) {
if (window->view) window->dirty = 1;
window->view = NULL;
window->view_id = NULL;
}
int eve_window_dirty(EVEWindow *window) {
return window->dirty;
}
void eve_window_clean(EVEWindow *window) {
window->dirty = 0;
}
int eve_window_visible(EVEWindow *window) {
if (window->g.x >= window->root->w.g.w) return 0;
if (window->g.y >= window->root->w.g.h) return 0;
if ((window->g.x + window->g.w) <= 0) return 0;
if ((window->g.y + window->g.h) <= 0) return 0;
return 1;
}
static void window_visible_g(EVEWindow *win, EVERect *rect) {
while (win) {
if (eve_window_visible(win)) {
if (win->g.x > rect->x) rect->w = MIN(rect->w, win->g.x - rect->x);
if (win->g.y > rect->y) rect->h = MIN(rect->h, win->g.y - rect->y);
if (win->g.x + win->g.w < rect->x + rect->w) {
uint16_t x0 = rect->w - MIN(rect->w, (rect->x + rect->w) - (win->g.x + win->g.w));
rect->x += x0;
rect->w -= x0;
}
if (win->g.y + win->g.h < rect->y + rect->h) {
uint16_t y0 = rect->h - MIN(rect->h, (rect->y + rect->h) - (win->g.y + win->g.h));
rect->y += y0;
rect->h -= y0;
}
if ((rect->w == 0) || (rect->h == 0)) return;
}
if (win->child_head) window_visible_g(win->child_head, rect);
win = win->next;
}
}
void eve_window_visible_g(EVEWindow *window, EVERect *rect) {
*rect = window->g;
if (window->child_head) window_visible_g(window->child_head, rect);
window_visible_g(window->next, rect);
}
void eve_window_append(EVEWindow *window) {
EVEWindow *parent = window->parent;
window->prev = parent->child_tail;
window->next = NULL;
if (parent->child_tail) {
parent->child_tail->next = window;
} else {
parent->child_head = window;
}
parent->child_tail = window;
}
void eve_window_insert_above(EVEWindow *window, EVEWindow *win_prev) {
EVEWindow *parent = window->parent;
window->prev = win_prev;
window->next = win_prev->next;
if (window->next) {
window->next->prev = window;
} else {
parent->child_tail = window;
}
win_prev->next = window;
}
void eve_window_insert_below(EVEWindow *window, EVEWindow *win_next) {
EVEWindow *parent = window->parent;
window->prev = win_next->prev;
window->next = win_next;
win_next->prev = window;
if (window->prev) {
window->prev->next = window;
} else {
parent->child_head = window;
}
}
void eve_window_remove(EVEWindow *window) {
EVEWindow *parent = window->parent;
if (window->prev) {
window->prev->next = window->next;
} else {
parent->child_head = window->next;
}
if (window->next) {
window->next->prev = window->prev;
} else {
parent->child_tail = window->prev;
}
window->parent = NULL;
window->prev = NULL;
window->next = NULL;
}
EVEWindow *eve_window_search(EVEWindow *window, char *name) {
while (window) {
if (window->name && (strcmp(name, window->name) == 0)) return window;
if (window->child_head) {
EVEWindow *rv = eve_window_search(window->child_head, name);
if (rv) return rv;
}
window = window->next;
}
return NULL;
}
uint8_t eve_window_draw(EVEWindow *window, uint8_t tag0) {
while (window) {
if (eve_window_visible(window) && window->view) {
int16_t s_x = window->g.x;
int16_t s_y = window->g.y;
uint16_t s_w = window->g.w;
uint16_t s_h = window->g.h;
if (s_x < 0) {
s_w += s_x;
s_x = 0;
}
if (s_y < 0) {
s_h += s_y;
s_y = 0;
}
if (s_x + s_w > window->root->w.g.w) s_w = window->root->w.g.w - s_x;
if (s_y + s_h > window->root->w.g.h) s_h = window->root->w.g.h - s_y;
eve_cmd_dl(SCISSOR_XY(s_x, s_y));
eve_cmd_dl(SCISSOR_SIZE(s_w, s_h));
tag0 = window->view->draw(window->view, tag0);
}
if (window->child_head) tag0 = eve_window_draw(window->child_head, tag0);
window = window->next;
}
return tag0;
}
int eve_window_touch(EVEWindow *window, EVETouch *touch, uint16_t evt) {
int rv = 0;
while (window) {
if (window->child_tail) {
rv = eve_window_touch(window->child_tail, touch, evt);
if (rv) return 1;
}
if (eve_window_visible(window) && window->view) {
rv = window->view->touch(window->view, touch, evt);
window->dirty = 0;
if (rv) return 1;
}
window = window->prev;
}
return 0;
}
void eve_window_root_draw(EVEWindowRoot *root) {
uint8_t tag0 = 0x80;
int rv;
eve_cmd_burst_start();
eve_cmd_dl(CMD_DLSTART);
if (root->tag_scroll != EVE_NOTAG) tag0 = EVE_NOTAG;
eve_window_draw(&root->w, tag0);
eve_cmd_dl(DISPLAY());
eve_cmd_dl(CMD_SWAP);
eve_cmd_burst_end();
rv = eve_cmd_exec(1);
if (rv) EVE_LOG(EVE_LOG_ERR, "EVE CMD EXEC ERR:%d\n", rv);
}
void eve_window_root_touch(EVETouch *touch, uint16_t evt, void *win) {
EVEWindowRoot *root = (EVEWindowRoot *)win;
int rv;
rv = eve_window_touch(&root->w, touch, evt);
if (rv) {
uint8_t tag_opt = 0;
if (root->tag_scroll != EVE_NOTAG) {
tag_opt = eve_tag_get_opt(root->tag_scroll);
}
eve_tag_clear_opt();
if (root->tag_scroll != EVE_NOTAG) {
eve_tag_set_opt(root->tag_scroll, tag_opt);
}
eve_window_root_draw(root);
}
}
EVEKbd *eve_window_kbd(EVEWindow *window) {
EVEWindowRoot *root = window->root;
EVEWindowKbd *win_kbd = root->win_kbd;
if (win_kbd) return win_kbd->kbd;
return NULL;
}
void eve_window_kbd_attach(EVEWindow *window) {
EVEWindowRoot *root = window->root;
EVEWindowKbd *win_kbd = root->win_kbd;
EVEKbd *kbd = win_kbd ? win_kbd->kbd : NULL;
if (kbd) {
eve_window_set_parent(&win_kbd->w, window);
eve_window_append(&win_kbd->w);
}
}
void eve_window_kbd_detach(EVEWindow *window) {
EVEWindowRoot *root = window->root;
EVEWindowKbd *win_kbd = root->win_kbd;
EVEKbd *kbd = win_kbd ? win_kbd->kbd : NULL;
if (kbd && win_kbd->w.parent) {
eve_window_remove(&win_kbd->w);
eve_kbd_close(kbd);
}
}
EVEWindow *eve_window_scroll(EVEWindow *window, uint8_t *tag) {
EVEWindowRoot *root = window->root;
if (tag) *tag = root->tag_scroll;
return root->win_scroll;
}
void eve_window_scroll_start(EVEWindow *window, uint8_t tag) {
EVEWindowRoot *root = window->root;
root->win_scroll = window;
root->tag_scroll = tag;
}
void eve_window_scroll_stop(EVEWindow *window) {
EVEWindowRoot *root = window->root;
root->win_scroll = NULL;
root->tag_scroll = EVE_NOTAG;
}
EVEFont *eve_window_font(EVEWindow *window) {
EVEWindowRoot *root = window->root;
return root->font;
}
|