#include #include #include "eve.h" #include "eve_kbd.h" #include "eve_font.h" #include "window.h" void eve_view_init(EVEView *view, EVEWindow *window, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, void *param) { view->draw = draw; view->touch = touch; view->uievt = uievt; view->param = param; view->window = window; view->color_bg = 0x000000; view->color_fg = 0xffffff; } void eve_view_attach(EVEView *view, EVEWindow *window, void *view_id) { view->window = window; eve_window_attach_view(window, view, view_id); } void eve_view_detach(EVEView *view) { eve_window_detach_view(view->window); } void eve_view_set_param(EVEView *view, void *param) { view->param = param; } void eve_view_set_color_bg(EVEView *view, uint8_t r, uint8_t g, uint8_t b) { view->color_bg = (r << 16) | (g << 8) | b; } 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 tag_opt) { EVEWindow *win_scroll = NULL; EVEWindow *window = view->window; uint8_t scroll_tag; win_scroll = eve_window_scroll(window, &scroll_tag); eve_cmd_dl(CLEAR_COLOR_RGBC(view->color_bg)); eve_cmd_dl(COLOR_RGBC(view->color_fg)); if (win_scroll == window) { view->tag = scroll_tag; } else if (win_scroll) { view->tag = EVE_NOTAG; } else { view->tag = tag0; if (tag0 != EVE_NOTAG) { eve_tag_set_opt(tag0, tag_opt); tag0++; } } eve_cmd_dl(CLEAR_TAG(view->tag)); eve_cmd_dl(CLEAR(1,1,1)); return tag0; } uint8_t eve_view_tag(EVEView *view, uint8_t tag, uint8_t tag_opt) { if (tag != EVE_NOTAG) { eve_tag_set_opt(tag, tag_opt); eve_cmd_dl(TAG(tag)); tag++; } return tag; } void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) { if (view->uievt) view->uievt(view, evt, param); } void eve_view_uievt_push_gest(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt) { EVEUIEvtTouch param; if (view->uievt == NULL) return; param.touch = touch; param.evt = t_evt; view->uievt(view, evt, ¶m); } void eve_vstack_init(EVEVStack *stack) { memset(stack, 0, sizeof(EVEVStack)); } int eve_vstack_push(EVEVStack *stack, eve_view_constructor_t constructor) { if (stack->level == EVE_VIEW_SIZE_STACK) return EVE_ERR_FULL; stack->constructor[stack->level] = constructor; stack->level++; return EVE_OK; } eve_view_constructor_t eve_vstack_pull(EVEVStack *stack) { eve_view_constructor_t constructor; constructor = eve_vstack_get(stack); if (stack->level) { stack->level--; stack->constructor[stack->level] = NULL; } return constructor; } eve_view_constructor_t eve_vstack_get(EVEVStack *stack) { if (stack->level) return stack->constructor[stack->level - 1]; return NULL; } int eve_vstack_empty(EVEVStack *stack) { return (stack->level == 0); } int eve_vstack_full(EVEVStack *stack) { return (stack->level == EVE_VIEW_SIZE_STACK); } int eve_vstack_level(EVEVStack *stack) { return stack->level; } int eve_vstack_create_view(EVEVStack *stack, EVEWindow *window, eve_view_constructor_t constructor) { EVEView *view; int rv; rv = eve_vstack_push(stack, constructor); if (rv) return rv; view = constructor(window, stack); if (view == NULL) { eve_vstack_pull(stack); return EVE_ERR; } eve_view_attach(view, window, constructor); return EVE_OK; } int eve_vstack_back(EVEVStack *stack, EVEWindow *window) { EVEView *view; eve_view_constructor_t constructor; eve_vstack_pull(stack); constructor = eve_vstack_get(stack); if (constructor == NULL) return EVE_ERR_EMPTY; view = constructor(window, stack); if (view == NULL) return EVE_ERR; eve_view_attach(view, window, constructor); return EVE_OK; }