the basic tool and color selection code
This commit is contained in:
parent
6a4938e4ee
commit
90da46505e
|
@ -4,6 +4,11 @@ import upiwin
|
||||||
# Save off some color values.
|
# Save off some color values.
|
||||||
WHITE = upiwin.rgb(255, 255, 255)
|
WHITE = upiwin.rgb(255, 255, 255)
|
||||||
LTGRAY = upiwin.rgb(204, 204, 204)
|
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)
|
YELLOW = upiwin.rgb(255, 255, 0)
|
||||||
|
|
||||||
# Get the stock bitmaps.
|
# 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):
|
def point_in_rect(rect, x, y):
|
||||||
return (x >= rect[0]) and (x < rect[2]) and (y >= rect[1]) and (y < rect[3])
|
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 --
|
# --- Graphic feedback --
|
||||||
|
@ -63,8 +83,26 @@ def rubberband_line(x, y, down, up):
|
||||||
hdc.line_to(current_x, current_y)
|
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 ---
|
# --- Message handlers ---
|
||||||
|
|
||||||
|
@ -84,11 +122,10 @@ def on_touchup(x, y):
|
||||||
rubberband_line(x, y, False, True)
|
rubberband_line(x, y, False, True)
|
||||||
|
|
||||||
def on_touchclick(x, y):
|
def on_touchclick(x, y):
|
||||||
print("Click at {0},{1}".format(x, y))
|
|
||||||
if point_in_rect(cmd1_rect, 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):
|
elif point_in_rect(cmd2_rect, x, y):
|
||||||
print("Click command 2")
|
select_next_color()
|
||||||
elif point_in_rect(cmd3_rect, x, y):
|
elif point_in_rect(cmd3_rect, x, y):
|
||||||
print("Click command 3")
|
print("Click command 3")
|
||||||
elif point_in_rect(cmd4_rect, x, y):
|
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(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(cmd4_rect[0], cmd4_rect[1], cmd4_rect[2], cmd4_rect[3])
|
||||||
|
|
||||||
hdc_bits.select_object(bmp_freehand)
|
draw_current_tool()
|
||||||
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_color()
|
||||||
|
|
||||||
# Main message loop
|
# Main message loop
|
||||||
msg = {}
|
msg = {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user