diff options
Diffstat (limited to 'fw/fe310/eos/eve/screen')
-rw-r--r-- | fw/fe310/eos/eve/screen/form.c | 233 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/form.h | 23 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/page.c | 305 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/page.h | 42 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/uievt.h | 10 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/view.c | 41 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/view.h | 7 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/window.c | 85 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/window.h | 18 |
9 files changed, 515 insertions, 249 deletions
diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c index 8ea53c8..81c1b86 100644 --- a/fw/fe310/eos/eve/screen/form.c +++ b/fw/fe310/eos/eve/screen/form.c @@ -9,20 +9,20 @@ #include "page.h" #include "form.h" -#include "widget/label.h" -#include "widget/widget.h" +#include "widget/widgets.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; + EVEPage *page = &form->p; + EVEWidget *widget = page->widget; int i; uint16_t w = 0; uint16_t h = 0; uint16_t l_h = 0; - for (i=0; i<form->widget_size; i++) { + for (i=0; i<page->widget_size; i++) { if (widget->label) { h += l_h; w = widget->label->g.w; @@ -43,173 +43,124 @@ static void form_update_g(EVEForm *form, EVEWidget *_widget) { widget = eve_widget_next(widget); } - form->w = form->p.v.window->g.w; - form->h = h + l_h; + page->g.w = page->v.window->g.w; + page->g.h = h + l_h; } -static int form_handle_evt(EVEForm *form, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0) { - int ret = 0; - EVEPage *page = &form->p; +static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) { + int i; - if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & (EVE_TOUCH_EETYPE_TRACK_XY | EVE_TOUCH_EETYPE_ABORT))) { - if (page->widget_f) eve_page_set_focus(page, NULL, NULL); - ret = 1; + for (i=0; i<widget_size; i++) { + if (widget->label) eve_free(widget->label); + eve_widget_destroy(widget); + widget = eve_widget_next(widget); } +} - /* Scroll start */ - if ((evt & EVE_TOUCH_ETYPE_TRACK_START) && !(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) { - form->evt_lock = 1; - } +EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor) { + EVEWidget *widgets; + EVEWidget *widget; + EVELabel *label; + EVEForm *form; + int w_size = 0; + int i, r; - /* Scroll stop */ - if (((evt & EVE_TOUCH_ETYPE_TRACK_STOP) && !(evt & EVE_TOUCH_ETYPE_TRACK_ABORT)) || - ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_ABORT) && !(touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY))) { - int wmax_x, wmax_y; - int lho_x, lho_y; - EVERect vg; - - eve_window_visible_g(page->v.window, &vg); - wmax_x = form->w > vg.w ? form->w - vg.w : 0; - wmax_y = form->h > vg.h ? form->h - vg.h : 0; - lho_x = page->win_x < 0 ? 0 : wmax_x; - lho_y = page->win_y < 0 ? 0 : wmax_y; - if ((page->win_x < 0) || (page->win_x > wmax_x) || - (page->win_y < 0) || (page->win_y > wmax_y)) { - EVEPhyLHO *lho = &form->lho; - eve_phy_lho_init(lho, lho_x, lho_y, 1000, 0.5, 0); - eve_phy_lho_start(lho, page->win_x, page->win_y); - form->lho_t0 = eve_time_get_tick(); - eve_touch_timer_start(tag0, 20); - } else { - form->evt_lock = 0; - if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) { - if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) { - eve_page_close((EVEPage *)form); - return 1; - } - if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) { - if (form->action) form->action(form); - return 1; - } - } - } + for (i=0; i<spec_size; i++) { + w_size += eve_widget_size(spec[i].widget.type); } - - if (evt & EVE_TOUCH_ETYPE_TRACK_START) { - if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y) { - form->win_y0 = page->win_y; - } + form = eve_malloc(sizeof(EVEForm)); + if (form == NULL) { + return NULL; } - if (evt & EVE_TOUCH_ETYPE_TRACK) { - if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y) { - page->win_y = form->win_y0 + touch->y0 - touch->y; - } - ret = 1; + if (destructor == NULL) destructor = eve_form_destroy; + eve_form_init(form, window, stack, NULL, 0, action, destructor); + + widgets = eve_malloc(w_size); + if (widgets == NULL) { + eve_free(form); + return NULL; } - if (evt & EVE_TOUCH_ETYPE_TIMER) { - EVEPhyLHO *lho = &form->lho; - int more = eve_phy_lho_tick(lho, eve_time_get_tick() - form->lho_t0, NULL, &page->win_y); - if (!more) { - form->evt_lock = 0; - eve_touch_timer_stop(); + widget = widgets; + for (i=0; i<spec_size; i++) { + r = eve_widget_create(widget, spec[i].widget.type, &spec[i].widget.g, (EVEPage *)form, &spec[i].widget.spec); + if (r) { + widgets_destroy(widgets, i); + eve_free(widgets); + eve_free(form); + return NULL; } - ret = 1; + if (spec[i].label.title) { + EVEFont *font = spec[i].label.font ? spec[i].label.font : eve_window_font(window); + label = eve_malloc(sizeof(EVELabel)); + if (label == NULL) { + eve_widget_destroy(widget); + widgets_destroy(widgets, i); + eve_free(widgets); + eve_free(form); + return NULL; + } + eve_label_init(label, &spec[i].label.g, font, spec[i].label.title); + eve_widget_set_label(widget, label); + if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title); + } + if (widget->label && (widget->label->g.w == 0)) eve_font_str_w(label->font, label->title) + EVE_FORM_LABEL_MARGIN; + if (widget->g.w == 0) widget->g.w = window->g.w - (widget->label ? widget->label->g.w : 0); + widget = eve_widget_next(widget); } + eve_form_update(form, widgets, spec_size); - return ret; + return form; } void 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_draw, eve_form_touch, NULL, (eve_page_destructor_t)destructor); - eve_form_update(form, widget, widget_size, action); + eve_page_init(&form->p, window, stack, NULL, 0, EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_BACK | EVE_PAGE_OPT_TRACK_EXT_Y, eve_page_draw, eve_page_touch, eve_form_uievt, (eve_page_destructor_t)destructor); + form->action = action; + eve_form_update(form, widget, widget_size); } -void eve_form_update(EVEForm *form, EVEWidget *widget, uint16_t widget_size, eve_form_action_t action) { - if (widget) { - form->widget = widget; - form->widget_size = widget_size; - } - if (action) form->action = action; +void eve_form_update(EVEForm *form, EVEWidget *widget, uint16_t widget_size) { + eve_page_update((EVEPage *)form, widget, widget_size); form_update_g(form, NULL); } -uint8_t eve_form_draw(EVEView *view, uint8_t tag0) { - EVEForm *form = (EVEForm *)view; - 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; - - tagN = eve_view_clear(view, tagN); - - 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, tagN); - if (h != widget->g.h) form_update_g(form, widget); - } - widget = eve_widget_next(widget); - } +void eve_form_destroy(EVEForm *form) { + widgets_destroy(form->p.widget, form->p.widget_size); + eve_free(form->p.widget); + eve_free(form); +} - eve_cmd_dl(RESTORE_CONTEXT()); +int eve_form_uievt(EVEView *view, uint16_t evt, void *param) { + EVEForm *form = (EVEForm *)view; - for (i=tag0; i<tagN; i++) { - eve_touch_set_opt(i, eve_touch_get_opt(i) | tag_opt); - } - if (view->tag != EVE_TAG_NOTAG) eve_touch_set_opt(view->tag, eve_touch_get_opt(view->tag) | tag_opt); + switch (evt) { + case EVE_UIEVT_WIDGET_UPDATE_G: + form_update_g(form, (EVEWidget *)param); + break; - return tagN; -} + case EVE_UIEVT_PAGE_SCROLL_START: + break; -int eve_form_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) { - EVEForm *form = (EVEForm *)view; - EVEWidget *widget = form->widget; - int8_t touch_idx = eve_touch_get_idx(touch); - uint16_t _evt; - int i, ret; + case EVE_UIEVT_PAGE_SCROLL_STOP: + break; - if (touch_idx > 0) return 0; + case EVE_UIEVT_PAGE_TRACK_START: + break; - _evt = eve_touch_evt(touch, evt, tag0, form->p.v.tag, 1); - if (_evt) { - ret = form_handle_evt(form, NULL, touch, _evt, tag0); - if (ret) return 1; - } - for (i=0; i<form->widget_size; i++) { - _evt = eve_touch_evt(touch, evt, tag0, widget->tag0, widget->tagN - widget->tag0); - if (_evt) { - if (!form->evt_lock) { - ret = widget->touch(widget, touch, _evt); - if (ret) return 1; + case EVE_UIEVT_PAGE_TRACK_STOP: { + EVEUIEvtTouch *touch_p = (EVEUIEvtTouch *)param; + if (touch_p->evt & EVE_TOUCH_ETYPE_TRACK_STOP) { + if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) { + eve_page_close((EVEPage *)form); + return 1; + } + if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) { + if (form->action) form->action(form); + } } - ret = form_handle_evt(form, widget, touch, _evt, tag0); - if (ret) return 1; + break; } - widget = eve_widget_next(widget); } - return 0; } - -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; -} diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h index eb817e5..87da85c 100644 --- a/fw/fe310/eos/eve/screen/form.h +++ b/fw/fe310/eos/eve/screen/form.h @@ -1,6 +1,9 @@ #include <stdint.h> +#define EVE_FORM_LABEL_MARGIN 10 + struct EVEWidget; +struct EVEWidgetSpec; struct EVEForm; typedef void (*eve_form_action_t) (struct EVEForm *); @@ -8,24 +11,12 @@ typedef void (*eve_form_destructor_t) (struct EVEForm *); typedef struct EVEForm { EVEPage p; - struct EVEWidget *widget; - uint16_t widget_size; eve_form_action_t action; - int win_x0; - int win_y0; - uint16_t w; - uint16_t h; - uint8_t evt_lock; - EVEPhyLHO lho; - uint64_t lho_t0; } EVEForm; +EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, struct EVEWidgetSpec *spec, uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor); void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor); -void eve_form_update(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size, eve_form_action_t action); - -uint8_t eve_form_draw(EVEView *view, uint8_t tag0); -int eve_form_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0); +void eve_form_update(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size); +void eve_form_destroy(EVEForm *form); -void eve_form_update_g(EVEForm *form, struct EVEWidget *widget); -int eve_form_handle_evt(EVEForm *form, struct EVEWidget *widget, EVETouch *touch, uint16_t evt); -struct EVEWidget *eve_form_widget(EVEForm *form, uint16_t idx); +int eve_form_uievt(EVEView *view, uint16_t evt, void *param); diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c index 4b8799c..032d746 100644 --- a/fw/fe310/eos/eve/screen/page.c +++ b/fw/fe310/eos/eve/screen/page.c @@ -11,12 +11,24 @@ #include "widget/label.h" #include "widget/widget.h" -void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor) { +#define PAGE_TMODE_NONE 0 +#define PAGE_TMODE_TRACK 1 +#define PAGE_TMODE_SCROLL 2 + +void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, uint8_t opt, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor) { memset(page, 0, sizeof(EVEPage)); eve_view_init(&page->v, window, draw, touch, uievt, NULL); - page->destructor = destructor; page->stack = stack; - page->widget_f = NULL; + page->opt = opt; + page->destructor = destructor; + eve_page_update(page, widget, widget_size); +} + +void eve_page_update(EVEPage *page, EVEWidget *widget, uint16_t widget_size) { + if (widget) { + page->widget = widget; + page->widget_size = widget_size; + } } void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor) { @@ -33,6 +45,13 @@ void eve_page_close(EVEPage *page) { EVEViewStack *stack = page->stack; eve_page_destructor_t destructor = page->destructor; + if (page->lho_t0) { + page->lho_t0 = 0; + eve_touch_timer_stop(); + } + if (eve_window_scroll(window->root, NULL) == window) { + eve_window_scroll_stop(window); + } if (stack->level > 1) { if (destructor) destructor(page); eve_window_kbd_detach(window); @@ -40,77 +59,289 @@ void eve_page_close(EVEPage *page) { } } +/* Screen to page coordinates */ int16_t eve_page_x(EVEPage *page, int16_t x) { - return x + page->win_x - page->v.window->g.x; + return x + page->g.x - page->v.window->g.x; } int16_t eve_page_y(EVEPage *page, int16_t y) { - return y + page->win_y - page->v.window->g.y; + return y + page->g.y - page->v.window->g.y; +} + +/* Page to window coordinates */ +int16_t eve_page_win_x(EVEPage *page, int16_t x) { + return x - page->g.x; +} + +int16_t eve_page_win_y(EVEPage *page, int16_t y) { + return y - page->g.y; } +/* Page to screen coordinates */ int16_t eve_page_scr_x(EVEPage *page, int16_t x) { - return x - page->win_x + page->v.window->g.x; + return eve_page_win_x(page, x) + page->v.window->g.x; } int16_t eve_page_scr_y(EVEPage *page, int16_t y) { - return y - page->win_y + page->v.window->g.y; + return eve_page_win_y(page, y) + page->v.window->g.y; +} + +int eve_page_rect_visible(EVEPage *page, EVERect *g) { + uint16_t w = page->v.window->g.w; + uint16_t h = page->v.window->g.h; + + if (((g->x + g->w) >= page->g.x) && ((g->y + g->h) >= page->g.y) && (g->x <= (page->g.x + w)) && (g->y <= (page->g.y + h))) return 1; + return 0; +} + +void eve_page_focus(EVEPage *page, EVERect *rect) { + if (rect) { + EVERect g; + + eve_window_visible_g(page->v.window, &g); + g.x -= page->v.window->g.x; + g.y -= page->v.window->g.y; + + if (rect->x < page->g.x + g.x) { + page->g.x = rect->x - g.x; + } + if (rect->y < page->g.y + g.y) { + page->g.y = rect->y - g.y; + } + if ((rect->x + rect->w) > (page->g.x + g.x + g.w)) { + page->g.x = (rect->x + rect->w) - (g.x + g.w); + } + if ((rect->y + rect->h) > (page->g.y + g.y + g.h)) { + page->g.y = (rect->y + rect->h) - (g.y + g.h); + } + } } -void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *f) { +void eve_page_focus_widget(EVEPage *page, EVEWidget *widget, EVERect *rect) { if (page->widget_f != widget) { EVEWindow *window = page->v.window; EVEWidget *widget_f = page->widget_f; if (widget_f && widget_f->putc) { - eve_window_kbd_detach(window); widget_f->putc(widget_f, EVE_PAGE_KBDCH_CLOSE); + if (!(widget && widget->putc)) eve_window_kbd_detach(window); } if (widget && widget->putc) { EVEKbd *kbd = eve_window_kbd(window); - if (kbd) { - eve_kbd_set_handler(kbd, widget->putc, widget); - eve_window_kbd_attach(window); - } + if (kbd) eve_kbd_set_handler(kbd, widget->putc, widget); + if (!(widget_f && widget_f->putc)) eve_window_kbd_attach(window); } page->widget_f = widget; } + if (rect) eve_page_focus(page, rect); +} - if (f) { - EVERect g; +EVEWidget *eve_page_focus_widget_get(EVEPage *page) { + return page->widget_f; +} - eve_window_visible_g(page->v.window, &g); - g.x -= page->v.window->g.x; - g.y -= page->v.window->g.y; +EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx) { + EVEWidget *w = page->widget; + int i; + + if (idx >= page->widget_size) return NULL; + + for (i=0; i<idx; i++) { + w = eve_widget_next(w); + } + return w; +} + +static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0) { + EVEView *view = &page->v; + EVEWindow *window = view->window; + int scroll, scroll_x, scroll_y; + int ret = 0; + + scroll_x = page->opt & (EVE_PAGE_OPT_SCROLL_X | EVE_PAGE_OPT_SCROLL_XY); + if (scroll_x && touch) scroll_x = touch->eevt & ((page->opt & EVE_PAGE_OPT_SCROLL_XY) ? EVE_TOUCH_EETYPE_TRACK_XY : EVE_TOUCH_EETYPE_TRACK_X); + + scroll_y = page->opt & (EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_XY); + if (scroll_y && touch) scroll_y = touch->eevt & ((page->opt & EVE_PAGE_OPT_SCROLL_XY) ? EVE_TOUCH_EETYPE_TRACK_XY : EVE_TOUCH_EETYPE_TRACK_Y); - if (f->x < page->win_x + g.x) { - page->win_x = f->x - g.x; + scroll = scroll_x || scroll_y; + + if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & (EVE_TOUCH_EETYPE_TRACK_XY | EVE_TOUCH_EETYPE_ABORT))) { + if (page->widget_f) eve_page_focus_widget(page, NULL, NULL); + ret = 1; + } + + /* Scroll start */ + if ((evt & EVE_TOUCH_ETYPE_TRACK_START) && !(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) { + int _ret = 0; + + if (scroll) { + page->track_mode = PAGE_TMODE_SCROLL; + eve_window_scroll_start(window, touch->tracker.tag); + _ret = eve_view_uievt_tpush(view, EVE_UIEVT_PAGE_SCROLL_START, touch, evt, tag0); + } else { + page->track_mode = PAGE_TMODE_TRACK; + _ret = eve_view_uievt_tpush(view, EVE_UIEVT_PAGE_TRACK_START, touch, evt, tag0); + } + if (_ret) return _ret; + ret = 1; + } + + /* Scroll stop */ + if (((evt & EVE_TOUCH_ETYPE_TRACK_STOP) && !(evt & EVE_TOUCH_ETYPE_TRACK_ABORT)) || + ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_ABORT) && !(touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY))) { + if ((page->track_mode == PAGE_TMODE_SCROLL) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) { + int wmax_x, wmax_y; + int lho_x, lho_y; + EVERect vg; + + eve_window_visible_g(page->v.window, &vg); + wmax_x = page->g.w > vg.w ? page->g.w - vg.w : 0; + wmax_y = page->g.h > vg.h ? page->g.h - vg.h : 0; + lho_x = page->g.x < 0 ? 0 : wmax_x; + lho_y = page->g.y < 0 ? 0 : wmax_y; + if ((page->g.x < 0) || (page->g.x > wmax_x) || + (page->g.y < 0) || (page->g.y > wmax_y)) { + EVEPhyLHO *lho = &page->lho; + uint8_t _tag; + + eve_window_scroll(window->root, &_tag); + + eve_phy_lho_init(lho, lho_x, lho_y, 1000, 0.5, 0); + eve_phy_lho_start(lho, page->g.x, page->g.y); + page->lho_t0 = eve_time_get_tick(); + eve_touch_timer_start(_tag, 20); + } + } + + if (!page->lho_t0) { + int _ret = 0; + + if (page->track_mode == PAGE_TMODE_SCROLL) { + page->track_mode = PAGE_TMODE_NONE; + eve_window_scroll_stop(window); + _ret = eve_view_uievt_tpush(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0); + } else if (!(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) { + page->track_mode = PAGE_TMODE_NONE; + _ret = eve_view_uievt_tpush(view, EVE_UIEVT_PAGE_TRACK_STOP, touch, evt, tag0); + } + if (_ret) return _ret; + ret = 1; + } + } + + if (page->track_mode == PAGE_TMODE_SCROLL) { + if (evt & EVE_TOUCH_ETYPE_TRACK_START) { + if (scroll_x) { + page->x0 = page->g.x; + } + if (scroll_y) { + page->y0 = page->g.y; + } } - if (f->y < page->win_y + g.y) { - page->win_y = f->y - g.y; + if (evt & EVE_TOUCH_ETYPE_TRACK) { + if (scroll_x) { + page->g.x = page->x0 + touch->x0 - touch->x; + } + if (scroll_y) { + page->g.y = page->y0 + touch->y0 - touch->y; + } + ret = 1; } - if ((f->x + f->w) > (page->win_x + g.x + g.w)) { - page->win_x = (f->x + f->w) - (g.x + g.w); + if ((evt & EVE_TOUCH_ETYPE_TIMER) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) { + EVEPhyLHO *lho = &page->lho; + int x, y, more; + + more = eve_phy_lho_tick(lho, eve_time_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL); + if (scroll_x) page->g.x = x; + if (scroll_y) page->g.y = y; + if (!more) { + int _ret = 0; + + page->lho_t0 = 0; + eve_touch_timer_stop(); + page->track_mode = PAGE_TMODE_NONE; + eve_window_scroll_stop(window); + _ret = eve_view_uievt_tpush(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0); + if (_ret) return _ret; + } + ret = 1; } - if ((f->y + f->h) > (page->win_y + g.y + g.h)) { - page->win_y = (f->y + f->h) - (g.y + g.h); + if (evt & EVE_TOUCH_EETYPE_TIMER_ABORT) { + page->lho_t0 = 0; } } -} -EVEWidget *eve_page_get_focus(EVEPage *page) { - return page->widget_f; + return ret; } -int eve_page_rect_visible(EVEPage *page, EVERect *g) { - uint16_t w = page->v.window->g.w; - uint16_t h = page->v.window->g.h; +uint8_t eve_page_draw(EVEView *view, uint8_t tag0) { + EVEPage *page = (EVEPage *)view; + EVEWidget *widget = page->widget; + int i; + uint8_t tagN = tag0; + uint8_t tag_opt; - if (((g->x + g->w) >= page->win_x) && ((g->y + g->h) >= page->win_y) && (g->x <= (page->win_x + w)) && (g->y <= (page->win_y + h))) return 1; - return 0; + tag_opt = EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY; + if (page->opt & EVE_PAGE_OPT_TRACK_EXT_X) tag_opt |= EVE_TOUCH_OPT_TRACK_EXT_X; + if (page->opt & EVE_PAGE_OPT_TRACK_EXT_Y) tag_opt |= EVE_TOUCH_OPT_TRACK_EXT_Y; + + tag0 = eve_view_clear(view, tag0, tag_opt); + tagN = tag0; + eve_cmd_dl(SAVE_CONTEXT()); + eve_cmd_dl(VERTEX_FORMAT(0)); + eve_cmd_dl(VERTEX_TRANSLATE_X(eve_page_scr_x(page, 0) * 16)); + eve_cmd_dl(VERTEX_TRANSLATE_Y(eve_page_scr_y(page, 0) * 16)); + for (i=0; i<page->widget_size; i++) { + if (widget->label && eve_page_rect_visible(page, &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(page, &widget->g)) { + tagN = widget->draw(widget, tagN); + } + widget = eve_widget_next(widget); + } + + eve_cmd_dl(RESTORE_CONTEXT()); + + for (i=tag0; i<tagN; i++) { + if (i != EVE_NOTAG) eve_touch_set_opt(i, eve_touch_get_opt(i) | tag_opt); + } + + return tagN; } -void eve_page_uievt_push(EVEPage *page, uint16_t evt, void *param) { - EVEView *view = &page->v; - eve_view_uievt_push(view, evt, param ? param : page); +int eve_page_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) { + EVEPage *page = (EVEPage *)view; + EVEWidget *widget = page->widget; + int8_t touch_idx = eve_touch_get_idx(touch); + uint16_t _evt; + int i, ret; + + if (touch_idx > 0) return 0; + + _evt = eve_touch_evt(touch, evt, tag0, page->v.tag, 1); + if (_evt) { + ret = page_touch(page, touch, _evt, tag0); + if (ret) return 1; + } + for (i=0; i<page->widget_size; i++) { + if (eve_page_rect_visible(page, &widget->g)) { + _evt = eve_touch_evt(touch, evt, tag0, widget->tag0, widget->tagN - widget->tag0); + if (_evt) { + if (page->track_mode == PAGE_TMODE_NONE) { + ret = widget->touch(widget, touch, _evt); + if (ret) return 1; + } + ret = page_touch(page, touch, _evt, tag0); + if (ret) return 1; + } + } + widget = eve_widget_next(widget); + } + + return 0; } diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h index ded7185..26c33c5 100644 --- a/fw/fe310/eos/eve/screen/page.h +++ b/fw/fe310/eos/eve/screen/page.h @@ -1,6 +1,14 @@ #include <stdint.h> -#define EVE_PAGE_KBDCH_CLOSE 0x1a +#define EVE_PAGE_KBDCH_CLOSE 0x1a + +#define EVE_PAGE_OPT_SCROLL_X 0x01 +#define EVE_PAGE_OPT_SCROLL_Y 0x02 +#define EVE_PAGE_OPT_SCROLL_BACK 0x04 +#define EVE_PAGE_OPT_SCROLL_XY 0x08 +#define EVE_PAGE_OPT_TRACK_EXT_X 0x10 +#define EVE_PAGE_OPT_TRACK_EXT_Y 0x20 +#define EVE_PAGE_OPT_TRACK_EXT_XY (EVE_PAGE_OPT_TRACK_EXT_X | EVE_PAGE_OPT_TRACK_EXT_Y) struct EVEWidget; struct EVEPage; @@ -9,24 +17,40 @@ typedef void (*eve_page_destructor_t) (struct EVEPage *); typedef struct EVEPage { EVEView v; - int win_x; - int win_y; - eve_page_destructor_t destructor; + EVERect g; + int16_t x0; + int16_t y0; EVEViewStack *stack; + eve_page_destructor_t destructor; + struct EVEWidget *widget; + uint16_t widget_size; struct EVEWidget *widget_f; + EVEPhyLHO lho; + uint64_t lho_t0; + uint8_t track_mode; + uint8_t opt; } EVEPage; -void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor); +void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, uint8_t opt,eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor); +void eve_page_update(EVEPage *page, struct EVEWidget *widget, uint16_t widget_size); void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor); void eve_page_close(EVEPage *page); +/* Screen to page coordinates */ int16_t eve_page_x(EVEPage *page, int16_t x); int16_t eve_page_y(EVEPage *page, int16_t y); +/* Page to window coordinates */ +int16_t eve_page_win_x(EVEPage *page, int16_t x); +int16_t eve_page_win_y(EVEPage *page, int16_t y); +/* Page to screen coordinates */ int16_t eve_page_scr_x(EVEPage *page, int16_t x); int16_t eve_page_scr_y(EVEPage *page, int16_t y); - -void eve_page_set_focus(EVEPage *page, struct EVEWidget *widget, EVERect *focus); -struct EVEWidget *eve_page_get_focus(EVEPage *page); int eve_page_rect_visible(EVEPage *page, EVERect *g); -void eve_page_uievt_push(EVEPage *page, uint16_t evt, void *param);
\ No newline at end of file +void eve_page_focus(EVEPage *page, EVERect *rect); +void eve_page_focus_widget(EVEPage *page, struct EVEWidget *widget, EVERect *rect); +struct EVEWidget *eve_page_focus_widget_get(EVEPage *page); +struct EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx); + +uint8_t eve_page_draw(EVEView *view, uint8_t tag0); +int eve_page_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0); diff --git a/fw/fe310/eos/eve/screen/uievt.h b/fw/fe310/eos/eve/screen/uievt.h index a2657d7..0a751ae 100644 --- a/fw/fe310/eos/eve/screen/uievt.h +++ b/fw/fe310/eos/eve/screen/uievt.h @@ -2,4 +2,12 @@ #define EVE_UIEVT_PAGE_UPDATE_G 2 #define EVE_UIEVT_PAGE_SCROLL_START 3 #define EVE_UIEVT_PAGE_SCROLL_STOP 4 -#define EVE_UIEVT_WIDGET_UPDATE_G 5 +#define EVE_UIEVT_PAGE_TRACK_START 5 +#define EVE_UIEVT_PAGE_TRACK_STOP 6 +#define EVE_UIEVT_WIDGET_UPDATE_G 7 + +typedef struct EVEUIEvtTouch { + EVETouch *touch; + uint16_t evt; + uint8_t tag0; +} EVEUIEvtTouch; diff --git a/fw/fe310/eos/eve/screen/view.c b/fw/fe310/eos/eve/screen/view.c index 3f93c2f..10a3ac1 100644 --- a/fw/fe310/eos/eve/screen/view.c +++ b/fw/fe310/eos/eve/screen/view.c @@ -26,13 +26,30 @@ void eve_view_set_color_fg(EVEView *view, uint8_t r, uint8_t g, uint8_t b) { view->color_fg = (r << 16) | (g << 8) | b; } -uint8_t eve_view_clear(EVEView *view, uint8_t tag0) { +uint8_t eve_view_clear(EVEView *view, uint8_t tag0, uint8_t tag_opt) { + EVEWindow *win_scroll = NULL; + EVEWindow *window = view->window; + uint8_t _tag; + + win_scroll = eve_window_scroll(window->root, &_tag); eve_cmd_dl(CLEAR_COLOR_RGBC(view->color_bg)); eve_cmd_dl(COLOR_RGBC(view->color_fg)); - view->tag = tag0; - if (tag0 != EVE_TAG_NOTAG) { - eve_cmd_dl(CLEAR_TAG(tag0)); - tag0++; + if (win_scroll == window) { + view->tag = _tag; + eve_touch_set_opt(view->tag, tag_opt); + eve_cmd_dl(TAG(view->tag)); + eve_cmd_dl(CLEAR_TAG(view->tag)); + } else if (win_scroll) { + view->tag = EVE_NOTAG; + eve_cmd_dl(TAG(view->tag)); + eve_cmd_dl(CLEAR_TAG(view->tag)); + } else { + view->tag = tag0; + if (tag0 != EVE_NOTAG) { + eve_touch_set_opt(tag0, tag_opt); + eve_cmd_dl(CLEAR_TAG(tag0)); + tag0++; + } } eve_cmd_dl(CLEAR(1,1,1)); return tag0; @@ -62,4 +79,16 @@ void eve_view_destroy(EVEWindow *window, EVEViewStack *stack) { void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) { if (view->uievt) view->uievt(view, evt, param); -}
\ No newline at end of file +} + +int eve_view_uievt_tpush(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0) { + if (view->uievt) { + EVEUIEvtTouch param; + + param.touch = touch; + param.evt = t_evt; + param.tag0 = tag0; + view->uievt(view, evt, ¶m); + } + return 0; +} diff --git a/fw/fe310/eos/eve/screen/view.h b/fw/fe310/eos/eve/screen/view.h index 527282b..4f93627 100644 --- a/fw/fe310/eos/eve/screen/view.h +++ b/fw/fe310/eos/eve/screen/view.h @@ -10,7 +10,7 @@ struct EVEWindow; typedef uint8_t (*eve_view_draw_t) (struct EVEView *, uint8_t); typedef int (*eve_view_touch_t) (struct EVEView *, EVETouch *, uint16_t, uint8_t); -typedef void (*eve_view_uievt_t) (struct EVEView *, uint16_t, void *); +typedef int (*eve_view_uievt_t) (struct EVEView *, uint16_t, void *); typedef void (*eve_view_constructor_t) (struct EVEWindow *window, struct EVEViewStack *); typedef struct EVEView { @@ -32,10 +32,11 @@ typedef struct EVEViewStack { void eve_view_init(EVEView *view, struct EVEWindow *window, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, void *param); void eve_view_set_color_bg(EVEView *view, uint8_t r, uint8_t g, uint8_t b); void eve_view_set_color_fg(EVEView *view, uint8_t r, uint8_t g, uint8_t b); -uint8_t eve_view_clear(EVEView *view, uint8_t tag0); +uint8_t eve_view_clear(EVEView *view, uint8_t tag0, uint8_t tag_opt); void eve_view_stack_init(EVEViewStack *stack); void eve_view_create(struct EVEWindow *window, EVEViewStack *stack, eve_view_constructor_t constructor); void eve_view_destroy(struct EVEWindow *window, EVEViewStack *stack); -void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param);
\ No newline at end of file +void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param); +int eve_view_uievt_tpush(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0); diff --git a/fw/fe310/eos/eve/screen/window.c b/fw/fe310/eos/eve/screen/window.c index 2971ab5..4f059c4 100644 --- a/fw/fe310/eos/eve/screen/window.c +++ b/fw/fe310/eos/eve/screen/window.c @@ -18,21 +18,22 @@ void eve_window_init(EVEWindow *window, EVERect *g, EVEWindow *parent, char *nam window->name = name; } -void eve_window_init_root(EVEWindowRoot *window, EVERect *g, char *name, EVEFont *font) { - EVEWindow *_window = &window->w; +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 = _window; - window->mem_next = EVE_RAM_G; - window->font = font; - window->win_kbd = NULL; - eve_touch_set_handler(eve_window_root_touch, window); + _window->root = root; + root->mem_next = EVE_RAM_G; + root->font = font; + root->win_kbd = NULL; + root->tag0 = 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); + tag0 = eve_view_clear(view, tag0, 0); eve_kbd_draw(kbd); return tag0; @@ -44,14 +45,14 @@ static int kbd_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) return eve_kbd_touch(kbd, touch, evt, tag0); } -void eve_window_init_kbd(EVEWindowKbd *window, EVERect *g, EVEWindowRoot *root, char *name, EVEKbd *kbd) { - EVEWindow *_window = &window->w; +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 = (EVEWindow *)root; - window->kbd = kbd; - root->win_kbd = window; - eve_view_init(&window->v, _window, kbd_draw, kbd_touch, NULL, kbd); + _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); } void eve_window_set_parent(EVEWindow *window, EVEWindow *parent) { @@ -60,8 +61,8 @@ void eve_window_set_parent(EVEWindow *window, EVEWindow *parent) { } int eve_window_visible(EVEWindow *window) { - if (window->g.x >= window->root->g.w) return 0; - if (window->g.y >= window->root->g.h) return 0; + 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; @@ -182,8 +183,8 @@ uint8_t eve_window_draw(EVEWindow *window, uint8_t tag0) { s_h += s_y; s_y = 0; } - if (s_x + s_w > window->root->g.w) s_w = window->root->g.w - s_x; - if (s_y + s_h > window->root->g.h) s_h = window->root->g.h - s_y; + 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); @@ -213,13 +214,14 @@ int eve_window_touch(EVEWindow *window, EVETouch *touch, uint16_t evt, uint8_t t return 0; } -void eve_window_root_draw(EVEWindow *window) { +void eve_window_root_draw(EVEWindowRoot *root) { uint8_t tag0 = 0x80; eve_cmd_burst_start(); eve_cmd_dl(CMD_DLSTART); - eve_window_draw(window, tag0); + if (root->tag0 != EVE_NOTAG) tag0 = EVE_NOTAG; + eve_window_draw(&root->w, tag0); eve_cmd_dl(DISPLAY()); eve_cmd_dl(CMD_SWAP); @@ -228,26 +230,28 @@ void eve_window_root_draw(EVEWindow *window) { } void eve_window_root_touch(EVETouch *touch, uint16_t evt, uint8_t tag0, void *win) { - EVEWindow *window = (EVEWindow *)win; - int ret = eve_window_touch(window, touch, evt, tag0); + EVEWindowRoot *root = (EVEWindowRoot *)win; + int ret; + if (root->tag0 != EVE_NOTAG) tag0 = root->tag0; + ret = eve_window_touch(&root->w, touch, evt, tag0); if (ret) { eve_touch_clear_opt(); - eve_window_root_draw(window); + eve_window_root_draw(root); } } EVEKbd *eve_window_kbd(EVEWindow *window) { - EVEWindowRoot *win_root = (EVEWindowRoot *)window->root; - EVEWindowKbd *win_kbd = win_root->win_kbd; + 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 *win_root = (EVEWindowRoot *)window->root; - EVEWindowKbd *win_kbd = win_root->win_kbd; + EVEWindowRoot *root = window->root; + EVEWindowKbd *win_kbd = root->win_kbd; EVEKbd *kbd = win_kbd ? win_kbd->kbd : NULL; if (kbd) { @@ -257,8 +261,8 @@ void eve_window_kbd_attach(EVEWindow *window) { } void eve_window_kbd_detach(EVEWindow *window) { - EVEWindowRoot *win_root = (EVEWindowRoot *)window->root; - EVEWindowKbd *win_kbd = win_root->win_kbd; + EVEWindowRoot *root = window->root; + EVEWindowKbd *win_kbd = root->win_kbd; EVEKbd *kbd = win_kbd ? win_kbd->kbd : NULL; if (kbd && win_kbd->w.parent) { @@ -268,7 +272,26 @@ void eve_window_kbd_detach(EVEWindow *window) { } EVEFont *eve_window_font(EVEWindow *window) { - EVEWindowRoot *win_root = (EVEWindowRoot *)window->root; + EVEWindowRoot *root = window->root; - return win_root->font; + return root->font; +} + +EVEWindow *eve_window_scroll(EVEWindowRoot *root, uint8_t *tag) { + if (tag) *tag = root->tag0; + return root->win_scroll; +} + +void eve_window_scroll_start(EVEWindow *window, uint8_t tag) { + EVEWindowRoot *root = window->root; + + root->win_scroll = window; + root->tag0 = tag; +} + +void eve_window_scroll_stop(EVEWindow *window) { + EVEWindowRoot *root = window->root; + + root->win_scroll = NULL; + root->tag0 = EVE_NOTAG; } diff --git a/fw/fe310/eos/eve/screen/window.h b/fw/fe310/eos/eve/screen/window.h index 76ccee9..27465c4 100644 --- a/fw/fe310/eos/eve/screen/window.h +++ b/fw/fe310/eos/eve/screen/window.h @@ -2,11 +2,13 @@ #include "view.h" +struct EVEWindowRoot; + typedef struct EVEWindow { EVERect g; char *name; EVEView *view; - struct EVEWindow *root; + struct EVEWindowRoot *root; struct EVEWindow *parent; struct EVEWindow *next; struct EVEWindow *prev; @@ -25,11 +27,13 @@ typedef struct EVEWindowRoot { uint32_t mem_next; EVEFont *font; EVEWindowKbd *win_kbd; + EVEWindow *win_scroll; + uint8_t tag0; } EVEWindowRoot; void eve_window_init(EVEWindow *window, EVERect *g, EVEWindow *parent, char *name); -void eve_window_init_root(EVEWindowRoot *window, EVERect *g, char *name, EVEFont *font); -void eve_window_init_kbd(EVEWindowKbd *window, EVERect *g, EVEWindowRoot *root, char *name, EVEKbd *kbd); +void eve_window_init_root(EVEWindowRoot *root, EVERect *g, char *name, EVEFont *font); +void eve_window_init_kbd(EVEWindowKbd *win_kbd, EVERect *g, EVEWindowRoot *root, char *name, EVEKbd *kbd); void eve_window_set_parent(EVEWindow *window, EVEWindow *parent); int eve_window_visible(EVEWindow *window); @@ -43,10 +47,14 @@ EVEWindow *eve_window_search(EVEWindow *window, char *name); uint8_t eve_window_draw(EVEWindow *window, uint8_t tag0); int eve_window_touch(EVEWindow *window, EVETouch *touch, uint16_t evt, uint8_t tag0); -void eve_window_root_draw(EVEWindow *window); +void eve_window_root_draw(EVEWindowRoot *root); void eve_window_root_touch(EVETouch *touch, uint16_t evt, uint8_t tag0, void *win); EVEKbd *eve_window_kbd(EVEWindow *window); void eve_window_kbd_attach(EVEWindow *window); void eve_window_kbd_detach(EVEWindow *window); -EVEFont *eve_window_font(EVEWindow *window);
\ No newline at end of file +EVEFont *eve_window_font(EVEWindow *window); + +EVEWindow *eve_window_scroll(EVEWindowRoot *root, uint8_t *tag); +void eve_window_scroll_start(EVEWindow *window, uint8_t tag); +void eve_window_scroll_stop(EVEWindow *window); |