diff options
Diffstat (limited to 'fw/fe310/eos/eve/widget')
-rw-r--r-- | fw/fe310/eos/eve/widget/Makefile | 2 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/freew.c | 29 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/freew.h | 6 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/pagew.c | 28 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/pagew.h | 3 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/selectw.c | 24 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/selectw.h | 6 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/spacerw.c | 6 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/spacerw.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/strw.c | 132 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/strw.h | 3 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/textw.c | 159 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/textw.h | 7 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/widget.c | 3 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/widget.h | 5 | ||||
-rw-r--r-- | fw/fe310/eos/eve/widget/widgets.h | 2 |
16 files changed, 175 insertions, 242 deletions
diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile index 720029e..fa5b41c 100644 --- a/fw/fe310/eos/eve/widget/Makefile +++ b/fw/fe310/eos/eve/widget/Makefile @@ -2,7 +2,7 @@ include ../../../common.mk CFLAGS += -I.. -I../.. -obj = clipb.o font.o label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o +obj = clipb.o font.o label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o %.o: %.c %.h diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c index eaf982c..8fcc2f6 100644 --- a/fw/fe310/eos/eve/widget/freew.c +++ b/fw/fe310/eos/eve/widget/freew.c @@ -36,35 +36,26 @@ void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_ } void eve_freew_tag(EVEFreeWidget *widget) { - if (widget->tagN != EVE_TAG_NOTAG) { - eve_cmd_dl(TAG(widget->tagN)); - widget->tagN++; + EVEWidget *_widget = &widget->w; + + if (_widget->tagN != EVE_TAG_NOTAG) { + eve_cmd_dl(TAG(_widget->tagN)); + _widget->tagN++; } } -int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { +int eve_freew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) { EVEFreeWidget *widget = (EVEFreeWidget *)_widget; - EVETouch *t; - uint16_t evt; - int ret = 0; - - if (touch_idx > 0) return 0; - - t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt); - if (t && evt) { - ret = widget->_touch(widget, page, t, evt, tag0, touch_idx); - if (!ret && page && page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx); - } - return ret; + return widget->_touch(widget, page, t, evt); } uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { EVEFreeWidget *widget = (EVEFreeWidget *)_widget; - widget->tag0 = tag0; - widget->tagN = tag0; + _widget->tag0 = tag0; + _widget->tagN = tag0; widget->_draw(widget, page); - return widget->tagN; + return _widget->tagN; } diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h index 3347e68..c7d8076 100644 --- a/fw/fe310/eos/eve/widget/freew.h +++ b/fw/fe310/eos/eve/widget/freew.h @@ -2,15 +2,13 @@ struct EVEFreeWidget; -typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVEPage *, EVETouch *, uint16_t, uint8_t, int); +typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVEPage *, EVETouch *, uint16_t); typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *, EVEPage *); typedef struct EVEFreeWidget { EVEWidget w; eve_freew_touch_t _touch; eve_freew_draw_t _draw; - uint8_t tag0; - uint8_t tagN; } EVEFreeWidget; typedef struct EVEFreeSpec { @@ -24,5 +22,5 @@ void eve_freew_init(EVEFreeWidget *widget, EVERect *g, eve_freew_touch_t touch, void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc); void eve_freew_tag(EVEFreeWidget *widget); -int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); +int eve_freew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt); uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c index 319e207..2142cb9 100644 --- a/fw/fe310/eos/eve/widget/pagew.c +++ b/fw/fe310/eos/eve/widget/pagew.c @@ -39,36 +39,28 @@ void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_vie if (_widget->g.h == 0) _widget->g.h = eve_font_h(font); } -int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { +int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) { EVEPageWidget *widget = (EVEPageWidget *)_widget; - EVETouch *t; - uint16_t evt; - int ret = 0; - - if (touch_idx > 0) return 0; - - t = eve_touch_evt(tag0, touch_idx, widget->tag, 1, &evt); - if (t && evt) { - if (evt & EVE_TOUCH_ETYPE_TRACK_MASK) { - if (page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx); - } else if (evt & EVE_TOUCH_ETYPE_TAG_UP) { - eve_page_open(page, widget->constructor); - ret = 1; - } + + if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + eve_page_open(page, widget->constructor); + return 1; } - return ret; + return 0; } uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { EVEPageWidget *widget = (EVEPageWidget *)_widget; - widget->tag = tag0; + _widget->tag0 = tag0; if (tag0 != EVE_TAG_NOTAG) { eve_cmd_dl(TAG(tag0)); tag0++; } + _widget->tagN = tag0; + eve_cmd(CMD_TEXT, "hhhhs", _widget->g.x, _widget->g.y, widget->font->id, 0, widget->title); - return tag0; + return _widget->tagN; } diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h index 67b1199..6560654 100644 --- a/fw/fe310/eos/eve/widget/pagew.h +++ b/fw/fe310/eos/eve/widget/pagew.h @@ -5,7 +5,6 @@ typedef struct EVEPageWidget { char *title; EVEFont *font; eve_view_constructor_t constructor; - uint8_t tag; } EVEPageWidget; typedef struct EVEPageSpec { @@ -18,5 +17,5 @@ int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPageSpec *spec); void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEFont *font, char *title, eve_view_constructor_t constructor); void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_view_constructor_t constructor); -int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); +int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt); uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c index 48f7f6d..eeb956f 100644 --- a/fw/fe310/eos/eve/widget/selectw.c +++ b/fw/fe310/eos/eve/widget/selectw.c @@ -50,11 +50,11 @@ void eve_selectw_update(EVESelectWidget *widget, EVEFont *font, utf8_t *option, if (option) { widget->option = option; widget->option_size = option_size; + widget->select = SELECTW_NOSELECT; } - widget->select = SELECTW_NOSELECT; } -int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt, uint8_t tag0, int touch_idx) { +int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) { EVESelectWidget *widget = (EVESelectWidget *)_widget; if (evt & EVE_TOUCH_ETYPE_TAG_UP) { @@ -111,11 +111,7 @@ uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { } } while (o_len); - new_h = i * widget->font->h; - if (_widget->g.h != new_h) { - _widget->g.h = new_h; - if (page && page->update_g) page->update_g(page, _widget); - } + _widget->g.h = i * widget->font->h; return _widget->tagN; } @@ -138,10 +134,8 @@ utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) { return NULL; } -int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size) { - if (size > widget->option_size) return EVE_ERR_FULL; - memcpy(widget->option, opt, size); - memset(widget->option + size, 0, widget->option_size - size); +utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) { + return eve_selectw_option_get(widget, widget->select); } int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt) { @@ -162,6 +156,10 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt) { return EVE_OK; } -utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) { - return eve_selectw_option_get(widget, widget->select); +int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size) { + if (size > widget->option_size) return EVE_ERR_FULL; + memcpy(widget->option, opt, size); + memset(widget->option + size, 0, widget->option_size - size); + + return EVE_OK; } diff --git a/fw/fe310/eos/eve/widget/selectw.h b/fw/fe310/eos/eve/widget/selectw.h index 6e2c203..953ba4a 100644 --- a/fw/fe310/eos/eve/widget/selectw.h +++ b/fw/fe310/eos/eve/widget/selectw.h @@ -18,10 +18,10 @@ void eve_selectw_destroy(EVESelectWidget *widget); void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEFont *font, utf8_t *option, uint16_t option_size); void eve_selectw_update(EVESelectWidget *widget, EVEFont *font, utf8_t *option, uint16_t option_size); -int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt, uint8_t tag0, int touch_idx); +int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt); uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx); -int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size); -int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt); utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget); +int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt); +int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size); diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c index e53c9c1..3a0216f 100644 --- a/fw/fe310/eos/eve/widget/spacerw.c +++ b/fw/fe310/eos/eve/widget/spacerw.c @@ -28,10 +28,12 @@ void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g) { eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, eve_spacerw_touch, eve_spacerw_draw, NULL); } -int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { +int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) { return 0; } uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { - return tag0; + _widget->tag0 = tag0; + _widget->tagN = tag0; + return _widget->tagN; } diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h index cbde4e8..073f134 100644 --- a/fw/fe310/eos/eve/widget/spacerw.h +++ b/fw/fe310/eos/eve/widget/spacerw.h @@ -10,5 +10,5 @@ typedef struct EVESpacerSpec { int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVESpacerSpec *spec); void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g); -int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); +int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt); uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c index 0e1c97f..fe71b89 100644 --- a/fw/fe310/eos/eve/widget/strw.c +++ b/fw/fe310/eos/eve/widget/strw.c @@ -24,9 +24,9 @@ #define CH_CTRLC 0x03 #define CH_CTRLV 0x16 -#define STRW_TMODE_CURSOR 1 -#define STRW_TMODE_SCROLL_X 2 -#define STRW_TMODE_SCROLL_Y 3 +#define STRW_TRACK_NONE 0 +#define STRW_TRACK_CRSR 1 +#define STRW_TRACK_TXT 2 #define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f)) @@ -97,93 +97,76 @@ static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVE return NULL; } -int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { +int eve_strw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) { EVEStrWidget *widget = (EVEStrWidget *)_widget; - EVETouch *t; - uint16_t evt; + EVEStrCursor *t_cursor = NULL; + short dx; + int ret = 0; - if (touch_idx > 0) return 0; - - t = eve_touch_evt(tag0, touch_idx, widget->tag, 1, &evt); - if (t && evt) { - EVEStrCursor *t_cursor = NULL; - short dx; - - if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) { - if (widget->cursor2.on) { - t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx); - } - if ((t_cursor == NULL) && widget->cursor1.on) { - t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx); - } - if (evt & EVE_TOUCH_ETYPE_TRACK_START) { + if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) { + if (widget->cursor2.on) { + t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx); + } + if ((t_cursor == NULL) && widget->cursor1.on) { + t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx); + } + if (evt & EVE_TOUCH_ETYPE_TRACK_START) { + if (t_cursor) { + widget->track.mode = STRW_TRACK_CRSR; widget->track.cursor = t_cursor; - if (t_cursor) { - widget->track.mode = STRW_TMODE_CURSOR; - widget->track.dx = dx; - } else if (t->eevt & EVE_TOUCH_EETYPE_TRACK_X) { - widget->track.mode = STRW_TMODE_SCROLL_X; - } else if (t->eevt & EVE_TOUCH_EETYPE_TRACK_Y) { - widget->track.mode = STRW_TMODE_SCROLL_Y; - } + widget->track.dx = dx; + } else if (t->eevt & EVE_TOUCH_EETYPE_TRACK_X) { + widget->track.mode = STRW_TRACK_TXT; } } + } - switch (widget->track.mode) { - case STRW_TMODE_SCROLL_Y: - if (page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx); - break; + if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.mode) { + int x, w1; - case STRW_TMODE_SCROLL_X: + switch (widget->track.mode) { + case STRW_TRACK_TXT: if (evt & EVE_TOUCH_ETYPE_TRACK_START) { widget->str_g.x0 = widget->str_g.x; } - if (evt & EVE_TOUCH_ETYPE_TRACK) { - int x = widget->str_g.x0 + t->x0 - t->x; - int w1 = widget->w.g.w - widget->font->w; - - if (x > widget->str_g.w - w1) x = widget->str_g.w - w1; - if (x < 0) x = 0; - widget->str_g.x = x; - } - break; - - case STRW_TMODE_CURSOR: - if (evt & EVE_TOUCH_ETYPE_TRACK) eve_strw_cursor_set(widget, widget->track.cursor, eve_page_x(page, t->x) + widget->track.dx); + x = widget->str_g.x0 + t->x0 - t->x; + w1 = widget->w.g.w - widget->font->w; + if (x > widget->str_g.w - w1) x = widget->str_g.w - w1; + if (x < 0) x = 0; + widget->str_g.x = x; break; - default: - if (evt & EVE_TOUCH_ETYPE_LPRESS) { - if (widget->cursor2.on) { - // copy - } else if (widget->cursor1.on) { - if (t_cursor) { - // paste - } else { - eve_strw_cursor_set(widget, &widget->cursor2, eve_page_x(page, t->x)); - } - } else { - // select - } - } - if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) { - eve_strw_cursor_set(widget, &widget->cursor1, eve_page_x(page, t->x0)); - if (widget->cursor2.on) eve_strw_cursor_clear(widget, &widget->cursor2); - set_focus(widget, page); - } + case STRW_TRACK_CRSR: + eve_strw_cursor_set(widget, widget->track.cursor, eve_page_x(page, t->x) + widget->track.dx); break; } - - if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) { - widget->track.mode = 0; - widget->track.cursor = NULL; - widget->track.dx = 0; + ret = 1; + } else if (evt & EVE_TOUCH_ETYPE_LPRESS) { + if (widget->cursor2.on) { + // copy + } else if (widget->cursor1.on) { + if (t_cursor) { + // paste + } else { + eve_strw_cursor_set(widget, &widget->cursor2, eve_page_x(page, t->x)); + } + } else { + // select } + ret = 1; + } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) { + eve_strw_cursor_set(widget, &widget->cursor1, eve_page_x(page, t->x0)); + if (widget->cursor2.on) eve_strw_cursor_clear(widget, &widget->cursor2); + set_focus(widget, page); + } - return 1; + if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) { + widget->track.mode = STRW_TRACK_NONE; + widget->track.cursor = NULL; + widget->track.dx = 0; } - return 0; + return ret; } static void _draw_str(EVEStrWidget *widget, EVEWindow *window, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) { @@ -227,12 +210,13 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { EVEStrWidget *widget = (EVEStrWidget *)_widget; char cut = widget->str_g.x || (widget->str_g.w > _widget->g.w); - widget->tag = tag0; + _widget->tag0 = tag0; if (tag0 != EVE_TAG_NOTAG) { eve_cmd_dl(TAG(tag0)); eve_touch_set_opt(tag0, EVE_TOUCH_OPT_LPRESS); tag0++; } + _widget->tagN = tag0; if (cut) { EVEWindow *window = page->v.window; @@ -293,7 +277,7 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { eve_cmd_dl(RESTORE_CONTEXT()); } - return tag0; + return _widget->tagN; } void eve_strw_putc(void *_page, int c) { diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h index 9456603..dcb34c1 100644 --- a/fw/fe310/eos/eve/widget/strw.h +++ b/fw/fe310/eos/eve/widget/strw.h @@ -19,7 +19,6 @@ typedef struct EVEStrWidget { } str_g; EVEStrCursor cursor1; EVEStrCursor cursor2; - uint8_t tag; struct { EVEStrCursor *cursor; short dx; @@ -37,7 +36,7 @@ void eve_strw_destroy(EVEStrWidget *widget); void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, utf8_t *str, uint16_t str_size); void eve_strw_update(EVEStrWidget *widget, EVEFont *font, utf8_t *str, uint16_t str_size); -int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); +int eve_strw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt); uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); void eve_strw_putc(void *_page, int c); void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x); diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c index c81031a..62cbeff 100644 --- a/fw/fe310/eos/eve/widget/textw.c +++ b/fw/fe310/eos/eve/widget/textw.c @@ -24,9 +24,6 @@ #define CH_CTRLC 0x03 #define CH_CTRLV 0x16 -#define TEXTW_TMODE_CURSOR 1 -#define TEXTW_TMODE_SCROLL 2 - #define LINE_LEN(w,l) ((l) ? (w->line[l] ? w->line[l] - w->line[(l) - 1] - 1 : 0) : w->line[l]) #define LINE_START(w,l) ((l) ? w->line[(l) - 1] + 1 : 0) #define LINE_END(w,l) (w->line[l]) @@ -88,7 +85,7 @@ void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16 widget->line_size = line_size; } memset(widget->line, 0xff, line_size * sizeof(uint16_t)); - eve_textw_text_update(widget, NULL, 0); + eve_textw_text_update(widget, 0); } static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page) { @@ -105,7 +102,7 @@ static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *pag static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page, EVETouch *t, short *dx, short *dl) { EVEWidget *_widget = &widget->w; int x = eve_page_x(page, t->x0) - _widget->g.x; - int l = (int)t->tag0 - widget->tag0 + widget->line0; + int l = (int)t->tag0 - _widget->tag0 + widget->line0; int _dx, _dl; *dx = cursor->x - x; @@ -118,81 +115,55 @@ static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, return NULL; } -int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) { +int eve_textw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) { EVETextWidget *widget = (EVETextWidget *)_widget; - EVETouch *t; - uint16_t evt; - - if (touch_idx > 0) return 0; + EVETextCursor *t_cursor = NULL; + short dx, dl; + int ret = 0; - t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt); - if (t && evt) { - EVETextCursor *t_cursor = NULL; - short dx, dl; - - if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) { - if (widget->cursor2.on) { - t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx, &dl); - } - if ((t_cursor == NULL) && widget->cursor1.on) { - t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx, &dl); - } - if (evt & EVE_TOUCH_ETYPE_TRACK_START) { - widget->track.cursor = t_cursor; - if (t_cursor) { - widget->track.mode = TEXTW_TMODE_CURSOR; - widget->track.dx = dx; - widget->track.dl = dl; - } else { - widget->track.mode = TEXTW_TMODE_SCROLL; - } - } + if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) { + if (widget->cursor2.on) { + t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx, &dl); } - - switch (widget->track.mode) { - case TEXTW_TMODE_SCROLL: - if (page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx); - break; - - case TEXTW_TMODE_CURSOR: - if (evt & EVE_TOUCH_ETYPE_TRACK) { - eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx); - } - break; - - default: - if (evt & EVE_TOUCH_ETYPE_LPRESS) { - if (widget->cursor2.on) { - // copy - } else if (widget->cursor1.on) { - if (t_cursor && (dl == 0)) { - // paste - } else { - eve_textw_cursor_set(widget, &widget->cursor2, t->tag, eve_page_x(page, t->x)); - } - } else { - // select - } - } - if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) { - eve_textw_cursor_set(widget, &widget->cursor1, t->tag_up, eve_page_x(page, t->x0)); - if (widget->cursor2.on) eve_textw_cursor_clear(widget, &widget->cursor2); - set_focus(widget, &widget->cursor1, page); - } - break; + if ((t_cursor == NULL) && widget->cursor1.on) { + t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx, &dl); } + if (t_cursor && (evt & EVE_TOUCH_ETYPE_TRACK_START)) { + widget->track.cursor = t_cursor; + widget->track.dx = dx; + widget->track.dl = dl; + } + } - if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) { - widget->track.mode = 0; - widget->track.cursor = NULL; - widget->track.dx = 0; - widget->track.dl = 0; + if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.cursor) { + eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx); + ret = 1; + } else if (evt & EVE_TOUCH_ETYPE_LPRESS) { + if (widget->cursor2.on) { + // copy + } else if (widget->cursor1.on) { + if (t_cursor && (dl == 0)) { + // paste + } else { + eve_textw_cursor_set(widget, &widget->cursor2, t->tag, eve_page_x(page, t->x)); + } + } else { + // select } + ret = 1; + } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) { + eve_textw_cursor_set(widget, &widget->cursor1, t->tag_up, eve_page_x(page, t->x0)); + if (widget->cursor2.on) eve_textw_cursor_clear(widget, &widget->cursor2); + set_focus(widget, &widget->cursor1, page); + } - return 1; + if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) { + widget->track.cursor = NULL; + widget->track.dx = 0; + widget->track.dl = 0; } - return 0; + return ret; } static void _draw_line(EVETextWidget *widget, EVEWindow *window, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) { @@ -250,8 +221,8 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { EVETextCursor *c1, *c2; widget->line0 = line0; - widget->tag0 = tag0; - widget->tagN = tag0; + _widget->tag0 = tag0; + _widget->tagN = tag0; if (widget->cursor2.on) { if (widget->cursor1.ch <= widget->cursor2.ch) { @@ -267,10 +238,10 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { } for (i=line0; i<lineN; i++) { - if (widget->tagN != EVE_TAG_NOTAG) { - eve_cmd_dl(TAG(widget->tagN)); - eve_touch_set_opt(widget->tagN, EVE_TOUCH_OPT_LPRESS); - widget->tagN++; + if (_widget->tagN != EVE_TAG_NOTAG) { + eve_cmd_dl(TAG(_widget->tagN)); + eve_touch_set_opt(_widget->tagN, EVE_TOUCH_OPT_LPRESS); + _widget->tagN++; } if (!s && c1 && (c1->line == i)) { int l1, l2, l3; @@ -306,22 +277,22 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { } } if (lineNvisible) { - if (widget->tagN != EVE_TAG_NOTAG) { - eve_cmd_dl(TAG(widget->tagN)); - eve_touch_set_opt(widget->tagN, EVE_TOUCH_OPT_LPRESS); - widget->tagN++; + if (_widget->tagN != EVE_TAG_NOTAG) { + eve_cmd_dl(TAG(_widget->tagN)); + eve_touch_set_opt(_widget->tagN, EVE_TOUCH_OPT_LPRESS); + _widget->tagN++; } _draw_line(widget, page->v.window, lineN, 0, 0, 0, _widget->g.w, 0); } - - return widget->tagN; } else { widget->line0 = 0; - widget->tag0 = EVE_TAG_NOTAG; - widget->tagN = EVE_TAG_NOTAG; - - return tag0; + _widget->tag0 = EVE_TAG_NOTAG; + _widget->tagN = EVE_TAG_NOTAG; } + + _widget->g.h = (widget->line_len + 1) * widget->font->h; + + return _widget->tagN; } void eve_textw_putc(void *_page, int c) { @@ -428,8 +399,8 @@ void eve_textw_putc(void *_page, int c) { } r = cursor1->line; - if (cursor1->line) r = eve_textw_text_update(widget, page, cursor1->line - 1); - if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_text_update(widget, page, cursor1->line); + if (cursor1->line) r = eve_textw_text_update(widget, cursor1->line - 1); + if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_text_update(widget, cursor1->line); if (cursor1->line && (cursor1->ch < LINE_START(widget, cursor1->line))) { cursor1->line--; @@ -444,7 +415,7 @@ void eve_textw_putc(void *_page, int c) { } } -uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t line) { +uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line) { int i; utf32_t ch; uint8_t ch_w; @@ -501,16 +472,10 @@ uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t li } widget->line_len = line; - new_h = (line + 1) * widget->font->h; for (i=line; i<widget->line_size; i++) { widget->line[i] = LINE_EMPTY; } - if (_widget->g.h != new_h) { - _widget->g.h = new_h; - if (page && page->update_g) page->update_g(page, _widget); - } - return line; } @@ -537,7 +502,7 @@ void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t uint8_t ch_l; EVEWidget *_widget = &widget->w; - if ((tag >= widget->tag0) && ((widget->tagN == EVE_TAG_NOTAG) || (tag < widget->tagN))) c_line = tag - widget->tag0 + widget->line0; + if ((tag >= _widget->tag0) && ((_widget->tagN == EVE_TAG_NOTAG) || (tag < _widget->tagN))) c_line = tag - _widget->tag0 + widget->line0; if (c_line < widget->line_len) { cursor->line = c_line; } else if (c_line == widget->line_len) { diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h index 36ab466..95f0091 100644 --- a/fw/fe310/eos/eve/widget/textw.h +++ b/fw/fe310/eos/eve/widget/textw.h @@ -19,13 +19,10 @@ typedef struct EVETextWidget { EVETextCursor cursor1; EVETextCursor cursor2; uint16_t line0; - uint8_t tag0; - uint8_t tagN; struct { EVETextCursor *cursor; short dx; short dl; - char mode; } track; } EVETextWidget; @@ -40,10 +37,10 @@ void eve_textw_destroy(EVETextWidget *widget); void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size); void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size); -int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx); +int eve_textw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt); uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); void eve_textw_putc(void *_w, int c); -uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t line); +uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line); void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor); void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t tag, int16_t x); void eve_textw_cursor_clear(EVETextWidget *widget, EVETextCursor *cursor); diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c index 1d610bf..a223169 100644 --- a/fw/fe310/eos/eve/widget/widget.c +++ b/fw/fe310/eos/eve/widget/widget.c @@ -19,6 +19,7 @@ static const size_t _widget_size[] = { sizeof(EVEPageWidget), sizeof(EVEStrWidget), sizeof(EVETextWidget), + sizeof(EVESelectWidget), }; static const eve_widget_create_t _widget_create[] = { @@ -28,6 +29,7 @@ static const eve_widget_create_t _widget_create[] = { (eve_widget_create_t)eve_pagew_create, (eve_widget_create_t)eve_strw_create, (eve_widget_create_t)eve_textw_create, + (eve_widget_create_t)eve_selectw_create, }; static const eve_widget_destroy_t _widget_destroy[] = { @@ -37,6 +39,7 @@ static const eve_widget_destroy_t _widget_destroy[] = { NULL, (eve_widget_destroy_t)eve_strw_destroy, (eve_widget_destroy_t)eve_textw_destroy, + (eve_widget_destroy_t)eve_selectw_destroy, }; void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc) { diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h index cff5c1d..3e04f3e 100644 --- a/fw/fe310/eos/eve/widget/widget.h +++ b/fw/fe310/eos/eve/widget/widget.h @@ -5,10 +5,11 @@ #define EVE_WIDGET_TYPE_PAGE 3 #define EVE_WIDGET_TYPE_STR 4 #define EVE_WIDGET_TYPE_TEXT 5 +#define EVE_WIDGET_TYPE_SELECT 6 struct EVEWidget; -typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, uint8_t, int); +typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, EVETouch *, uint16_t); typedef uint8_t (*eve_widget_draw_t) (struct EVEWidget *, EVEPage *, uint8_t); typedef struct EVEWidget { @@ -18,6 +19,8 @@ typedef struct EVEWidget { eve_kbd_input_handler_t putc; EVELabel *label; uint8_t type; + uint8_t tag0; + uint8_t tagN; } EVEWidget; void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc); diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h index 4206894..542b350 100644 --- a/fw/fe310/eos/eve/widget/widgets.h +++ b/fw/fe310/eos/eve/widget/widgets.h @@ -7,6 +7,7 @@ #include "pagew.h" #include "strw.h" #include "textw.h" +#include "selectw.h" typedef union EVEWidgetSpec { EVEFreeSpec free; @@ -14,6 +15,7 @@ typedef union EVEWidgetSpec { EVEPageSpec page; EVEStrSpec str; EVETextSpec text; + EVESelectSpec select; } EVEWidgetSpec; typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *g, EVEWidgetSpec *); |