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
|
#include <stdlib.h>
#include <string.h>
#include "unicode.h"
#include "eve.h"
#include "eve_kbd.h"
#include "eve_font.h"
#include "screen.h"
#include "window.h"
#include "view.h"
#include "page.h"
#include "form.h"
#include "widget/label.h"
#include "widget/widget.h"
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
static void form_update_g(EVEForm *form, EVEWidget *_widget) {
EVEWidget *widget = form->widget;
int i;
uint16_t w = 0;
uint16_t h = 0;
uint16_t _h = 0;
for (i=0; i<form->widget_size; i++) {
if (widget->label) {
h += _h;
w = widget->label->g.w;
_h = widget->label->g.h;
widget->label->g.x = 0;
widget->label->g.y = h;
}
if (w + widget->g.w > form->p.v.window->g.w) {
h += _h;
w = 0;
_h = 0;
}
widget->g.x = w;
widget->g.y = h;
w += widget->g.w;
_h = MAX(_h, widget->g.h);
widget = eve_widget_next(widget);
}
}
static int form_handle_evt(EVEForm *form, EVEWidget *widget, EVETouch *touch, uint16_t evt) {
if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
form->win_x0 = form->p.win_x;
form->win_y0 = form->p.win_y;
form->evt_lock = 1;
}
if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
form->evt_lock = 0;
}
if ((evt & EVE_TOUCH_ETYPE_TRACK) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)) {
form->p.win_y = form->win_y0 + touch->y0 - touch->y;
return 1;
}
if (evt & EVE_TOUCH_ETYPE_POINT_UP) {
if ((touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY) == 0) {
if (form->p.widget_f) eve_page_set_focus(&form->p, NULL, NULL);
return 1;
}
if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) {
eve_page_close((EVEPage *)form);
return 1;
}
if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) {
form->action(form);
return 1;
}
}
return 0;
}
int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor) {
memset(form, 0, sizeof(EVEForm));
eve_page_init(&form->p, window, stack, eve_form_touch, eve_form_draw, (eve_page_destructor_t)destructor);
form->widget = widget;
form->widget_size = widget_size;
form->action = action;
form_update_g(form, NULL);
}
int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx) {
EVEForm *form = (EVEForm *)v;
EVEWidget *widget = form->widget;
EVETouch *t;
uint16_t evt;
int i, ret = 0;
if (touch_idx > 0) return 0;
t = eve_touch_evt(tag0, touch_idx, form->p.v.window->tag, 1, &evt);
if (t && evt) {
ret = form_handle_evt(form, NULL, t, evt);
if (ret) return 1;
}
for (i=0; i<form->widget_size; i++) {
if (eve_page_rect_visible(&form->p, &widget->g)) {
t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt);
if (t && evt) {
if (!form->evt_lock) {
ret = widget->touch(widget, &form->p, t, evt);
if (ret) return 1;
}
ret = form_handle_evt(form, widget, t, evt);
if (ret) return 1;
}
}
widget = eve_widget_next(widget);
}
return 0;
}
uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
EVEForm *form = (EVEForm *)v;
EVEWidget *widget = form->widget;
int i;
uint8_t tagN = tag0;
uint8_t tag_opt = EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT_Y;
eve_cmd_dl(SAVE_CONTEXT());
eve_cmd_dl(VERTEX_FORMAT(0));
eve_cmd_dl(VERTEX_TRANSLATE_X(eve_page_scr_x(&form->p, 0) * 16));
eve_cmd_dl(VERTEX_TRANSLATE_Y(eve_page_scr_y(&form->p, 0) * 16));
for (i=0; i<form->widget_size; i++) {
if (widget->label && eve_page_rect_visible(&form->p, &widget->label->g)) {
eve_cmd_dl(TAG_MASK(0));
eve_label_draw(widget->label);
eve_cmd_dl(TAG_MASK(1));
}
if (eve_page_rect_visible(&form->p, &widget->g)) {
uint16_t h = widget->g.h;
tagN = widget->draw(widget, &form->p, tagN);
if (h != widget->g.h) form_update_g(form, widget);
}
widget = eve_widget_next(widget);
}
eve_cmd_dl(RESTORE_CONTEXT());
for (i=tag0; i<tagN; i++) {
eve_touch_set_opt(i, eve_touch_get_opt(i) | tag_opt);
}
if (v->window->tag != EVE_TAG_NOTAG) eve_touch_set_opt(v->window->tag, eve_touch_get_opt(v->window->tag) | tag_opt);
return tagN;
}
EVEWidget *eve_form_widget(EVEForm *form, uint16_t idx) {
EVEWidget *w = form->widget;
int i;
if (idx >= form->widget_size) return NULL;
for (i=0; i<idx; i++) {
w = eve_widget_next(w);
}
return w;
}
|