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DNWSPWAC
W7JMT5V2ELDFZG354LUL5AR6IQLIYQUDXBEPDNZ2BEBXDCZLQJTAC
KAUD3YIKPOXHIUZVR3VCIQHQGBPWTBHXEXC3VQIPAN2BAV6SEMIQC
BLWAYPKV3MLDZ4ALXLUJ25AIR6PCIL4RFYNRYLB26GFVC2KQBYBAC
NYQ7HD4D5L44UORK52TH7CAEXYN5CE4ZUVLCWMY6XXPYHXVBTGHAC
HYEAFRZ2UEKDYTAE2GDQLHEJBPQASP2NDLMXB7F6MTVK2BKOXKEAC
DLQAEAC76KLM3KZXQ2C5DASP4IBS64GR6L7QYEP67CNXJ6LRL7LQC
4PHDQ5L5N644QYM73IXMNCLAKQELYEPBDFXHTGCTTAKJAR6PEMTAC
QXVD2RIFQPTO3H6J3IJHRHRDRBW6C6MLUWMCEDQ6Z75SW2TMRBIQC
DRFE3B3ZKRG4RY2R5Q3SDFD3LH4EXUX3CZCDFBNAXVI2SLDS57PAC
IHHNPJ5QIEYWJTC34GSVWJ7KSHAEO7RQCQULTA7MA5RUMQ2GVOZQC
NVSWVPW5IGHXNRE2OMV4OEWRFJA25DP37CRFPZEVWAZINWGCCVXAC
23MA4T3GWPOLM5S6JCNQJU2SRT7VQGYZ2JZJN26KA5MKI4LOCC4QC
3HVBAZPADERJZTVHKZWOBNGDWYPJKPOEDZCCI6TLAFU4BFEKFOKAC
SRVDX4I5QKWAH3Y5DX25PG34U7NY55H46ZYG2APH47BUZT3EJ2HAC
Editor_state.lines = load_array{'abc', 'def'}
Editor_state.filename = 'foo'
schedule_save(Editor_state)
-- now drag a new file bar from the filesystem
App.filesystem['bar'] = 'abc\ndef\nghi\n'
local fake_dropped_file = {
opened = false,
getFilename = function(self)
return 'bar'
end,
open = function(self)
self.opened = true
end,
lines = function(self)
assert(self.opened)
return App.filesystem['bar']:gmatch('[^\n]+')
end,
close = function(self)
self.opened = false
end,
}
App.filedropped(fake_dropped_file)
-- filesystem now contains a file called foo
check_eq(App.filesystem['foo'], 'abc\ndef\n', 'F - test_drop_file_saves_previous')
check_eq(#Editor_state.lines, 3, 'F - test_drop_file/#lines')
check_eq(Editor_state.lines[1].data, 'abc', 'F - test_drop_file/lines:1')
check_eq(Editor_state.lines[2].data, 'def', 'F - test_drop_file/lines:2')
check_eq(Editor_state.lines[3].data, 'ghi', 'F - test_drop_file/lines:3')
App.screen.init{width=Editor_state.left+300, height=300}
-- initially editing a file called foo that hasn't been saved to filesystem yet
end
function test_drop_file_saves_previous()
io.write('\ntest_drop_file_saves_previous')
Editor_state.filename = 'foo'
App.screen.init{width=Editor_state.left+300, height=300}
check_eq(App.screen.width, Editor_state.left+300, 'F - test_resize_window/baseline/width')
App.screen.init{width=Editor_state.left+300, height=300}
App.filesystem['foo'] = 'abc\ndef\nghi\n'
local fake_dropped_file = {
opened = false,
getFilename = function(self)
return 'foo'
end,
open = function(self)
self.opened = true
end,
lines = function(self)
assert(self.opened)
return App.filesystem['foo']:gmatch('[^\n]+')
end,
close = function(self)
self.opened = false
end,
}
App.filedropped(fake_dropped_file)
check_eq(App.screen.height, 300, 'F - test_resize_window/baseline/height')
App.resize(200, 400)
check_eq(App.screen.width, 200, 'F - test_resize_window/width')
check_eq(App.screen.height, 400, 'F - test_resize_window/height')
-- TODO: how to make assertions about when App.update got past the early exit?
end
Lines = load_array{'the quick brown fox jumped over the lazy dog'}
Margin_right = 0; Margin_width = Margin_left
Cursor1 = {line=1, pos=1}
Screen_top1 = {line=1, pos=1}
Screen_bottom1 = {}
App.draw()
local y = Margin_top
Text.clear_cache(State.lines[State.cursor1.line])
assert(Text.le1(State.screen_top1, State.cursor1))
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})
if State.selection1.line then
Text.delete_selection(State, State.left, State.right)
schedule_save(State)
Filename = 'foo'
App.screen.init{width=Margin_left+300, height=300}
check_eq(App.screen.width, Margin_left+300, 'F - test_resize_window/baseline/width')
Editor_state.filename = 'foo'
App.screen.init{width=Editor_state.left+300, height=300}
check_eq(App.screen.width, Editor_state.left+300, 'F - test_resize_window/baseline/width')
check_eq(#Lines, 3, 'F - test_drop_file/#lines')
check_eq(Lines[1].data, 'abc', 'F - test_drop_file/lines:1')
check_eq(Lines[2].data, 'def', 'F - test_drop_file/lines:2')
check_eq(Lines[3].data, 'ghi', 'F - test_drop_file/lines:3')
check_eq(#Editor_state.lines, 3, 'F - test_drop_file/#lines')
check_eq(Editor_state.lines[1].data, 'abc', 'F - test_drop_file/lines:1')
check_eq(Editor_state.lines[2].data, 'def', 'F - test_drop_file/lines:2')
check_eq(Editor_state.lines[3].data, 'ghi', 'F - test_drop_file/lines:3')
-- an array vertices for mode 'rectangle'
-- center, p1, num_vertices for mode 'polygon'
Current_drawing_submode = nil
Next_save = nil
Selection1 = {} -- no support for shift drag while we're resizing
Text.tweak_screen_top_and_cursor(Margin_left, App.screen.height-Margin_right)
Last_resize_time = App.getTime()
Text.redraw_all(Editor_state)
Editor_state.selection1 = {} -- no support for shift drag while we're resizing
Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)
love.graphics.setColor(0, 0, 0)
end
end
function schedule_save()
if Next_save == nil then
Next_save = App.getTime() + 3 -- short enough that you're likely to still remember what you did
end
if Next_save then
save_to_disk(Lines, Filename)
end
-- make sure to save before quitting
local byte_offset = Text.offset(Search_term, len)
schedule_save()
schedule_save()
end
function icon.line_width(x, y)
love.graphics.setColor(0.7,0.7,0.7)
love.graphics.line(x+0,y+0, x+9,y+0)
love.graphics.line(x+0,y+1, x+9,y+1)
love.graphics.line(x+0,y+2, x+9,y+2)
love.graphics.line(x+0,y+3, x+9,y+3)
love.graphics.line(x+0,y+4, x+9,y+4)
love.graphics.line(x+0,y+5, x+9,y+5)
love.graphics.line(x+1,y+6, x+8,y+6)
love.graphics.line(x+2,y+7, x+7,y+7)
love.graphics.line(x+3,y+8, x+6,y+8)
love.graphics.line(x+4,y+9, x+5,y+9)
end
love.graphics.print("Things you can do:", Margin_left+30,y)
love.graphics.print("* Hover on a point and press 'ctrl+u' to pick it up and start moving it,", Margin_left+30,y)
love.graphics.print("then press the mouse button to drop it", Margin_left+30+bullet_indent(),y)
love.graphics.print("* Hover on a point or shape and press 'ctrl+d' to delete it", Margin_left+30,y)
love.graphics.print("* Press 'ctrl+p' to switch to drawing freehand strokes", Margin_left+30,y)
y = y + State.line_height
love.graphics.print("* Press the mouse button to start drawing a "..current_shape(State), State.left+30,y)
y = y + State.line_height
y = y + Line_height
love.graphics.print("* Press the mouse button to start drawing a "..current_shape(), State.left+30,y)
y = y + Line_height
love.graphics.print("* Press 'ctrl+2' to switch to drawing lines", Margin_left+30,y)
if State.current_drawing_mode ~= 'line' then
love.graphics.print("* Press 'ctrl+l' to switch to drawing lines", State.left+30,y)
y = y + State.line_height
if Current_drawing_mode ~= 'line' then
love.graphics.print("* Press 'ctrl+2' to switch to drawing lines", State.left+30,y)
y = y + Line_height
love.graphics.print("* Press 'ctrl+m' to switch to drawing horizontal/vertical lines", Margin_left+30,y)
if State.current_drawing_mode ~= 'manhattan' then
if Current_drawing_mode ~= 'manhattan' then
love.graphics.print("* Press 'ctrl+<digit>' to switch to drawing regular polygons", Margin_left+30,y)
if State.current_drawing_mode ~= 'polygon' then
love.graphics.print("* Press 'ctrl+g' to switch to drawing polygons", State.left+30,y)
y = y + State.line_height
if Current_drawing_mode ~= 'polygon' then
love.graphics.print("* Press 'ctrl+<digit>' to switch to drawing regular polygons", State.left+30,y)
y = y + Line_height
love.graphics.print("* Press 'ctrl+r' to switch to drawing rectangles", Margin_left+30,y)
if State.current_drawing_mode ~= 'rectangle' then
if Current_drawing_mode ~= 'rectangle' then
love.graphics.print("* Press 'ctrl+=' or 'ctrl+-' to zoom in or out, ctrl+0 to reset zoom", Margin_left+30,y)
if State.current_drawing_mode ~= 'square' then
love.graphics.print("* Press 'ctrl+s' to switch to drawing squares", State.left+30,y)
y = y + State.line_height
love.graphics.print("* Press 'ctrl+=' or 'ctrl+-' to zoom in or out, ctrl+0 to reset zoom", State.left+30,y)
love.graphics.print("Press 'esc' now to hide this message", State.left+30,y)
y = y + State.line_height
App.color(Help_background_color)
love.graphics.rectangle('fill', State.left,drawing.y, State.width, math.max(Drawing.pixels(drawing.h, State.width),y-drawing.y))
y = y + Line_height
love.graphics.setColor(0,0.5,0, 0.1)
love.graphics.rectangle('fill', State.left,drawing.y, State.right, math.max(Drawing.pixels(drawing.h),y-drawing.y))
love.graphics.print("You're currently drawing a "..current_shape(drawing.pending), Margin_left+30,y)
love.graphics.print('Things you can do now:', Margin_left+30,y)
love.graphics.print('* Release the mouse button to finish drawing the stroke', Margin_left+30,y)
love.graphics.print('* Release the mouse button to finish drawing the line', Margin_left+30,y)
love.graphics.print('* Release the mouse button to finish drawing the regular polygon', Margin_left+30,y)
y = y + State.line_height
elseif State.current_drawing_mode == 'polygon' then
love.graphics.print('* Release the mouse button to finish drawing the polygon', State.left+30,y)
y = y + State.line_height
love.graphics.print("* Press 'p' to add a vertex to the polygon", State.left+30,y)
y = y + State.line_height
elseif State.current_drawing_mode == 'rectangle' then
love.graphics.print('* Release the mouse button to finish drawing the rectangle', Margin_left+30,y)
y = y + Line_height
love.graphics.print("* Press 'p' to replace the second vertex of the rectangle", Margin_left+30,y)
y = y + Line_height
love.graphics.print('* Release the mouse button to finish drawing the rectangle', State.left+30,y)
y = y + State.line_height
love.graphics.print("* Press 'p' to replace the second vertex of the rectangle", State.left+30,y)
y = y + State.line_height
love.graphics.print("* Press 'esc' then release the mouse button to cancel the current shape", Margin_left+30,y)
love.graphics.print("* Press '2' to switch to drawing lines", Margin_left+30,y)
y = y + State.line_height
y = y + State.line_height
if State.current_drawing_mode ~= 'line' then
love.graphics.print("* Press 'l' to switch to drawing lines", State.left+30,y)
y = y + State.line_height
y = y + Line_height
y = y + Line_height
if Current_drawing_mode ~= 'line' then
love.graphics.print("* Press '2' to switch to drawing lines", State.left+30,y)
y = y + Line_height
if Current_drawing_mode ~= 'manhattan' then
if State.current_drawing_mode ~= 'polygon' then
love.graphics.print("* Press 'g' to switch to drawing polygons", State.left+30,y)
y = y + State.line_height
if State.current_drawing_mode ~= 'rectangle' then
App.color(Help_background_color)
love.graphics.rectangle('fill', State.left,drawing.y, State.width, math.max(Drawing.pixels(drawing.h, State.width),y-drawing.y))
love.graphics.setColor(0,0.5,0, 0.1)
love.graphics.rectangle('fill', State.left,drawing.y, State.right, math.max(Drawing.pixels(drawing.h),y-drawing.y))
if State.current_drawing_mode ~= 'square' then
love.graphics.print("* Press 's' to switch to drawing squares", State.left+30,y)
y = y + State.line_height
love.graphics.print("* Press 'p' to add a vertex to the rectangle", State.left+30,y)
y = y + State.line_height
love.graphics.print('* Release the mouse button to finish drawing the rectangle', State.left+30,y)
y = y + State.line_height
love.graphics.print("* Press 'p' to replace the second vertex of the rectangle", State.left+30,y)
y = y + State.line_height
elseif State.current_drawing_mode == 'square' then
love.graphics.print("* Press 'p' to add a vertex to the square", State.left+30,y)
y = y + State.line_height
love.graphics.print('* Release the mouse button to finish drawing the square', State.left+30,y)
y = y + State.line_height
love.graphics.print("* Press 'p' to replace the second vertex of the square", State.left+30,y)
y = y + State.line_height
App.screen.init{width=Margin_width+256, height=300} -- drawing coordinates 1:1 with pixels
Lines = load_array{'```lines', '```', ''}
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')
App.screen.init{width=Margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width) -- zero right margin
Editor_state.lines = load_array{'```lines', '```', ''}
edit.draw(Editor_state)
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_polygon/baseline/drawing_mode')
check_eq(#Editor_state.lines, 2, 'F - test_draw_polygon/baseline/#lines')
check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_polygon/baseline/mode')
check_eq(Editor_state.lines[1].y, Editor_state.top+Editor_state.drawing_padding_top, 'F - test_draw_polygon/baseline/y')
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_polygon/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes')
local drawing = Editor_state.lines[1]
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_keychord(Editor_state, 'g') -- polygon mode
App.mouse_move(Editor_state.left+65, Editor_state.top+Editor_state.drawing_padding_top+36)
edit.run_after_keychord(Editor_state, 'p') -- add point
edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Editor_state.drawing_padding_top+26, 1)
-- start a stroke
edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Editor_state.drawing_padding_top+36, 1)
-- switch to polygon mode
edit.run_after_keychord(Editor_state, '5')
edit.run_after_mouse_release(Editor_state, Editor_state.left+55, Editor_state.top+Editor_state.drawing_padding_top+26, 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')
App.screen.init{width=Margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width) -- zero right margin
Editor_state.lines = load_array{'```lines', '```', ''}
edit.draw(Editor_state)
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_square/baseline/drawing_mode')
check_eq(#Editor_state.lines, 2, 'F - test_draw_square/baseline/#lines')
check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_square/baseline/mode')
check_eq(Editor_state.lines[1].y, Editor_state.top+Editor_state.drawing_padding_top, 'F - test_draw_square/baseline/y')
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_square/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes')
edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_keychord(Editor_state, 's') -- square mode
App.mouse_move(Editor_state.left+42, Editor_state.top+Editor_state.drawing_padding_top+45)
edit.run_after_keychord(Editor_state, 'p')
App.mouse_move(Editor_state.left+65, Editor_state.top+Editor_state.drawing_padding_top+66)
edit.run_after_keychord(Editor_state, 'p')
edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
App.screen.init{width=Margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width) -- zero right margin
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_keychord(Editor_state, 'g') -- polygon mode
App.mouse_move(Editor_state.left+65, Editor_state.top+Editor_state.drawing_padding_top+36)
edit.run_after_keychord(Editor_state, 'p') -- add point
App.mouse_move(Editor_state.left+35, Editor_state.top+Editor_state.drawing_padding_top+26)
edit.run_after_keychord(Editor_state, 'p') -- add point
edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Editor_state.drawing_padding_top+16, 1)
local drawing = Editor_state.lines[1]
App.mouse_move(Editor_state.left+35, Editor_state.top+Editor_state.drawing_padding_top+26)
edit.run_after_keychord(Editor_state, 'C-d')
App.screen.init{width=Margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width) -- zero right margin
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_keychord(Editor_state, 'g') -- polygon mode
App.mouse_move(Editor_state.left+65, Editor_state.top+Editor_state.drawing_padding_top+36)
edit.run_after_keychord(Editor_state, 'p') -- add point
edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Editor_state.drawing_padding_top+16, 1)
local drawing = Editor_state.lines[1]
App.mouse_move(Editor_state.left+65, Editor_state.top+Editor_state.drawing_padding_top+36)
edit.run_after_keychord(Editor_state, 'C-d')
love.graphics.line(Drawing.pixels(prev.x, width)+left,Drawing.pixels(prev.y, width)+top, Drawing.pixels(curr.x, width)+left,Drawing.pixels(curr.y, width)+top)
love.graphics.line(Drawing.pixels(prev.x, width)+left,Drawing.pixels(prev.y, width)+top, App.mouse_x(),App.mouse_y())
love.graphics.line(Drawing.pixels(first.x, width)+left,Drawing.pixels(first.y, width)+top, Drawing.pixels(second.x, width)+left,Drawing.pixels(second.y, width)+top)
love.graphics.line(Drawing.pixels(second.x, width)+left,Drawing.pixels(second.y, width)+top, Drawing.pixels(thirdx, width)+left,Drawing.pixels(thirdy, width)+top)
love.graphics.line(Drawing.pixels(thirdx, width)+left,Drawing.pixels(thirdy, width)+top, Drawing.pixels(fourthx, width)+left,Drawing.pixels(fourthy, width)+top)
love.graphics.line(Drawing.pixels(fourthx, width)+left,Drawing.pixels(fourthy, width)+top, Drawing.pixels(first.x, width)+left,Drawing.pixels(first.y, width)+top)
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())
love.graphics.line(Drawing.pixels(first.x, width)+left,Drawing.pixels(first.y, width)+top, Drawing.pixels(second.x, width)+left,Drawing.pixels(second.y, width)+top)
love.graphics.line(Drawing.pixels(second.x, width)+left,Drawing.pixels(second.y, width)+top, Drawing.pixels(thirdx, width)+left,Drawing.pixels(thirdy, width)+top)
love.graphics.line(Drawing.pixels(thirdx, width)+left,Drawing.pixels(thirdy, width)+top, Drawing.pixels(fourthx, width)+left,Drawing.pixels(fourthy, width)+top)
love.graphics.line(Drawing.pixels(fourthx, width)+left,Drawing.pixels(fourthy, width)+top, Drawing.pixels(first.x, width)+left,Drawing.pixels(first.y, width)+top)
love.graphics.line(Drawing.pixels(first.x, width)+left,Drawing.pixels(first.y, width)+top, pmx,pmy)
local mx,my = Drawing.coord(pmx-left, width), Drawing.coord(pmy-top, width)
love.graphics.line(Drawing.pixels(first.x, width)+left,Drawing.pixels(first.y, width)+top, Drawing.pixels(second.x, width)+left,Drawing.pixels(second.y, width)+top)
love.graphics.line(Drawing.pixels(second.x, width)+left,Drawing.pixels(second.y, width)+top, Drawing.pixels(thirdx, width)+left,Drawing.pixels(thirdy, width)+top)
love.graphics.line(Drawing.pixels(thirdx, width)+left,Drawing.pixels(thirdy, width)+top, Drawing.pixels(fourthx, width)+left,Drawing.pixels(fourthy, width)+top)
love.graphics.line(Drawing.pixels(fourthx, width)+left,Drawing.pixels(fourthy, width)+top, Drawing.pixels(first.x, width)+left,Drawing.pixels(first.y, width)+top)
local cx,cy = Drawing.pixels(center.x, width)+left, Drawing.pixels(center.y, width)+top
Drawing.draw_polygon(State.current_drawing_submode, cx,cy, App.mouse_x(),App.mouse_y())
elseif Current_drawing_mode == 'rectangle' then
elseif Current_drawing_mode == 'polygon' then
local j = Drawing.insert_point(drawing.points, Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y))
drawing.pending = {mode=Current_drawing_mode, num_vertices=Current_drawing_submode, center=j}
local j = Drawing.find_or_insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width), State.width)
local j = Drawing.insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width))
elseif State.current_drawing_mode == 'polygon' or State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square' then
local j = Drawing.find_or_insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width), State.width)
elseif State.current_drawing_mode == 'rectangle' then
local j = Drawing.insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width))
elseif State.current_drawing_mode == 'polygon' then
local j = Drawing.insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width))
drawing.pending = {mode=State.current_drawing_mode, num_vertices=State.current_drawing_submode, center=j}
local j = Drawing.find_or_insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width), State.width)
local j = Drawing.insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width))
local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y)
drawing.pending.p1 = Drawing.insert_point(drawing.points, mx,my)
local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
drawing.pending.p1 = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
drawing.pending.p1 = Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)
drawing.pending.p1 = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)
State.current_drawing_mode = 'polygon'
State.current_drawing_mode = 'polygon'
local _,drawing = Drawing.current_drawing(State)
elseif App.mouse_down(1) and chord == 'p' and State.current_drawing_mode == 'polygon' then
local _,drawing = Drawing.current_drawing(State)
elseif App.mouse_down(1) and chord == 'p' and Current_drawing_mode == 'rectangle' then
elseif App.mouse_down(1) and chord == 'p' and (State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square') then
local _,drawing = Drawing.current_drawing(State)
local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-drawing.y, State.width)
local j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
drawing.pending.center = Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)
drawing.pending.center = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)
local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-drawing.y, State.width)
local j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
drawing.pending.vertices = {Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)}
drawing.pending.vertices = {Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)}
State.current_drawing_mode = 'freehand'
State.current_drawing_mode = 'line'
local _,drawing = Drawing.current_drawing(State)
State.current_drawing_mode = 'line'
State.current_drawing_mode = 'manhattan'
local drawing = Drawing.select_drawing_at_mouse(State)
drawing.pending.p1 = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)
drawing.pending.p1 = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)
table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, thirdx,thirdy, State.width))
table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, fourthx,fourthy, State.width))
local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)
table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, mx,my, State.width))
local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width)