From b7e9de7d7eb0015cf9b33a9669a7309063e1f905 Mon Sep 17 00:00:00 2001 From: Amy Bowersox Date: Wed, 11 Dec 2019 12:59:45 -0700 Subject: [PATCH] now try rubberbanding lines --- scripts/demo1.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/demo1.py b/scripts/demo1.py index 7e3a5c0..93a7fe7 100755 --- a/scripts/demo1.py +++ b/scripts/demo1.py @@ -42,6 +42,18 @@ def rubberband_rectangle(x, y, down, up): if not up: hdc.rectangle(min(origin_x, current_x), min(origin_y, current_y), max(origin_x, current_x), max(origin_y, current_y)) +def rubberband_line(x, y, down, up): + global current_x, current_y + hdc.text_color = YELLOW + hdc.rop2 = upiwin.R2_XORPEN + if not down: + hdc.move_to(origin_x, origin_y) + hdc_line_to(current_x, current_y) + current_x = x + current_y = y + if not up: + hdc.move_to(origin_x, origin_y) + hdc_line_to(current_x, current_y) @@ -54,15 +66,15 @@ def on_touchdown(x, y): if point_in_rect(drawing_rect, x, y): origin_x = x origin_y = y - rubberband_rectangle(x, y, True, False) + rubberband_line(x, y, True, False) def on_touchmove(x, y): if point_in_rect(drawing_rect, x, y): - rubberband_rectangle(x, y, False, False) + rubberband_line(x, y, False, False) def on_touchup(x, y): if point_in_rect(drawing_rect, x, y): - rubberband_rectangle(x, y, False, True) + rubberband_line(x, y, False, True) def on_touchclick(x, y): print("Click at {0},{1}".format(x, y))