summaryrefslogtreecommitdiff
path: root/code/fe310/eos/eve/screen
diff options
context:
space:
mode:
Diffstat (limited to 'code/fe310/eos/eve/screen')
-rw-r--r--code/fe310/eos/eve/screen/Makefile17
-rw-r--r--code/fe310/eos/eve/screen/font.c8
-rw-r--r--code/fe310/eos/eve/screen/font.h9
-rw-r--r--code/fe310/eos/eve/screen/form.c78
-rw-r--r--code/fe310/eos/eve/screen/form.h14
-rw-r--r--code/fe310/eos/eve/screen/page.c64
-rw-r--r--code/fe310/eos/eve/screen/page.h29
-rw-r--r--code/fe310/eos/eve/screen/screen.c43
-rw-r--r--code/fe310/eos/eve/screen/screen.h30
-rw-r--r--code/fe310/eos/eve/screen/tile.c32
-rw-r--r--code/fe310/eos/eve/screen/tile.h24
11 files changed, 348 insertions, 0 deletions
diff --git a/code/fe310/eos/eve/screen/Makefile b/code/fe310/eos/eve/screen/Makefile
new file mode 100644
index 0000000..313d390
--- /dev/null
+++ b/code/fe310/eos/eve/screen/Makefile
@@ -0,0 +1,17 @@
+include ../../../common.mk
+
+CFLAGS += -I. -I.. -I../.. -I../../../include -I../../../drivers
+
+obj = font.o screen.o tile.o page.o form.o
+
+
+%.o: %.c %.h
+ $(CC) $(CFLAGS) -c $<
+
+%.o: %.S
+ $(CC) $(CFLAGS) -c $<
+
+all: $(obj)
+
+clean:
+ rm -f *.o \ No newline at end of file
diff --git a/code/fe310/eos/eve/screen/font.c b/code/fe310/eos/eve/screen/font.c
new file mode 100644
index 0000000..6721f00
--- /dev/null
+++ b/code/fe310/eos/eve/screen/font.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+
+#include "eve.h"
+#include "font.h"
+
+void eve_font_init(EVEFont *font, uint8_t font_id) {
+ font->id = font_id;
+} \ No newline at end of file
diff --git a/code/fe310/eos/eve/screen/font.h b/code/fe310/eos/eve/screen/font.h
new file mode 100644
index 0000000..409b109
--- /dev/null
+++ b/code/fe310/eos/eve/screen/font.h
@@ -0,0 +1,9 @@
+#include <stdint.h>
+
+typedef struct EVEFont {
+ uint8_t id;
+ uint8_t w[128];
+ uint8_t h;
+} EVEFont;
+
+void eve_font_init(EVEFont *font, uint8_t font_id); \ No newline at end of file
diff --git a/code/fe310/eos/eve/screen/form.c b/code/fe310/eos/eve/screen/form.c
new file mode 100644
index 0000000..b4e59b9
--- /dev/null
+++ b/code/fe310/eos/eve/screen/form.c
@@ -0,0 +1,78 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+
+#include "screen.h"
+#include "tile.h"
+#include "page.h"
+#include "form.h"
+
+#include "widget/widget.h"
+
+#define CH_EOF 0x1a
+
+int eve_form_init(EVEForm *form, EVETile *tile, eve_page_open_t open, eve_page_close_t close, EVEWidget *widget, uint16_t widget_size) {
+ memset(form, 0, sizeof(EVEForm));
+ eve_page_init(&form->p, tile, eve_form_touch, eve_form_draw, open, close);
+ form->widget = widget;
+ form->widget_size = widget_size;
+
+}
+int eve_form_touch(EVECanvas *c, uint8_t tag0, int touch_idx) {
+ EVEForm *form = (EVEForm *)c;
+ EVEWidget *widget = form->widget;
+ int a, i, ret = 0;
+ EVEPageFocus focus = { NULL, {0,0,0,0}};
+
+ for (i=0; i<form->widget_size; i++) {
+ a = widget->touch(widget, &form->p, tag0, touch_idx, &focus);
+ ret = ret || a;
+ if (focus.w && (form->widget_f != focus.w)) {
+ EVEKbd *kbd = eve_screen_get_kbd(form->p.tile->screen);
+
+ if (kbd) {
+ if (form->widget_f && form->widget_f->putc) {
+ eve_screen_hide_kbd(form->p.tile->screen);
+ form->widget_f->putc(form->widget_f, CH_EOF);
+ }
+ eve_kbd_set_handler(kbd, widget->putc);
+ if (widget && widget->putc) {
+ eve_screen_show_kbd(form->p.tile->screen);
+ }
+ }
+ form->widget_f = widget;
+ }
+ widget = eve_widget_next(widget);
+ }
+
+ eve_page_focus(&form->p, &focus);
+ return ret;
+}
+
+uint8_t eve_form_draw(EVECanvas *c, uint8_t tag0) {
+ EVEForm *form = (EVEForm *)c;
+ EVEWidget *widget = form->widget;
+ int i, j;
+ uint8_t tagN, _tagN = 0;
+
+ for (i=0; i<form->widget_size; i++) {
+ tagN = widget->draw(widget, &form->p, tag0);
+ if (tagN) {
+ for (j=tag0; j<=tagN; j++) {
+ eve_touch_set_opt(j, eve_touch_get_opt(j) | EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_INERT);
+ }
+ if (tagN < 0xfe) {
+ tag0 = tagN + 1;
+ } else {
+ tag0 = 0;
+ }
+ _tagN = tagN;
+ }
+ widget = eve_widget_next(widget);
+ }
+
+ return _tagN;
+}
+
diff --git a/code/fe310/eos/eve/screen/form.h b/code/fe310/eos/eve/screen/form.h
new file mode 100644
index 0000000..3edafe8
--- /dev/null
+++ b/code/fe310/eos/eve/screen/form.h
@@ -0,0 +1,14 @@
+#include <stdint.h>
+
+struct EVEWidget;
+
+typedef struct EVEForm {
+ EVEPage p;
+ struct EVEWidget *widget_f;
+ struct EVEWidget *widget;
+ uint16_t widget_size;
+} EVEForm;
+
+int eve_form_init(EVEForm *form, EVETile *tile, eve_page_open_t open, eve_page_close_t close, struct EVEWidget *widget, uint16_t widget_size);
+int eve_form_touch(EVECanvas *c, uint8_t tag0, int touch_idx);
+uint8_t eve_form_draw(EVECanvas *c, uint8_t tag0);
diff --git a/code/fe310/eos/eve/screen/page.c b/code/fe310/eos/eve/screen/page.c
new file mode 100644
index 0000000..f703bd6
--- /dev/null
+++ b/code/fe310/eos/eve/screen/page.c
@@ -0,0 +1,64 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+
+#include "screen.h"
+#include "tile.h"
+#include "page.h"
+
+#include "widget/widget.h"
+
+void eve_page_init(EVEPage *page, EVETile *tile, eve_canvas_touch_t touch, eve_canvas_draw_t draw, eve_page_open_t open, eve_page_close_t close) {
+ memset(page, 0, sizeof(EVEPage));
+ page->tile = tile;
+ page->handle_evt = eve_page_handle_evt;
+}
+
+void eve_page_focus(EVEPage *page, EVEPageFocus *focus) {
+ uint16_t tile_w, tile_h;
+
+ if (focus->w == NULL) return;
+ eve_tile_get_pos(page->tile, NULL, NULL, &tile_w, &tile_h);
+
+ if (focus->f.x < page->win_x) {
+ page->win_x -= page->win_x - focus->f.x;
+ }
+ if (focus->f.y < page->win_y) {
+ page->win_y -= page->win_y - focus->f.y;
+ }
+ if ((focus->f.x + focus->f.w) > (page->win_x + tile_w)) {
+ page->win_x += (focus->f.x + focus->f.w) - (page->win_x + tile_w);
+ }
+ if ((focus->f.y + focus->f.h) > (page->win_y + tile_h)) {
+ page->win_y += (focus->f.y + focus->f.h) - (page->win_y + tile_h);
+ }
+}
+
+void eve_page_widget_focus(EVEPageFocus *focus, EVEWidget *widget) {
+ focus->w = widget;
+ focus->f.x = widget->x;
+ focus->f.y = widget->y;
+ focus->f.w = widget->w;
+ focus->f.h = widget->h;
+}
+
+int eve_page_widget_visible(EVEPage *page, EVEWidget *widget) {
+ uint16_t tile_w, tile_h;
+ eve_tile_get_pos(page->tile, NULL, NULL, &tile_w, &tile_h);
+
+ if (((widget->x + widget->w) >= page->win_x) && ((widget->y + widget->h) >= page->win_y) && (widget->x <= (page->win_x + tile_w)) && (widget->y <= (page->win_y + tile_h))) return 1;
+ return 0;
+}
+
+void eve_page_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) {
+ /*
+ if (evt & EVE_TOUCH_ETYPE_TRACK_Y) {
+ // do scroll
+ } else {
+ // go back / forward
+ }
+ */
+}
+
diff --git a/code/fe310/eos/eve/screen/page.h b/code/fe310/eos/eve/screen/page.h
new file mode 100644
index 0000000..453bfcf
--- /dev/null
+++ b/code/fe310/eos/eve/screen/page.h
@@ -0,0 +1,29 @@
+#include <stdint.h>
+
+struct EVEPage;
+struct EVEWidget;
+
+typedef void (*eve_page_open_t) (struct EVEPage *, struct EVEPage *);
+typedef void (*eve_page_close_t) (struct EVEPage *);
+typedef void (*eve_page_evt_handler_t) (struct EVEPage *, struct EVEWidget *, EVETouch *, uint16_t, uint8_t, int);
+
+typedef struct EVEPage {
+ EVECanvas c;
+ int16_t win_x;
+ int16_t win_y;
+ eve_page_evt_handler_t handle_evt;
+ eve_page_open_t open;
+ eve_page_close_t close;
+ EVETile *tile;
+} EVEPage;
+
+typedef struct EVEPageFocus {
+ struct EVEWidget *w;
+ EVEWindow f;
+} EVEPageFocus;
+
+void eve_page_init(EVEPage *page, EVETile *tile, eve_canvas_touch_t touch, eve_canvas_draw_t draw, eve_page_open_t open, eve_page_close_t close);
+void eve_page_focus(EVEPage *page, EVEPageFocus *focus);
+void eve_page_widget_focus(EVEPageFocus *focus, struct EVEWidget *widget);
+int eve_page_widget_visible(EVEPage *page, struct EVEWidget *widget);
+void eve_page_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx);
diff --git a/code/fe310/eos/eve/screen/screen.c b/code/fe310/eos/eve/screen/screen.c
new file mode 100644
index 0000000..c65e8fc
--- /dev/null
+++ b/code/fe310/eos/eve/screen/screen.c
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+
+#include "screen.h"
+#include "tile.h"
+
+int eve_screen_init(EVEScreen *screen, uint16_t w, uint16_t h) {
+ memset(screen, 0, sizeof(EVEScreen));
+ screen->w = w;
+ screen->h = h;
+}
+
+void eve_screen_set_kbd(EVEScreen *screen, EVEKbd *kbd) {
+ screen->kbd = kbd;
+}
+
+EVEKbd *eve_screen_get_kbd(EVEScreen *screen) {
+ return screen->kbd;
+}
+
+void eve_screen_show_kbd(EVEScreen *screen) {
+ screen->kbd_active = 1;
+}
+
+void eve_screen_hide_kbd(EVEScreen *screen) {
+ screen->kbd_active = 0;
+}
+
+void eve_screen_add_tile(EVEScreen *screen, EVETile *tile) {
+ if (screen->tile_size < EVE_MAX_TILES) {
+ screen->tile[screen->tile_size] = tile;
+ screen->tile_size++;
+ }
+}
+
+void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx) {
+ eve_touch_clear_opt();
+}
+
+
diff --git a/code/fe310/eos/eve/screen/screen.h b/code/fe310/eos/eve/screen/screen.h
new file mode 100644
index 0000000..8627517
--- /dev/null
+++ b/code/fe310/eos/eve/screen/screen.h
@@ -0,0 +1,30 @@
+#include <stdint.h>
+
+#define EVE_MAX_TILES 8
+
+struct EVETile;
+
+typedef struct EVEWindow {
+ uint16_t x;
+ uint16_t y;
+ uint16_t w;
+ uint16_t h;
+} EVEWindow;
+
+typedef struct EVEScreen {
+ uint16_t w;
+ uint16_t h;
+ EVEKbd *kbd;
+ struct EVETile *tile[EVE_MAX_TILES];
+ uint8_t tile_size;
+ char kbd_active;
+} EVEScreen;
+
+int eve_screen_init(EVEScreen *screen, uint16_t w, uint16_t h);
+void eve_screen_set_kbd(EVEScreen *screen, EVEKbd *kbd) ;
+EVEKbd *eve_screen_get_kbd(EVEScreen *screen);
+void eve_screen_show_kbd(EVEScreen *screen);
+void eve_screen_hide_kbd(EVEScreen *screen);
+
+void eve_screen_add_tile(EVEScreen *screen, struct EVETile *tile);
+void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx);
diff --git a/code/fe310/eos/eve/screen/tile.c b/code/fe310/eos/eve/screen/tile.c
new file mode 100644
index 0000000..3715f6d
--- /dev/null
+++ b/code/fe310/eos/eve/screen/tile.c
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+
+#include "screen.h"
+#include "tile.h"
+
+#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
+
+void eve_tile_init(EVETile *tile, EVEScreen *screen, uint16_t x, uint16_t y, uint16_t w, uint16_t h, EVECanvas *canvas) {
+ tile->screen = screen;
+ tile->x = x;
+ tile->y = y;
+ tile->w = w;
+ tile->h = h;
+ tile->canvas = canvas;
+}
+
+void eve_tile_get_pos(EVETile *tile, uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h) {
+ if (x) *x = tile->x;
+ if (y) *y = tile->y;
+ if (w) *w = tile->w;
+ if (h) *h = MIN(tile->x + tile->h, tile->screen->h - (tile->screen->kbd && tile->screen->kbd_active ? tile->screen->kbd->h : 0));
+}
+
+void eve_canvas_init(EVECanvas *canvas, eve_canvas_touch_t touch, eve_canvas_draw_t draw) {
+ canvas->touch = touch;
+ canvas->draw = draw;
+}
+
diff --git a/code/fe310/eos/eve/screen/tile.h b/code/fe310/eos/eve/screen/tile.h
new file mode 100644
index 0000000..5fea8bf
--- /dev/null
+++ b/code/fe310/eos/eve/screen/tile.h
@@ -0,0 +1,24 @@
+#include <stdint.h>
+
+struct EVECanvas;
+
+typedef int (*eve_canvas_touch_t) (struct EVECanvas *, uint8_t, int);
+typedef uint8_t (*eve_canvas_draw_t) (struct EVECanvas *, uint8_t);
+
+typedef struct EVECanvas {
+ eve_canvas_touch_t touch;
+ eve_canvas_draw_t draw;
+} EVECanvas;
+
+typedef struct EVETile {
+ uint16_t x;
+ uint16_t y;
+ uint16_t w;
+ uint16_t h;
+ EVECanvas *canvas;
+ EVEScreen *screen;
+} EVETile;
+
+void eve_tile_init(EVETile *tile, EVEScreen *screen, uint16_t x, uint16_t y, uint16_t w, uint16_t h, EVECanvas *canvas);
+void eve_tile_get_pos(EVETile *tile, uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h);
+void eve_canvas_init(EVECanvas *canvas, eve_canvas_touch_t touch, eve_canvas_draw_t draw);