From b620f55420a72b09e1d4e13b6205bbb63f03a374 Mon Sep 17 00:00:00 2001 From: Amy Bowersox Date: Wed, 11 Dec 2019 14:52:32 -0700 Subject: [PATCH] adding feedback for each of the tools --- scripts/demo1.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/demo1.py b/scripts/demo1.py index 2f4037d..ab1d7a8 100755 --- a/scripts/demo1.py +++ b/scripts/demo1.py @@ -50,8 +50,6 @@ def select_next_color(): current_color = 0 draw_current_color() - - # --- Graphic feedback -- origin_x = 0 @@ -59,9 +57,17 @@ origin_y = 0 current_x = 0 current_y = 0 +def freehand_draw(x, y, down, up): + global current_x, current_y + hdc.text_color = color_list[current_color] + hdc.move_to(current_x, current_y) + hdc.line_to(x, y) + current_x = x + current_y = y + def rubberband_rectangle(x, y, down, up): global current_x, current_y - hdc.text_color = YELLOW + hdc.text_color = LTGRAY hdc.rop2 = upiwin.R2_XORPEN if not down: hdc.rectangle(min(origin_x, current_x), min(origin_y, current_y), max(origin_x, current_x), max(origin_y, current_y)) @@ -72,7 +78,7 @@ def rubberband_rectangle(x, y, down, up): def rubberband_line(x, y, down, up): global current_x, current_y - hdc.text_color = YELLOW + hdc.text_color = LTGRAY hdc.rop2 = upiwin.R2_XORPEN if not down: hdc.move_to(origin_x, origin_y) @@ -83,14 +89,13 @@ def rubberband_line(x, y, down, up): hdc.move_to(origin_x, origin_y) hdc.line_to(current_x, current_y) - # --- Tool definitions --- tool_list = [ - { 'icon': bmp_freehand }, - { 'icon': bmp_line }, - { 'icon': bmp_rect }, - { 'icon': bmp_fillrect } + { 'icon': bmp_freehand, 'feedback': freehand_draw }, + { 'icon': bmp_line, 'feedback': rubberband_line }, + { 'icon': bmp_rect, 'feedback': rubberband_rect }, + { 'icon': bmp_fillrect, 'feedback': rubberband_rect } ] current_tool = 0 @@ -113,15 +118,15 @@ def on_touchdown(x, y): if point_in_rect(drawing_rect, x, y): origin_x = x origin_y = y - rubberband_line(x, y, True, False) + tool_list[current_tool]['feedback'](x, y, True, False) def on_touchmove(x, y): if point_in_rect(drawing_rect, x, y): - rubberband_line(x, y, False, False) + tool_list[current_tool]['feedback'](x, y, False, False) def on_touchup(x, y): if point_in_rect(drawing_rect, x, y): - rubberband_line(x, y, False, True) + tool_list[current_tool]['feedback'](x, y, False, True) def on_touchclick(x, y): if point_in_rect(cmd1_rect, x, y):