summaryrefslogtreecommitdiff
path: root/code/fe310/eos/eve/screen
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-06-10 02:39:37 +0200
committerUros Majstorovic <majstor@majstor.org>2020-06-10 02:39:37 +0200
commit294d4533489e9ed6b7e71c63a1faa9722a2621c6 (patch)
tree04a3b9be039206e4457ff5632b98a7f793ddc001 /code/fe310/eos/eve/screen
parentb5aa60b256dd2b328515779883ba365aba3d995f (diff)
page/form refactor; implemented form layout, labels
Diffstat (limited to 'code/fe310/eos/eve/screen')
-rw-r--r--code/fe310/eos/eve/screen/font.c14
-rw-r--r--code/fe310/eos/eve/screen/font.h2
-rw-r--r--code/fe310/eos/eve/screen/form.c82
-rw-r--r--code/fe310/eos/eve/screen/form.h3
-rw-r--r--code/fe310/eos/eve/screen/page.c29
-rw-r--r--code/fe310/eos/eve/screen/page.h11
-rw-r--r--code/fe310/eos/eve/screen/screen.c10
7 files changed, 112 insertions, 39 deletions
diff --git a/code/fe310/eos/eve/screen/font.c b/code/fe310/eos/eve/screen/font.c
index b5b7b74..26e7cf0 100644
--- a/code/fe310/eos/eve/screen/font.c
+++ b/code/fe310/eos/eve/screen/font.c
@@ -6,3 +6,17 @@
void eve_font_init(EVEFont *font, uint8_t font_id) {
font->id = font_id;
}
+
+uint16_t eve_font_string_width(EVEFont *font, char *s) {
+ uint16_t r = 0;
+
+ while (*s) {
+ r += font->w[*s];
+ s++;
+ }
+ return r;
+}
+
+uint8_t eve_font_height(EVEFont *font) {
+ return font->h;
+} \ No newline at end of file
diff --git a/code/fe310/eos/eve/screen/font.h b/code/fe310/eos/eve/screen/font.h
index 0572015..24b745e 100644
--- a/code/fe310/eos/eve/screen/font.h
+++ b/code/fe310/eos/eve/screen/font.h
@@ -7,3 +7,5 @@ typedef struct EVEFont {
} EVEFont;
void eve_font_init(EVEFont *font, uint8_t font_id);
+uint16_t eve_font_string_width(EVEFont *font, char *s);
+uint8_t eve_font_height(EVEFont *font);
diff --git a/code/fe310/eos/eve/screen/form.c b/code/fe310/eos/eve/screen/form.c
index ae381e6..442b329 100644
--- a/code/fe310/eos/eve/screen/form.c
+++ b/code/fe310/eos/eve/screen/form.c
@@ -7,48 +7,57 @@
#include "screen.h"
#include "window.h"
#include "page.h"
+#include "font.h"
#include "form.h"
+#include "widget/label.h"
#include "widget/widget.h"
#define CH_EOF 0x1a
int eve_form_init(EVEForm *form, EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close, EVEWindow *window) {
memset(form, 0, sizeof(EVEForm));
- eve_page_init(&form->p, eve_form_touch, eve_form_draw, open, close, window);
+ eve_page_init(&form->p, eve_form_touch, eve_form_draw, open, close, eve_form_handle_evt, eve_form_update_g, window);
form->widget = widget;
form->widget_size = widget_size;
+ eve_form_update_g(&form->p, NULL);
}
int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx) {
EVEForm *form = (EVEForm *)v;
EVEWidget *widget = form->widget;
- int a, i, ret = 0;
+ EVEWidget *widget_f = eve_page_get_focus(&form->p);
+ int i, ret = 0;
EVERect focus = {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 && focus.h && (form->widget_f != widget)) {
- EVEKbd *kbd = eve_screen_get_kbd(form->p.window->screen);
-
- if (kbd) {
- if (form->widget_f && form->widget_f->putc) {
- eve_screen_hide_kbd(form->p.window->screen);
- form->widget_f->putc(form->widget_f, CH_EOF);
- }
- eve_kbd_set_handler(kbd, widget->putc, widget);
- if (widget && widget->putc) {
- eve_screen_show_kbd(form->p.window->screen);
+ if (eve_page_rect_visible(&form->p, &widget->g)) {
+ int a;
+ EVERect r = {0,0,0,0};
+
+ a = widget->touch(widget, &form->p, tag0, touch_idx, &r);
+ ret = ret || a;
+ if (r.w && r.h && (widget_f != widget)) {
+ EVEKbd *kbd = eve_screen_get_kbd(form->p.window->screen);
+
+ if (kbd) {
+ if (widget_f && widget_f->putc) {
+ eve_screen_hide_kbd(form->p.window->screen);
+ widget_f->putc(widget_f, CH_EOF);
+ }
+ eve_kbd_set_handler(kbd, widget->putc, &form->p);
+ if (widget->putc) {
+ eve_screen_show_kbd(form->p.window->screen);
+ }
}
+ widget_f = widget;
+ focus = r;
}
- form->widget_f = widget;
}
widget = eve_widget_next(widget);
- memset(&focus, 0, sizeof(focus));
}
- eve_page_focus(&form->p, &focus);
+ if (focus.w && focus.h) eve_page_set_focus(&form->p, widget_f, &focus);
return ret;
}
@@ -58,8 +67,15 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
int i;
uint8_t tagN = tag0;
+ eve_cmd_dl(VERTEX_FORMAT(0));
+
for (i=0; i<form->widget_size; i++) {
- tagN = widget->draw(widget, &form->p, tagN);
+ if (widget->label && eve_page_rect_visible(&form->p, &widget->label->g)) {
+ eve_cmd_dl(TAG_MASK(0));
+ eve_label_draw(widget->label);
+ eve_cmd_dl(TAG_MASK(1));
+ }
+ if (eve_page_rect_visible(&form->p, &widget->g)) tagN = widget->draw(widget, &form->p, tagN);
widget = eve_widget_next(widget);
}
@@ -69,3 +85,31 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
return tagN;
}
+
+void eve_form_handle_evt(EVEPage *page, 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
+ }
+ */
+}
+
+void eve_form_update_g(EVEPage *page, EVEWidget *_widget) {
+ EVEForm *form = (EVEForm *)page;
+ EVEWidget *widget = form->widget;
+ int i;
+ uint16_t h = 0;
+
+ for (i=0; i<form->widget_size; i++) {
+ if (widget->label) {
+ widget->label->g.y = h;
+ if (widget->label->g.w + widget->g.w > form->p.window->screen->w) h += widget->label->g.h;
+ }
+ widget->g.y = h;
+ h += widget->g.h;
+
+ widget = eve_widget_next(widget);
+ }
+}
diff --git a/code/fe310/eos/eve/screen/form.h b/code/fe310/eos/eve/screen/form.h
index e667fc8..006ef2e 100644
--- a/code/fe310/eos/eve/screen/form.h
+++ b/code/fe310/eos/eve/screen/form.h
@@ -4,7 +4,6 @@ struct EVEWidget;
typedef struct EVEForm {
EVEPage p;
- struct EVEWidget *widget_f;
struct EVEWidget *widget;
uint16_t widget_size;
} EVEForm;
@@ -12,3 +11,5 @@ typedef struct EVEForm {
int eve_form_init(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size, eve_page_open_t open, eve_page_close_t close, EVEWindow *window);
int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx);
uint8_t eve_form_draw(EVEView *v, uint8_t tag0);
+void eve_form_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx);
+void eve_form_update_g(EVEPage *page, struct EVEWidget *widget);
diff --git a/code/fe310/eos/eve/screen/page.c b/code/fe310/eos/eve/screen/page.c
index fbd9327..4c72243 100644
--- a/code/fe310/eos/eve/screen/page.c
+++ b/code/fe310/eos/eve/screen/page.c
@@ -7,20 +7,24 @@
#include "screen.h"
#include "window.h"
#include "page.h"
+#include "font.h"
+#include "widget/label.h"
#include "widget/widget.h"
-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, EVEWindow *window) {
+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) {
memset(page, 0, sizeof(EVEPage));
page->v.touch = touch;
page->v.draw = draw;
page->open = open;
page->close = close;
- page->handle_evt = eve_page_handle_evt;
+ page->handle_evt = handle_evt;
+ page->update_g = update_g;
+ page->widget_f = NULL;
page->window = window;
}
-void eve_page_focus(EVEPage *page, EVERect *f) {
+void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *f) {
EVERect g;
eve_window_visible_g(page->window, &g);
@@ -39,22 +43,17 @@ void eve_page_focus(EVEPage *page, EVERect *f) {
if ((f->y + f->h) > (page->win_y + g.y + g.h)) {
page->win_y = (f->y + f->h) - (g.y + g.h);
}
+ page->widget_f = widget;
}
-int eve_page_widget_visible(EVEPage *page, EVEWidget *widget) {
+EVEWidget *eve_page_get_focus(EVEPage *page) {
+ return page->widget_f;
+}
+
+int eve_page_rect_visible(EVEPage *page, EVERect *g) {
uint16_t w = page->window->g.w;
uint16_t h = page->window->g.h;
- if (((widget->g.x + widget->g.w) >= page->win_x) && ((widget->g.y + widget->g.h) >= page->win_y) && (widget->g.x <= (page->win_x + w)) && (widget->g.y <= (page->win_y + h))) return 1;
+ if (((g->x + g->w) >= page->win_x) && ((g->y + g->h) >= page->win_y) && (g->x <= (page->win_x + w)) && (g->y <= (page->win_y + h))) return 1;
return 0;
}
-
-void eve_page_handle_evt(EVEPage *page, 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
index 42cae7d..a2e5898 100644
--- a/code/fe310/eos/eve/screen/page.h
+++ b/code/fe310/eos/eve/screen/page.h
@@ -6,6 +6,7 @@ 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 void (*eve_page_g_updater_t) (struct EVEPage *, struct EVEWidget *);
typedef struct EVEPage {
EVEView v;
@@ -14,10 +15,12 @@ typedef struct EVEPage {
eve_page_open_t open;
eve_page_close_t close;
eve_page_evt_handler_t handle_evt;
+ eve_page_g_updater_t update_g;
+ struct EVEWidget *widget_f;
EVEWindow *window;
} 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, EVEWindow *window);
-void eve_page_focus(EVEPage *page, EVERect *focus);
-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);
+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);
+void eve_page_set_focus(EVEPage *page, struct EVEWidget *widget, EVERect *focus);
+struct EVEWidget *eve_page_get_focus(EVEPage *page);
+int eve_page_rect_visible(EVEPage *page, EVERect *g);
diff --git a/code/fe310/eos/eve/screen/screen.c b/code/fe310/eos/eve/screen/screen.c
index d31cd2c..68b6fb8 100644
--- a/code/fe310/eos/eve/screen/screen.c
+++ b/code/fe310/eos/eve/screen/screen.c
@@ -81,9 +81,19 @@ void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx) {
w = w->next;
}
+ eve_cmd_burst_start();
+ eve_cmd_dl(CMD_DLSTART);
+ eve_cmd_dl(CLEAR_COLOR_RGB(0,0,0));
+ eve_cmd_dl(CLEAR(1,1,1));
+
w = screen->win_head;
while(w) {
if (eve_window_visible(w)) tagN = w->view->draw(w->view, tagN);
w = w->next;
}
+
+ eve_cmd_dl(DISPLAY());
+ eve_cmd_dl(CMD_SWAP);
+ eve_cmd_burst_end();
+ eve_cmd_exec(1);
}