From 1088f630a0e2df70660c6b3a1a41f6ddf39b0b38 Mon Sep 17 00:00:00 2001 From: Amy Bowersox Date: Wed, 11 Dec 2019 12:05:53 -0700 Subject: [PATCH] added the rgb function to upiwin and started building the demo script --- scripts/demo1.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile | 2 +- src/ep_graphics.c | 13 +++++++++++ src/ep_upiwin.c | 3 +++ src/ep_upiwin.h | 2 ++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 scripts/demo1.py create mode 100755 src/ep_graphics.c diff --git a/scripts/demo1.py b/scripts/demo1.py new file mode 100755 index 0000000..1c30f00 --- /dev/null +++ b/scripts/demo1.py @@ -0,0 +1,58 @@ +# Demo script that implements a simple drawing program +import upiwin + +# Save off some color values. +WHITE = upiwin.rgb(255, 255, 255) +LTGRAY = upiwin.rgb(204, 204, 204) +YELLOW = upiwin.rgb(255, 255, 0) + +hdc = upiwin.DevCtxt(type='screen') + +# divide the screen into "drawing" and "command" areas +drawing_rect = hdc.get_clip_rect() +command_rect = drawing_rect +drawing_rect[2] -= 60; +command_rect[0] = drawing_rect[2] + 1 + +# further divide up the "command" area +cmd1_rect = command_rect +cmd2_rect = command_rect +cmd3_rect = command_rect +cmd4_rect = command_rect +cmd1_rect[3] = 60; +cmd2_rect[1] = 60; +cmd2_rect[3] = 120; +cmd3_rect[1] = 120; +cmd3_rect[3] = 180; +cmd4_rect[1] = 180; + +def point_in_rect(rect, x, y): + return (x >= rect[0]) and (x < rect[2]) and (y >= rect[1]) and (y < rect[3]) + + + + +# --- Initialize and start message loop --- + +# Draw the basic layout. +hdc.set_text_color(LTGRAY) +hdc.rectangle(cmd1_rect[0], cmd1_rect[1], cmd1_rect[2], cmd1_rect[3]) +hdc.rectangle(cmd2_rect[0], cmd2_rect[1], cmd2_rect[2], cmd2_rect[3]) +hdc.rectangle(cmd3_rect[0], cmd3_rect[1], cmd3_rect[2], cmd3_rect[3]) +hdc.rectangle(cmd4_rect[0], cmd4_rect[1], cmd4_rect[2], cmd4_rect[3]) + +# Main message loop +msg = {} +while upiwin.get_message(msg): + if msg['message'] == upiwin.WM_TOUCHCLICK: + if point_in_rect(cmd1_rect, msg['attrs'][0], msg['attrs'][1]): + print("Click command 1") + elif point_in_rect(cmd2_rect, msg['attrs'][0], msg['attrs'][1]): + print("Click command 2") + elif point_in_rect(cmd3_rect, msg['attrs'][0], msg['attrs'][1]): + print("Click command 3") + elif point_in_rect(cmd4_rect, msg['attrs'][0], msg['attrs'][1]): + print("Click command 4") + elif msg['message'] == upiwin.WM_HWBUTTONCLICK: + if msg['attrs'][0] == 4: # Button 4 = Exit app + upiwin.post_quit_message(0) diff --git a/src/Makefile b/src/Makefile index 95a4c9e..e9843a7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ BUILDUTILS=../buildutils RESOURCES=../resources SPLASHSCREEN=splash-vmwcblk.png -OBJS=main.o sysinput.o ep_init.o ep_upiwin.o ep_backlight.o ep_msg.o ep_devctxt.o ep_bitmap.o \ +OBJS=main.o sysinput.o ep_init.o ep_upiwin.o ep_backlight.o ep_msg.o ep_graphics.o ep_devctxt.o ep_bitmap.o \ ep_upiwin_tmp.o ep_util.o fbinit.o rect.o gfxobj.o devctxt.o dc_screen.o fontengine.o \ bitmap.o fbprimitive.o log.o gpio.o msg_queue.o time_func.o config.o splash.o LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm diff --git a/src/ep_graphics.c b/src/ep_graphics.c new file mode 100755 index 0000000..3643889 --- /dev/null +++ b/src/ep_graphics.c @@ -0,0 +1,13 @@ +#define PY_SSIZE_T_CLEAN +#include +#include "wintype.h" +#include "gfxtype.h" + +PyObject *Epython_rgb(PyObject *self, PyObject *args) +{ + UINT32 r, g, b; + + if (!PyArg_ParseTuple(args, "kkk", &r, &g, &b)) + return NULL; + return PyLong_FromUnsignedLong(RGB(r, g, b)); +} diff --git a/src/ep_upiwin.c b/src/ep_upiwin.c index 1354d06..16ca9ed 100644 --- a/src/ep_upiwin.c +++ b/src/ep_upiwin.c @@ -23,6 +23,9 @@ static PyMethodDef UPIWINMethods[] = { "Retrieves a message from the message queue, blocking if necessary."}, {"post_quit_message", Epython_post_quit_message, METH_VARARGS, "Posts a WM_QUIT message to the message queue, with an exit code."}, + /* Graphics functions */ + {"rgb", Epython_rgb, METH_VARARGS, + "Creates a color value from separate red, green, and blue indexes."}, {NULL, NULL, 0, NULL} }; diff --git a/src/ep_upiwin.h b/src/ep_upiwin.h index b6dbe14..b80fd0c 100644 --- a/src/ep_upiwin.h +++ b/src/ep_upiwin.h @@ -22,5 +22,7 @@ extern PyObject *Epython_set_backlight_level(PyObject *self, PyObject *args); extern PyObject *Epython_get_message(PyObject *self, PyObject *args); extern PyObject *Epython_post_quit_message(PyObject *self, PyObject *args); +/* ep_graphics.c */ +extern PyObject *Epython_rgb(PyObject *self, PyObject *args); #endif /* __EP_UPIWIN_H_INCLUDED */