diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-08-26 02:06:39 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-08-26 02:06:39 +0200 |
commit | 48d934f5b422d87a59ffb38e6215a851f28c1b0e (patch) | |
tree | 74f7b9d78261c68e09aace1e09e4dc9052eef3cc | |
parent | 3b4ddebe631b14d15abe7355fbabe53e08c61a61 (diff) |
eve text box fixed
-rw-r--r-- | fw/fe310/eos/eve/eve_text.c | 167 | ||||
-rw-r--r-- | fw/fe310/eos/eve/eve_text.h | 12 |
2 files changed, 94 insertions, 85 deletions
diff --git a/fw/fe310/eos/eve/eve_text.c b/fw/fe310/eos/eve/eve_text.c index 9b8dcc0..7a42a24 100644 --- a/fw/fe310/eos/eve/eve_text.c +++ b/fw/fe310/eos/eve/eve_text.c @@ -17,10 +17,11 @@ static void scroll1(EVEText *box) { box->line0 = (box->line0 + 1) % box->line_size; eve_cmd(CMD_MEMSET, "www", box->mem_addr + box->ch_idx, 0x0, box->w * 2); eve_cmd_exec(1); + eve_text_update(box); box->dirty = 1; } -void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint8_t tag, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next) { +void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next) { double scale_x, scale_y; if (g->w == 0) { @@ -35,12 +36,12 @@ void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint8_t tag box->g = *g; box->w = w; box->h = h; - box->tag = tag; + box->tag = EVE_TAG_NOTAG; box->transform_a = 256 / scale_x; box->transform_e = 256 / scale_y; box->ch_w = scale_x * 8; box->ch_h = scale_y * 16; - box->dl_size = 17; + box->dl_size = 14; box->mem_addr = mem_addr; box->line_size = line_size; box->line0 = 0; @@ -54,8 +55,6 @@ void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint8_t tag box->dl_size += 1; } - eve_touch_set_opt(tag, EVE_TOUCH_OPT_TRACK); - eve_cmd(CMD_MEMSET, "www", mem_addr, 0x0, box->w * 2 * box->line_size); eve_cmd_exec(1); @@ -63,10 +62,66 @@ void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint8_t tag *mem_next = box->mem_addr + box->w * 2 * box->line_size + box->dl_size * 4; } +void eve_text_update(EVEText *box) { + int text_h1; + int text_h2; + int line_top; + + line_top = box->line_top >= 0 ? box->line_top : box->line0; + + if (line_top + box->h > box->line_size) { + text_h1 = box->line_size - line_top; + text_h2 = box->h - text_h1; + } else { + text_h1 = box->h; + text_h2 = 0; + } + + eve_dl_start(box->mem_addr + box->w * 2 * box->line_size, 1); + eve_dl_write(BEGIN(EVE_BITMAPS)); + eve_dl_write(VERTEX_FORMAT(0)); + eve_dl_write(BITMAP_HANDLE(15)); + if (box->transform_a != 256) { + eve_dl_write(BITMAP_TRANSFORM_A(box->transform_a)); + } + if (box->transform_e != 256) { + eve_dl_write(BITMAP_TRANSFORM_E(box->transform_e)); + } + eve_dl_write(BITMAP_SOURCE(box->mem_addr + line_top * box->w * 2)); + eve_dl_write(BITMAP_LAYOUT(EVE_TEXTVGA, box->w * 2, text_h1)); + eve_dl_write(BITMAP_SIZE(EVE_NEAREST, EVE_BORDER, EVE_BORDER, box->w * box->ch_w, text_h1 * box->ch_h)); + eve_dl_write(BITMAP_SIZE_H(box->w * box->ch_w, text_h1 * box->ch_h)); + eve_dl_write(VERTEX2F(box->g.x, box->g.y)); + + if (text_h2) { + eve_dl_write(BITMAP_SOURCE(box->mem_addr)); + eve_dl_write(BITMAP_LAYOUT(EVE_TEXTVGA, box->w * 2, text_h2)); + eve_dl_write(BITMAP_SIZE(EVE_NEAREST, EVE_BORDER, EVE_BORDER, box->w * box->ch_w, text_h2 * box->ch_h)); + eve_dl_write(BITMAP_SIZE_H(box->w * box->ch_w, text_h2 * box->ch_h)); + eve_dl_write(VERTEX2F(box->g.x, box->g.y + text_h1 * box->ch_h)); + } else { + eve_dl_write(NOP()); + eve_dl_write(NOP()); + eve_dl_write(NOP()); + eve_dl_write(NOP()); + eve_dl_write(NOP()); + } + + eve_dl_write(END()); + eve_dl_end(); +} + +void eve_text_scroll0(EVEText *box) { + if (box->line_top >= 0) { + box->line_top = -1; + box->line_top0 = -1; + eve_text_update(box); + } +} + int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx) { EVETouch *t; uint16_t evt; - int ret = 0; t = eve_touch_evt(tag0, touch_idx, box->tag, 1, &evt); if (t && evt) { @@ -78,28 +133,31 @@ int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx) { int line = LINE_IDX_ADD(box->line_top0, (t->y0 - t->y) / box->ch_h, box->line_size); if (LINE_IDX_LTE(line, box->line0, box->line_size, box->h)) { box->line_top = line; - box->dirty = 1; + eve_text_update(box); } } if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) { box->line_top0 = box->line_top; } - ret = 1; - } else if (box->line_top >= 0) { - box->line_top = -1; - box->line_top0 = -1; - box->dirty = 1; + + return 1; } - return ret; + + return 0; } -uint8_t eve_text_draw(EVEText *box) { - if (box->dirty) { - eve_text_update(box); - box->dirty = 0; +uint8_t eve_text_draw(EVEText *box, uint8_t tag) { + eve_cmd_dl(SAVE_CONTEXT()); + box->tag = tag; + if (tag != EVE_TAG_NOTAG) { + eve_cmd_dl(TAG(tag)); + eve_touch_set_opt(tag, EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_EXT); + tag++; } eve_cmd(CMD_APPEND, "ww", box->mem_addr + box->w * 2 * box->line_size, box->dl_size * 4); - return box->tag; + eve_cmd_dl(RESTORE_CONTEXT()); + + return tag; } void eve_text_putc(EVEText *box, int c) { @@ -126,62 +184,15 @@ void eve_text_putc(EVEText *box, int c) { } } -void eve_text_puts(EVEText *box, char *s) { - while (*s) { - eve_text_putc(box, *s); - s++; - } -} - -void eve_text_update(EVEText *box) { - int text_h1; - int text_h2; - int line_top; - - line_top = box->line_top >= 0 ? box->line_top : box->line0; - - if (line_top + box->h > box->line_size) { - text_h1 = box->line_size - line_top; - text_h2 = box->h - text_h1; - } else { - text_h1 = box->h; - text_h2 = 0; - } - eve_dl_start(box->mem_addr + box->w * 2 * box->line_size); - - eve_dl_write(SAVE_CONTEXT()); - eve_dl_write(BEGIN(EVE_BITMAPS)); - eve_dl_write(TAG(box->tag)); - eve_dl_write(VERTEX_FORMAT(0)); - eve_dl_write(BITMAP_HANDLE(15)); - if (box->transform_a != 256) { - eve_dl_write(BITMAP_TRANSFORM_A(box->transform_a)); - } - if (box->transform_e != 256) { - eve_dl_write(BITMAP_TRANSFORM_E(box->transform_e)); - } - eve_dl_write(BITMAP_SOURCE(box->mem_addr + line_top * box->w * 2)); - eve_dl_write(BITMAP_LAYOUT(EVE_TEXTVGA, box->w * 2, text_h1)); - eve_dl_write(BITMAP_SIZE(EVE_NEAREST, EVE_BORDER, EVE_BORDER, box->w * box->ch_w, text_h1 * box->ch_h)); - eve_dl_write(BITMAP_SIZE_H(box->w * box->ch_w, text_h1 * box->ch_h)); - eve_dl_write(VERTEX2F(box->g.x, box->g.y)); +void eve_text_backspace(EVEText *box) { + uint16_t c; - if (text_h2) { - eve_dl_write(BITMAP_SOURCE(box->mem_addr)); - eve_dl_write(BITMAP_LAYOUT(EVE_TEXTVGA, box->w * 2, text_h2)); - eve_dl_write(BITMAP_SIZE(EVE_NEAREST, EVE_BORDER, EVE_BORDER, box->w * box->ch_w, text_h2 * box->ch_h)); - eve_dl_write(BITMAP_SIZE_H(box->w * box->ch_w, text_h2 * box->ch_h)); - eve_dl_write(VERTEX2F(box->g.x, box->g.y + text_h1 * box->ch_h)); - } else { - eve_dl_write(NOP()); - eve_dl_write(NOP()); - eve_dl_write(NOP()); - eve_dl_write(NOP()); - eve_dl_write(NOP()); + eve_write16(box->mem_addr + box->ch_idx, 0); + box->ch_idx = (box->ch_idx - 2) % (box->line_size * box->w * 2); + if (eve_read16(box->mem_addr + box->ch_idx) == 0) { + box->ch_idx = (box->ch_idx + 2) % (box->line_size * box->w * 2); } - - eve_dl_write(END()); - eve_dl_write(RESTORE_CONTEXT()); + eve_write16(box->mem_addr + box->ch_idx, TEXT_CRSR); } void eve_text_newline(EVEText *box) { @@ -193,13 +204,9 @@ void eve_text_newline(EVEText *box) { eve_write16(box->mem_addr + box->ch_idx, TEXT_CRSR); } -void eve_text_backspace(EVEText *box) { - uint16_t c; - - eve_write16(box->mem_addr + box->ch_idx, 0); - box->ch_idx = (box->ch_idx - 2) % (box->line_size * box->w * 2); - if (eve_read16(box->mem_addr + box->ch_idx) == 0) { - box->ch_idx = (box->ch_idx + 2) % (box->line_size * box->w * 2); +void eve_text_puts(EVEText *box, char *s) { + while (*s) { + eve_text_putc(box, *s); + s++; } - eve_write16(box->mem_addr + box->ch_idx, TEXT_CRSR); } diff --git a/fw/fe310/eos/eve/eve_text.h b/fw/fe310/eos/eve/eve_text.h index a76e659..8f1ed71 100644 --- a/fw/fe310/eos/eve/eve_text.h +++ b/fw/fe310/eos/eve/eve_text.h @@ -19,12 +19,14 @@ typedef struct EVEText { char dirty; } EVEText; -void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint8_t tag, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next); +void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint16_t line_size, uint32_t mem_addr, uint32_t *mem_next); +void eve_text_update(EVEText *box); +void eve_text_scroll0(EVEText *box); + int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx); -uint8_t eve_text_draw(EVEText *box); +uint8_t eve_text_draw(EVEText *box, uint8_t tag); void eve_text_putc(EVEText *box, int c); -void eve_text_puts(EVEText *box, char *s); -void eve_text_update(EVEText *box); -void eve_text_newline(EVEText *box); void eve_text_backspace(EVEText *box); +void eve_text_newline(EVEText *box); +void eve_text_puts(EVEText *box, char *s); |