add the undo and clear commands with their icons
This commit is contained in:
parent
4d5b53fcdc
commit
cb9ecc89ca
BIN
resources/i_clear.png
Executable file
BIN
resources/i_clear.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
resources/i_undo.png
Executable file
BIN
resources/i_undo.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
|
@ -17,6 +17,8 @@ bmp_freehand = upiwin.Bitmap(stock='freehand')
|
|||
bmp_line = upiwin.Bitmap(stock='line')
|
||||
bmp_rect = upiwin.Bitmap(stock='rect')
|
||||
bmp_fillrect = upiwin.Bitmap(stock='fillrect')
|
||||
bmp_undo = upiwin.Bitmap(stock='undo')
|
||||
bmp_clear = upiwin.Bitmap(stock='clear')
|
||||
|
||||
hdc = upiwin.DevCtxt(type='screen')
|
||||
hdc_bits = upiwin.DevCtxt(type='memory')
|
||||
|
@ -29,8 +31,8 @@ command_rect = (drawing_rect[2], screen_rect[1], screen_rect[2], screen_rect[3])
|
|||
# further divide up the "command" area
|
||||
tool_select_rect = (command_rect[0], command_rect[1], command_rect[2], 60)
|
||||
color_select_rect = (command_rect[0], 60, command_rect[2], 120)
|
||||
cmd3_rect = (command_rect[0], 120, command_rect[2], 180)
|
||||
cmd4_rect = (command_rect[0], 180, command_rect[2], command_rect[3])
|
||||
undo_rect = (command_rect[0], 120, command_rect[2], 180)
|
||||
clear_rect = (command_rect[0], 180, command_rect[2], command_rect[3])
|
||||
|
||||
def point_in_rect(rect, x, y):
|
||||
return (x >= rect[0]) and (x < rect[2]) and (y >= rect[1]) and (y < rect[3])
|
||||
|
@ -106,6 +108,19 @@ def repaint():
|
|||
hdc.solid_rectangle(drawing_rect[0], drawing_rect[1], drawing_rect[2], drawing_rect[3])
|
||||
for obj in objects_drawn:
|
||||
draw_object(obj)
|
||||
|
||||
def undo_last():
|
||||
global objects_drawn
|
||||
if len(objects_drawn) > 0:
|
||||
last = len(objects_drawn) - 1
|
||||
del objects_drawn[last]
|
||||
repaint()
|
||||
|
||||
def clear_all():
|
||||
global objects_drawn
|
||||
if len(objects_drawn) > 0:
|
||||
objects_drawn.clear()
|
||||
repaint()
|
||||
|
||||
# --- Graphic feedback --
|
||||
|
||||
|
@ -215,10 +230,10 @@ def on_touchclick(x, y):
|
|||
select_next_tool()
|
||||
elif point_in_rect(color_select_rect, x, y):
|
||||
select_next_color()
|
||||
elif point_in_rect(cmd3_rect, x, y):
|
||||
print("Click command 3")
|
||||
elif point_in_rect(cmd4_rect, x, y):
|
||||
print("Click command 4")
|
||||
elif point_in_rect(undo_rect, x, y):
|
||||
undo_last()
|
||||
elif point_in_rect(clear_rect, x, y):
|
||||
clear_all()
|
||||
|
||||
def on_button_click(button):
|
||||
if button == 1: # Button 1 = Set backlight level
|
||||
|
@ -235,12 +250,17 @@ hdc.text_color = LTGRAY
|
|||
hdc.rop2 = upiwin.R2_COPYPEN
|
||||
hdc.rectangle(tool_select_rect[0], tool_select_rect[1], tool_select_rect[2], tool_select_rect[3])
|
||||
hdc.rectangle(color_select_rect[0], color_select_rect[1], color_select_rect[2], color_select_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.rectangle(undo_rect[0], undo_rect[1], undo_rect[2], undo_rect[3])
|
||||
hdc.rectangle(clear_rect[0], clear_rect[1], clear_rect[2], clear_rect[3])
|
||||
|
||||
draw_current_tool()
|
||||
draw_current_color()
|
||||
|
||||
hdc_bits.select_object(bmp_undo)
|
||||
hdc.bitblt(undo_rect[0] + 6, undo_rect[1] + 6, undo_rect[0] + 54, undo_rect[1] + 54, hdc_bits, 0, 0, 0)
|
||||
hdc_bits.select_object(bmp_clear)
|
||||
hdc.bitblt(clear_rect[0] + 6, clear_rect[1] + 6, clear_rect[0] + 54, clear_rect[1] + 54, hdc_bits, 0, 0, 0)
|
||||
|
||||
# Main message loop
|
||||
msg = {}
|
||||
while upiwin.get_message(msg):
|
||||
|
|
|
@ -5,7 +5,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 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
|
||||
i_freehand.o i_line.o i_rect.o i_fillrect.o i_undo.o i_clear.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 \
|
||||
-Wall -Werror -fstack-protector -fwrapv -fno-PIE -g -O3 -DDEBUG_ASSERT
|
||||
|
@ -39,5 +39,11 @@ i_rect.bin: $(RESOURCES)/i_rect.png $(BUILDUTILS)/mkgfx
|
|||
i_fillrect.bin: $(RESOURCES)/i_fillrect.png $(BUILDUTILS)/mkgfx
|
||||
$(BUILDUTILS)/mkgfx $(RESOURCES)/i_fillrect.png i_fillrect.bin
|
||||
|
||||
i_undo.bin: $(RESOURCES)/i_undo.png $(BUILDUTILS)/mkgfx
|
||||
$(BUILDUTILS)/mkgfx $(RESOURCES)/i_undo.png undo.bin
|
||||
|
||||
i_clear.bin: $(RESOURCES)/i_clear.png $(BUILDUTILS)/mkgfx
|
||||
$(BUILDUTILS)/mkgfx $(RESOURCES)/i_clear.png i_clear.bin
|
||||
|
||||
clean:
|
||||
rm -f upiwin *.o splash.bin *~
|
||||
|
|
|
@ -20,6 +20,14 @@ extern uint8_t _binary_i_fillrect_bin_start[];
|
|||
extern uint8_t _binary_i_fillrect_bin_end;
|
||||
extern uint8_t _binary_i_fillrect_bin_size;
|
||||
|
||||
extern uint8_t _binary_i_undo_bin_start[];
|
||||
extern uint8_t _binary_i_undo_bin_end;
|
||||
extern uint8_t _binary_i_undo_bin_size;
|
||||
|
||||
extern uint8_t _binary_i_clear_bin_start[];
|
||||
extern uint8_t _binary_i_clear_bin_end;
|
||||
extern uint8_t _binary_i_clear_bin_size;
|
||||
|
||||
typedef struct tagSTOCKBITMAPDESC {
|
||||
PCSTR name;
|
||||
INT32 width;
|
||||
|
@ -32,6 +40,8 @@ static const STOCKBITMAPDESC stock_bitmaps[] = {
|
|||
{"line", 48, 48, _binary_i_line_bin_start },
|
||||
{"rect", 48, 48, _binary_i_rect_bin_start },
|
||||
{"fillrect", 48, 48, _binary_i_fillrect_bin_start },
|
||||
{"undo", 48, 48, _binary_i_undo_bin_start },
|
||||
{"clear", 48, 48, _binary_i_clear_bin_start },
|
||||
{NULL, 0, 0, NULL }
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user