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/Makefile2
-rw-r--r--code/fe310/eos/eve/screen/form.c26
-rw-r--r--code/fe310/eos/eve/screen/form.h6
-rw-r--r--code/fe310/eos/eve/screen/page.c51
-rw-r--r--code/fe310/eos/eve/screen/page.h16
-rw-r--r--code/fe310/eos/eve/screen/screen.c42
-rw-r--r--code/fe310/eos/eve/screen/screen.h21
-rw-r--r--code/fe310/eos/eve/screen/tile.c32
-rw-r--r--code/fe310/eos/eve/screen/tile.h24
-rw-r--r--code/fe310/eos/eve/screen/window.c39
-rw-r--r--code/fe310/eos/eve/screen/window.h21
11 files changed, 154 insertions, 126 deletions
diff --git a/code/fe310/eos/eve/screen/Makefile b/code/fe310/eos/eve/screen/Makefile
index a579f8f..372cf9e 100644
--- a/code/fe310/eos/eve/screen/Makefile
+++ b/code/fe310/eos/eve/screen/Makefile
@@ -2,7 +2,7 @@ include ../../../common.mk
CFLAGS += -I. -I.. -I../..
-obj = font.o screen.o tile.o page.o form.o
+obj = font.o screen.o window.o page.o form.o
%.o: %.c %.h
diff --git a/code/fe310/eos/eve/screen/form.c b/code/fe310/eos/eve/screen/form.c
index 10f17ad..41105f6 100644
--- a/code/fe310/eos/eve/screen/form.c
+++ b/code/fe310/eos/eve/screen/form.c
@@ -5,7 +5,7 @@
#include "eve_kbd.h"
#include "screen.h"
-#include "tile.h"
+#include "window.h"
#include "page.h"
#include "form.h"
@@ -13,33 +13,33 @@
#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) {
+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, tile, eve_form_touch, eve_form_draw, open, close);
+ eve_page_init(&form->p, eve_form_touch, eve_form_draw, open, close, window);
form->widget = widget;
form->widget_size = widget_size;
-
}
-int eve_form_touch(EVECanvas *c, uint8_t tag0, int touch_idx) {
- EVEForm *form = (EVEForm *)c;
+
+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;
- EVEPageFocus focus = {NULL, {0,0,0,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 && (form->widget_f != focus.w)) {
- EVEKbd *kbd = eve_screen_get_kbd(form->p.tile->screen);
+ 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.tile->screen);
+ eve_screen_hide_kbd(form->p.window->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);
+ eve_screen_show_kbd(form->p.window->screen);
}
}
form->widget_f = widget;
@@ -51,8 +51,8 @@ int eve_form_touch(EVECanvas *c, uint8_t tag0, int touch_idx) {
return ret;
}
-uint8_t eve_form_draw(EVECanvas *c, uint8_t tag0) {
- EVEForm *form = (EVEForm *)c;
+uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
+ EVEForm *form = (EVEForm *)v;
EVEWidget *widget = form->widget;
int i, j;
uint8_t tagN, _tagN = 0;
diff --git a/code/fe310/eos/eve/screen/form.h b/code/fe310/eos/eve/screen/form.h
index 3edafe8..e667fc8 100644
--- a/code/fe310/eos/eve/screen/form.h
+++ b/code/fe310/eos/eve/screen/form.h
@@ -9,6 +9,6 @@ typedef struct EVEForm {
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);
+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);
diff --git a/code/fe310/eos/eve/screen/page.c b/code/fe310/eos/eve/screen/page.c
index f703bd6..b2ef091 100644
--- a/code/fe310/eos/eve/screen/page.c
+++ b/code/fe310/eos/eve/screen/page.c
@@ -5,54 +5,51 @@
#include "eve_kbd.h"
#include "screen.h"
-#include "tile.h"
+#include "window.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) {
+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) {
memset(page, 0, sizeof(EVEPage));
- page->tile = tile;
+ page->v.touch = touch;
+ page->v.draw = draw;
+ page->open = open;
+ page->close = close;
page->handle_evt = eve_page_handle_evt;
+ page->window = window;
}
-void eve_page_focus(EVEPage *page, EVEPageFocus *focus) {
- uint16_t tile_w, tile_h;
+void eve_page_focus(EVEPage *page, EVERect *f) {
+ EVERect g;
- if (focus->w == NULL) return;
- eve_tile_get_pos(page->tile, NULL, NULL, &tile_w, &tile_h);
+ eve_window_get_visible(page->window, &g);
+ g.x -= page->window->g.x;
+ g.y -= page->window->g.y;
- if (focus->f.x < page->win_x) {
- page->win_x -= page->win_x - focus->f.x;
+ if (f->x < page->win_x + g.x) {
+ page->win_x = f->x - g.x;
}
- if (focus->f.y < page->win_y) {
- page->win_y -= page->win_y - focus->f.y;
+ if (f->y < page->win_y + g.y) {
+ page->win_y = f->y - g.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 ((f->x + f->w) > (page->win_x + g.x + g.w)) {
+ page->win_x = (f->x + f->w) - (g.x + g.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);
+ if ((f->y + f->h) > (page->win_y + g.y + g.h)) {
+ page->win_y = (f->y + f->h) - (g.y + g.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);
+ uint16_t w = page->window->g.w;
+ uint16_t h = page->window->g.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;
+ 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;
return 0;
}
-void eve_page_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) {
+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
diff --git a/code/fe310/eos/eve/screen/page.h b/code/fe310/eos/eve/screen/page.h
index 453bfcf..42cae7d 100644
--- a/code/fe310/eos/eve/screen/page.h
+++ b/code/fe310/eos/eve/screen/page.h
@@ -8,22 +8,16 @@ 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;
+ EVEView v;
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;
+ eve_page_evt_handler_t handle_evt;
+ EVEWindow *window;
} 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);
+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);
diff --git a/code/fe310/eos/eve/screen/screen.c b/code/fe310/eos/eve/screen/screen.c
index c65e8fc..52015be 100644
--- a/code/fe310/eos/eve/screen/screen.c
+++ b/code/fe310/eos/eve/screen/screen.c
@@ -5,7 +5,7 @@
#include "eve_kbd.h"
#include "screen.h"
-#include "tile.h"
+#include "window.h"
int eve_screen_init(EVEScreen *screen, uint16_t w, uint16_t h) {
memset(screen, 0, sizeof(EVEScreen));
@@ -29,11 +29,43 @@ 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++;
+int eve_screen_win_insert(EVEScreen *screen, EVEWindow *window, int idx) {
+ if (idx) {
+ int i;
+ EVEWindow *h = screen->win_head;
+
+ for (i=1; i<idx; i++) {
+ h = h->next;
+ if (h == NULL) return EVE_ERR;
+ }
+ window->next = h->next;
+ h->next = window;
+ } else {
+ window->next = screen->win_head;
+ screen->win_head = window;
}
+ if (window->next == NULL) screen->win_tail = window;
+ return EVE_OK;
+}
+
+int eve_screen_win_remove(EVEScreen *screen, EVEWindow *window) {
+ EVEWindow *h = screen->win_head;
+ if (h == NULL) return EVE_ERR;
+ if (h == window) {
+ screen->win_head = window->next;
+ if (screen->win_head == NULL) screen->win_tail = NULL;
+ } else {
+ while (h->next && (h->next != window)) h = h->next;
+ if (h->next == NULL) return EVE_ERR;
+
+ h->next = window->next;
+ if (h->next == NULL) screen->win_tail = h;
+ }
+}
+
+void eve_screen_win_append(EVEScreen *screen, EVEWindow *window) {
+ screen->win_tail->next = window;
+ screen->win_tail = window;
}
void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx) {
diff --git a/code/fe310/eos/eve/screen/screen.h b/code/fe310/eos/eve/screen/screen.h
index 8627517..ff634b4 100644
--- a/code/fe310/eos/eve/screen/screen.h
+++ b/code/fe310/eos/eve/screen/screen.h
@@ -1,22 +1,20 @@
#include <stdint.h>
-#define EVE_MAX_TILES 8
+struct EVEWindow;
-struct EVETile;
-
-typedef struct EVEWindow {
- uint16_t x;
- uint16_t y;
+typedef struct EVERect {
+ int16_t x;
+ int16_t y;
uint16_t w;
uint16_t h;
-} EVEWindow;
+} EVERect;
typedef struct EVEScreen {
uint16_t w;
uint16_t h;
EVEKbd *kbd;
- struct EVETile *tile[EVE_MAX_TILES];
- uint8_t tile_size;
+ struct EVEWindow *win_head;
+ struct EVEWindow *win_tail;
char kbd_active;
} EVEScreen;
@@ -26,5 +24,8 @@ 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);
+int eve_screen_win_insert(EVEScreen *screen, struct EVEWindow *window, int idx);
+int eve_screen_win_remove(EVEScreen *screen, struct EVEWindow *window);
+void eve_screen_win_append(EVEScreen *screen, struct EVEWindow *window);
+
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
deleted file mode 100644
index 3715f6d..0000000
--- a/code/fe310/eos/eve/screen/tile.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#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
deleted file mode 100644
index 5fea8bf..0000000
--- a/code/fe310/eos/eve/screen/tile.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#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);
diff --git a/code/fe310/eos/eve/screen/window.c b/code/fe310/eos/eve/screen/window.c
new file mode 100644
index 0000000..8341e8a
--- /dev/null
+++ b/code/fe310/eos/eve/screen/window.c
@@ -0,0 +1,39 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+
+#include "screen.h"
+#include "window.h"
+
+#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
+
+void eve_window_init(EVEWindow *window, EVERect *g, EVEView *view, EVEScreen *screen) {
+ memset(window, 0, sizeof(EVEWindow));
+
+ if (g) window->g = *g;
+ window->view = view;
+ window->screen = screen;
+}
+
+void eve_window_get_visible(EVEWindow *window, EVERect *g) {
+ EVEWindow *w = window->next;
+
+ *g = window->g;
+ while (w) {
+ if (w->g.x > g->x) g->w = MIN(g->w, w->g.x - g->x);
+ if (w->g.y > g->y) g->h = MIN(g->h, w->g.y - g->y);
+ if (w->g.x + w->g.w < g->x + g->w) {
+ uint16_t x0 = g->w - MIN(g->w, (g->x + g->w) - (w->g.x + w->g.w));
+ g->x += x0;
+ g->w -= x0;
+ }
+ if (w->g.y + w->g.h < g->y + g->h) {
+ uint16_t y0 = g->h - MIN(g->h, (g->y + g->h) - (w->g.y + w->g.h));
+ g->y += y0;
+ g->h -= y0;
+ }
+ w = w->next;
+ }
+}
diff --git a/code/fe310/eos/eve/screen/window.h b/code/fe310/eos/eve/screen/window.h
new file mode 100644
index 0000000..f3a1c77
--- /dev/null
+++ b/code/fe310/eos/eve/screen/window.h
@@ -0,0 +1,21 @@
+#include <stdint.h>
+
+struct EVEView;
+
+typedef int (*eve_view_touch_t) (struct EVEView *, uint8_t, int);
+typedef uint8_t (*eve_view_draw_t) (struct EVEView *, uint8_t);
+
+typedef struct EVEView {
+ eve_view_touch_t touch;
+ eve_view_draw_t draw;
+} EVEView;
+
+typedef struct EVEWindow {
+ EVERect g;
+ EVEView *view;
+ EVEScreen *screen;
+ struct EVEWindow *next;
+} EVEWindow;
+
+void eve_window_init(EVEWindow *window, EVERect *g, EVEView *view, EVEScreen *screen);
+void eve_window_get_visible(EVEWindow *window, EVERect *g);