diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-08-09 22:23:08 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-08-09 22:23:08 +0200 |
commit | 3f913efda03fd840cd526ef72e6f397c7da61bd7 (patch) | |
tree | 08f62c93e0e0660fdb7beba32276ff1ceb7a8a3c /fw/fe310/eos/eve | |
parent | 810dde21ee65653c15606917b19566cfbaaf165e (diff) |
code layout
Diffstat (limited to 'fw/fe310/eos/eve')
41 files changed, 703 insertions, 375 deletions
diff --git a/fw/fe310/eos/eve/Makefile b/fw/fe310/eos/eve/Makefile index 462891c..650bff8 100644 --- a/fw/fe310/eos/eve/Makefile +++ b/fw/fe310/eos/eve/Makefile @@ -1,7 +1,8 @@ include ../../common.mk -CFLAGS += -I$(bsp_dir)/include obj = eve.o eve_platform.o eve_touch.o eve_touch_engine.o eve_phy.o eve_vtrack.o eve_font.o eve_kbd.o eve_text.o clipb.o +subdirs = screen widget +lib = ../../libeve.a %.o: %.c %.h @@ -10,7 +11,16 @@ obj = eve.o eve_platform.o eve_touch.o eve_touch_engine.o eve_phy.o eve_vtrack.o %.o: %.S $(CC) $(CFLAGS) -c $< -all: $(obj) +all: $(lib) + +$(lib): $(obj) + for i in $(subdirs); do \ + (cd $$i && $(MAKE)) || exit; \ + done + $(AR) rcs $@ $(obj) screen/*.o widget/*.o clean: - rm -f *.o + for i in $(subdirs); do \ + (cd $$i && $(MAKE) clean) || exit; \ + done + rm -f *.o $(lib) diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c index 02e0cae..5103e5f 100644 --- a/fw/fe310/eos/eve/eve.c +++ b/fw/fe310/eos/eve/eve.c @@ -311,7 +311,7 @@ void eve_handle_intr(void) { if (intr_flags & (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)) eve_handle_touch(intr_flags); } -int eve_init(uint8_t gpio_dir) { +int eve_init(void) { uint8_t chipid = 0; uint8_t reset = 0x07; uint16_t timeout; @@ -343,7 +343,7 @@ int eve_init(uint8_t gpio_dir) { eve_write8(REG_PWM_DUTY, 0x00); eve_write16(REG_GPIOX, 0x0000); - eve_write16(REG_GPIOX_DIR, 0x8000 | (gpio_dir & 0x0f)); + eve_write16(REG_GPIOX_DIR, 0x8000); /* initialize display */ eve_write16(REG_HCYCLE, EVE_HCYCLE); /* total number of clocks per line, incl front/back porch */ @@ -363,7 +363,8 @@ int eve_init(uint8_t gpio_dir) { /* do not set PCLK yet - wait for just after the first display list */ /* disable audio */ - eve_write16(REG_SOUND, 0x0000); /* set synthesizer to silence */ + eve_write16(REG_SOUND, 0x0060); /* set synthesizer to mute */ + eve_write8(REG_PLAY, 0x01); eve_write8(REG_VOL_SOUND, 0x00); /* turn synthesizer volume off */ eve_write8(REG_VOL_PB, 0x00); /* turn recorded audio volume off */ diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h index 6b31818..c1b91e4 100644 --- a/fw/fe310/eos/eve/eve.h +++ b/fw/fe310/eos/eve/eve.h @@ -58,7 +58,7 @@ void eve_cmd_burst_end(void); void eve_handle_intr(void); -int eve_init(uint8_t gpio_dir); +int eve_init(void); void eve_start(void); void eve_stop(void); void eve_start_clk(void); diff --git a/fw/fe310/eos/eve/eve_config.h b/fw/fe310/eos/eve/eve_config.h index b151c63..1126277 100755 --- a/fw/fe310/eos/eve/eve_config.h +++ b/fw/fe310/eos/eve/eve_config.h @@ -3,19 +3,20 @@ /* FocusLCDs E50RG84885LWAM520-CA */ -#define EVE_HLPW 20 /* horizontal low pulse width */ -#define EVE_HBP 60 /* horizontal back porch */ -#define EVE_HFP 40 /* horizontal front porch */ +#define EVE_HLPW 6 /* horizontal low pulse width */ +#define EVE_HBP 6 /* horizontal back porch */ +#define EVE_HFP 6 /* horizontal front porch */ #define EVE_HACT 480 /* horizontal active pixels */ #define EVE_HTOT (EVE_HLPW + EVE_HBP + EVE_HFP + EVE_HACT + 10) -#define EVE_VLPW 26 /* vertical low pulse width */ -#define EVE_VBP 50 /* vertical back porch */ -#define EVE_VFP 30 /* vertical front porch */ +#define EVE_VLPW 6 /* vertical low pulse width */ +#define EVE_VBP 6 /* vertical back porch */ +#define EVE_VFP 6 /* vertical front porch */ #define EVE_VACT 854 /* vertical active pixels */ #define EVE_VTOT (EVE_VLPW + EVE_VBP + EVE_VFP + EVE_VACT + 10) + #define EVE_HCYCLE (EVE_HTOT) /* Th Total length of line (visible and non-visible) (in PCLKs) */ #define EVE_HSIZE (EVE_HACT) /* Length of visible part of line (in PCLKs) - display width */ #define EVE_HOFFSET (EVE_HFP + EVE_HLPW + EVE_HBP) /* Length of non-visible part of line (in PCLK cycles) */ @@ -32,7 +33,8 @@ #define EVE_SWIZZLE 0 /* Defines the arrangement of the RGB pins */ #define EVE_CSPREAD 0 /* helps with noise, when set to 1 fewer signals are changed simultaneously, reset-default: 1 */ -#define EVE_PCLK 2 /* 36 MHz */ +#define EVE_PCLK 1 /* Clock from EVE_PCLK_FREQ */ +#define EVE_PCLK_FREQ 27000000 #define EVE_GEN 4 diff --git a/fw/fe310/eos/eve/eve_phy.c b/fw/fe310/eos/eve/eve_phy.c index 09a86c6..cfddc80 100644 --- a/fw/fe310/eos/eve/eve_phy.c +++ b/fw/fe310/eos/eve/eve_phy.c @@ -9,14 +9,21 @@ void eve_phy_acc_init(EVEPhyAcc *param, int a) { param->a = a; } -void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y) { - double v0 = sqrt(v0x * v0x + v0y * v0y); +int eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, uint32_t t0, int v0x, int v0y) { + double v0; + uint32_t dt = eve_get_tick() - t0; + v0 = sqrt(v0x * v0x + v0y * v0y); + param->k = 2 * v0 / param->a * EVE_RTC_FREQ; + if ((param->k < 0) && (dt >= -param->k / 2)) { + return 0; + } param->x0 = x0; param->y0 = y0; param->v0x = v0x; param->v0y = v0y; - param->k = 2 * v0 / param->a * EVE_RTC_FREQ; + + return 1; } int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y) { @@ -60,6 +67,8 @@ void eve_phy_lho_init(EVEPhyLHO *param, int x, int y, uint32_t T, double d, uint int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0) { param->x0 = x0; param->y0 = y0; + + return 1; } int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y) { diff --git a/fw/fe310/eos/eve/eve_phy.h b/fw/fe310/eos/eve/eve_phy.h index 37d0221..e747b44 100644 --- a/fw/fe310/eos/eve/eve_phy.h +++ b/fw/fe310/eos/eve/eve_phy.h @@ -10,7 +10,7 @@ typedef struct EVEPhyAcc { } EVEPhyAcc; void eve_phy_acc_init(EVEPhyAcc *param, int a); -void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y); +int eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, uint32_t t0, int v0x, int v0y); int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y); typedef struct EVEPhyLHO { diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h index 9d472b5..29240d5 100644 --- a/fw/fe310/eos/eve/eve_platform.h +++ b/fw/fe310/eos/eve/eve_platform.h @@ -1,9 +1,9 @@ #include <stdint.h> #include <stdlib.h> -#include "timer.h" -#include "spi.h" -#include "spi_dev.h" +#include "../soc/timer.h" +#include "../soc/spi.h" +#include "../dev/spi.h" #define EVE_ETYPE_INTR 1 diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c index 0dc8b31..d17a509 100644 --- a/fw/fe310/eos/eve/eve_touch.c +++ b/fw/fe310/eos/eve/eve_touch.c @@ -128,10 +128,18 @@ void eve_handle_touch(uint16_t intr_flags) { touch->tracker.tag = 0; } if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { - if (dx > EVE_TOUCH_THRESHOLD_X) { - touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; + int track_x = 0; + + if ((dx > EVE_TOUCH_THRESHOLD_X) && (dx > EVE_TOUCH_THRESHOLD_Y) && ((touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY) == EVE_TOUCH_OPT_TRACK_XY)) { + if (dx > dy) { + track_x = 1; + } + } else if (dx > EVE_TOUCH_THRESHOLD_X) { + track_x = 1; } - if (dy > EVE_TOUCH_THRESHOLD_Y) { + if (track_x) { + touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; + } else { touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP; } touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; @@ -166,14 +174,18 @@ void eve_handle_touch(uint16_t intr_flags) { eve_timer_set_evt(touch, timer_evt & ~EVE_TOUCH_ETYPE_LPRESS); } if (touch->tracker.tag && touch->tracker.track) { + int start = 0; uint8_t opt = touch_tag_opt[touch->tracker.tag]; uint8_t track_ext = ((opt & EVE_TOUCH_OPT_TRACK_EXT_X) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X)) || ((opt & EVE_TOUCH_OPT_TRACK_EXT_Y) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)); + if (!eve_timer_get_evt(NULL) && track_ext) { EVEVTrack *vtrack = eve_vtrack_get(); + if (vtrack->start) start = vtrack->start(touch, vtrack->param); + } + if (start) { eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK); - if (vtrack->start) vtrack->start(touch, vtrack->param); } else { touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP; } @@ -372,6 +384,10 @@ void eve_timer_stop(void) { if (touch_timer.touch == NULL) eve_timer_clear(NULL); } +int eve_timer_running(void) { + return (touch_timer.evt == EVE_TOUCH_ETYPE_TIMER); +} + void eve_touch_clear_tag0(void) { touch_tag0 = 0; } diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h index e3e92b0..8ec6e0e 100644 --- a/fw/fe310/eos/eve/eve_touch.h +++ b/fw/fe310/eos/eve/eve_touch.h @@ -118,4 +118,5 @@ EVETouchTimer *eve_timer_get_obj(void); void eve_timer_start(uint8_t tag0, uint32_t to); void eve_timer_stop(void); +int eve_timer_running(void); void eve_touch_clear_tag0(void); diff --git a/fw/fe310/eos/eve/eve_touch_engine.c b/fw/fe310/eos/eve/eve_touch_engine.c new file mode 100644 index 0000000..2c75ca0 --- /dev/null +++ b/fw/fe310/eos/eve/eve_touch_engine.c @@ -0,0 +1,119 @@ +#include <stdlib.h> + +#include "eve.h" +#include "eve_touch_engine.h" + +static const uint32_t _reg_touch[] = { + REG_CTOUCH_TOUCH0_XY, + REG_CTOUCH_TOUCH1_XY, + REG_CTOUCH_TOUCH2_XY, + REG_CTOUCH_TOUCH3_XY +}; + +static const uint32_t _reg_tag[] = { + REG_TOUCH_TAG, + REG_TOUCH_TAG1, + REG_TOUCH_TAG2, + REG_TOUCH_TAG3, + REG_TOUCH_TAG4 +}; + +static const uint32_t _reg_track[] = { + REG_TRACKER, + REG_TRACKER_1, + REG_TRACKER_2, + REG_TRACKER_3, + REG_TRACKER_4 +}; + +void eve_touch_init_engine(void) { + /* configure touch */ + eve_write8(REG_CPURESET, 2); /* touch engine reset */ + eve_write16(REG_TOUCH_CONFIG, 0x4000); /* host mode multi touch */ + eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */ + eve_write8(REG_CPURESET, 0); /* clear reset */ + + eve_touch_ehost_enter(0, 0x8000, 0x8000); + eve_touch_ehost_end(); +} + +void eve_touch_start(void) { + uint16_t intr_mask; + + intr_mask = eve_read16(REG_INT_MASK); + eve_write16(REG_INT_MASK, intr_mask | (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)); + + eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); +} + +void eve_touch_stop(void) { + uint16_t intr_mask; + + intr_mask = eve_read16(REG_INT_MASK); + eve_write16(REG_INT_MASK, intr_mask & ~(EVE_INT_CONVCOMPLETE | EVE_INT_TAG)); + eve_timer_clear(NULL); + + eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF); +} + +void eve_touch_set_extended(int extended) { + eve_write8(REG_CPURESET, 2); /* touch engine reset */ + eve_write8(REG_CTOUCH_EXTENDED, !extended); /* set / clear extended mode */ + eve_write8(REG_CPURESET, 0); /* clear reset */ +} + +void eve_touch_get_matrix(uint32_t *touch_matrix) { + touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A); + touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B); + touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C); + touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D); + touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E); + touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F); +} + +void eve_touch_set_matrix(const uint32_t *touch_matrix) { + eve_write32(REG_TOUCH_TRANSFORM_A, touch_matrix[0]); + eve_write32(REG_TOUCH_TRANSFORM_B, touch_matrix[1]); + eve_write32(REG_TOUCH_TRANSFORM_C, touch_matrix[2]); + eve_write32(REG_TOUCH_TRANSFORM_D, touch_matrix[3]); + eve_write32(REG_TOUCH_TRANSFORM_E, touch_matrix[4]); + eve_write32(REG_TOUCH_TRANSFORM_F, touch_matrix[5]); +} + +uint32_t eve_touch_reg_xy(int i) { + uint32_t touch_xy; + + touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y)); + return touch_xy; +} + +uint8_t eve_touch_reg_tag(int i) { + uint8_t touch_tag; + + touch_tag = eve_read8(_reg_tag[i]); + return touch_tag; +} + +uint32_t eve_touch_reg_track(int i) { + uint32_t touch_track; + + touch_track = eve_read32(_reg_track[i]); + return touch_track; +} + +int eve_touch_ehost_ready(void) { + uint8_t ack; + + ack = eve_read8(REG_EHOST_TOUCH_ACK); + return (ack == 1); +} + +void eve_touch_ehost_enter(uint8_t id, uint16_t x, uint16_t y) { + eve_write16(REG_EHOST_TOUCH_X, x); + eve_write16(REG_EHOST_TOUCH_Y, y); + eve_write8(REG_EHOST_TOUCH_ID, id); +} + +void eve_touch_ehost_end(void) { + eve_write8(REG_EHOST_TOUCH_ID, 0xf); +} diff --git a/fw/fe310/eos/eve/eve_touch_engine.h b/fw/fe310/eos/eve/eve_touch_engine.h new file mode 100644 index 0000000..3a7508f --- /dev/null +++ b/fw/fe310/eos/eve/eve_touch_engine.h @@ -0,0 +1,17 @@ +#include <stdint.h> + +void eve_touch_init_engine(void); +void eve_touch_start(void); +void eve_touch_stop(void); + +void eve_touch_set_extended(int extended); +void eve_touch_get_matrix(uint32_t *touch_matrix); +void eve_touch_set_matrix(const uint32_t *touch_matrix); + +int eve_touch_ehost_ready(void); +void eve_touch_ehost_enter(uint8_t id, uint16_t x, uint16_t y); +void eve_touch_ehost_end(void); + +uint32_t eve_touch_reg_xy(int i); +uint8_t eve_touch_reg_tag(int i); +uint32_t eve_touch_reg_track(int i); diff --git a/fw/fe310/eos/eve/eve_vtrack.c b/fw/fe310/eos/eve/eve_vtrack.c index bd9158b..a7619fb 100644 --- a/fw/fe310/eos/eve/eve_vtrack.c +++ b/fw/fe310/eos/eve/eve_vtrack.c @@ -26,9 +26,16 @@ void eve_vtrack_reset(void) { eve_vtrack_set(eve_vtrack_acc_start, eve_vtrack_acc_tick, NULL, &vtrack_acc); } -void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) { - eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to); - if (vtrack.start) vtrack.start(touch, vtrack.param); +int eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) { + if (vtrack.start) { + int start; + + start = vtrack.start(touch, vtrack.param); + if (start) eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to); + + return start; + } + return 0; } void eve_vtrack_stop(EVETouch *touch) { @@ -36,9 +43,10 @@ void eve_vtrack_stop(EVETouch *touch) { eve_vtrack_reset(); } -void eve_vtrack_acc_start(EVETouch *touch, void *p) { +int eve_vtrack_acc_start(EVETouch *touch, void *p) { EVEPhyAcc *param = (EVEPhyAcc *)p; - eve_phy_acc_start(param, touch->x, touch->y, touch->vx, touch->vy); + + return eve_phy_acc_start(param, touch->x, touch->y, touch->t, touch->vx, touch->vy); } int eve_vtrack_acc_tick(EVETouch *touch, void *p) { @@ -46,19 +54,3 @@ int eve_vtrack_acc_tick(EVETouch *touch, void *p) { return eve_phy_acc_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y); } - -void eve_vtrack_lho_start(EVETouch *touch, void *p) { - EVEPhyLHO *param = (EVEPhyLHO *)p; - - eve_phy_lho_start(param, touch->x, touch->y); -} - -int eve_vtrack_lho_tick(EVETouch *touch, void *p) { - EVEPhyLHO *param = (EVEPhyLHO *)p; - - return eve_phy_lho_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y); -} - -void eve_vtrack_lho_stop(EVETouch *touch, void *p) { - eve_vtrack_reset(); -} diff --git a/fw/fe310/eos/eve/eve_vtrack.h b/fw/fe310/eos/eve/eve_vtrack.h index fa7e7b7..8455502 100644 --- a/fw/fe310/eos/eve/eve_vtrack.h +++ b/fw/fe310/eos/eve/eve_vtrack.h @@ -2,7 +2,7 @@ #define EVE_VTRACK_ACC_A 10000 -typedef void (*eve_vtrack_start_t) (EVETouch *, void *); +typedef int (*eve_vtrack_start_t) (EVETouch *, void *); typedef int (*eve_vtrack_tick_t) (EVETouch *, void *); typedef void (*eve_vtrack_stop_t) (EVETouch *, void *); @@ -17,12 +17,8 @@ void eve_vtrack_init(void); EVEVTrack *eve_vtrack_get(void); void eve_vtrack_set(eve_vtrack_start_t start, eve_vtrack_tick_t tick, eve_vtrack_stop_t stop, void *param); void eve_vtrack_reset(void); -void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to); +int eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to); void eve_vtrack_stop(EVETouch *touch); -void eve_vtrack_acc_start(EVETouch *touch, void *p); -int eve_vtrack_acc_tick(EVETouch *touch, void *p); - -void eve_vtrack_lho_start(EVETouch *touch, void *p); -int eve_vtrack_lho_tick(EVETouch *touch, void *p); -void eve_vtrack_lho_stop(EVETouch *touch, void *p); +int eve_vtrack_acc_start(EVETouch *touch, void *p); +int eve_vtrack_acc_tick(EVETouch *touch, void *p);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c index 8555158..13021a0 100644 --- a/fw/fe310/eos/eve/screen/form.c +++ b/fw/fe310/eos/eve/screen/form.c @@ -9,8 +9,6 @@ #include "page.h" #include "form.h" -#include "widget/widgets.h" - #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) @@ -57,7 +55,7 @@ static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) { } } -EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) { +EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec spec[], uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) { EVEWidget *widgets; EVEWidget *widget; EVELabel *label; @@ -65,17 +63,17 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s int w_size = 0; int i, r; - for (i=0; i<spec_size; i++) { - w_size += eve_widget_size(spec[i].widget.type); - } + if (uievt == NULL) uievt = eve_form_uievt; + if (destructor == NULL) destructor = eve_form_destroy; form = eve_malloc(sizeof(EVEForm)); if (form == NULL) { return NULL; } - if (uievt == NULL) uievt = eve_form_uievt; - if (destructor == NULL) destructor = eve_form_destroy; eve_form_init(form, window, stack, NULL, 0, uievt, action, destructor); + for (i=0; i<spec_size; i++) { + w_size += eve_widget_size(spec[i].widget.type); + } widgets = eve_malloc(w_size); if (widgets == NULL) { eve_free(form); @@ -84,7 +82,7 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s 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); + r = eve_widget_create(widget, &spec[i].widget, (EVEPage *)form); if (r) { widgets_destroy(widgets, i); eve_free(widgets); @@ -92,7 +90,6 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s return NULL; } 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); @@ -101,15 +98,13 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s eve_free(form); return NULL; } - eve_label_init(label, &spec[i].label.g, font, spec[i].label.title); + eve_label_create(label, &spec[i].label, (EVEPage *)form); 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); + eve_form_set_widget(form, widgets, spec_size); return form; } @@ -118,11 +113,11 @@ void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWid memset(form, 0, sizeof(EVEForm)); 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_view_uievt_t)uievt, (eve_page_destructor_t)destructor); form->action = action; - eve_form_update(form, widget, widget_size); + eve_form_set_widget(form, widget, widget_size); } -void eve_form_update(EVEForm *form, EVEWidget *widget, uint16_t widget_size) { - eve_page_update((EVEPage *)form, widget, widget_size); +void eve_form_set_widget(EVEForm *form, EVEWidget *widget, uint16_t widget_size) { + eve_page_set_widget((EVEPage *)form, widget, widget_size); form_update_g(form, NULL); } @@ -138,25 +133,24 @@ int eve_form_uievt(EVEForm *form, uint16_t evt, void *param) { form_update_g(form, (EVEWidget *)param); break; - case EVE_UIEVT_PAGE_SCROLL_START: + case EVE_UIEVT_GEST_SCROLL_START: break; - case EVE_UIEVT_PAGE_SCROLL_STOP: + case EVE_UIEVT_GEST_SCROLL_STOP: break; - case EVE_UIEVT_PAGE_TRACK_START: + case EVE_UIEVT_GEST_TRACK_START: break; - case EVE_UIEVT_PAGE_TRACK_STOP: { + case EVE_UIEVT_GEST_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); - } + + 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); } break; } diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h index 272b6ed..62e10f7 100644 --- a/fw/fe310/eos/eve/screen/form.h +++ b/fw/fe310/eos/eve/screen/form.h @@ -1,10 +1,10 @@ #include <stdint.h> -#define EVE_FORM_LABEL_MARGIN 10 +#include "../widget/widget.h" struct EVEWidget; -struct EVEWidgetSpec; struct EVEForm; +struct EVEFormSpec; typedef int (*eve_form_uievt_t) (struct EVEForm *, uint16_t, void *); typedef void (*eve_form_action_t) (struct EVEForm *); @@ -15,9 +15,15 @@ typedef struct EVEForm { eve_form_action_t action; } EVEForm; -EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, struct EVEWidgetSpec *spec, uint16_t spec_size, eve_form_uievt_t uievt, 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_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor); -void eve_form_update(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size); +typedef struct EVEFormSpec { + EVELabelSpec label; + EVEWidgetSpec widget; +} EVEFormSpec; + +EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec *spec, uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor); +void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor); +void eve_form_set_widget(EVEForm *form, EVEWidget *widget, uint16_t widget_size); void eve_form_destroy(EVEForm *form); int eve_form_uievt(EVEForm *form, uint16_t evt, void *param); + diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c index 28526ca..64fc473 100644 --- a/fw/fe310/eos/eve/screen/page.c +++ b/fw/fe310/eos/eve/screen/page.c @@ -8,7 +8,6 @@ #include "window.h" #include "page.h" -#include "widget/label.h" #include "widget/widget.h" #define PAGE_TMODE_NONE 0 @@ -21,10 +20,22 @@ void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, EVEWid page->stack = stack; page->opt = opt; page->destructor = destructor; - eve_page_update(page, widget, widget_size); + eve_page_set_widget(page, widget, widget_size); } -void eve_page_update(EVEPage *page, EVEWidget *widget, uint16_t widget_size) { +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; +} + +void eve_page_set_widget(EVEPage *page, EVEWidget *widget, uint16_t widget_size) { page->widget = widget; page->widget_size = widget_size; } @@ -45,16 +56,16 @@ void eve_page_close(EVEPage *page) { if (stack->level <= 1) return; - if (page->lho_t0) { - page->lho_t0 = 0; + if (eve_timer_running()) { eve_timer_stop(); } if (eve_window_scroll(window->root, NULL) == window) { eve_window_scroll_stop(window); } - if (destructor) destructor(page); eve_window_kbd_detach(window); + + if (destructor) destructor(page); eve_view_destroy(window, stack); } @@ -93,30 +104,32 @@ int eve_page_rect_visible(EVEPage *page, EVERect *g) { return 0; } -void eve_page_focus(EVEPage *page, EVERect *rect) { - if (rect) { - EVERect g; +void eve_page_rect_set_visible(EVEPage *page, EVERect *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; + 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); - } + 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); + } +} + +EVEWidget *eve_page_focus(EVEPage *page) { + return page->widget_f; } -void eve_page_focus_widget(EVEPage *page, EVEWidget *widget, EVERect *rect) { +void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *rect) { if (page->widget_f != widget) { EVEWindow *window = page->v.window; EVEWidget *widget_f = page->widget_f; @@ -131,67 +144,59 @@ void eve_page_focus_widget(EVEPage *page, EVEWidget *widget, EVERect *rect) { if (kbd) eve_kbd_set_handler(kbd, widget->putc, widget); if (!(widget_f && widget_f->putc)) eve_window_kbd_attach(window); } + if (page->widget_f) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_FOCUS_OUT, page->widget_f); page->widget_f = widget; + if (page->widget_f) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_FOCUS_IN, page->widget_f); } - if (rect) eve_page_focus(page, rect); + if (rect) eve_page_rect_set_visible(page, rect); } -EVEWidget *eve_page_focus_widget_get(EVEPage *page) { - return page->widget_f; -} - -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; -} +#include <stdio.h> 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 scroll_x = 0, scroll_y = 0, scroll; 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 (touch) { + if ((page->opt & EVE_PAGE_OPT_SCROLL_XY) == EVE_PAGE_OPT_SCROLL_XY) { + scroll_x = scroll_y = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY); + } else if (page->opt & EVE_PAGE_OPT_SCROLL_X) { + scroll_x = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X); + } else if (page->opt & EVE_PAGE_OPT_SCROLL_Y) { + scroll_y = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y); + } + } scroll = scroll_x || scroll_y; if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & (EVE_TOUCH_EETYPE_TRACK_XY | EVE_TOUCH_EETYPE_ABORT))) { int _ret = 0; - if (page->widget_f) eve_page_focus_widget(page, NULL, NULL); - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TOUCH, touch, evt, tag0); + if (page->widget_f) eve_page_set_focus(page, NULL, NULL); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TOUCH, touch, evt, tag0); if (_ret) return _ret; ret = 1; } - /* Scroll start */ + /* Scroll / track 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_pusht(view, EVE_UIEVT_PAGE_SCROLL_START, touch, evt, tag0); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_START, touch, evt, tag0); } else { page->track_mode = PAGE_TMODE_TRACK; - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TRACK_START, touch, evt, tag0); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TRACK_START, touch, evt, tag0); } if (_ret) return _ret; ret = 1; } - /* Scroll stop */ + /* Scroll / track 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)) { @@ -211,23 +216,29 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0 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_get_tick(); + eve_phy_lho_init(lho, lho_x, lho_y, 100, 0.5, 0); + eve_phy_lho_start(lho, page->g.x, page->g.y); eve_timer_start(_tag, 20); } } - if (!page->lho_t0) { + if (!eve_timer_running()) { 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_pusht(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_pusht(view, EVE_UIEVT_PAGE_TRACK_STOP, touch, evt, tag0); + switch (page->track_mode) { + case PAGE_TMODE_SCROLL: { + page->track_mode = PAGE_TMODE_NONE; + eve_window_scroll_stop(window); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_STOP, touch, evt, tag0); + break; + } + + case PAGE_TMODE_TRACK: { + page->track_mode = PAGE_TMODE_NONE; + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TRACK_STOP, touch, evt, tag0); + break; + } } if (_ret) return _ret; ret = 1; @@ -254,26 +265,26 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0 } if ((evt & EVE_TOUCH_ETYPE_TIMER) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) { EVEPhyLHO *lho = &page->lho; + int scroll_x = page->opt & EVE_PAGE_OPT_SCROLL_X; + int scroll_y = page->opt & EVE_PAGE_OPT_SCROLL_Y; int x, y, more; more = eve_phy_lho_tick(lho, eve_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; + printf("TIMER: %d\n", y); if (!more) { int _ret = 0; - page->lho_t0 = 0; - eve_timer_stop(); + printf("TIMER STOP!\n"); page->track_mode = PAGE_TMODE_NONE; + eve_timer_stop(); eve_window_scroll_stop(window); - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_STOP, touch, evt, tag0); if (_ret) return _ret; } ret = 1; } - if (evt & EVE_TOUCH_EETYPE_TIMER_ABORT) { - page->lho_t0 = 0; - } } return ret; diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h index 0fc9809..7aa8c1d 100644 --- a/fw/fe310/eos/eve/screen/page.h +++ b/fw/fe310/eos/eve/screen/page.h @@ -5,10 +5,11 @@ #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) + +#define EVE_PAGE_OPT_SCROLL_XY (EVE_PAGE_OPT_SCROLL_X | EVE_PAGE_OPT_SCROLL_Y) +#define EVE_PAGE_OPT_TRACK_EXT_XY (EVE_PAGE_OPT_TRACK_EXT_X | EVE_PAGE_OPT_TRACK_EXT_Y) struct EVEWidget; struct EVEPage; @@ -32,7 +33,10 @@ typedef struct EVEPage { } EVEPage; 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); + +struct EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx); +void eve_page_set_widget(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); @@ -46,11 +50,10 @@ int16_t eve_page_win_y(EVEPage *page, int16_t y); int16_t eve_page_scr_x(EVEPage *page, int16_t x); int16_t eve_page_scr_y(EVEPage *page, int16_t y); int eve_page_rect_visible(EVEPage *page, EVERect *g); +void eve_page_rect_set_visible(EVEPage *page, EVERect *rect); -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); +struct EVEWidget *eve_page_focus(EVEPage *page); +void eve_page_set_focus(EVEPage *page, struct EVEWidget *widget, EVERect *rect); 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 98f0d95..8e1e682 100644 --- a/fw/fe310/eos/eve/screen/uievt.h +++ b/fw/fe310/eos/eve/screen/uievt.h @@ -1,11 +1,13 @@ -#define EVE_UIEVT_WIN_UPDATE_G 1 -#define EVE_UIEVT_PAGE_UPDATE_G 2 -#define EVE_UIEVT_PAGE_TOUCH 3 -#define EVE_UIEVT_PAGE_SCROLL_START 4 -#define EVE_UIEVT_PAGE_SCROLL_STOP 5 -#define EVE_UIEVT_PAGE_TRACK_START 6 -#define EVE_UIEVT_PAGE_TRACK_STOP 7 +#define EVE_UIEVT_GEST_TOUCH 1 +#define EVE_UIEVT_GEST_SCROLL_START 2 +#define EVE_UIEVT_GEST_SCROLL_STOP 3 +#define EVE_UIEVT_GEST_TRACK_START 4 +#define EVE_UIEVT_GEST_TRACK_STOP 5 +#define EVE_UIEVT_WIN_UPDATE_G 6 +#define EVE_UIEVT_PAGE_UPDATE_G 7 #define EVE_UIEVT_WIDGET_UPDATE_G 8 +#define EVE_UIEVT_WIDGET_FOCUS_IN 9 +#define EVE_UIEVT_WIDGET_FOCUS_OUT 10 typedef struct EVEUIEvtTouch { EVETouch *touch; diff --git a/fw/fe310/eos/eve/screen/view.c b/fw/fe310/eos/eve/screen/view.c index ac9aef4..466644d 100644 --- a/fw/fe310/eos/eve/screen/view.c +++ b/fw/fe310/eos/eve/screen/view.c @@ -77,18 +77,19 @@ 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); +int eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) { + if (view->uievt) return view->uievt(view, evt, param); + return 0; } -int eve_view_uievt_pusht(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0) { +int eve_view_uievt_push_gest(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 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 65999d7..c8be33a 100644 --- a/fw/fe310/eos/eve/screen/view.h +++ b/fw/fe310/eos/eve/screen/view.h @@ -38,5 +38,5 @@ 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); -int eve_view_uievt_pusht(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0); +int eve_view_uievt_push(EVEView *view, uint16_t evt, void *param); +int eve_view_uievt_push_gest(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0); diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile index 31349a8..0bb1533 100644 --- a/fw/fe310/eos/eve/widget/Makefile +++ b/fw/fe310/eos/eve/widget/Makefile @@ -1,7 +1,7 @@ include ../../../common.mk CFLAGS += -I.. -obj = label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o +obj = label.o widget.o widgets.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o togglew.o %.o: %.c %.h diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c index 86c2686..e7591da 100644 --- a/fw/fe310/eos/eve/widget/freew.c +++ b/fw/fe310/eos/eve/widget/freew.c @@ -8,15 +8,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "freew.h" - -int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec) { - eve_freew_init(widget, g, page, spec->draw, spec->touch, spec->putc); - - return EVE_OK; -} void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc) { EVEWidget *_widget = &widget->w; @@ -25,16 +17,15 @@ void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_ eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, page, eve_freew_draw, eve_freew_touch, putc); widget->_draw = draw; widget->_touch = touch; - widget->w.putc = putc; } -void eve_freew_tag(EVEFreeWidget *widget) { - EVEWidget *_widget = &widget->w; +int eve_freew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEFreeWidget *widget = (EVEFreeWidget *)_widget; + EVEFreeSpec *tspec = &spec->tspec.free; - if (_widget->tagN != EVE_NOTAG) { - eve_cmd_dl(TAG(_widget->tagN)); - _widget->tagN++; - } + eve_freew_init(widget, &spec->g, page, tspec->draw, tspec->touch, tspec->putc); + + return EVE_OK; } uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) { @@ -49,6 +40,18 @@ uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) { int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { EVEFreeWidget *widget = (EVEFreeWidget *)_widget; + int ret; + + ret = widget->_touch(widget, touch, evt); + if (ret) eve_widget_set_focus(_widget, NULL); + return ret; +} - return widget->_touch(widget, touch, evt); +void eve_freew_tag(EVEFreeWidget *widget) { + EVEWidget *_widget = &widget->w; + + if (_widget->tagN != EVE_NOTAG) { + eve_cmd_dl(TAG(_widget->tagN)); + _widget->tagN++; + } } diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h index 7eda8c1..324e98d 100644 --- a/fw/fe310/eos/eve/widget/freew.h +++ b/fw/fe310/eos/eve/widget/freew.h @@ -1,6 +1,7 @@ #include <stdint.h> struct EVEFreeWidget; +struct EVEWidgetSpec; typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *); typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVETouch *, uint16_t); @@ -17,9 +18,10 @@ typedef struct EVEFreeSpec { eve_kbd_input_handler_t putc; } EVEFreeSpec; -int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec); void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc); -void eve_freew_tag(EVEFreeWidget *widget); +int eve_freew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0); int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); + +void eve_freew_tag(EVEFreeWidget *widget); diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c index f2d2e8e..43d555d 100644 --- a/fw/fe310/eos/eve/widget/label.c +++ b/fw/fe310/eos/eve/widget/label.c @@ -16,6 +16,13 @@ void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) { label->font = font; label->title = title; if (label->g.h == 0) label->g.h = eve_font_h(font); + if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title) + EVE_LABEL_MARGIN; +} + +void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page) { + EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); + + eve_label_init(label, &spec->g, font, spec->title); } void eve_label_draw(EVELabel *label) { diff --git a/fw/fe310/eos/eve/widget/label.h b/fw/fe310/eos/eve/widget/label.h index 659c057..9992f8c 100644 --- a/fw/fe310/eos/eve/widget/label.h +++ b/fw/fe310/eos/eve/widget/label.h @@ -1,10 +1,21 @@ #include <stdint.h> +#define EVE_LABEL_MARGIN 10 + typedef struct EVELabel { EVERect g; EVEFont *font; char *title; } EVELabel; +typedef struct EVELabelSpec { + EVERect g; + EVEFont *font; + char *title; + int16_t margin; +} EVELabelSpec; + void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title); + +void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page); void eve_label_draw(EVELabel *label);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c index bd7819f..c926892 100644 --- a/fw/fe310/eos/eve/widget/pagew.c +++ b/fw/fe310/eos/eve/widget/pagew.c @@ -8,17 +8,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "pagew.h" - -int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - - eve_pagew_init(widget, g, page, font, spec->title, spec->constructor); - - return EVE_OK; -} void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor) { EVEWidget *_widget = &widget->w; @@ -31,6 +21,16 @@ void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *f if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font); } +int eve_pagew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEPageWidget *widget = (EVEPageWidget *)_widget; + EVEPageSpec *tspec = &spec->tspec.page; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + + eve_pagew_init(widget, &spec->g, page, font, tspec->title, tspec->constructor); + + return EVE_OK; +} + uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0) { EVEPageWidget *widget = (EVEPageWidget *)_widget; @@ -51,6 +51,7 @@ int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { EVEPageWidget *widget = (EVEPageWidget *)_widget; if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + eve_widget_set_focus(_widget, NULL); eve_page_open(parent, widget->constructor); return 1; } diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h index 76ac0d2..b1a91b2 100644 --- a/fw/fe310/eos/eve/widget/pagew.h +++ b/fw/fe310/eos/eve/widget/pagew.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVEPageWidget { EVEWidget w; EVEFont *font; @@ -13,8 +15,8 @@ typedef struct EVEPageSpec { eve_view_constructor_t constructor; } EVEPageSpec; -int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec); void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor); +int eve_pagew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0); int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c index 46ed3d1..5acf998 100644 --- a/fw/fe310/eos/eve/widget/selectw.c +++ b/fw/fe310/eos/eve/widget/selectw.c @@ -8,9 +8,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "selectw.h" #define SELECTW_NOSELECT 0xffffffff @@ -59,21 +57,6 @@ static void selectw_update_sz(EVESelectWidget *widget, int uievt) { if (uievt) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_UPDATE_G, _widget); } -int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - utf8_t *option; - - option = eve_malloc(spec->option_size); - if (option == NULL) { - return EVE_ERR_NOMEM; - } - memset(option, 0, spec->option_size); - - eve_selectw_init(widget, g, page, font, option, spec->option_size, spec->multi); - - return EVE_OK; -} - void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi) { EVEWidget *_widget = &widget->w; int rv; @@ -92,13 +75,32 @@ void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFon widget->select = widget->multi ? 0 : SELECTW_NOSELECT; } -void eve_selectw_destroy(EVESelectWidget *widget) { +int eve_selectw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVESelectWidget *widget = (EVESelectWidget *)_widget; + EVESelectSpec *tspec = &spec->tspec.select; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + utf8_t *option; + + option = eve_malloc(tspec->option_size); + if (option == NULL) { + return EVE_ERR_NOMEM; + } + memset(option, 0, tspec->option_size); + + eve_selectw_init(widget, &spec->g, page, font, option, tspec->option_size, tspec->multi); + + return EVE_OK; +} + +void eve_selectw_destroy(EVEWidget *_widget) { + EVESelectWidget *widget = (EVESelectWidget *)_widget; + eve_free(widget->option); } uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0) { - EVEPage *page = _widget->page; EVESelectWidget *widget = (EVESelectWidget *)_widget; + EVEPage *page = _widget->page; int o_len; int o_curr; int i, s; @@ -161,6 +163,7 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { if (evt & EVE_TOUCH_ETYPE_TAG_UP) { int i = touch->tag0 - _widget->tag0 + widget->line0; + if (widget->multi) { uint32_t f = (0x1 << i); @@ -176,12 +179,15 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { widget->select = i; } } + + eve_widget_set_focus(_widget, NULL); return 1; } + return 0; } -utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) { +utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx) { int o_len; int o_curr; int i; @@ -199,11 +205,11 @@ utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) { return NULL; } -utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) { - return eve_selectw_option_get(widget, widget->select); +utf8_t *eve_selectw_option_selected(EVESelectWidget *widget) { + return eve_selectw_option(widget, widget->select); } -int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) { +int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option) { int o_len; int o_curr; int rv, i; @@ -231,7 +237,7 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) { return EVE_OK; } -int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) { +int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) { int rv, i; rv = selectw_verify(option, option_size); diff --git a/fw/fe310/eos/eve/widget/selectw.h b/fw/fe310/eos/eve/widget/selectw.h index 939e362..f1b7071 100644 --- a/fw/fe310/eos/eve/widget/selectw.h +++ b/fw/fe310/eos/eve/widget/selectw.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVESelectWidget { EVEWidget w; EVEFont *font; @@ -17,14 +19,14 @@ typedef struct EVESelectSpec { uint8_t multi; } EVESelectSpec; -int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec); void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi); -void eve_selectw_destroy(EVESelectWidget *widget); +int eve_selectw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +void eve_selectw_destroy(EVEWidget *_widget); uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0); int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); -utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx); -utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget); -int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option); -int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size); +utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx); +utf8_t *eve_selectw_option_selected(EVESelectWidget *widget); +int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option); +int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size); diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c index d9f9104..aa5bec1 100644 --- a/fw/fe310/eos/eve/widget/spacerw.c +++ b/fw/fe310/eos/eve/widget/spacerw.c @@ -8,21 +8,17 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "spacerw.h" -int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec) { - eve_spacerw_init(widget, g, page); - - return EVE_OK; +void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page) { + memset(widget, 0, sizeof(EVEWidget)); + eve_widget_init(widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL); } -void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page) { - EVEWidget *_widget = &widget->w; +int eve_spacerw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + eve_spacerw_init(_widget, &spec->g, page); - memset(widget, 0, sizeof(EVESpacerWidget)); - eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL); + return EVE_OK; } uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0) { diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h index 9dafa8b..621b45b 100644 --- a/fw/fe310/eos/eve/widget/spacerw.h +++ b/fw/fe310/eos/eve/widget/spacerw.h @@ -1,14 +1,9 @@ #include <stdint.h> -typedef struct EVESpacerWidget { - EVEWidget w; -} EVESpacerWidget; +struct EVEWidgetSpec; -typedef struct EVESpacerSpec { -} EVESpacerSpec; - -int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec); -void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page); +void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page); +int eve_spacerw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0); int eve_spacerw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c index 55eeca4..ae9ccab 100644 --- a/fw/fe310/eos/eve/widget/strw.c +++ b/fw/fe310/eos/eve/widget/strw.c @@ -10,9 +10,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "strw.h" #define STRW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_EXT_X | EVE_TOUCH_OPT_LPRESS @@ -29,20 +27,6 @@ #define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f)) -int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - utf8_t *str; - uint16_t *line; - - str = eve_malloc(spec->str_size); - if (str == NULL) return EVE_ERR_NOMEM; - str[0] = '\0'; - - eve_strw_init(widget, g, page, font, str, spec->str_size); - - return EVE_OK; -} - void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size) { EVEWidget *_widget = &widget->w; int rv, str_len; @@ -75,7 +59,25 @@ int eve_strw_update(EVEStrWidget *widget) { return (rv == UTF_OK) ? EVE_OK : EVE_ERR; } -void eve_strw_destroy(EVEStrWidget *widget) { +int eve_strw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEStrWidget *widget = (EVEStrWidget *)_widget; + EVEStrSpec *tspec = &spec->tspec.str; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + utf8_t *str; + uint16_t *line; + + str = eve_malloc(tspec->str_size); + if (str == NULL) return EVE_ERR_NOMEM; + str[0] = '\0'; + + eve_strw_init(widget, &spec->g, page, font, str, tspec->str_size); + + return EVE_OK; +} + +void eve_strw_destroy(EVEWidget *_widget) { + EVEStrWidget *widget = (EVEStrWidget *)_widget; + eve_free(widget->str); } @@ -87,7 +89,7 @@ static void set_focus(EVEStrWidget *widget) { focus.y = _widget->g.y; focus.w = _widget->g.w; focus.h = 2 * widget->font->h; - eve_widget_focus(_widget, &focus); + eve_widget_set_focus(_widget, &focus); } static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVETouch *touch, short *dx) { @@ -216,8 +218,8 @@ uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0) { } int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { - EVEPage *page = _widget->page; EVEStrWidget *widget = (EVEStrWidget *)_widget; + EVEPage *page = _widget->page; EVEStrCursor *t_cursor = NULL; short dx; int ret = 0; @@ -291,6 +293,7 @@ int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { widget->track.dx = 0; } + if (ret) eve_widget_set_focus(_widget, NULL); return ret; } diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h index 44e5e2d..acfd74b 100644 --- a/fw/fe310/eos/eve/widget/strw.h +++ b/fw/fe310/eos/eve/widget/strw.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVEStrCursor { char on; uint16_t x; @@ -31,13 +33,14 @@ typedef struct EVEStrSpec { uint16_t str_size; } EVEStrSpec; -int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec); void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size); -void eve_strw_destroy(EVEStrWidget *widget); int eve_strw_update(EVEStrWidget *widget); +int eve_strw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +void eve_strw_destroy(EVEWidget *_widget); uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0); int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); + void eve_strw_putc(void *_page, int c); void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x); void eve_strw_cursor_clear(EVEStrWidget *widget, EVEStrCursor *cursor);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c index e994c0e..70a1e06 100644 --- a/fw/fe310/eos/eve/widget/textw.c +++ b/fw/fe310/eos/eve/widget/textw.c @@ -10,9 +10,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "textw.h" #define TEXTW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT_XY | EVE_TOUCH_OPT_LPRESS @@ -32,27 +30,6 @@ #define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0)) -int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - utf8_t *text; - uint16_t *line; - - text = eve_malloc(spec->text_size); - if (text == NULL) { - return EVE_ERR_NOMEM; - } - text[0] = '\0'; - line = eve_malloc(sizeof(uint16_t) * spec->line_size); - if (line == NULL) { - free(text); - return EVE_ERR_NOMEM; - } - - eve_textw_init(widget, g, page, font, text, spec->text_size, line, spec->line_size); - - return EVE_OK; -} - void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) { EVEWidget *_widget = &widget->w; int rv, text_len; @@ -74,7 +51,32 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *f eve_textw_text_update(widget, 0, 0); } -void eve_textw_destroy(EVETextWidget *widget) { +int eve_textw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVETextWidget *widget = (EVETextWidget *)_widget; + EVETextSpec *tspec = &spec->tspec.text; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + utf8_t *text; + uint16_t *line; + + text = eve_malloc(tspec->text_size); + if (text == NULL) { + return EVE_ERR_NOMEM; + } + text[0] = '\0'; + line = eve_malloc(sizeof(uint16_t) * tspec->line_size); + if (line == NULL) { + free(text); + return EVE_ERR_NOMEM; + } + + eve_textw_init(widget, &spec->g, page, font, text, tspec->text_size, line, tspec->line_size); + + return EVE_OK; +} + +void eve_textw_destroy(EVEWidget *_widget) { + EVETextWidget *widget = (EVETextWidget *)_widget; + eve_free(widget->line); eve_free(widget->text); } @@ -87,7 +89,7 @@ static void set_focus(EVETextWidget *widget, EVETextCursor *cursor) { focus.y = _widget->g.y + cursor->line * widget->font->h; focus.w = _widget->g.w; focus.h = 2 * widget->font->h; - eve_widget_focus(_widget, &focus); + eve_widget_set_focus(_widget, &focus); } static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVETouch *touch, short *dx, short *dl) { @@ -144,8 +146,8 @@ static void draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) { } uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) { - EVEPage *page = _widget->page; EVETextWidget *widget = (EVETextWidget *)_widget; + EVEPage *page = _widget->page; int line0, lineN; int _line0, _lineN; char lineNvisible; @@ -237,8 +239,8 @@ uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) { } int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { - EVEPage *page = _widget->page; EVETextWidget *widget = (EVETextWidget *)_widget; + EVEPage *page = _widget->page; EVETextCursor *t_cursor = NULL; short dx, dl; int ret = 0; @@ -289,6 +291,7 @@ int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { widget->track.dl = 0; } + if (ret) eve_widget_set_focus(_widget, NULL); return ret; } diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h index 570bba8..1c33733 100644 --- a/fw/fe310/eos/eve/widget/textw.h +++ b/fw/fe310/eos/eve/widget/textw.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVETextCursor { char on; uint16_t x; @@ -32,10 +34,10 @@ typedef struct EVETextSpec { uint16_t line_size; } EVETextSpec; -int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec); void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size); -void eve_textw_destroy(EVETextWidget *widget); +int eve_textw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +void eve_textw_destroy(EVEWidget *_widget); uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0); int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); void eve_textw_putc(void *_w, int c); diff --git a/fw/fe310/eos/eve/widget/togglew.c b/fw/fe310/eos/eve/widget/togglew.c new file mode 100644 index 0000000..fbebacb --- /dev/null +++ b/fw/fe310/eos/eve/widget/togglew.c @@ -0,0 +1,58 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" +#include "eve_font.h" + +#include "screen/window.h" +#include "screen/page.h" + +#include "widget.h" + +void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels) { + EVEWidget *_widget = &widget->w; + + memset(widget, 0, sizeof(EVEPageWidget)); + eve_widget_init(_widget, EVE_WIDGET_TYPE_TOGGLE, g, page, eve_togglew_draw, eve_togglew_touch, NULL); + widget->font = font; + widget->labels = labels; + if (_widget->g.w == 0) _widget->g.w = 3 * eve_font_h(widget->font); + if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font); +} + +int eve_togglew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + EVEToggleSpec *tspec = &spec->tspec.toggle; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + + eve_togglew_init(widget, &spec->g, page, font, tspec->labels); + + return EVE_OK; +} + +uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + + _widget->tag0 = tag0; + if (tag0 != EVE_NOTAG) { + eve_cmd_dl(TAG(tag0)); + tag0++; + } + _widget->tagN = tag0; + + eve_cmd(CMD_TOGGLE, "hhhhhhs", _widget->g.x, _widget->g.y, _widget->g.w, widget->font->id, 0, widget->state ? 65535 : 0, widget->labels); + + return _widget->tagN; +} + +int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + + if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + widget->state = !widget->state; + return 1; + } + + return 0; +} diff --git a/fw/fe310/eos/eve/widget/togglew.h b/fw/fe310/eos/eve/widget/togglew.h new file mode 100644 index 0000000..26ff77c --- /dev/null +++ b/fw/fe310/eos/eve/widget/togglew.h @@ -0,0 +1,21 @@ +#include <stdint.h> + +struct EVEWidgetSpec; + +typedef struct EVEToggleWidget { + EVEWidget w; + EVEFont *font; + char *labels; + uint8_t state; +} EVEToggleWidget; + +typedef struct EVEToggleSpec { + EVEFont *font; + char *labels; +} EVEToggleSpec; + +void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels); + +int eve_togglew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0); +int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c index 96d2ddf..a157301 100644 --- a/fw/fe310/eos/eve/widget/widget.c +++ b/fw/fe310/eos/eve/widget/widget.c @@ -8,37 +8,11 @@ #include "screen/window.h" #include "screen/page.h" -#include "widgets.h" - -static const size_t _widget_size[] = { - 0, - sizeof(EVEFreeWidget), - sizeof(EVESpacerWidget), - sizeof(EVEPageWidget), - sizeof(EVEStrWidget), - sizeof(EVETextWidget), - sizeof(EVESelectWidget), -}; - -static const eve_widget_create_t _widget_create[] = { - NULL, - (eve_widget_create_t)eve_freew_create, - (eve_widget_create_t)eve_spacerw_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[] = { - NULL, - NULL, - NULL, - NULL, - (eve_widget_destroy_t)eve_strw_destroy, - (eve_widget_destroy_t)eve_textw_destroy, - (eve_widget_destroy_t)eve_selectw_destroy, -}; +#include "widget.h" + +extern const size_t _eve_widget_size[]; +extern const eve_widget_create_t _eve_widget_create[]; +extern const eve_widget_destroy_t _eve_widget_destroy[]; void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc) { if (g) widget->g = *g; @@ -50,7 +24,7 @@ void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, } size_t eve_widget_size(uint8_t type) { - return _widget_size[type]; + return _eve_widget_size[type]; } void eve_widget_set_label(EVEWidget *widget, EVELabel *label) { @@ -59,19 +33,32 @@ void eve_widget_set_label(EVEWidget *widget, EVELabel *label) { EVEWidget *eve_widget_next(EVEWidget *widget) { char *_w = (char *)widget; - return (EVEWidget *)(_w + _widget_size[widget->type]); + return (EVEWidget *)(_w + _eve_widget_size[widget->type]); } -int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec) { - return _widget_create[type](widget, g, page, spec); +int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page) { + int rv; + + rv = _eve_widget_create[spec->type](widget, spec, page); + if (!rv) eve_widget_set_flags(widget, spec->flags); + + return rv; } void eve_widget_destroy(EVEWidget *widget) { - if (_widget_destroy[widget->type]) _widget_destroy[widget->type](widget); + if (_eve_widget_destroy[widget->type]) _eve_widget_destroy[widget->type](widget); } -void eve_widget_focus(EVEWidget *widget, EVERect *rect) { +void eve_widget_set_focus(EVEWidget *widget, EVERect *rect) { EVEPage *page = widget->page; - eve_page_focus_widget(page, widget, rect); + eve_page_set_focus(page, widget, rect); +} + +void eve_widget_set_flags(EVEWidget *widget, uint8_t flags) { + widget->flags |= flags; +} + +void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags) { + widget->flags &= ~flags; } diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h index f081b4c..0bef06e 100644 --- a/fw/fe310/eos/eve/widget/widget.h +++ b/fw/fe310/eos/eve/widget/widget.h @@ -1,11 +1,10 @@ #include <stdint.h> -#define EVE_WIDGET_TYPE_FREE 1 -#define EVE_WIDGET_TYPE_SPACER 2 -#define EVE_WIDGET_TYPE_PAGE 3 -#define EVE_WIDGET_TYPE_STR 4 -#define EVE_WIDGET_TYPE_TEXT 5 -#define EVE_WIDGET_TYPE_SELECT 6 +#include "label.h" + +#define EVEP_WIDGET_FLAG_RO 0x01 +#define EVEP_WIDGET_FLAG_HIDDEN 0x02 +#define EVEP_WIDGET_FLAG_BUSY 0x04 struct EVEWidget; @@ -20,12 +19,31 @@ typedef struct EVEWidget { eve_kbd_input_handler_t putc; EVELabel *label; uint8_t type; + uint8_t flags; uint8_t tag0; uint8_t tagN; } EVEWidget; +#include "widgets.h" + +typedef struct EVEWidgetSpec { + EVERect g; + EVEWidgetSpecT tspec; + uint8_t type; + uint8_t flags; +} EVEWidgetSpec; + +typedef int (*eve_widget_create_t) (EVEWidget *, EVEWidgetSpec *, EVEPage *); +typedef void (*eve_widget_destroy_t) (EVEWidget *); + +int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page); +void eve_widget_destroy(EVEWidget *widget); + void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc); size_t eve_widget_size(uint8_t type); void eve_widget_set_label(EVEWidget *widget, EVELabel *label); EVEWidget *eve_widget_next(EVEWidget *widget); -void eve_widget_focus(EVEWidget *widget, EVERect *rect);
\ No newline at end of file + +void eve_widget_set_focus(EVEWidget *widget, EVERect *rect); +void eve_widget_set_flags(EVEWidget *widget, uint8_t flags); +void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/widget/widgets.c b/fw/fe310/eos/eve/widget/widgets.c new file mode 100644 index 0000000..ec422c1 --- /dev/null +++ b/fw/fe310/eos/eve/widget/widgets.c @@ -0,0 +1,43 @@ +#include <stdlib.h> + +#include "eve.h" +#include "eve_kbd.h" +#include "eve_font.h" + +#include "screen/window.h" +#include "screen/page.h" + +#include "widget.h" + +const size_t _eve_widget_size[] = { + 0, + sizeof(EVEFreeWidget), + sizeof(EVEWidget), + sizeof(EVEPageWidget), + sizeof(EVEToggleWidget), + sizeof(EVEStrWidget), + sizeof(EVETextWidget), + sizeof(EVESelectWidget), +}; + +const eve_widget_create_t _eve_widget_create[] = { + NULL, + eve_freew_create, + eve_spacerw_create, + eve_pagew_create, + eve_togglew_create, + eve_strw_create, + eve_textw_create, + eve_selectw_create, +}; + +const eve_widget_destroy_t _eve_widget_destroy[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + eve_strw_destroy, + eve_textw_destroy, + eve_selectw_destroy, +}; diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h index 2f8d3ca..9c96d8c 100644 --- a/fw/fe310/eos/eve/widget/widgets.h +++ b/fw/fe310/eos/eve/widget/widgets.h @@ -1,39 +1,24 @@ -#include "label.h" -#include "widget.h" - #include "freew.h" #include "spacerw.h" #include "pagew.h" #include "strw.h" #include "textw.h" #include "selectw.h" +#include "togglew.h" + +#define EVE_WIDGET_TYPE_FREE 1 +#define EVE_WIDGET_TYPE_SPACER 2 +#define EVE_WIDGET_TYPE_PAGE 3 +#define EVE_WIDGET_TYPE_TOGGLE 4 +#define EVE_WIDGET_TYPE_STR 5 +#define EVE_WIDGET_TYPE_TEXT 6 +#define EVE_WIDGET_TYPE_SELECT 7 typedef union EVEWidgetSpecT { EVEFreeSpec free; - EVESpacerSpec spacer; EVEPageSpec page; + EVEToggleSpec toggle; EVEStrSpec str; EVETextSpec text; EVESelectSpec select; } EVEWidgetSpecT; - -typedef struct EVELabelSpec { - EVERect g; - EVEFont *font; - char *title; -} APPLabelSpec; - -typedef struct EVEWidgetSpec { - APPLabelSpec label; - struct { - EVERect g; - EVEWidgetSpecT spec; - uint8_t type; - } widget; -} EVEWidgetSpec; - -typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *, EVEPage *, EVEWidgetSpecT *); -typedef void (*eve_widget_destroy_t) (EVEWidget *); - -int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec); -void eve_widget_destroy(EVEWidget *widget); |