Simplify screen: make it absolute and fill the whole TFT

This commit is contained in:
Pim van Pelt
2017-11-26 20:07:26 +01:00
parent 43fad07afe
commit d5e01dedd2
7 changed files with 25 additions and 32 deletions

View File

@ -21,8 +21,8 @@ static void touch_handler(struct mgos_stmpe610_event_data *ed) {
x = map(ed->x, 0, 4095, 0, _width-1);
y = map(ed->y, 0, 4095, 0, _height-1);
LOG(LL_INFO, ("Touch %s at (%d,%d) pressure=%d, length=%d", ed->direction==TOUCH_UP?"UP":"DOWN", x, y, ed->z, ed->length));
widget = screen_widget_find_by_xy(screen, x, y);
if (ed->direction==TOUCH_DOWN) {
widget_network_recv();
if (widget && widget->handler)

View File

@ -1,15 +1,11 @@
#include "screen.h"
struct screen_t *screen_create(char *name, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
struct screen_t *screen_create(char *name) {
struct screen_t *screen = NULL;
screen = (struct screen_t *) calloc(1, sizeof(*screen));
if (!screen)
return NULL;
screen->x=x;
screen->y=y;
screen->w=w;
screen->h=h;
if (name)
screen->name=strdup(name);
SLIST_INIT(&screen->widget_entries);
@ -39,14 +35,13 @@ struct screen_t *screen_create_from_json(char *json, widget_event_fn handler, vo
int idx;
struct screen_t *screen = NULL;
struct widget_t *widget = NULL;
int screen_x, screen_y, screen_w, screen_h;
char *screen_name = NULL;
if (json_scanf(json, strlen(json), "{x:%d,y:%d,w:%d,h:%d,name:%Q}", &screen_x, &screen_y, &screen_w, &screen_h, &screen_name) != 5) {
LOG(LL_ERROR, ("Incomplete JSON: require 'x', 'y', 'w', 'h' and 'name' fields"));
if (json_scanf(json, strlen(json), "{name:%Q}", &screen_name) != 1) {
LOG(LL_ERROR, ("Incomplete JSON: require 'name' fields"));
screen=NULL; goto exit;
}
screen = screen_create(screen_name, screen_x, screen_y, screen_w, screen_h);
screen = screen_create(screen_name);
if (!screen)
return NULL;
screen_widget_set_handler(screen, handler, user_data);

View File

@ -2,6 +2,17 @@
#include "tft.h"
#include "mongoose-touch.h"
static void widget_default_draw(struct widget_t *w) {
if (!w)
return;
mgos_ili9341_setclipwin(w->x, w->y, w->x+w->w, w->y+w->h);
mgos_ili9341_drawRect(0, 0, w->w, w->h, ILI9341_GREEN);
if (w->img)
mgos_ili9341_jpg_image(0, 0, 1, w->img, NULL, 0);
}
void widget_default_ev(int ev, struct widget_t *w, void *ev_data) {
char evname[15];
@ -15,6 +26,8 @@ void widget_default_ev(int ev, struct widget_t *w, void *ev_data) {
case EV_WIDGET_CREATE:
case EV_WIDGET_DRAW:
case EV_WIDGET_REDRAW:
widget_default_draw(w);
break;
case EV_WIDGET_TIMER:
case EV_WIDGET_TOUCH_UP:
case EV_WIDGET_TOUCH_DOWN: