DDXXXXBRUH4UHHPOLAK2IG45C4QAPGSR4MTLV3MVFV3EMND43DIAC
IHHNPJ5QIEYWJTC34GSVWJ7KSHAEO7RQCQULTA7MA5RUMQ2GVOZQC
VHQCNMARPMNBSIUFLJG7HVK4QGDNPCGNVFLHS3I4IGNVSV5MRLYQC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
UN7L3DNN4Y3BCIA7SM6GYYWQG3OKVCH7ADPKAVF33E6QXY2HEJMQC
QYIFOHW3WDDQMK4ATY6IOSQRFHJOQ5QCPDKRC4GVGWLQEH4HGWVQC
CRYGI3LRKVHD4D76Q2VTNSX4B2JP5FPDEFJU6DBO7QWFHER2E4OQC
OWK3U6VDHPZM6Q6MB7PVFZPDD2KD5NJ3WHVMGTQ2XGUNYDNWSPWAC
K2X6G75Z6XBC4DVIRWC5HC7XA3A2SKOM3MWSQTCFEYWIJL7LME2QC
NYQ7HD4D5L44UORK52TH7CAEXYN5CE4ZUVLCWMY6XXPYHXVBTGHAC
BLWAYPKV3MLDZ4ALXLUJ25AIR6PCIL4RFYNRYLB26GFVC2KQBYBAC
W7JMT5V2ELDFZG354LUL5AR6IQLIYQUDXBEPDNZ2BEBXDCZLQJTAC
WTDKUACNTWB4KD34TZZNPILNX4FQ6MR64XYBAA5GOMICF73WLIAAC
HYEAFRZ2UEKDYTAE2GDQLHEJBPQASP2NDLMXB7F6MTVK2BKOXKEAC
6DE7RBZ6RHNEICJ7EUMCTROK43LW4LYINULIF2QEQOKCXWLUYUXAC
SRVDX4I5QKWAH3Y5DX25PG34U7NY55H46ZYG2APH47BUZT3EJ2HAC
XNFTJHC4QSHNSIWNN7K6QZEZ37GTQYKHS4EPNSVPQCUSWREROGIQC
DRFE3B3ZKRG4RY2R5Q3SDFD3LH4EXUX3CZCDFBNAXVI2SLDS57PAC
elseif shape.mode == 'polygon' then
local name = shape.center.name
shape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)
drawing.points[shape.center].name = name
local name = shape.p1.name
shape.p1 = Drawing.insert_point(drawing.points, shape.p1.x,shape.p1.y)
drawing.points[shape.p1].name = name
elseif shape.mode == 'polygon' then
local name = shape.center.name
shape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)
drawing.points[shape.center].name = name
local name = shape.p1.name
shape.p1 = Drawing.insert_point(drawing.points, shape.p1.x,shape.p1.y)
drawing.points[shape.p1].name = name
end
function test_draw_polygon()
io.write('\ntest_draw_polygon')
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
App.draw()
check_eq(Current_drawing_mode, 'line', 'F - test_draw_polygon/baseline/drawing_mode')
check_eq(#Lines, 2, 'F - test_draw_polygon/baseline/#lines')
check_eq(Lines[1].mode, 'drawing', 'F - test_draw_polygon/baseline/mode')
check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_polygon/baseline/y')
check_eq(Lines[1].h, 128, 'F - test_draw_polygon/baseline/y')
check_eq(#Lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes')
-- start a stroke
App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
-- switch to polygon mode
App.run_after_keychord('5')
App.run_after_mouse_release(Margin_left+55, Margin_top+Drawing_padding_top+26, 1)
local drawing = Lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_polygon/#shapes')
check_eq(#drawing.points, 2, 'F - test_draw_polygon/vertices')
local shape = drawing.shapes[1]
check_eq(shape.mode, 'polygon', 'F - test_draw_polygon/shape_mode')
check_eq(shape.num_vertices, 5, 'F - test_draw_polygon/vertices')
elseif shape.mode == 'polygon' then
local center = drawing.points[shape.center]
local cx,cy = Drawing.pixels(center.x)+left, Drawing.pixels(center.y)+top
local p1 = drawing.points[shape.p1]
local x,y = Drawing.pixels(p1.x)+left, Drawing.pixels(p1.y)+top
Drawing.draw_polygon(shape.num_vertices, cx,cy, x,y)
elseif shape.mode == 'polygon' then
local center = drawing.points[shape.center]
local mx,my = Drawing.coord(App.mouse_x()-left), Drawing.coord(App.mouse_y()-top)
if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
return
end
local cx,cy = Drawing.pixels(center.x)+left, Drawing.pixels(center.y)+top
Drawing.draw_polygon(Current_drawing_submode, cx,cy, App.mouse_x(),App.mouse_y())
elseif chord == 'C-3' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 3
elseif chord == 'C-4' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 4
elseif chord == 'C-5' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 5
elseif chord == 'C-6' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 6
elseif chord == 'C-7' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 7
elseif chord == 'C-8' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 8
elseif chord == 'C-9' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 9
elseif chord == '3' and App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 3
Drawing.switch_current_drawing_pending_to_polygon()
elseif chord == '4' and App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 4
Drawing.switch_current_drawing_pending_to_polygon()
elseif chord == '5' and App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 5
Drawing.switch_current_drawing_pending_to_polygon()
elseif chord == '6' and App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 6
Drawing.switch_current_drawing_pending_to_polygon()
elseif chord == '7' and App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 7
Drawing.switch_current_drawing_pending_to_polygon()
elseif chord == '8' and App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 8
Drawing.switch_current_drawing_pending_to_polygon()
elseif chord == '9' and App.mouse_down(1) then
Current_drawing_mode = 'polygon'
Current_drawing_submode = 9
Drawing.switch_current_drawing_pending_to_polygon()
function Drawing.switch_current_drawing_pending_to_polygon()
local _,drawing = Drawing.current_drawing()
if drawing.pending.mode == 'freehand' then
drawing.pending.center = Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)
elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
drawing.pending.center = drawing.pending.p1
elseif drawing.pending.mode == 'rectangle' then
drawing.pending.center = drawing.pending.vertices[1]
elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
-- reuse center
end
drawing.pending.mode = 'polygon'
drawing.pending.num_vertices = Current_drawing_submode
end