summaryrefslogtreecommitdiff
path: root/code/fe310/eos/eve
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-07-03 02:02:27 +0200
committerUros Majstorovic <majstor@majstor.org>2020-07-03 02:02:27 +0200
commitd8ced7b070beaa010f557c4c244c5c386d4e6efd (patch)
tree9f676f5ec4654f5d4b306393b2c35c34e50bdfe4 /code/fe310/eos/eve
parentf550a31fda2cb7d76e917ab69d075daa1557bf99 (diff)
str widget draw selection and cursor implemented
Diffstat (limited to 'code/fe310/eos/eve')
-rw-r--r--code/fe310/eos/eve/screen/font.c4
-rw-r--r--code/fe310/eos/eve/screen/font.h4
-rw-r--r--code/fe310/eos/eve/screen/page.c4
-rw-r--r--code/fe310/eos/eve/screen/page.h4
-rw-r--r--code/fe310/eos/eve/widget/label.c2
-rw-r--r--code/fe310/eos/eve/widget/page.c2
-rw-r--r--code/fe310/eos/eve/widget/str.c74
-rw-r--r--code/fe310/eos/eve/widget/text.c8
8 files changed, 81 insertions, 21 deletions
diff --git a/code/fe310/eos/eve/screen/font.c b/code/fe310/eos/eve/screen/font.c
index ae0ac88..6fc7d39 100644
--- a/code/fe310/eos/eve/screen/font.c
+++ b/code/fe310/eos/eve/screen/font.c
@@ -14,7 +14,7 @@ void eve_font_init(EVEFont *font, uint8_t font_id) {
eve_readb(p, font->w_ch, 128);
}
-uint16_t eve_font_strw(EVEFont *font, char *s) {
+uint16_t eve_font_str_w(EVEFont *font, char *s) {
uint16_t r = 0;
while (*s) {
@@ -25,7 +25,7 @@ uint16_t eve_font_strw(EVEFont *font, char *s) {
return r;
}
-uint16_t eve_font_bufw(EVEFont *font, char *buf, uint16_t buf_len) {
+uint16_t eve_font_buf_w(EVEFont *font, char *buf, uint16_t buf_len) {
int i;
uint16_t r = 0;
diff --git a/code/fe310/eos/eve/screen/font.h b/code/fe310/eos/eve/screen/font.h
index 7de3ff5..525e669 100644
--- a/code/fe310/eos/eve/screen/font.h
+++ b/code/fe310/eos/eve/screen/font.h
@@ -8,6 +8,6 @@ typedef struct EVEFont {
} EVEFont;
void eve_font_init(EVEFont *font, uint8_t font_id);
-uint16_t eve_font_strw(EVEFont *font, char *s);
-uint16_t eve_font_bufw(EVEFont *font, char *buf, uint16_t buf_len);
+uint16_t eve_font_str_w(EVEFont *font, char *s);
+uint16_t eve_font_buf_w(EVEFont *font, char *buf, uint16_t buf_len);
uint8_t eve_font_h(EVEFont *font);
diff --git a/code/fe310/eos/eve/screen/page.c b/code/fe310/eos/eve/screen/page.c
index d96a2ba..b1b3985 100644
--- a/code/fe310/eos/eve/screen/page.c
+++ b/code/fe310/eos/eve/screen/page.c
@@ -32,11 +32,11 @@ int16_t eve_page_y(EVEPage *page, int16_t y) {
return y + page->win_y - page->window->g.y;
}
-int16_t eve_page_scrx(EVEPage *page, int16_t x) {
+int16_t eve_page_scr_x(EVEPage *page, int16_t x) {
return x - page->win_x + page->window->g.x;
}
-int16_t eve_page_scry(EVEPage *page, int16_t y) {
+int16_t eve_page_scr_y(EVEPage *page, int16_t y) {
return y - page->win_y + page->window->g.y;
}
diff --git a/code/fe310/eos/eve/screen/page.h b/code/fe310/eos/eve/screen/page.h
index 1db859e..8f2fba9 100644
--- a/code/fe310/eos/eve/screen/page.h
+++ b/code/fe310/eos/eve/screen/page.h
@@ -23,8 +23,8 @@ typedef struct EVEPage {
void eve_page_init(EVEPage *page, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_open_t open, eve_page_close_t close, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, EVEWindow *window);
int16_t eve_page_x(EVEPage *page, int16_t x);
int16_t eve_page_y(EVEPage *page, int16_t y);
-int16_t eve_page_scrx(EVEPage *page, int16_t x);
-int16_t eve_page_scry(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);
void eve_page_set_focus(EVEPage *page, struct EVEWidget *widget, EVERect *focus);
struct EVEWidget *eve_page_get_focus(EVEPage *page);
diff --git a/code/fe310/eos/eve/widget/label.c b/code/fe310/eos/eve/widget/label.c
index f47b7f4..23d31a6 100644
--- a/code/fe310/eos/eve/widget/label.c
+++ b/code/fe310/eos/eve/widget/label.c
@@ -16,7 +16,7 @@ void eve_label_init(EVELabel *label, EVERect *g, char *title, EVEFont *font) {
if (g) label->g = *g;
label->title = title;
label->font = font;
- if (label->g.w == 0) label->g.w = eve_font_strw(font, label->title);
+ if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title);
if (label->g.h == 0) label->g.h = eve_font_h(font);
}
diff --git a/code/fe310/eos/eve/widget/page.c b/code/fe310/eos/eve/widget/page.c
index 4c35bda..f83850c 100644
--- a/code/fe310/eos/eve/widget/page.c
+++ b/code/fe310/eos/eve/widget/page.c
@@ -21,7 +21,7 @@ void eve_pagew_init(EVEPageWidget *widget, EVERect *g, char *title, EVEFont *fon
widget->title = title;
widget->font = font;
widget->page = page;
- if (_widget->g.w == 0) _widget->g.w = eve_font_strw(font, widget->title);
+ if (_widget->g.w == 0) _widget->g.w = eve_font_str_w(font, widget->title);
if (_widget->g.h == 0) _widget->g.h = eve_font_h(font);
}
diff --git a/code/fe310/eos/eve/widget/str.c b/code/fe310/eos/eve/widget/str.c
index a0caa9d..e18b515 100644
--- a/code/fe310/eos/eve/widget/str.c
+++ b/code/fe310/eos/eve/widget/str.c
@@ -147,9 +147,41 @@ int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_id
return 0;
}
+static void _draw_str(EVEStrWidget *widget, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
+ int16_t x;
+ EVEWidget *_widget = &widget->w;
+
+ x = _widget->g.x - widget->str_g.x;
+ if (x1 != x2) {
+ eve_cmd_dl(BEGIN(EVE_RECTS));
+ if (!s) eve_cmd_dl(COLOR_MASK(0 ,0 ,0 ,0));
+ eve_cmd_dl(VERTEX2F(x + x1, _widget->g.y));
+ eve_cmd_dl(VERTEX2F(x + x2, _widget->g.y + widget->font->h));
+ if (!s) eve_cmd_dl(COLOR_MASK(1 ,1 ,1 ,1));
+ eve_cmd_dl(END());
+ if (len) {
+ if (s) eve_cmd_dl(COLOR_RGB(0, 0, 0));
+ eve_cmd(CMD_TEXT, "hhhhpb", x + x1, _widget->g.y, widget->font->id, 0, widget->str + ch, len, 0);
+ if (s) eve_cmd_dl(COLOR_RGB(255, 255, 255));
+ }
+ }
+}
+
+static void _draw_cursor(EVEStrWidget *widget, EVEStrCursor *cursor) {
+ uint16_t x, y;
+ EVEWidget *_widget = &widget->w;
+
+ x = _widget->g.x - widget->str_g.x + cursor->x;
+ y = _widget->g.y;
+ eve_cmd_dl(BEGIN(EVE_LINES));
+ eve_cmd_dl(VERTEX2F(x, y));
+ eve_cmd_dl(VERTEX2F(x, y + widget->font->h));
+ eve_cmd_dl(END());
+}
+
+
uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
EVEStrWidget *widget = (EVEStrWidget *)_widget;
- int16_t x = _widget->g.x - widget->str_g.x;
char cut = widget->str_g.x || (widget->str_g.w > _widget->g.w);
widget->tag = tag0;
@@ -159,8 +191,8 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
}
if (cut && page) {
- int16_t x = eve_page_scrx(page, _widget->g.x);
- int16_t y = eve_page_scrx(page, _widget->g.y);
+ int16_t x = eve_page_scr_x(page, _widget->g.x);
+ int16_t y = eve_page_scr_y(page, _widget->g.y);
if (x < 0) x = 0;
if (y < 0) y = 0;
@@ -168,7 +200,31 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
eve_cmd_dl(SCISSOR_XY(x, y));
eve_cmd_dl(SCISSOR_SIZE(_widget->g.w, _widget->g.h));
}
- eve_cmd(CMD_TEXT, "hhhhs", x, _widget->g.y, widget->font->id, 0, widget->str);
+
+ if (widget->cursor2.on) {
+ EVEStrCursor *c1, *c2;
+ int l1, l2, l3;
+
+ if (widget->cursor1.ch <= widget->cursor2.ch) {
+ c1 = &widget->cursor1;
+ c2 = &widget->cursor2;
+ } else {
+ c1 = &widget->cursor2;
+ c2 = &widget->cursor1;
+ }
+
+
+ l1 = c1->ch;
+ l2 = c2->ch - c1->ch;
+ l3 = strlen(widget->str) - c2->ch;
+ _draw_str(widget, 0, l1, 0, c1->x, 0);
+ _draw_str(widget, c1->ch, l2, c1->x, c2->x, 1);
+ _draw_str(widget, c2->ch, l3, c2->x, widget->str_g.w, 0);
+ } else {
+ if (widget->cursor1.on) _draw_cursor(widget, &widget->cursor1);
+ _draw_str(widget, 0, strlen(widget->str), 0, widget->str_g.w, 0);
+ }
+
if (cut && page) {
eve_cmd_dl(RESTORE_CONTEXT());
}
@@ -191,6 +247,8 @@ void eve_strw_putc(void *_page, int c) {
return;
}
+ if (!cursor1->on) return;
+
if (cursor2->on) {
EVEStrCursor *c1;
EVEStrCursor *c2;
@@ -208,7 +266,7 @@ void eve_strw_putc(void *_page, int c) {
str = widget->str + c1->ch;
del_c = c2->ch - c1->ch;
- del_ch_w = eve_font_bufw(widget->font, str, del_c);
+ del_ch_w = eve_font_buf_w(widget->font, str, del_c);
if ((c == CH_CTRLX) || (c == CH_CTRLC)) {
// eve_clipb_push(str, del_c);
if (c == CH_CTRLC) return;
@@ -221,7 +279,7 @@ void eve_strw_putc(void *_page, int c) {
ins_c = clipb ? strlen(clipb) : 0;
if (ins_c) {
if (widget->str_len >= widget->str_size - (ins_c - del_c)) ins_c = widget->str_size - widget->str_len + del_c - 1;
- ins_ch_w = eve_font_bufw(widget->font, clipb, ins_c);
+ ins_ch_w = eve_font_buf_w(widget->font, clipb, ins_c);
}
}
if (ins_c != del_c) memmove(str + ins_c, str + del_c, widget->str_len - c2->ch + 1);
@@ -238,7 +296,7 @@ void eve_strw_putc(void *_page, int c) {
widget->str_g.w += ins_ch_w - del_ch_w;
if (c1 == cursor2) widget->cursor1 = widget->cursor2;
eve_strw_cursor_clear(widget, cursor2);
- } else if (cursor1->on) {
+ } else {
uint8_t ch_w;
str = widget->str + cursor1->ch;
@@ -277,7 +335,7 @@ void eve_strw_putc(void *_page, int c) {
}
}
- if (cursor1->x - widget->str_g.x < w0) widget->str_g.x = cursor1->x - w0 > 0 ? cursor1->x - w0 : 0;
+ if (cursor1->x - widget->str_g.x < w0) widget->str_g.x = cursor1->x > w0 ? cursor1->x - w0 : 0;
if (cursor1->x - widget->str_g.x > w1) widget->str_g.x = cursor1->x - w1;
}
diff --git a/code/fe310/eos/eve/widget/text.c b/code/fe310/eos/eve/widget/text.c
index a389fa7..0537e3d 100644
--- a/code/fe310/eos/eve/widget/text.c
+++ b/code/fe310/eos/eve/widget/text.c
@@ -157,7 +157,7 @@ static void _draw_line(EVETextWidget *widget, uint16_t l, uint16_t ch, uint16_t
eve_cmd_dl(END());
if (len) {
if (s) eve_cmd_dl(COLOR_RGB(0, 0, 0));
- eve_cmd(CMD_TEXT, "hhhhpb", _widget->g.x, _widget->g.y + l * widget->font->h, widget->font->id, 0, widget->text + ch, len, 0);
+ eve_cmd(CMD_TEXT, "hhhhpb", _widget->g.x + x1, _widget->g.y + l * widget->font->h, widget->font->id, 0, widget->text + ch, len, 0);
if (s) eve_cmd_dl(COLOR_RGB(255, 255, 255));
}
}
@@ -291,6 +291,8 @@ void eve_textw_putc(void *_page, int c) {
return;
}
+ if (!cursor1->on) return;
+
if (cursor2->on) {
EVETextCursor *c1;
EVETextCursor *c2;
@@ -318,7 +320,7 @@ void eve_textw_putc(void *_page, int c) {
ins_c = clipb ? strlen(clipb) : 0;
if (ins_c) {
if (widget->text_len >= widget->text_size - (ins_c - del_c)) ins_c = widget->text_size - widget->text_len + del_c - 1;
- ch_w = eve_font_bufw(widget->font, clipb, ins_c);
+ ch_w = eve_font_buf_w(widget->font, clipb, ins_c);
}
}
if (ins_c != del_c) memmove(text + ins_c, text + del_c, widget->text_len - c2->ch + 1);
@@ -332,7 +334,7 @@ void eve_textw_putc(void *_page, int c) {
}
if (c1 == cursor2) widget->cursor1 = widget->cursor2;
eve_textw_cursor_clear(widget, cursor2);
- } else if (cursor1->on) {
+ } else {
text = widget->text + cursor1->ch;
switch (c) {