add the undo and clear commands with their icons
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user