diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-08-23 22:37:16 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-08-23 22:37:16 +0200 |
commit | 1e5eb7cb910e6f23c69c2c986b6373e9f9abb980 (patch) | |
tree | 5e8ed0ad6b2fcba747c626c1c51afebbf76b3b9d /fw/fe310/eos/eve/screen | |
parent | 57c1824affca858023c65c84e188ea7dc6c0a5f2 (diff) |
dynamic memory alloc for gui added; page navigation added
Diffstat (limited to 'fw/fe310/eos/eve/screen')
-rw-r--r-- | fw/fe310/eos/eve/screen/Makefile | 4 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/font.c | 61 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/font.h | 14 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/form.c | 28 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/form.h | 4 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/page.c | 42 | ||||
-rw-r--r-- | fw/fe310/eos/eve/screen/page.h | 25 |
7 files changed, 83 insertions, 95 deletions
diff --git a/fw/fe310/eos/eve/screen/Makefile b/fw/fe310/eos/eve/screen/Makefile index b6cb393..b1650bd 100644 --- a/fw/fe310/eos/eve/screen/Makefile +++ b/fw/fe310/eos/eve/screen/Makefile @@ -2,7 +2,7 @@ include ../../../common.mk CFLAGS += -I.. -I../.. -obj = font.o screen.o window.o kbdwin.o page.o form.o +obj = screen.o window.o kbdwin.o page.o form.o %.o: %.c %.h @@ -14,4 +14,4 @@ obj = font.o screen.o window.o kbdwin.o page.o form.o all: $(obj) clean: - rm -f *.o
\ No newline at end of file + rm -f *.o diff --git a/fw/fe310/eos/eve/screen/font.c b/fw/fe310/eos/eve/screen/font.c deleted file mode 100644 index da02983..0000000 --- a/fw/fe310/eos/eve/screen/font.c +++ /dev/null @@ -1,61 +0,0 @@ -#include <stdlib.h> - -#include "eve.h" -#include "unicode.h" - -#include "font.h" - -void eve_font_init(EVEFont *font, uint8_t font_id) { - uint32_t p; - - p = eve_read32(EVE_ROM_FONT_ADDR); - p += (148 * (font_id - 16)); - font->id = font_id; - font->w = eve_read32(p + 136); - font->h = eve_read32(p + 140); - eve_readb(p, font->w_ch, 128); -} - -uint8_t eve_font_ch_w(EVEFont *font, utf32_t ch) { - if (ch < 128) return font->w_ch[ch]; - return 0; -} - -uint16_t eve_font_str_w(EVEFont *font, utf8_t *str) { - uint16_t r = 0; - utf32_t ch; - uint8_t ch_w; - uint8_t ch_l; - - if (str == NULL) return 0; - - while (*str) { - ch_l = utf8_dec(str, &ch); - ch_w = eve_font_ch_w(font, ch); - r += ch_w; - str += ch_l; - } - - return r; -} - -uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len) { - int i = 0; - uint16_t r = 0; - utf32_t ch; - uint8_t ch_w; - uint8_t ch_l; - - while (i < buf_len) { - ch_l = utf8_dec(buf + i, &ch); - ch_w = eve_font_ch_w(font, ch); - r += ch_w; - i += ch_l; - } - - return r; -} - -uint8_t eve_font_h(EVEFont *font) { - return font->h; -}
\ No newline at end of file diff --git a/fw/fe310/eos/eve/screen/font.h b/fw/fe310/eos/eve/screen/font.h deleted file mode 100644 index aff038c..0000000 --- a/fw/fe310/eos/eve/screen/font.h +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdint.h> - -typedef struct EVEFont { - uint8_t id; - uint8_t w; - uint8_t h; - uint8_t w_ch[128]; -} EVEFont; - -void eve_font_init(EVEFont *font, uint8_t font_id); -uint8_t eve_font_ch_w(EVEFont *font, utf32_t ch); -uint16_t eve_font_str_w(EVEFont *font, utf8_t *str); -uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len); -uint8_t eve_font_h(EVEFont *font); diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c index f7d37ee..52cfdc6 100644 --- a/fw/fe310/eos/eve/screen/form.c +++ b/fw/fe310/eos/eve/screen/form.c @@ -8,15 +8,18 @@ #include "screen.h" #include "window.h" #include "page.h" -#include "font.h" #include "form.h" +#include "widget/font.h" #include "widget/label.h" #include "widget/widget.h" -int eve_form_init(EVEForm *form, EVEWindow *window, EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close) { +#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) +#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) + +int eve_form_init(EVEForm *form, EVEWindow *window, EVEPageStack *stack, EVEWidget *widget, uint16_t widget_size, eve_page_destructor_t destructor) { memset(form, 0, sizeof(EVEForm)); - eve_page_init(&form->p, window, eve_form_touch, eve_form_draw, open, close, eve_form_handle_evt, eve_form_update_g); + eve_page_init(&form->p, window, stack, eve_form_touch, eve_form_draw, eve_form_handle_evt, eve_form_update_g, destructor); form->widget = widget; form->widget_size = widget_size; eve_form_update_g(&form->p, NULL); @@ -80,7 +83,7 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) { return tagN; } -void eve_form_handle_evt(EVEPage *page, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) { +int eve_form_handle_evt(EVEPage *page, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) { /* if (evt & EVE_TOUCH_ETYPE_TRACK_Y) { // do scroll @@ -94,15 +97,28 @@ void eve_form_update_g(EVEPage *page, EVEWidget *_widget) { EVEForm *form = (EVEForm *)page; 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 (widget->label->g.w + widget->g.w > form->p.v.window->g.w) h += widget->label->g.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; - h += widget->g.h; + + w += widget->g.w; + _h = MAX(_h, widget->g.h); widget = eve_widget_next(widget); } diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h index 7742b8c..91a4f8a 100644 --- a/fw/fe310/eos/eve/screen/form.h +++ b/fw/fe310/eos/eve/screen/form.h @@ -8,8 +8,8 @@ typedef struct EVEForm { uint16_t widget_size; } EVEForm; -int eve_form_init(EVEForm *form, EVEWindow *window, struct EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close); +int eve_form_init(EVEForm *form, EVEWindow *window, EVEPageStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_page_destructor_t destructor); int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx); uint8_t eve_form_draw(EVEView *v, uint8_t tag0); -void eve_form_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx); +int eve_form_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx); void eve_form_update_g(EVEPage *page, struct EVEWidget *widget); diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c index f54056c..9579346 100644 --- a/fw/fe310/eos/eve/screen/page.c +++ b/fw/fe310/eos/eve/screen/page.c @@ -8,26 +8,60 @@ #include "screen.h" #include "window.h" #include "page.h" -#include "font.h" +#include "widget/font.h" #include "widget/label.h" #include "widget/widget.h" #define CH_EOF 0x1a -void eve_page_init(EVEPage *page, EVEWindow *window, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g) { +void eve_page_init(EVEPage *page, EVEWindow *window, EVEPageStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, eve_page_destructor_t destructor) { memset(page, 0, sizeof(EVEPage)); page->v.touch = touch; page->v.draw = draw; page->v.window = window; - page->open = open; - page->close = close; page->handle_evt = handle_evt; page->update_g = update_g; + page->destructor = destructor; + page->stack = stack; page->widget_f = NULL; window->view = (EVEView *)page; } +void eve_page_stack_init(EVEPageStack *stack) { + memset(stack, 0, sizeof(EVEPageStack)); +} + +void eve_page_create(EVEWindow *window, EVEPageStack *stack, eve_page_constructor_t constructor) { + if (stack->level < EVE_PAGE_SIZE_STACK - 1) { + stack->constructor[stack->level] = constructor; + stack->level++; + constructor(window, stack); + } +} + +void eve_page_open(EVEPage *parent, eve_page_constructor_t constructor) { + EVEWindow *window = parent->v.window; + EVEPageStack *stack = parent->stack; + + parent->destructor(parent); + eve_page_create(window, stack, constructor); +} + +void eve_page_close(EVEPage *page) { + EVEWindow *window = page->v.window; + EVEPageStack *stack = page->stack; + + if (stack->level > 1) { + eve_page_constructor_t constructor; + + stack->level--; + constructor = stack->constructor[stack->level - 1]; + page->destructor(page); + constructor(window, stack); + } +} + int16_t eve_page_x(EVEPage *page, int16_t x) { return x + page->win_x - page->v.window->g.x; } diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h index eebedfd..227375c 100644 --- a/fw/fe310/eos/eve/screen/page.h +++ b/fw/fe310/eos/eve/screen/page.h @@ -1,25 +1,38 @@ #include <stdint.h> +#define EVE_PAGE_SIZE_STACK 16 + struct EVEPage; struct EVEWidget; +struct EVEPageStack; -typedef void (*eve_page_open_t) (struct EVEPage *, struct EVEPage *); -typedef void (*eve_page_close_t) (struct EVEPage *); -typedef void (*eve_page_evt_handler_t) (struct EVEPage *, struct EVEWidget *, EVETouch *, uint16_t, uint8_t, int); +typedef void (*eve_page_constructor_t) (EVEWindow *window, struct EVEPageStack *); +typedef void (*eve_page_destructor_t) (struct EVEPage *); +typedef int (*eve_page_evt_handler_t) (struct EVEPage *, struct EVEWidget *, EVETouch *, uint16_t, uint8_t, int); typedef void (*eve_page_g_updater_t) (struct EVEPage *, struct EVEWidget *); typedef struct EVEPage { EVEView v; int16_t win_x; int16_t win_y; - eve_page_open_t open; - eve_page_close_t close; eve_page_evt_handler_t handle_evt; eve_page_g_updater_t update_g; + eve_page_destructor_t destructor; + struct EVEPageStack *stack; struct EVEWidget *widget_f; } EVEPage; -void eve_page_init(EVEPage *page, EVEWindow *window, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g); +typedef struct EVEPageStack { + eve_page_constructor_t constructor[EVE_PAGE_SIZE_STACK]; + uint8_t level; +} EVEPageStack; + +void eve_page_init(EVEPage *page, EVEWindow *window, EVEPageStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, eve_page_destructor_t destructor); +void eve_page_stack_init(EVEPageStack *stack); +void eve_page_create(EVEWindow *window, EVEPageStack *stack, eve_page_constructor_t constructor); +void eve_page_open(EVEPage *parent, eve_page_constructor_t constructor); +void eve_page_close(EVEPage *page); + int16_t eve_page_x(EVEPage *page, int16_t x); int16_t eve_page_y(EVEPage *page, int16_t y); int16_t eve_page_scr_x(EVEPage *page, int16_t x); |