diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-03-07 05:15:17 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-03-07 05:15:17 +0100 |
commit | 8592a98072740de43a5b469f60854d805641c999 (patch) | |
tree | 6a98fc6e90089a2c7257374832299f875bfbefd2 /code/fe310 | |
parent | a0688d29102539f8bc0f5b412683bf3d899d85c0 (diff) |
eve screen/tile/canvas/page/form fw added; page widget added
Diffstat (limited to 'code/fe310')
28 files changed, 624 insertions, 186 deletions
diff --git a/code/fe310/Makefile b/code/fe310/Makefile index e37f235..89ab01b 100644 --- a/code/fe310/Makefile +++ b/code/fe310/Makefile @@ -2,7 +2,7 @@ include common.mk CFLAGS += -I./include -subdirs = drivers gloss metal eos eos/eve eos/eve/widget +subdirs = drivers gloss metal eos eos/eve eos/eve/screen eos/eve/widget all: libeos.a diff --git a/code/fe310/eos/eve/eve.c b/code/fe310/eos/eve/eve.c index 4677dc0..adfe5f9 100644 --- a/code/fe310/eos/eve/eve.c +++ b/code/fe310/eos/eve/eve.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <string.h> #include <stdarg.h> #include <stdio.h> #include <math.h> @@ -168,28 +169,28 @@ static void _cmd_end(void) { } static void _cmd_string(const char *s, uint8_t flags) { - int i = 0, p = 0; + int i = 0; while (s[i] != 0) { - eve_spi_xchg8(s[i], EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg8(s[i], flags); i++; } - eve_spi_xchg8(0, EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg8(0, flags); i++; _cmd_inc(i); } static void _cmd_buffer(const char *b, int size, uint8_t flags) { - int i = 0, p = 0; + int i = 0; for (i=0; i<size; i++) { - eve_spi_xchg8(b[i], EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg8(b[i], flags); } _cmd_inc(size); } void eve_cmd(uint32_t cmd, const char *fmt, ...) { - uint8_t flags = _cmd_burst ? EVE_SPI_FLAG_TX : 0; + uint8_t flags = _cmd_burst ? (EVE_SPI_FLAG_TX | EVE_SPI_FLAG_BSWAP) : EVE_SPI_FLAG_BSWAP; va_list argv; uint16_t *p; int i = 0; @@ -199,21 +200,21 @@ void eve_cmd(uint32_t cmd, const char *fmt, ...) { while (fmt[i]) { switch (fmt[i]) { case 'b': - eve_spi_xchg8(va_arg(argv, int), EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg8(va_arg(argv, int), flags); _cmd_inc(1); break; case 'h': - eve_spi_xchg16(va_arg(argv, int), EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg16(va_arg(argv, int), flags); _cmd_inc(2); break; case 'w': - eve_spi_xchg32(va_arg(argv, int), EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg32(va_arg(argv, int), flags); _cmd_inc(4); break; case '&': p = va_arg(argv, uint16_t *); *p = _cmd_offset; - eve_spi_xchg32(0, EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg32(0, flags); _cmd_inc(4); break; case 's': @@ -225,6 +226,7 @@ void eve_cmd(uint32_t cmd, const char *fmt, ...) { } i++; } + va_end(argv); /* padding */ i = _cmd_offset & 3; /* equivalent to _cmd_offset % 4 */ if (i) { @@ -232,12 +234,11 @@ void eve_cmd(uint32_t cmd, const char *fmt, ...) { _cmd_inc(i); while (i > 0) { - eve_spi_xchg8(0, EVE_SPI_FLAG_BSWAP | flags); + eve_spi_xchg8(0, flags); i--; } } _cmd_end(); - va_end(argv); } uint32_t eve_cmd_result(uint16_t offset) { @@ -403,7 +404,7 @@ void eve_handle_touch(void) { if (touch->tracker.tag && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { touch->tracker.track = 1; touch->evt |= EVE_TOUCH_ETYPE_TRACK_START; - if (!touch->t && (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_INERT)) touch->t = now; + touch->t = now; } if (!_tag0 && ((_tag_opt[touch_tag] | _tag_opt[EVE_TAG_SCREEN]) & EVE_TOUCH_OPT_TIMER_MASK)) { _touch_timer.tag = _tag_opt[touch_tag] & EVE_TOUCH_OPT_TIMER_MASK ? touch_tag : EVE_TAG_SCREEN; @@ -444,7 +445,7 @@ void eve_handle_touch(void) { } touch->tracker.track = 1; touch->evt |= EVE_TOUCH_ETYPE_TRACK_START; - if (!touch->t && (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_INERT)) touch->t = now; + touch->t = now; } } if (_touch_timer.tag && ((dx > EVE_THRESHOLD_X) || (dy > EVE_THRESHOLD_Y))) { @@ -653,6 +654,7 @@ EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t ta *evt = 0; if ((touch_idx < 0) || (touch_idx > 4)) return ret; + if ((tag_min == 0) || (tag_max == 0)) return ret; if ((tag0 < tag_min) || (tag0 > tag_max)) return ret; ret = &_touch[touch_idx]; @@ -667,6 +669,10 @@ EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t ta _tag = ret->tag_up; if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EVE_TOUCH_ETYPE_TAG_UP; } + if (_evt & EVE_TOUCH_ETYPE_TRACK_REG) { + _tag = ret->tracker.tag; + if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EVE_TOUCH_ETYPE_TRACK_REG; + } if (_evt & EVE_TOUCH_ETYPE_TRACK_MASK) { _tag = ret->tracker.tag; if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= _evt & (EVE_TOUCH_ETYPE_TRACK_MASK | EVE_TOUCH_ETYPE_TRACK_XY); @@ -683,6 +689,14 @@ void eve_touch_set_opt(uint8_t tag, uint8_t opt) { _tag_opt[tag] = opt; } +uint8_t eve_touch_get_opt(uint8_t tag) { + return _tag_opt[tag]; +} + +void eve_touch_clear_opt(void) { + memset(_tag_opt, 0, sizeof(_tag_opt)); +} + EVETouchTimer *eve_touch_get_timer(void) { return &_touch_timer; } diff --git a/code/fe310/eos/eve/eve.h b/code/fe310/eos/eve/eve.h index b72fdf5..41882c2 100644 --- a/code/fe310/eos/eve/eve.h +++ b/code/fe310/eos/eve/eve.h @@ -24,7 +24,7 @@ #define EVE_TOUCH_ETYPE_TAG_MASK (EVE_TOUCH_ETYPE_TAG | EVE_TOUCH_ETYPE_TAG_UP) #define EVE_TOUCH_ETYPE_TAP_MASK (EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2) -#define EVE_TOUCH_ETYPE_TRACK_MASK (EVE_TOUCH_ETYPE_TRACK | EVE_TOUCH_ETYPE_TRACK_REG | EVE_TOUCH_ETYPE_TRACK_START | EVE_TOUCH_ETYPE_TRACK_STOP) +#define EVE_TOUCH_ETYPE_TRACK_MASK (EVE_TOUCH_ETYPE_TRACK | EVE_TOUCH_ETYPE_TRACK_START | EVE_TOUCH_ETYPE_TRACK_STOP) #define EVE_TOUCH_ETYPE_POINT_MASK (EVE_TOUCH_ETYPE_POINT | EVE_TOUCH_ETYPE_POINT_UP) /* extended events */ @@ -112,5 +112,7 @@ int eve_init(uint32_t *touch_transform); void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param); EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_max, uint16_t *evt); void eve_touch_set_opt(uint8_t tag, uint8_t opt); +uint8_t eve_touch_get_opt(uint8_t tag); +void eve_touch_clear_opt(void); EVETouchTimer *eve_touch_get_timer(void);
\ No newline at end of file diff --git a/code/fe310/eos/eve/eve_kbd.c b/code/fe310/eos/eve/eve_kbd.c index 73bd9c9..282cb37 100644 --- a/code/fe310/eos/eve/eve_kbd.c +++ b/code/fe310/eos/eve/eve_kbd.c @@ -1,3 +1,5 @@ +#include <stdlib.h> + #include "eve.h" #include "eve_kbd.h" @@ -17,29 +19,39 @@ #define KEY_BS 0x08 #define KEY_RET 0x0a -void eve_kbd_init(EVEKbd *kbd, eve_kbd_input_handler_t putc, uint32_t mem_addr, uint32_t *mem_next) { +void eve_kbd_init(EVEKbd *kbd, uint32_t mem_addr, uint32_t *mem_next) { uint16_t mem_size; + kbd->w = 480; + kbd->h = 225; + kbd->mem_addr = mem_addr; + kbd->mem_size = mem_size; + kbd->key_modifier = 0; + kbd->key_count = 0; + kbd->key_down = 0; + kbd->putc = NULL; + + kbd->active = 1; eve_write16(REG_CMD_DL, 0); - eve_kbd_draw(kbd, 1); + eve_kbd_draw(kbd); eve_cmd_exec(1); mem_size = eve_read16(REG_CMD_DL); eve_cmd(CMD_MEMCPY, "www", mem_addr, EVE_RAM_DL, mem_size); eve_cmd_exec(1); + kbd->active = 0; - kbd->mem_addr = mem_addr; - kbd->mem_size = mem_size; - kbd->key_modifier = 0; - kbd->key_count = 0; - kbd->key_down = 0; - kbd->putc = putc; *mem_next = kbd->mem_addr + kbd->mem_size; } +void eve_kbd_set_handler(EVEKbd *kbd, eve_kbd_input_handler_t putc) { + kbd->putc = putc; +} + int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx, void *w) { + EVETouch *t; uint16_t evt; - EVETouch *t = eve_touch_evt(tag0, touch_idx, 1, 0x7e, &evt); + t = eve_touch_evt(tag0, touch_idx, 1, 0x7e, &evt); if (t && evt) { if (evt & EVE_TOUCH_ETYPE_TAG) { uint8_t _tag = t->tag; @@ -91,14 +103,15 @@ int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx, void *w) { } } } - return 1; + kbd->active = 1; } else { - return 0; + kbd->active = 0; } + return kbd->active; } -uint8_t eve_kbd_draw(EVEKbd *kbd, char active) { - if (active) { +uint8_t eve_kbd_draw(EVEKbd *kbd) { + if (kbd->active) { eve_cmd_dl(SAVE_CONTEXT()); eve_cmd(CMD_KEYS, "hhhhhhs", 0, KEYS_Y + KEYS_RSIZE * 0, 480, KEYS_HEIGHT, KEYS_FSIZE, kbd->key_down, kbd->key_modifier & (FLAG_FN | FLAG_SHIFT) ? "!@#$%^&*()" : (kbd->key_modifier & FLAG_CTRL ? " @[\\]^_? " : "1234567890")); eve_cmd(CMD_KEYS, "hhhhhhs", 0, KEYS_Y + KEYS_RSIZE * 1, 480, KEYS_HEIGHT, KEYS_FSIZE, kbd->key_down, kbd->key_modifier & FLAG_FN ? "-_=+[]{}\\|" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "QWERTYUIOP" : "qwertyuiop"); diff --git a/code/fe310/eos/eve/eve_kbd.h b/code/fe310/eos/eve/eve_kbd.h index c65f7d3..01bd950 100644 --- a/code/fe310/eos/eve/eve_kbd.h +++ b/code/fe310/eos/eve/eve_kbd.h @@ -3,6 +3,8 @@ typedef void (*eve_kbd_input_handler_t) (void *, int); typedef struct EVEKbd { + uint16_t w; + uint16_t h; uint32_t mem_addr; uint16_t mem_size; uint8_t key_count; @@ -10,9 +12,11 @@ typedef struct EVEKbd { uint8_t key_modifier; uint8_t key_modifier_sticky; uint8_t key_modifier_lock; + char active; eve_kbd_input_handler_t putc; } EVEKbd; -void eve_kbd_init(EVEKbd *kbd, eve_kbd_input_handler_t putc_f, uint32_t mem_addr, uint32_t *mem_next); +void eve_kbd_init(EVEKbd *kbd, uint32_t mem_addr, uint32_t *mem_next); +void eve_kbd_set_handler(EVEKbd *kbd, eve_kbd_input_handler_t putc); int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx, void *w); -uint8_t eve_kbd_draw(EVEKbd *kbd, char active);
\ No newline at end of file +uint8_t eve_kbd_draw(EVEKbd *kbd);
\ No newline at end of file diff --git a/code/fe310/eos/eve/eve_platform.c b/code/fe310/eos/eve/eve_platform.c index bc0a7b9..803b071 100644 --- a/code/fe310/eos/eve/eve_platform.c +++ b/code/fe310/eos/eve/eve_platform.c @@ -22,8 +22,6 @@ static void handle_time(unsigned char type) { } static void handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { - uint8_t flags; - eos_spi_dev_start(EOS_DEV_DISP); eve_handle_touch(); eos_spi_dev_stop(); diff --git a/code/fe310/eos/eve/eve_text.c b/code/fe310/eos/eve/eve_text.c index 275f334..1d4174c 100644 --- a/code/fe310/eos/eve/eve_text.c +++ b/code/fe310/eos/eve/eve_text.c @@ -17,7 +17,7 @@ static void scroll1(EVEText *box) { box->dirty = 1; } -void eve_text_init(EVEText *box, uint16_t x, uint16_t y, uint16_t w, uint16_t h, double scale_x, double scale_y, uint8_t tag, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next) { +void eve_text_init(EVEText *box, int16_t x, int16_t y, uint16_t w, uint16_t h, double scale_x, double scale_y, uint8_t tag, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next) { box->x = x; box->y = y; box->w = w; @@ -51,9 +51,11 @@ void eve_text_init(EVEText *box, uint16_t x, uint16_t y, uint16_t w, uint16_t h, } int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx) { + EVETouch *t; uint16_t evt; - EVETouch *t = eve_touch_evt(tag0, touch_idx, box->tag, box->tag, &evt); + int ret = 0; + t = eve_touch_evt(tag0, touch_idx, box->tag, box->tag, &evt); if (t && evt) { if ((evt & EVE_TOUCH_ETYPE_TRACK_START) && (box->line_top < 0)) { box->line_top = box->line0; @@ -69,13 +71,13 @@ int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx) { if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) { box->line_top0 = box->line_top; } - return 1; + ret = 1; } else if (box->line_top >= 0) { box->line_top = -1; box->line_top0 = -1; box->dirty = 1; } - return 0; + return ret; } uint8_t eve_text_draw(EVEText *box) { diff --git a/code/fe310/eos/eve/eve_text.h b/code/fe310/eos/eve/eve_text.h index 814a0cd..0ccf62a 100644 --- a/code/fe310/eos/eve/eve_text.h +++ b/code/fe310/eos/eve/eve_text.h @@ -1,8 +1,8 @@ #include <stdint.h> typedef struct EVEText { - uint16_t x; - uint16_t y; + int16_t x; + int16_t y; uint16_t w; uint16_t h; uint32_t mem_addr; @@ -20,7 +20,7 @@ typedef struct EVEText { char dirty; } EVEText; -void eve_text_init(EVEText *box, uint16_t x, uint16_t y, uint16_t w, uint16_t h, double scale_x, double scale_y, uint8_t tag, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next); +void eve_text_init(EVEText *box, int16_t x, int16_t y, uint16_t w, uint16_t h, double scale_x, double scale_y, uint8_t tag, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next); int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx); uint8_t eve_text_draw(EVEText *box); int eve_text_putc(EVEText *box, int c); diff --git a/code/fe310/eos/eve/screen/Makefile b/code/fe310/eos/eve/screen/Makefile new file mode 100644 index 0000000..313d390 --- /dev/null +++ b/code/fe310/eos/eve/screen/Makefile @@ -0,0 +1,17 @@ +include ../../../common.mk + +CFLAGS += -I. -I.. -I../.. -I../../../include -I../../../drivers + +obj = font.o screen.o tile.o page.o form.o + + +%.o: %.c %.h + $(CC) $(CFLAGS) -c $< + +%.o: %.S + $(CC) $(CFLAGS) -c $< + +all: $(obj) + +clean: + rm -f *.o
\ No newline at end of file diff --git a/code/fe310/eos/eve/screen/font.c b/code/fe310/eos/eve/screen/font.c new file mode 100644 index 0000000..6721f00 --- /dev/null +++ b/code/fe310/eos/eve/screen/font.c @@ -0,0 +1,8 @@ +#include <stdlib.h> + +#include "eve.h" +#include "font.h" + +void eve_font_init(EVEFont *font, uint8_t font_id) { + font->id = font_id; +}
\ No newline at end of file diff --git a/code/fe310/eos/eve/widget/font.h b/code/fe310/eos/eve/screen/font.h index 6fc32ab..409b109 100644 --- a/code/fe310/eos/eve/widget/font.h +++ b/code/fe310/eos/eve/screen/font.h @@ -1,9 +1,9 @@ #include <stdint.h> typedef struct EVEFont { - uint8_t idx; + uint8_t id; uint8_t w[128]; uint8_t h; } EVEFont; -void eve_font_init(EVEFont *font, uint8_t font_idx);
\ No newline at end of file +void eve_font_init(EVEFont *font, uint8_t font_id);
\ No newline at end of file diff --git a/code/fe310/eos/eve/screen/form.c b/code/fe310/eos/eve/screen/form.c new file mode 100644 index 0000000..b4e59b9 --- /dev/null +++ b/code/fe310/eos/eve/screen/form.c @@ -0,0 +1,78 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" + +#include "screen.h" +#include "tile.h" +#include "page.h" +#include "form.h" + +#include "widget/widget.h" + +#define CH_EOF 0x1a + +int eve_form_init(EVEForm *form, EVETile *tile, eve_page_open_t open, eve_page_close_t close, EVEWidget *widget, uint16_t widget_size) { + memset(form, 0, sizeof(EVEForm)); + eve_page_init(&form->p, tile, eve_form_touch, eve_form_draw, open, close); + form->widget = widget; + form->widget_size = widget_size; + +} +int eve_form_touch(EVECanvas *c, uint8_t tag0, int touch_idx) { + EVEForm *form = (EVEForm *)c; + EVEWidget *widget = form->widget; + int a, i, ret = 0; + EVEPageFocus focus = { NULL, {0,0,0,0}}; + + for (i=0; i<form->widget_size; i++) { + a = widget->touch(widget, &form->p, tag0, touch_idx, &focus); + ret = ret || a; + if (focus.w && (form->widget_f != focus.w)) { + EVEKbd *kbd = eve_screen_get_kbd(form->p.tile->screen); + + if (kbd) { + if (form->widget_f && form->widget_f->putc) { + eve_screen_hide_kbd(form->p.tile->screen); + form->widget_f->putc(form->widget_f, CH_EOF); + } + eve_kbd_set_handler(kbd, widget->putc); + if (widget && widget->putc) { + eve_screen_show_kbd(form->p.tile->screen); + } + } + form->widget_f = widget; + } + widget = eve_widget_next(widget); + } + + eve_page_focus(&form->p, &focus); + return ret; +} + +uint8_t eve_form_draw(EVECanvas *c, uint8_t tag0) { + EVEForm *form = (EVEForm *)c; + EVEWidget *widget = form->widget; + int i, j; + uint8_t tagN, _tagN = 0; + + for (i=0; i<form->widget_size; i++) { + tagN = widget->draw(widget, &form->p, tag0); + if (tagN) { + for (j=tag0; j<=tagN; j++) { + eve_touch_set_opt(j, eve_touch_get_opt(j) | EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_INERT); + } + if (tagN < 0xfe) { + tag0 = tagN + 1; + } else { + tag0 = 0; + } + _tagN = tagN; + } + widget = eve_widget_next(widget); + } + + return _tagN; +} + diff --git a/code/fe310/eos/eve/screen/form.h b/code/fe310/eos/eve/screen/form.h new file mode 100644 index 0000000..3edafe8 --- /dev/null +++ b/code/fe310/eos/eve/screen/form.h @@ -0,0 +1,14 @@ +#include <stdint.h> + +struct EVEWidget; + +typedef struct EVEForm { + EVEPage p; + struct EVEWidget *widget_f; + struct EVEWidget *widget; + uint16_t widget_size; +} EVEForm; + +int eve_form_init(EVEForm *form, EVETile *tile, eve_page_open_t open, eve_page_close_t close, struct EVEWidget *widget, uint16_t widget_size); +int eve_form_touch(EVECanvas *c, uint8_t tag0, int touch_idx); +uint8_t eve_form_draw(EVECanvas *c, uint8_t tag0); diff --git a/code/fe310/eos/eve/screen/page.c b/code/fe310/eos/eve/screen/page.c new file mode 100644 index 0000000..f703bd6 --- /dev/null +++ b/code/fe310/eos/eve/screen/page.c @@ -0,0 +1,64 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" + +#include "screen.h" +#include "tile.h" +#include "page.h" + +#include "widget/widget.h" + +void eve_page_init(EVEPage *page, EVETile *tile, eve_canvas_touch_t touch, eve_canvas_draw_t draw, eve_page_open_t open, eve_page_close_t close) { + memset(page, 0, sizeof(EVEPage)); + page->tile = tile; + page->handle_evt = eve_page_handle_evt; +} + +void eve_page_focus(EVEPage *page, EVEPageFocus *focus) { + uint16_t tile_w, tile_h; + + if (focus->w == NULL) return; + eve_tile_get_pos(page->tile, NULL, NULL, &tile_w, &tile_h); + + if (focus->f.x < page->win_x) { + page->win_x -= page->win_x - focus->f.x; + } + if (focus->f.y < page->win_y) { + page->win_y -= page->win_y - focus->f.y; + } + if ((focus->f.x + focus->f.w) > (page->win_x + tile_w)) { + page->win_x += (focus->f.x + focus->f.w) - (page->win_x + tile_w); + } + if ((focus->f.y + focus->f.h) > (page->win_y + tile_h)) { + page->win_y += (focus->f.y + focus->f.h) - (page->win_y + tile_h); + } +} + +void eve_page_widget_focus(EVEPageFocus *focus, EVEWidget *widget) { + focus->w = widget; + focus->f.x = widget->x; + focus->f.y = widget->y; + focus->f.w = widget->w; + focus->f.h = widget->h; +} + +int eve_page_widget_visible(EVEPage *page, EVEWidget *widget) { + uint16_t tile_w, tile_h; + eve_tile_get_pos(page->tile, NULL, NULL, &tile_w, &tile_h); + + if (((widget->x + widget->w) >= page->win_x) && ((widget->y + widget->h) >= page->win_y) && (widget->x <= (page->win_x + tile_w)) && (widget->y <= (page->win_y + tile_h))) return 1; + return 0; +} + +void eve_page_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) { + /* + if (evt & EVE_TOUCH_ETYPE_TRACK_Y) { + // do scroll + } else { + // go back / forward + } + */ +} + diff --git a/code/fe310/eos/eve/screen/page.h b/code/fe310/eos/eve/screen/page.h new file mode 100644 index 0000000..453bfcf --- /dev/null +++ b/code/fe310/eos/eve/screen/page.h @@ -0,0 +1,29 @@ +#include <stdint.h> + +struct EVEPage; +struct EVEWidget; + +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 struct EVEPage { + EVECanvas c; + int16_t win_x; + int16_t win_y; + eve_page_evt_handler_t handle_evt; + eve_page_open_t open; + eve_page_close_t close; + EVETile *tile; +} EVEPage; + +typedef struct EVEPageFocus { + struct EVEWidget *w; + EVEWindow f; +} EVEPageFocus; + +void eve_page_init(EVEPage *page, EVETile *tile, eve_canvas_touch_t touch, eve_canvas_draw_t draw, eve_page_open_t open, eve_page_close_t close); +void eve_page_focus(EVEPage *page, EVEPageFocus *focus); +void eve_page_widget_focus(EVEPageFocus *focus, struct EVEWidget *widget); +int eve_page_widget_visible(EVEPage *page, struct EVEWidget *widget); +void eve_page_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx); diff --git a/code/fe310/eos/eve/screen/screen.c b/code/fe310/eos/eve/screen/screen.c new file mode 100644 index 0000000..c65e8fc --- /dev/null +++ b/code/fe310/eos/eve/screen/screen.c @@ -0,0 +1,43 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" + +#include "screen.h" +#include "tile.h" + +int eve_screen_init(EVEScreen *screen, uint16_t w, uint16_t h) { + memset(screen, 0, sizeof(EVEScreen)); + screen->w = w; + screen->h = h; +} + +void eve_screen_set_kbd(EVEScreen *screen, EVEKbd *kbd) { + screen->kbd = kbd; +} + +EVEKbd *eve_screen_get_kbd(EVEScreen *screen) { + return screen->kbd; +} + +void eve_screen_show_kbd(EVEScreen *screen) { + screen->kbd_active = 1; +} + +void eve_screen_hide_kbd(EVEScreen *screen) { + screen->kbd_active = 0; +} + +void eve_screen_add_tile(EVEScreen *screen, EVETile *tile) { + if (screen->tile_size < EVE_MAX_TILES) { + screen->tile[screen->tile_size] = tile; + screen->tile_size++; + } +} + +void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx) { + eve_touch_clear_opt(); +} + + diff --git a/code/fe310/eos/eve/screen/screen.h b/code/fe310/eos/eve/screen/screen.h new file mode 100644 index 0000000..8627517 --- /dev/null +++ b/code/fe310/eos/eve/screen/screen.h @@ -0,0 +1,30 @@ +#include <stdint.h> + +#define EVE_MAX_TILES 8 + +struct EVETile; + +typedef struct EVEWindow { + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; +} EVEWindow; + +typedef struct EVEScreen { + uint16_t w; + uint16_t h; + EVEKbd *kbd; + struct EVETile *tile[EVE_MAX_TILES]; + uint8_t tile_size; + char kbd_active; +} EVEScreen; + +int eve_screen_init(EVEScreen *screen, uint16_t w, uint16_t h); +void eve_screen_set_kbd(EVEScreen *screen, EVEKbd *kbd) ; +EVEKbd *eve_screen_get_kbd(EVEScreen *screen); +void eve_screen_show_kbd(EVEScreen *screen); +void eve_screen_hide_kbd(EVEScreen *screen); + +void eve_screen_add_tile(EVEScreen *screen, struct EVETile *tile); +void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx); diff --git a/code/fe310/eos/eve/screen/tile.c b/code/fe310/eos/eve/screen/tile.c new file mode 100644 index 0000000..3715f6d --- /dev/null +++ b/code/fe310/eos/eve/screen/tile.c @@ -0,0 +1,32 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" + +#include "screen.h" +#include "tile.h" + +#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) + +void eve_tile_init(EVETile *tile, EVEScreen *screen, uint16_t x, uint16_t y, uint16_t w, uint16_t h, EVECanvas *canvas) { + tile->screen = screen; + tile->x = x; + tile->y = y; + tile->w = w; + tile->h = h; + tile->canvas = canvas; +} + +void eve_tile_get_pos(EVETile *tile, uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h) { + if (x) *x = tile->x; + if (y) *y = tile->y; + if (w) *w = tile->w; + if (h) *h = MIN(tile->x + tile->h, tile->screen->h - (tile->screen->kbd && tile->screen->kbd_active ? tile->screen->kbd->h : 0)); +} + +void eve_canvas_init(EVECanvas *canvas, eve_canvas_touch_t touch, eve_canvas_draw_t draw) { + canvas->touch = touch; + canvas->draw = draw; +} + diff --git a/code/fe310/eos/eve/screen/tile.h b/code/fe310/eos/eve/screen/tile.h new file mode 100644 index 0000000..5fea8bf --- /dev/null +++ b/code/fe310/eos/eve/screen/tile.h @@ -0,0 +1,24 @@ +#include <stdint.h> + +struct EVECanvas; + +typedef int (*eve_canvas_touch_t) (struct EVECanvas *, uint8_t, int); +typedef uint8_t (*eve_canvas_draw_t) (struct EVECanvas *, uint8_t); + +typedef struct EVECanvas { + eve_canvas_touch_t touch; + eve_canvas_draw_t draw; +} EVECanvas; + +typedef struct EVETile { + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; + EVECanvas *canvas; + EVEScreen *screen; +} EVETile; + +void eve_tile_init(EVETile *tile, EVEScreen *screen, uint16_t x, uint16_t y, uint16_t w, uint16_t h, EVECanvas *canvas); +void eve_tile_get_pos(EVETile *tile, uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h); +void eve_canvas_init(EVECanvas *canvas, eve_canvas_touch_t touch, eve_canvas_draw_t draw); diff --git a/code/fe310/eos/eve/widget/Makefile b/code/fe310/eos/eve/widget/Makefile index 7659ef0..476cb77 100644 --- a/code/fe310/eos/eve/widget/Makefile +++ b/code/fe310/eos/eve/widget/Makefile @@ -1,8 +1,8 @@ include ../../../common.mk -CFLAGS += -I.. -I../.. -I../../../include -I../../../drivers +CFLAGS += -I. -I.. -I../.. -I../../../include -I../../../drivers -obj = font.o text.o +obj = widget.o page.o text.o %.o: %.c %.h diff --git a/code/fe310/eos/eve/widget/font.c b/code/fe310/eos/eve/widget/font.c deleted file mode 100644 index 302e998..0000000 --- a/code/fe310/eos/eve/widget/font.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "eve.h" -#include "font.h" - -void eve_font_init(EVEFont *font, uint8_t font_idx) { - font->idx = font_idx; -}
\ No newline at end of file diff --git a/code/fe310/eos/eve/widget/page.c b/code/fe310/eos/eve/widget/page.c new file mode 100644 index 0000000..4b78b3b --- /dev/null +++ b/code/fe310/eos/eve/widget/page.c @@ -0,0 +1,55 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" + +#include "screen/screen.h" +#include "screen/tile.h" +#include "screen/page.h" + +#include "widget.h" +#include "page.h" + +void eve_pagew_init(EVEPageWidget *widget, int16_t x, int16_t y, uint16_t w, uint16_t h, uint8_t font_id, char *title, EVEPage *page) { + memset(widget, 0, sizeof(EVEPageWidget)); + eve_widget_init(&widget->w, EVE_WIDGET_TYPE_PAGE, x, y, w, h, eve_pagew_touch, eve_pagew_draw, NULL); + widget->font_id = font_id; + widget->title = title; + widget->page = page; +} + +int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVEPageFocus *focus) { + 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, widget->tag, &evt); + if (t && evt) { + if (evt & EVE_TOUCH_ETYPE_TRACK_MASK) { + if (page && page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx); + } else if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + widget->page->open(widget->page, page); + if (focus) eve_page_widget_focus(focus, _widget); + } + ret = 1; + } + return ret; +} + +uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { + EVEPageWidget *widget = (EVEPageWidget *)_widget; + char draw = page ? eve_page_widget_visible(page, _widget) : 1; + + widget->tag = 0; + if (draw) { + widget->tag = tag0; + if (widget->tag) eve_cmd_dl(TAG(widget->tag)); + eve_cmd(CMD_TEXT, "hhhhs", _widget->x, _widget->y, widget->font_id, 0, widget->title); + } + + return widget->tag; +} diff --git a/code/fe310/eos/eve/widget/page.h b/code/fe310/eos/eve/widget/page.h new file mode 100644 index 0000000..3b6be70 --- /dev/null +++ b/code/fe310/eos/eve/widget/page.h @@ -0,0 +1,13 @@ +#include <stdint.h> + +typedef struct EVEPageWidget { + EVEWidget w; + char *title; + EVEPage *page; + uint8_t tag; + uint8_t font_id; +} EVEPageWidget; + +void eve_pagew_init(EVEPageWidget *widget, int16_t x, int16_t y, uint16_t w, uint16_t h, uint8_t font_id, char *title, EVEPage *page); +int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVEPageFocus *focus); +uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
\ No newline at end of file diff --git a/code/fe310/eos/eve/widget/screen.h b/code/fe310/eos/eve/widget/screen.h deleted file mode 100644 index d5b4534..0000000 --- a/code/fe310/eos/eve/widget/screen.h +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdint.h> - -struct EVETouch; -struct EVEWidget; - -typedef struct EVERect { - uint16_t x1; - uint16_t y1; - uint16_t x2; - uint16_t y2; -} EVERect; - -typedef struct EVEScreen { - char ro; - EVERect *visible; - void (*handle_evt) (struct EVEScreen *, struct EVEWidget *, uint8_t, int, struct EVETouch *, uint16_t); - void (*move) (struct EVEScreen *, struct EVEWidget *, EVERect *); -} EVEScreen; diff --git a/code/fe310/eos/eve/widget/text.c b/code/fe310/eos/eve/widget/text.c index 71fcf3c..ecdfb32 100644 --- a/code/fe310/eos/eve/widget/text.c +++ b/code/fe310/eos/eve/widget/text.c @@ -2,6 +2,14 @@ #include <string.h> #include "eve.h" +#include "eve_kbd.h" + +#include "screen/screen.h" +#include "screen/tile.h" +#include "screen/page.h" +#include "screen/font.h" + +#include "widget.h" #include "text.h" #define CH_BS 0x08 @@ -16,16 +24,11 @@ #define LINE_END(w,l) (w->line[l]) #define LINE_EMPTY 0xffff -void eve_textw_init(EVETextWidget *widget, uint16_t x, uint16_t y, uint16_t w, uint16_t h, char *text, uint64_t text_size, uint16_t *line, uint16_t line_size, EVEFont *font) { +#define PAGE_WIN_X(p) (p ? p->win_x : 0) + +void eve_textw_init(EVETextWidget *widget, int16_t x, int16_t y, uint16_t w, uint16_t h, EVEFont *font, char *text, uint64_t text_size, uint16_t *line, uint16_t line_size) { memset(widget, 0, sizeof(EVETextWidget)); - widget->w.type = EVE_WIDGET_TYPE_TEXT; - widget->w.x = x; - widget->w.y = y; - widget->w.w = w; - widget->w.h = h; - widget->w.touch = eve_textw_touch; - widget->w.draw = eve_textw_draw; - widget->w.putc = eve_textw_putc; + eve_widget_init(&widget->w, EVE_WIDGET_TYPE_TEXT, x, y, w, h, eve_textw_touch, eve_textw_draw, eve_textw_putc); widget->text = text; widget->text_size = text_size; widget->line = line; @@ -34,9 +37,9 @@ void eve_textw_init(EVETextWidget *widget, uint16_t x, uint16_t y, uint16_t w, u if (text_size && line_size) eve_textw_update(widget, 0); } -static EVETextCursor *cursor_prox(EVETouch *t, EVETextWidget *widget, EVETextCursor *cursor, short *dx, short *dl) { +static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page, EVETouch *t, short *dx, short *dl) { EVEWidget *_widget = (EVEWidget *)widget; - int x = (int)t->x0 - _widget->x; + int x = t->x0 + PAGE_WIN_X(page) - _widget->x; int l = (int)t->tag0 - widget->tag0 + widget->line0; int _dx, _dl; @@ -49,29 +52,27 @@ static EVETextCursor *cursor_prox(EVETouch *t, EVETextWidget *widget, EVETextCur return NULL; } -int eve_textw_touch(EVEWidget *_widget, EVEScreen *screen, uint8_t tag0, int touch_idx) { +int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVEPageFocus *focus) { EVETextWidget *widget = (EVETextWidget *)_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, &evt); if (t && evt) { EVETextCursor *t_cursor = NULL; - EVETextCursor *a_cursor = NULL; short dx, dl; - if (!(evt & EVE_TOUCH_ETYPE_TRACK) || !widget->track.mode) { - if (widget->cursor2.on && widget->tag0) { - t_cursor = cursor_prox(t, widget, &widget->cursor2, &dx, &dl); + if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAG_UP | EVE_TOUCH_ETYPE_TRACK_START)) { + if (widget->cursor2.on) { + t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx, &dl); } - if (widget->cursor1.on && widget->tag0 && (t_cursor == NULL)) { - t_cursor = cursor_prox(t, widget, &widget->cursor1, &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) { - if (!widget->track.mode) { + if (evt & EVE_TOUCH_ETYPE_TRACK_START) { widget->track.cursor = t_cursor; if (t_cursor) { widget->track.mode = TEXTW_TMODE_CURSOR; @@ -81,65 +82,65 @@ int eve_textw_touch(EVEWidget *_widget, EVEScreen *screen, uint8_t tag0, int tou widget->track.mode = TEXTW_TMODE_SCROLL; } } + } - if (widget->track.mode == TEXTW_TMODE_CURSOR) { - eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, t->x + widget->track.dx); - } else { - screen->handle_evt(screen, _widget, tag0, touch_idx, t, evt); - if (evt & EVE_TOUCH_ETYPE_TRACK_Y) { - // do scroll - } else { - // go back / forward - } + if ((evt & EVE_TOUCH_ETYPE_TRACK_MASK) && (widget->track.mode == TEXTW_TMODE_SCROLL)) { + if (page && page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx); + } else { + if (evt & EVE_TOUCH_ETYPE_TRACK) { + eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, t->x + PAGE_WIN_X(page) + widget->track.dx); } - } else if (evt & EVE_TOUCH_ETYPE_LPRESS) { - if (!t_cursor) { - if (widget->cursor2.on) { - // show context w cut / copy / paste - } else if (widget->cursor1.on) { - // show context w paste / select - eve_textw_cursor_set(widget, &widget->cursor2, t->tag, t->x); - } else { - // show context w paste + if (evt & EVE_TOUCH_ETYPE_LPRESS) { + if (!t_cursor) { + if (widget->cursor2.on) { + // show context w cut / copy / paste + } else if (widget->cursor1.on) { + // show context w paste / select + eve_textw_cursor_set(widget, &widget->cursor2, t->tag, t->x + PAGE_WIN_X(page)); + } else { + // show context w paste + } } } - } else if (evt & EVE_TOUCH_ETYPE_TAG_UP) { - if (!t_cursor) { - if (widget->cursor2.on) { - a_cursor = &widget->cursor2; - eve_textw_cursor_set(widget, a_cursor, t->tag_up, t->x); - } else { - a_cursor = &widget->cursor1; - eve_textw_cursor_set(widget, a_cursor, t->tag_up, t->x); + if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + if (!t_cursor) { + if (widget->cursor2.on) { + widget->cursor_f = &widget->cursor2; + eve_textw_cursor_set(widget, &widget->cursor2, t->tag_up, t->x + PAGE_WIN_X(page)); + } else { + widget->cursor_f = &widget->cursor1; + eve_textw_cursor_set(widget, &widget->cursor1, t->tag_up, t->x + PAGE_WIN_X(page)); + } } } + 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_POINT_UP) { - widget->track.mode = 0; - widget->track.cursor = NULL; - widget->track.dx = 0; - widget->track.dl = 0; - } - - if (a_cursor) { - EVERect a; - - a.x1 = _widget->x; - a.y1 = _widget->y + a_cursor->line * widget->font->h; - a.x2 = _widget->x + _widget->w; - a.y2 = _widget->y + (a_cursor->line + 2) * widget->font->h; - screen->move(screen, _widget, &a); - } - if (widget->cursor1.on) return 1; + ret = 1; + } + if (widget->cursor_f && focus) { + focus->f.x = _widget->x; + focus->f.y = _widget->y + widget->cursor_f->line * widget->font->h; + focus->f.w = _widget->w; + focus->f.h = 2 * widget->font->h; + focus->w = _widget; + widget->cursor_f = NULL; } - return 0; + return ret; } static void _draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) { EVEWidget *_widget = (EVEWidget *)widget; if (x1 != x2) { - eve_cmd_dl(TAG(widget->tagN)); + if (widget->tagN) { + eve_cmd_dl(TAG(widget->tagN)); + eve_touch_set_opt(widget->tagN, EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_LPRESS); + } eve_cmd_dl(BEGIN(EVE_RECTS)); if (!s) eve_cmd_dl(COLOR_MASK(0 ,0 ,0 ,0)); eve_cmd_dl(VERTEX2F(_widget->x + x1, _widget->y + l * widget->font->h)); @@ -147,10 +148,9 @@ static void _draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t if (!s) eve_cmd_dl(COLOR_MASK(1 ,1 ,1 ,1)); if (len) { if (s) eve_cmd_dl(COLOR_RGB(0, 0, 0)); - eve_cmd(CMD_TEXT, "hhhhpb", _widget->x, _widget->y + l * widget->font->h, widget->font->idx, 0, widget->text + ch, len, 0); + eve_cmd(CMD_TEXT, "hhhhpb", _widget->x, _widget->y + l * widget->font->h, widget->font->id, 0, widget->text + ch, len, 0); if (s) eve_cmd_dl(COLOR_RGB(255, 255, 255)); } - eve_touch_set_opt(widget->tagN, EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_INERT); } } @@ -166,31 +166,13 @@ static void _draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) { eve_cmd_dl(END()); } -uint8_t eve_textw_draw(EVEWidget *_widget, EVEScreen *screen, uint8_t tag0, char active) { +uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { int i; int line0, lineN; - int _line0, _lineN; char s, w, lineNvisible; - char ro = screen->ro; - EVERect *r = screen->visible; EVETextWidget *widget = (EVETextWidget *)_widget; EVETextCursor *c1, *c2; - if (ro) { - widget->line0 = 0; - widget->tag0 = 0; - widget->tagN = 0; - for (i=0; i<widget->line_len; i++) { - eve_cmd(CMD_TEXT, "hhhhpb", _widget->x, _widget->y + i * widget->font->h, widget->font->idx, 0, widget->text + LINE_START(widget, i), LINE_LEN(widget, i), 0); - } - return 0; - } - - if (widget->cursor1.on && !active) { - eve_textw_cursor_clear(&widget->cursor1); - eve_textw_cursor_clear(&widget->cursor2); - } - if (widget->cursor2.on) { if (widget->cursor1.ch <= widget->cursor2.ch) { c1 = &widget->cursor1; @@ -204,17 +186,21 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEScreen *screen, uint8_t tag0, char c2 = NULL; } - _line0 = line0 = ((int)r->y1 - _widget->y) / widget->font->h; - _lineN = lineN = ((int)r->y2 - _widget->y) / widget->font->h + 1; - // y1 = (int)y_min - y_offset - // y2 = (int)y_max - y_offset - // line0 = ((int)y_min - _widget->y - y_offset) / widget->font->h; - // lineN = ((int)y_max - _widget->y - y_offset) / widget->font->h + 1; - if (line0 < 0) line0 = 0; - if (lineN < 0) lineN = 0; - if (line0 > widget->line_len) line0 = widget->line_len; - if (lineN > widget->line_len) lineN = widget->line_len; - lineNvisible = (lineN >= _line0) && (lineN < _lineN); + if (page) { + int _line0, _lineN; + + _line0 = line0 = ((int)page->win_y - _widget->y) / widget->font->h; + _lineN = lineN = ((int)page->win_y + page->tile->h - _widget->y) / widget->font->h + 1; + if (line0 < 0) line0 = 0; + if (lineN < 0) lineN = 0; + if (line0 > widget->line_len) line0 = widget->line_len; + if (lineN > widget->line_len) lineN = widget->line_len; + lineNvisible = (lineN >= _line0) && (lineN < _lineN); + } else { + line0 = 0; + lineN = widget->line_len; + lineNvisible = 1; + } widget->line0 = line0; widget->tag0 = tag0; widget->tagN = tag0; @@ -265,7 +251,7 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEScreen *screen, uint8_t tag0, char if (widget->cursor2.on && (widget->cursor2.line >= line0) && (widget->cursor2.line < lineN)) _draw_cursor(widget, &widget->cursor2); if (lineNvisible) { _draw_line(widget, lineN, 0, 0, 0, _widget->w, 0); - } else { + } else if (widget->tagN) { widget->tagN--; } eve_cmd_dl(RESTORE_CONTEXT()); @@ -284,8 +270,8 @@ void eve_textw_putc(void *_w, int c) { EVETextCursor *cursor2 = &widget->cursor2; if (c == CH_EOF) { - eve_textw_cursor_clear(&widget->cursor1); - eve_textw_cursor_clear(&widget->cursor2); + if (widget->cursor1.on) eve_textw_cursor_clear(&widget->cursor1); + if (widget->cursor2.on) eve_textw_cursor_clear(&widget->cursor2); return; } @@ -415,7 +401,7 @@ void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor) { cursor->x = x; } -void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t tag, uint16_t x) { +void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t tag, int16_t x) { int i; uint16_t _x, _d; uint16_t c_line = LINE_EMPTY; diff --git a/code/fe310/eos/eve/widget/text.h b/code/fe310/eos/eve/widget/text.h index d75a075..83b131d 100644 --- a/code/fe310/eos/eve/widget/text.h +++ b/code/fe310/eos/eve/widget/text.h @@ -1,9 +1,5 @@ #include <stdint.h> -#include "widget.h" -#include "screen.h" -#include "font.h" - typedef struct EVETextCursor { char on; uint16_t x; @@ -22,6 +18,7 @@ typedef struct EVETextWidget { EVEFont *font; EVETextCursor cursor1; EVETextCursor cursor2; + EVETextCursor *cursor_f; uint16_t line0; uint8_t tag0; uint8_t tagN; @@ -33,11 +30,11 @@ typedef struct EVETextWidget { } track; } EVETextWidget; -void eve_textw_init(EVETextWidget *widget, uint16_t x, uint16_t y, uint16_t w, uint16_t h, char *text, uint64_t text_size, uint16_t *line, uint16_t line_size, EVEFont *font); -int eve_textw_touch(EVEWidget *_widget, EVEScreen *screen, uint8_t tag0, int touch_idx); -uint8_t eve_textw_draw(EVEWidget *_widget, EVEScreen *screen, uint8_t tag0, char active); +void eve_textw_init(EVETextWidget *widget, int16_t x, int16_t y, uint16_t w, uint16_t h, EVEFont *font, char *text, uint64_t text_size, uint16_t *line, uint16_t line_size); +int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx, EVEPageFocus *focus); +uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0); void eve_textw_putc(void *_w, int c); int eve_textw_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, uint16_t x); -void eve_textw_cursor_clear(EVETextCursor *cursor);
\ No newline at end of file +void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t tag, int16_t x); +void eve_textw_cursor_clear(EVETextCursor *cursor); diff --git a/code/fe310/eos/eve/widget/widget.c b/code/fe310/eos/eve/widget/widget.c new file mode 100644 index 0000000..44de4c6 --- /dev/null +++ b/code/fe310/eos/eve/widget/widget.c @@ -0,0 +1,35 @@ +#include <stdlib.h> + +#include "eve.h" +#include "eve_kbd.h" + +#include "screen/screen.h" +#include "screen/tile.h" +#include "screen/page.h" +#include "screen/font.h" + +#include "widget.h" +#include "page.h" +#include "text.h" + +static const size_t _eve_wsize[] = { + 0, + sizeof(EVETextWidget), + sizeof(EVEPageWidget) +}; + +void eve_widget_init(EVEWidget *widget, uint8_t type, int16_t x, int16_t y, uint16_t w, uint16_t h, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc) { + widget->type = type; + widget->x = x; + widget->y = y; + widget->w = w; + widget->h = h; + widget->touch = touch; + widget->draw = draw; + widget->putc = putc; +} + +EVEWidget *eve_widget_next(EVEWidget *widget) { + char *_w = (char *)widget; + return (EVEWidget *)(_w + _eve_wsize[widget->type]); +}
\ No newline at end of file diff --git a/code/fe310/eos/eve/widget/widget.h b/code/fe310/eos/eve/widget/widget.h index 7638bbf..8960e63 100644 --- a/code/fe310/eos/eve/widget/widget.h +++ b/code/fe310/eos/eve/widget/widget.h @@ -1,19 +1,23 @@ #include <stdint.h> -#include "eve_kbd.h" - #define EVE_WIDGET_TYPE_TEXT 1 +#define EVE_WIDGET_TYPE_PAGE 2 + +struct EVEWidget; -struct EVEScreen; +typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, uint8_t, int, EVEPageFocus *); +typedef uint8_t (*eve_widget_draw_t) (struct EVEWidget *, EVEPage *, uint8_t); typedef struct EVEWidget { uint8_t type; - uint16_t x; - uint16_t y; + int16_t x; + int16_t y; uint16_t w; uint16_t h; - int (*touch) (struct EVEWidget *, struct EVEScreen *, uint8_t, int); - uint8_t (*draw) (struct EVEWidget *, struct EVEScreen *, uint8_t, char); + eve_widget_touch_t touch; + eve_widget_draw_t draw; eve_kbd_input_handler_t putc; } EVEWidget; +void eve_widget_init(EVEWidget *widget, uint8_t type, int16_t x, int16_t y, uint16_t w, uint16_t h, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc); +EVEWidget *eve_widget_next(EVEWidget *widget); |