added stock bitmap handling and support for it in the demo script

This commit is contained in:
Amy Bowersox 2019-12-11 14:03:11 -07:00
parent 51fda759cc
commit ed9fd9320c
5 changed files with 78 additions and 7 deletions

View File

@ -6,7 +6,14 @@ WHITE = upiwin.rgb(255, 255, 255)
LTGRAY = upiwin.rgb(204, 204, 204)
YELLOW = upiwin.rgb(255, 255, 0)
# Get the stock bitmaps.
bmp_freehand = upiwin.Bitmap(stock='freehand')
bmp_line = upiwin.Bitmap(stock='line')
bmp_rect = upiwin.Bitmap(stock='rect')
bmp_fillrect = upiwin.Bitmap(stock='fillrect')
hdc = upiwin.DevCtxt(type='screen')
hdc_bits = upiwin.DevCtxt(type='memory')
# divide the screen into "drawing" and "command" areas
screen_rect = hdc.get_clip_rect()
@ -100,6 +107,9 @@ 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])
hdc_bits.select_object(bmp_freehand)
hdc.bitblt(cmd1_rect[0] + 6, cmd1_rect[1] + 6, cmd1_rect[0] + 54, cmd1_rect[1] + 54, hdc_bits, 0, 0, 0)
# Main message loop
msg = {}
while upiwin.get_message(msg):

View File

@ -4,7 +4,7 @@ SPLASHSCREEN=splash-vmwcblk.png
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 \
bitmap.o stockobj.o fbprimitive.o log.o gpio.o msg_queue.o time_func.o config.o \
i_freehand.o i_line.o i_rect.o i_fillrect.o splash.o
LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm
CFLAGS=-I/usr/include/python3.7m -I/usr/include/freetype2 -I/usr/include/libpng16 \

View File

@ -16,4 +16,6 @@ typedef struct tagBITMAP {
extern PBITMAP BMP_Create(INT32 width, INT32 height, const void *bits);
extern void BMP_Delete(PBITMAP pbmp);
extern PBITMAP _BMP_GetStock(PCSTR name);
#endif /* __BITMAP_H_INCLUDED */

View File

@ -40,12 +40,24 @@ static PyGetSetDef BitmapProperties[] = {
static int bitmap_init(BitmapObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = { "width", "height", NULL };
static char *kwlist[] = { "stock", "width", "height", NULL };
const char *stock;
int width = 0, height = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "$ii", kwlist, &width, &height))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "$sii", kwlist, &stock, &width, &height))
return -1;
if (stock)
{
self->pbmp = _BMP_GetStock(stock);
if (!(self->pbmp))
{
PyErr_Format(PyExc_RuntimeError, "no such stock bitmap: '%s'", stock);
return -1;
}
}
else
{
width = MAX(1, width);
height = MAX(1, height);
self->pbmp = BMP_Create(width, height, NULL);
@ -54,6 +66,7 @@ static int bitmap_init(BitmapObject *self, PyObject *args, PyObject *kwds)
PyErr_SetString(PyExc_RuntimeError, "unable to create bitmap");
return -1;
}
}
return 0;
}

46
src/stockobj.c Executable file
View File

@ -0,0 +1,46 @@
#include <stddef.h>
#include <string.h>
#include "wintype.h"
#include "bitmap.h"
/* references to the icon data */
extern uint8_t _binary_i_freehand_bin_start[];
extern uint8_t _binary_i_freehand_bin_end;
extern uint8_t _binary_i_freehand_bin_size;
extern uint8_t _binary_i_line_bin_start[];
extern uint8_t _binary_i_line_bin_end;
extern uint8_t _binary_i_line_bin_size;
extern uint8_t _binary_i_rect_bin_start[];
extern uint8_t _binary_i_rect_bin_end;
extern uint8_t _binary_i_rect_bin_size;
extern uint8_t _binary_i_fillrect_bin_start[];
extern uint8_t _binary_i_fillrect_bin_end;
extern uint8_t _binary_i_fillrect_bin_size;
typedef struct tagSTOCKBITMAPDESC {
PCSTR name;
INT32 width;
INT32 height;
const void *data;
} STOCKBITMAPDESC;
static const STOCKBITMAPDESC stock_bitmaps = {
{"freehand", 48, 48, _binary_i_freehand_bin_start },
{"line", 48, 48, _binary_i_line_bin_start },
{"rect", 48, 48, _binary_i_rect_bin_start },
{"fillrect", 48, 48, _binary_i_fillrect_bin_start },
{NULL, 0, 0, NULL }
};
PBITMAP _BMP_GetStock(PCSTR name)
{
INT32 i;
for (i = 0; stock_bitmaps[i].name; ++i)
if (strcmp(name, stock_bitmaps[i].name) == 0)
return BMP_Create(stock_bitmaps[i].width, stock_bitmaps[i].height, stock_bitmaps[i].data);
return NULL;
}