hackathon-dev #1

Merged
amy merged 101 commits from hackathon-dev into develop 2019-12-12 13:56:11 -07:00
Showing only changes of commit 90da46505e - Show all commits

View File

@ -4,6 +4,11 @@ import upiwin
# Save off some color values.
WHITE = upiwin.rgb(255, 255, 255)
LTGRAY = upiwin.rgb(204, 204, 204)
RED = upiwin.rgb(255, 0, 0)
GREEN = upiwin.rgb(0, 255, 0)
BLUE = upiwin.rgb(0, 0, 255)
CYAN = upiwin.rgb(0, 255, 255)
MAGENTA = upiwin.rgb(255, 0, 255)
YELLOW = upiwin.rgb(255, 255, 0)
# Get the stock bitmaps.
@ -29,6 +34,21 @@ cmd4_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])
# --- Color selections ---
color_list = [WHITE, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW]
current_color = 0
def draw_current_color():
hdc.text_color = color_list[current_color]
hdc.solid_rectangle(cmd2_rect[0] + 6, cmd2_rect[1] + 6, cmd2_rect[0] + 54, cmd2_rect[1] + 54)
def select_next_color():
current_color += 1
if current_color == len(color_list):
current_color = 0
draw_current_color()
# --- Graphic feedback --
@ -63,8 +83,26 @@ def rubberband_line(x, y, down, up):
hdc.line_to(current_x, current_y)
# --- Tool definitions ---
tool_list = [
{ 'icon': bmp_freehand },
{ 'icon': bmp_line },
{ 'icon': bmp_rect },
{ 'icon': bmp_fillrect }
]
current_tool = 0
def draw_current_tool():
hdc_bits.select_object(tool_list[current_tool]['icon'])
hdc.bitblt(cmd1_rect[0] + 6, cmd1_rect[1] + 6, cmd1_rect[0] + 54, cmd1_rect[1] + 54, hdc_bits, 0, 0, 0)
def select_next_tool():
current_tool += 1
if current_tool == len(tool_list):
current_tool = 0
draw_current_tool()
# --- Message handlers ---
@ -84,11 +122,10 @@ def on_touchup(x, y):
rubberband_line(x, y, False, True)
def on_touchclick(x, y):
print("Click at {0},{1}".format(x, y))
if point_in_rect(cmd1_rect, x, y):
print("Click command 1")
select_next_tool()
elif point_in_rect(cmd2_rect, x, y):
print("Click command 2")
select_next_color()
elif point_in_rect(cmd3_rect, x, y):
print("Click command 3")
elif point_in_rect(cmd4_rect, x, y):
@ -107,8 +144,8 @@ 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)
draw_current_tool()
draw_current_color()
# Main message loop
msg = {}