hackathon-dev #1
@ -23,8 +23,45 @@ def point_in_rect(rect, x, y):
 | 
			
		||||
	return (x >= rect[0]) and (x < rect[2]) and (y >= rect[1]) and (y < rect[3])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# --- Graphic feedback --
 | 
			
		||||
 | 
			
		||||
origin_x = 0
 | 
			
		||||
origin_y = 0
 | 
			
		||||
current_x = 0
 | 
			
		||||
current_y = 0
 | 
			
		||||
 | 
			
		||||
def rubberband_rectangle(x, y, down, up)
 | 
			
		||||
	hdc.text_color = YELLOW
 | 
			
		||||
	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))
 | 
			
		||||
	current_x = x;
 | 
			
		||||
	current_y = y;
 | 
			
		||||
	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))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# --- Message handlers ---
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
		
 | 
			
		||||
def on_touchmove(x, y):
 | 
			
		||||
	if point_in_rect(drawing_rect, x, y):
 | 
			
		||||
		rubberband_rectangle(x, y, False, False)
 | 
			
		||||
		
 | 
			
		||||
def on_touchup(x, y):
 | 
			
		||||
	if point_in_rect(drawing_rect, x, y):
 | 
			
		||||
		rubberband_rectangle(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):
 | 
			
		||||
@ -52,6 +89,12 @@ hdc.rectangle(cmd4_rect[0], cmd4_rect[1], cmd4_rect[2], cmd4_rect[3])
 | 
			
		||||
# Main message loop
 | 
			
		||||
msg = {}
 | 
			
		||||
while upiwin.get_message(msg):
 | 
			
		||||
	if msg['message'] == upiwin.WM_TOUCHDOWN:
 | 
			
		||||
		on_touchdown(msg['attrs'][0], msg['attrs'][1])
 | 
			
		||||
	if msg['message'] == upiwin.WM_TOUCHMOVE:
 | 
			
		||||
		on_touchmove(msg['attrs'][0], msg['attrs'][1])
 | 
			
		||||
	if msg['message'] == upiwin.WM_TOUCHUP:
 | 
			
		||||
		on_touchup(msg['attrs'][0], msg['attrs'][1])
 | 
			
		||||
	if msg['message'] == upiwin.WM_TOUCHCLICK:
 | 
			
		||||
		on_touchclick(msg['attrs'][0], msg['attrs'][1])
 | 
			
		||||
	elif msg['message'] == upiwin.WM_HWBUTTONCLICK:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user