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4AKD35DYLCUCUM4Z32FMKGZNUBQBAEDIQJJYPA547MAC PK5U572CFG4M7LEGO5UPJXXIYFWHYIVTLZN6FTQJBUTNFFREJ4SAC PTDO2SOTXEI6FROZ2AVRFXSKKNKCRMPPTQSI5LWD45UVGDJPMSGQC FS2ITYYHBLFT66YUC3ENPFYI2HOYHOVEPQIN7NQR6KF5MEK4NKZAC ZTMRQZSWUL6FJRI4C4H37MR2IMV22DB6KRGEOUNYRWW5CTAVQFKAC D4FEFHQCSILZFQ5VLWNXAIRZNUMCDNGJSM4UJ6T6FDMMIWYRYILQC CZRMAMSBRVX26IXKHNPG6M3YSWMOZTM73X3XHAMBDSNETTFVRCUQC KQWIMWJ5VRAXM7SFNWDSBZMQ6ZE3CZQTKZHVM5ZQCW4RHPTI64MQC MLG2OGU7OBWWPX5TDJQWTDTHSTM75WIMAW57546C4XLEVZQOYJ7AC 34TC5SYKYVUCVIQM3GNVYURQAMIXX64IOSJ4TYBPSRDS65QLTHWAC IEHG6OROGLZINLGZACEOD2PHQOM522TDUUF2UT6APHT42GUH2OXAC -- major tests for drawings-- We minimize assumptions about specific pixels, and try to test at the level-- of specific shapes. In particular, no tests of freehand drawings.function test_draw_line()io.write('\ntest_draw_line')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(#Editor_state.lines, 2, 'F - test_draw_line/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_line/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_line/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_line/baseline/#shapes')-- draw a linelocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_draw_line/#shapes')check_eq(#drawing.points, 2, 'F - test_draw_line/#points')check_eq(drawing.shapes[1].mode, 'line', 'F - test_draw_line/shape:1')local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_draw_line/p1:x')check_eq(p1.y, 6, 'F - test_draw_line/p1:y')check_eq(p2.x, 35, 'F - test_draw_line/p2:x')check_eq(p2.y, 36, 'F - test_draw_line/p2:y')endfunction test_draw_arc()io.write('\ntest_draw_arc')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(#Editor_state.lines, 2, 'F - test_draw_arc/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_arc/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_arc/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_arc/baseline/#shapes')-- draw an arclocal drawing = Editor_state.lines[1]edit.run_after_keychord(Editor_state, 'a') -- arc modeedit.run_after_mouse_release(Editor_state, Editor_state.left+35+50, Editor_state.top+Drawing_padding_top+36+50, 1) -- 45°check_eq(#drawing.shapes, 1, 'F - test_draw_arc/#shapes')check_eq(drawing.shapes[1].mode, 'arc', 'F - test_draw_horizontal_line/shape_mode')local arc = drawing.shapes[1]check_eq(arc.radius, 30, 'F - test_draw_arc/radius')local center = drawing.points[arc.center]check_eq(center.x, 35, 'F - test_draw_arc/center:x')check_eq(center.y, 36, 'F - test_draw_arc/center:y')check_eq(arc.start_angle, 0, 'F - test_draw_arc/start:angle')check_eq(arc.end_angle, math.pi/4, 'F - test_draw_arc/end:angle')endfunction 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)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].h, 128, 'F - test_draw_polygon/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes')-- first pointedit.run_after_keychord(Editor_state, 'g') -- polygon mode-- second pointedit.run_after_keychord(Editor_state, 'p') -- add point-- final pointlocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_draw_polygon/#shapes')check_eq(#drawing.points, 3, 'F - test_draw_polygon/vertices')local shape = drawing.shapes[1]check_eq(shape.mode, 'polygon', 'F - test_draw_polygon/shape_mode')check_eq(#shape.vertices, 3, 'F - test_draw_polygon/vertices')local p = drawing.points[shape.vertices[1]]check_eq(p.x, 5, 'F - test_draw_polygon/p1:x')check_eq(p.y, 6, 'F - test_draw_polygon/p1:y')local p = drawing.points[shape.vertices[2]]check_eq(p.x, 65, 'F - test_draw_polygon/p2:x')check_eq(p.y, 36, 'F - test_draw_polygon/p2:y')local p = drawing.points[shape.vertices[3]]check_eq(p.x, 35, 'F - test_draw_polygon/p3:x')check_eq(p.y, 26, 'F - test_draw_polygon/p3:y')endfunction test_draw_rectangle()io.write('\ntest_draw_rectangle')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_rectangle/baseline/drawing_mode')check_eq(#Editor_state.lines, 2, 'F - test_draw_rectangle/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_rectangle/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_rectangle/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle/baseline/#shapes')-- first pointedit.run_after_keychord(Editor_state, 'r') -- rectangle mode-- second point/first edgeedit.run_after_keychord(Editor_state, 'p')-- override second point/first edgeedit.run_after_keychord(Editor_state, 'p')-- release (decides 'thickness' of rectangle perpendicular to first edge)local drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_draw_rectangle/#shapes')check_eq(#drawing.points, 5, 'F - test_draw_rectangle/#points') -- currently includes every point addedlocal shape = drawing.shapes[1]check_eq(shape.mode, 'rectangle', 'F - test_draw_rectangle/shape_mode')check_eq(#shape.vertices, 4, 'F - test_draw_rectangle/vertices')local p = drawing.points[shape.vertices[1]]check_eq(p.x, 35, 'F - test_draw_rectangle/p1:x')check_eq(p.y, 36, 'F - test_draw_rectangle/p1:y')local p = drawing.points[shape.vertices[2]]check_eq(p.x, 75, 'F - test_draw_rectangle/p2:x')check_eq(p.y, 76, 'F - test_draw_rectangle/p2:y')local p = drawing.points[shape.vertices[3]]check_eq(p.x, 70, 'F - test_draw_rectangle/p3:x')check_eq(p.y, 81, 'F - test_draw_rectangle/p3:y')local p = drawing.points[shape.vertices[4]]check_eq(p.x, 30, 'F - test_draw_rectangle/p4:x')check_eq(p.y, 41, 'F - test_draw_rectangle/p4:y')endfunction test_draw_rectangle_intermediate()io.write('\ntest_draw_rectangle_intermediate')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_draw_rectangle_intermediate/baseline/drawing_mode')check_eq(#Editor_state.lines, 2, 'F - test_draw_rectangle_intermediate/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_rectangle_intermediate/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_rectangle_intermediate/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle_intermediate/baseline/#shapes')-- first pointedit.run_after_keychord(Editor_state, 'r') -- rectangle mode-- second point/first edgeedit.run_after_keychord(Editor_state, 'p')-- override second point/first edgelocal drawing = Editor_state.lines[1]edit.run_after_keychord(Editor_state, 'p')check_eq(#drawing.points, 3, 'F - test_draw_rectangle_intermediate/#points') -- currently includes every point addedlocal pending = drawing.pendingcheck_eq(pending.mode, 'rectangle', 'F - test_draw_rectangle_intermediate/shape_mode')check_eq(#pending.vertices, 2, 'F - test_draw_rectangle_intermediate/vertices')local p = drawing.points[pending.vertices[1]]check_eq(p.x, 35, 'F - test_draw_rectangle_intermediate/p1:x')check_eq(p.y, 36, 'F - test_draw_rectangle_intermediate/p1:y')local p = drawing.points[pending.vertices[2]]check_eq(p.x, 75, 'F - test_draw_rectangle_intermediate/p2:x')check_eq(p.y, 76, 'F - test_draw_rectangle_intermediate/p2:y')-- outline of rectangle is drawn based on where the mouse is, but we can't check that so farendfunction test_draw_square()io.write('\ntest_draw_square')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)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].h, 128, 'F - test_draw_square/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes')-- first pointedit.run_after_keychord(Editor_state, 's') -- square mode-- second point/first edgeedit.run_after_keychord(Editor_state, 'p')-- override second point/first edgeedit.run_after_keychord(Editor_state, 'p')-- release (decides which side of first edge to draw square on)local drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_draw_square/#shapes')check_eq(#drawing.points, 5, 'F - test_draw_square/#points') -- currently includes every point addedcheck_eq(drawing.shapes[1].mode, 'square', 'F - test_draw_square/shape_mode')check_eq(#drawing.shapes[1].vertices, 4, 'F - test_draw_square/vertices')local p = drawing.points[drawing.shapes[1].vertices[1]]check_eq(p.x, 35, 'F - test_draw_square/p1:x')check_eq(p.y, 36, 'F - test_draw_square/p1:y')local p = drawing.points[drawing.shapes[1].vertices[2]]check_eq(p.x, 65, 'F - test_draw_square/p2:x')check_eq(p.y, 66, 'F - test_draw_square/p2:y')local p = drawing.points[drawing.shapes[1].vertices[3]]check_eq(p.x, 35, 'F - test_draw_square/p3:x')check_eq(p.y, 96, 'F - test_draw_square/p3:y')local p = drawing.points[drawing.shapes[1].vertices[4]]check_eq(p.x, 5, 'F - test_draw_square/p4:x')check_eq(p.y, 66, 'F - test_draw_square/p4:y')endfunction test_name_point()io.write('\ntest_name_point')-- create a drawing with a lineEditor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'-- draw a linelocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_name_point/baseline/#shapes')check_eq(#drawing.points, 2, 'F - test_name_point/baseline/#points')check_eq(drawing.shapes[1].mode, 'line', 'F - test_name_point/baseline/shape:1')local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_name_point/baseline/p1:x')check_eq(p1.y, 6, 'F - test_name_point/baseline/p1:y')check_eq(p2.x, 35, 'F - test_name_point/baseline/p2:x')check_eq(p2.y, 36, 'F - test_name_point/baseline/p2:y')check_nil(p2.name, 'F - test_name_point/baseline/p2:name')-- enter 'name' mode without moving the mousecheck_eq(Editor_state.current_drawing_mode, 'name', 'F - test_name_point/mode:1')check_eq(p2.name, 'A', 'F - test_name_point')-- still in 'name' mode-- exit 'name' modecheck_eq(Editor_state.current_drawing_mode, 'line', 'F - test_name_point/mode:3')check_eq(p2.name, 'A', 'F - test_name_point')endfunction test_delete_point_from_polygon()io.write('\ntest_delete_point_from_polygon')-- create a drawing with two lines connected at a pointEditor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)-- first pointedit.run_after_keychord(Editor_state, 'g') -- polygon mode-- second pointedit.run_after_keychord(Editor_state, 'p') -- add point-- third pointlocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_delete_point_from_polygon/baseline/#shapes')check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/baseline/mode')check_eq(#drawing.shapes[1].vertices, 3, 'F - test_delete_point_from_polygon/baseline/vertices')-- hover on a point and deleteedit.run_after_keychord(Editor_state, 'C-d')-- there's < 3 points left, so the whole polygon is deletedcheck_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_point_from_polygon')endfunction test_undo_name_point()io.write('\ntest_undo_name_point')-- create a drawing with a lineEditor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'-- draw a linelocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_undo_name_point/baseline/#shapes')check_eq(#drawing.points, 2, 'F - test_undo_name_point/baseline/#points')check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_name_point/baseline/shape:1')local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_undo_name_point/baseline/p1:x')check_eq(p1.y, 6, 'F - test_undo_name_point/baseline/p1:y')check_eq(p2.x, 35, 'F - test_undo_name_point/baseline/p2:x')check_eq(p2.y, 36, 'F - test_undo_name_point/baseline/p2:y')check_nil(p2.name, 'F - test_undo_name_point/baseline/p2:name')-- enter 'name' mode without moving the mousecheck_eq(p2.name, 'A', 'F - test_undo_name_point/baseline')-- undolocal drawing = Editor_state.lines[1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p2.name, '', 'F - test_undo_name_point') -- not quite what it was before, but close enoughcheck_eq(p2.name, '', 'F - test_undo_name_point/save')endfunction test_undo_move_point()io.write('\ntest_undo_move_point')-- create a drawing with a linelocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_undo_move_point/baseline/#shapes')check_eq(#drawing.points, 2, 'F - test_undo_move_point/baseline/#points')check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_move_point/baseline/shape:1')local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_undo_move_point/baseline/p1:x')check_eq(p1.y, 6, 'F - test_undo_move_point/baseline/p1:y')check_eq(p2.x, 35, 'F - test_undo_move_point/baseline/p2:x')check_eq(p2.y, 36, 'F - test_undo_move_point/baseline/p2:y')check_nil(p2.name, 'F - test_undo_move_point/baseline/p2:name')-- move p2local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p2.x, 26, 'F - test_undo_move_point/x')check_eq(p2.y, 44, 'F - test_undo_move_point/y')-- exit 'move' modecheck_eq(Editor_state.next_history, 4, 'F - test_undo_move_point/next_history')-- undolocal drawing = Editor_state.lines[1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p2.x, 35, 'F - test_undo_move_point/x')check_eq(p2.y, 36, 'F - test_undo_move_point/y')check_eq(p2.x, 35, 'F - test_undo_move_point/save/x')check_eq(p2.y, 36, 'F - test_undo_move_point/save/y')endendfunction test_undo_delete_point()io.write('\ntest_undo_delete_point')-- create a drawing with two lines connected at a pointlocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 2, 'F - test_undo_delete_point/baseline/#shapes')check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_delete_point/baseline/shape:1')check_eq(drawing.shapes[2].mode, 'line', 'F - test_undo_delete_point/baseline/shape:2')-- hover on the common point and deleteedit.run_after_keychord(Editor_state, 'C-d')check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_undo_delete_point/shape:1')check_eq(drawing.shapes[2].mode, 'deleted', 'F - test_undo_delete_point/shape:2')-- undolocal drawing = Editor_state.lines[1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_delete_point/shape:1')check_eq(drawing.shapes[2].mode, 'line', 'F - test_undo_delete_point/shape:2')-- undo is savedText.redraw_all(Editor_state)check_eq(#Editor_state.lines[1].shapes, 2, 'F - test_undo_delete_point/save')load_from_disk(Editor_state)-- wait until saveApp.wait_fake_time(3.1)edit.update(Editor_state, 0)check_eq(Editor_state.next_history, 3, 'F - test_undo_move_point/next_history')edit.run_after_keychord(Editor_state, 'C-z')App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+36)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+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+55, Editor_state.top+Drawing_padding_top+26, 1)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'-- wait until saveApp.wait_fake_time(3.1)edit.update(Editor_state, 0)-- undo is savedText.redraw_all(Editor_state)local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]load_from_disk(Editor_state)check_eq(Editor_state.next_history, 2, 'F - test_undo_move_point/next_history')edit.run_after_keychord(Editor_state, 'C-z')edit.run_after_keychord(Editor_state, 'C-z') -- bug: need to undo twiceedit.run_after_mouse_click(Editor_state, Editor_state.left+26, Editor_state.top+Drawing_padding_top+44, 1)edit.run_after_keychord(Editor_state, 'C-u')edit.update(Editor_state, 0.05)App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)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+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'-- wait until saveApp.wait_fake_time(3.1)edit.update(Editor_state, 0)-- undo is savedText.redraw_all(Editor_state)local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]load_from_disk(Editor_state)check_eq(Editor_state.next_history, 3, 'F - test_undo_name_point/next_history')edit.run_after_keychord(Editor_state, 'C-z')check_eq(#Editor_state.history, 3, 'F - test_undo_name_point/baseline/history:2')check_eq(Editor_state.next_history, 4, 'F - test_undo_name_point/baseline/next_history')--? print('b', Editor_state.lines.current_drawing)edit.run_after_keychord(Editor_state, 'C-n')edit.run_after_textinput(Editor_state, 'A')edit.run_after_keychord(Editor_state, 'return')check_eq(#Editor_state.history, 1, 'F - test_undo_name_point/baseline/history:1')--? print('a', Editor_state.lines.current_drawing)edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1)App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()-- wait until saveApp.wait_fake_time(3.1)edit.update(Editor_state, 0)-- change is savedText.redraw_all(Editor_state)local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]check_eq(p2.name, 'A', 'F - test_name_point/save')load_from_disk(Editor_state)endfunction test_move_point()io.write('\ntest_move_point')-- create a drawing with a linelocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_move_point/baseline/#shapes')check_eq(#drawing.points, 2, 'F - test_move_point/baseline/#points')check_eq(drawing.shapes[1].mode, 'line', 'F - test_move_point/baseline/shape:1')local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_move_point/baseline/p1:x')check_eq(p1.y, 6, 'F - test_move_point/baseline/p1:y')check_eq(p2.x, 35, 'F - test_move_point/baseline/p2:x')check_eq(p2.y, 36, 'F - test_move_point/baseline/p2:y')-- wait until saveApp.wait_fake_time(3.1)-- line is saved to diskText.redraw_all(Editor_state)local drawing = Editor_state.lines[1]local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]check_eq(p2.x, 35, 'F - test_move_point/save/x')check_eq(p2.y, 36, 'F - test_move_point/save/y')-- enter 'move' mode without moving the mousecheck_eq(Editor_state.current_drawing_mode, 'move', 'F - test_move_point/mode:1')-- point is liftedcheck_eq(drawing.pending.mode, 'move', 'F - test_move_point/mode:2')check_eq(drawing.pending.target_point, p2, 'F - test_move_point/target')-- move pointlocal p2 = drawing.points[drawing.shapes[1].p2]check_eq(p2.x, 26, 'F - test_move_point/x')check_eq(p2.y, 44, 'F - test_move_point/y')-- exit 'move' modecheck_eq(Editor_state.current_drawing_mode, 'line', 'F - test_move_point/mode:3')check_eq(drawing.pending, {}, 'F - test_move_point/pending')-- wait until saveApp.wait_fake_time(3.1)edit.update(Editor_state, 0)-- change is savedText.redraw_all(Editor_state)local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]check_eq(p2.x, 26, 'F - test_move_point/save/x')check_eq(p2.y, 44, 'F - test_move_point/save/y')load_from_disk(Editor_state)endfunction test_delete_lines_at_point()io.write('\ntest_delete_lines_at_point')-- create a drawing with two lines connected at a pointlocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 2, 'F - test_delete_lines_at_point/baseline/#shapes')check_eq(drawing.shapes[1].mode, 'line', 'F - test_delete_lines_at_point/baseline/shape:1')check_eq(drawing.shapes[2].mode, 'line', 'F - test_delete_lines_at_point/baseline/shape:2')-- hover on the common point and deleteedit.run_after_keychord(Editor_state, 'C-d')check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_lines_at_point/shape:1')check_eq(drawing.shapes[2].mode, 'deleted', 'F - test_delete_lines_at_point/shape:2')endfunction test_delete_line_under_mouse_pointer()io.write('\ntest_delete_line_under_mouse_pointer')-- create a drawing with two lines connected at a pointlocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 2, 'F - test_delete_line_under_mouse_pointer/baseline/#shapes')check_eq(drawing.shapes[1].mode, 'line', 'F - test_delete_line_under_mouse_pointer/baseline/shape:1')check_eq(drawing.shapes[2].mode, 'line', 'F - test_delete_line_under_mouse_pointer/baseline/shape:2')-- hover on one of the lines and deleteedit.run_after_keychord(Editor_state, 'C-d')-- only that line is deletedcheck_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_line_under_mouse_pointer/shape:1')check_eq(drawing.shapes[2].mode, 'line', 'F - test_delete_line_under_mouse_pointer/shape:2')endfunction test_delete_point_from_polygon()io.write('\ntest_delete_point_from_polygon')-- create a drawing with two lines connected at a pointEditor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)-- first pointedit.run_after_keychord(Editor_state, 'g') -- polygon mode-- second pointedit.run_after_keychord(Editor_state, 'p') -- add point-- third pointedit.run_after_keychord(Editor_state, 'p') -- add point-- fourth pointlocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_delete_point_from_polygon/baseline/#shapes')check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/baseline/mode')check_eq(#drawing.shapes[1].vertices, 4, 'F - test_delete_point_from_polygon/baseline/vertices')-- hover on a point and deleteedit.run_after_keychord(Editor_state, 'C-d')-- just the one point is deletedcheck_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/shape')check_eq(#drawing.shapes[1].vertices, 3, 'F - test_delete_point_from_polygon/vertices')App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26)edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1)App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26)App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()App.mouse_move(Editor_state.left+25, Editor_state.top+Drawing_padding_top+26)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+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+55, Editor_state.top+Drawing_padding_top+26, 1)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()-- wait for some timeApp.wait_fake_time(3.1)edit.update(Editor_state, 0)-- deleted points disappear after file is reloadedText.redraw_all(Editor_state)check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_delete_lines_at_point/save')load_from_disk(Editor_state)App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+36)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+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+55, Editor_state.top+Drawing_padding_top+26, 1)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'function test_move_point_on_manhattan_line()io.write('\ntest_move_point_on_manhattan_line')-- create a drawing with a manhattan linelocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_move_point_on_manhattan_line/baseline/#shapes')check_eq(#drawing.points, 2, 'F - test_move_point_on_manhattan_line/baseline/#points')check_eq(drawing.shapes[1].mode, 'manhattan', 'F - test_move_point_on_manhattan_line/baseline/shape:1')-- enter 'move' modecheck_eq(Editor_state.current_drawing_mode, 'move', 'F - test_move_point_on_manhattan_line/mode:1')-- move point-- line is no longer manhattancheck_eq(drawing.shapes[1].mode, 'line', 'F - test_move_point_on_manhattan_line/baseline/shape:1')endedit.update(Editor_state, 0.05)App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)edit.run_after_keychord(Editor_state, 'C-u')edit.draw(Editor_state)Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'manhattan'edit.draw(Editor_state)edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+46, 1)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'edit.run_after_mouse_click(Editor_state, Editor_state.left+26, Editor_state.top+Drawing_padding_top+44, 1)edit.update(Editor_state, 0.05)App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)edit.run_after_keychord(Editor_state, 'C-u')edit.draw(Editor_state)load_from_disk(Editor_state)edit.update(Editor_state, 0)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+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'edit.run_after_keychord(Editor_state, 'return')check_eq(Editor_state.current_drawing_mode, 'name', 'F - test_name_point/mode:2')edit.run_after_textinput(Editor_state, 'A')edit.run_after_keychord(Editor_state, 'C-n')edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1)App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+66)App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_square/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76)App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_rectangle_intermediate/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1)App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76)App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_rectangle/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+26, 1)App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_polygon/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()check_eq(#drawing.points, 1, 'F - test_draw_arc/#points')edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)App.mouse_move(Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_arc/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'circle'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()-- wait until saveApp.wait_fake_time(3.1)edit.update(Editor_state, 0)-- The format on disk isn't perfectly stable. Table fields can be reordered.-- So just reload from disk to verify.Text.redraw_all(Editor_state)local drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_draw_line/save/#shapes')check_eq(#drawing.points, 2, 'F - test_draw_line/save/#points')check_eq(drawing.shapes[1].mode, 'line', 'F - test_draw_line/save/shape:1')local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_draw_line/save/p1:x')check_eq(p1.y, 6, 'F - test_draw_line/save/p1:y')check_eq(p2.x, 35, 'F - test_draw_line/save/p2:x')check_eq(p2.y, 36, 'F - test_draw_line/save/p2:y')load_from_disk(Editor_state)endfunction test_draw_horizontal_line()io.write('\ntest_draw_horizontal_line')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(#Editor_state.lines, 2, 'F - test_draw_horizontal_line/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_horizontal_line/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_horizontal_line/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_horizontal_line/baseline/#shapes')-- draw a line that is more horizontal than verticallocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 1, 'F - test_draw_horizontal_line/#shapes')check_eq(#drawing.points, 2, 'F - test_draw_horizontal_line/#points')check_eq(drawing.shapes[1].mode, 'manhattan', 'F - test_draw_horizontal_line/shape_mode')local p1 = drawing.points[drawing.shapes[1].p1]local p2 = drawing.points[drawing.shapes[1].p2]check_eq(p1.x, 5, 'F - test_draw_horizontal_line/p1:x')check_eq(p1.y, 6, 'F - test_draw_horizontal_line/p1:y')check_eq(p2.x, 35, 'F - test_draw_horizontal_line/p2:x')check_eq(p2.y, p1.y, 'F - test_draw_horizontal_line/p2:y')endfunction test_draw_circle()io.write('\ntest_draw_circle')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(#Editor_state.lines, 2, 'F - test_draw_circle/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_circle/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_circle/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_circle/baseline/#shapes')-- draw a circlelocal drawing = Editor_state.lines[1]edit.run_after_keychord(Editor_state, 'C-o')edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36, 1)check_eq(#drawing.shapes, 1, 'F - test_draw_circle/#shapes')check_eq(#drawing.points, 1, 'F - test_draw_circle/#points')check_eq(drawing.shapes[1].mode, 'circle', 'F - test_draw_horizontal_line/shape_mode')check_eq(drawing.shapes[1].radius, 30, 'F - test_draw_circle/radius')local center = drawing.points[drawing.shapes[1].center]check_eq(center.x, 35, 'F - test_draw_circle/center:x')check_eq(center.y, 36, 'F - test_draw_circle/center:y')endfunction test_keys_do_not_affect_shape_when_mouse_up()io.write('\ntest_keys_do_not_affect_shape_when_mouse_up')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)-- hover over drawing and press 'o' without holding mouseedit.run_after_keychord(Editor_state, 'o')-- no change to drawing mode-- no change to text either because we didn't run the textinput eventendfunction test_draw_circle_mid_stroke()io.write('\ntest_draw_circle_mid_stroke')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(#Editor_state.lines, 2, 'F - test_draw_circle_mid_stroke/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_circle_mid_stroke/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_circle_mid_stroke/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_circle_mid_stroke/baseline/#shapes')-- draw a circlelocal drawing = Editor_state.lines[1]edit.run_after_keychord(Editor_state, 'o')edit.run_after_mouse_release(Editor_state, Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36, 1)check_eq(#drawing.shapes, 1, 'F - test_draw_circle_mid_stroke/#shapes')check_eq(#drawing.points, 1, 'F - test_draw_circle_mid_stroke/#points')check_eq(drawing.shapes[1].mode, 'circle', 'F - test_draw_horizontal_line/shape_mode')check_eq(drawing.shapes[1].radius, 30, 'F - test_draw_circle_mid_stroke/radius')local center = drawing.points[drawing.shapes[1].center]check_eq(center.x, 35, 'F - test_draw_circle_mid_stroke/center:x')check_eq(center.y, 36, 'F - test_draw_circle_mid_stroke/center:y')App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawingedit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_circle_mid_stroke/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_keys_do_not_affect_shape_when_mouse_up/drawing_mode')App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawingApp.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()endfunction test_cancel_stroke()io.write('\ntest_cancel_stroke')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)check_eq(#Editor_state.lines, 2, 'F - test_cancel_stroke/baseline/#lines')check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_cancel_stroke/baseline/mode')check_eq(Editor_state.lines[1].h, 128, 'F - test_cancel_stroke/baseline/y')check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_cancel_stroke/baseline/#shapes')-- start drawing a line-- cancellocal drawing = Editor_state.lines[1]check_eq(#drawing.shapes, 0, 'F - test_cancel_stroke/#shapes')edit.run_after_keychord(Editor_state, 'escape')edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_cancel_stroke/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawingcheck_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_circle/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+26, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_horizontal_line/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'manhattan'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_line/baseline/y')Editor_state.lines = load_array{'```lines', '```', ''}Editor_state.current_drawing_mode = 'line'edit.draw(Editor_state)Text.redraw_all(Editor_state)App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixelsEditor_state = edit.initialize_test_state()Editor_state.filename = 'foo'function test_creating_drawing_saves()io.write('\ntest_creating_drawing_saves')App.screen.init{width=120, height=60}-- click on button to create drawing-- file not immediately savedcheck_nil(App.filesystem['foo'], 'F - test_creating_drawing_saves/early')-- wait until saveApp.wait_fake_time(3.1)-- filesystem contains drawing and an empty line of textcheck_eq(App.filesystem['foo'], '```lines\n```\n\n', 'F - test_creating_drawing_saves')endedit.update(Editor_state, 0)edit.update(Editor_state, 0.01)edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1)Editor_state.filename = 'foo'Editor_state.lines = load_array{}edit.draw(Editor_state)Text.redraw_all(Editor_state)Editor_state = edit.initialize_test_state()
-- primitives for editing drawingsDrawing = {}require 'drawing_tests'elseendreturnendendif line.show_help thenreturnendfor _,shape in ipairs(line.shapes) doassert(shape)elseendendif p.deleted == nil thenelseendif p.name thenlove.graphics.print(p.name, x,y)if State.current_drawing_mode == 'name' and i == line.pending.target_point then-- create a faint red box for the namelocal name_textif p.name == '' thenelseendendlove.graphics.rectangle('fill', x,y, App.width(name_text), State.line_height)name_text = App.newText(love.graphics.getFont(), p.name)name_text = State.em-- TODO: avoid computing name width on every repaintApp.color(Current_name_background_color)-- TODO: cliplocal x,y = px(p.x)+5, py(p.y)+5endendendendendif shape.mode == 'freehand' thenlocal prev = nilfor _,point in ipairs(shape.points) doif prev thenendprev = pointendelseif shape.mode == 'line' or shape.mode == 'manhattan' thenlocal p1 = drawing.points[shape.p1]local p2 = drawing.points[shape.p2]elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenlocal prev = nilfor _,point in ipairs(shape.vertices) dolocal curr = drawing.points[point]if prev thenendprev = currend-- close the looplocal curr = drawing.points[shape.vertices[1]]elseif shape.mode == 'circle' thenlocal center = drawing.points[shape.center]elseif shape.mode == 'arc' thenlocal center = drawing.points[shape.center]elseif shape.mode == 'deleted' then-- ignoreelseprint(shape.mode)assert(false)endendlocal shape = drawing.pendingelseif shape.mode == 'line' thenif mx < 0 or mx >= 256 or my < 0 or my >= drawing.h thenreturnendlocal p1 = drawing.points[shape.p1]elseif shape.mode == 'manhattan' thenif mx < 0 or mx >= 256 or my < 0 or my >= drawing.h thenreturnendif math.abs(mx-p1.x) > math.abs(my-p1.y) thenelseendelseif shape.mode == 'polygon' then-- don't close the loop on a pending polygonlocal prev = nilfor _,point in ipairs(shape.vertices) dolocal curr = drawing.points[point]if prev thenendprev = currendelseif shape.mode == 'rectangle' thenlocal first = drawing.points[shape.vertices[1]]if #shape.vertices == 1 thenreturnendlocal second = drawing.points[shape.vertices[2]]local thirdx,thirdy, fourthx,fourthy = Drawing.complete_rectangle(first.x,first.y, second.x,second.y, mx,my)elseif shape.mode == 'square' thenlocal first = drawing.points[shape.vertices[1]]if #shape.vertices == 1 thenreturnendlocal second = drawing.points[shape.vertices[2]]local thirdx,thirdy, fourthx,fourthy = Drawing.complete_square(first.x,first.y, second.x,second.y, mx,my)elseif shape.mode == 'circle' thenlocal center = drawing.points[shape.center]if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h thenreturnendelseif shape.mode == 'arc' thenlocal center = drawing.points[shape.center]if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h thenreturnendshape.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, shape.end_angle)love.graphics.arc('line', 'open', cx,cy, Drawing.pixels(shape.radius, width), shape.start_angle, shape.end_angle, 360)elseif shape.mode == 'move' then-- nothing pending; changes are immediately committedelseif shape.mode == 'name' then-- nothing pending; changes are immediately committedelseprint(shape.mode)assert(false)endendlocal width = right-leftreturn y >= line_cache.starty and y < line_cache.starty + Drawing.pixels(drawing.h, width) and x >= left and x < rightendelseassert(false)endend-- a couple of operations on drawings need to constantly check the state of the mouseassert(drawing.mode == 'drawing')if App.mouse_down(1) thenif Drawing.in_drawing(drawing, line_cache, pmx,pmy, State.left,State.right) thenif drawing.pending.mode == 'freehand' thenelseif drawing.pending.mode == 'move' thendrawing.pending.target_point.x = mxdrawing.pending.target_point.y = myDrawing.relax_constraints(drawing, drawing.pending.target_point_index)endenddrawing.pending.target_point.x = mxdrawing.pending.target_point.y = myDrawing.relax_constraints(drawing, drawing.pending.target_point_index)endelse-- do nothingendendfunction Drawing.relax_constraints(drawing, p)for _,shape in ipairs(drawing.shapes) doif shape.mode == 'manhattan' thenif shape.p1 == p thenshape.mode = 'line'elseif shape.p2 == p thenshape.mode = 'line'endelseif shape.mode == 'rectangle' or shape.mode == 'square' thenfor _,v in ipairs(shape.vertices) doif v == p thenshape.mode = 'polygon'endendendendendendelseif State.lines.current_drawing thenlocal drawing = State.lines.current_drawinglocal line_cache = State.line_cache[State.lines.current_drawing_index]-- the last point added during update is good enoughendif math.abs(mx-p1.x) > math.abs(my-p1.y) thenelseendendendlocal thirdx,thirdy, fourthx,fourthy = Drawing.complete_rectangle(first.x,first.y, second.x,second.y, mx,my)endelse-- too few points; draw nothingendlocal thirdx,thirdy, fourthx,fourthy = Drawing.complete_square(first.x,first.y, second.x,second.y, mx,my)endendelseif drawing.pending.mode == 'circle' thenif mx >= 0 and mx < 256 and my >= 0 and my < drawing.h thenlocal center = drawing.points[drawing.pending.center]table.insert(drawing.shapes, drawing.pending)drawing.pending.radius = round(geom.dist(center.x,center.y, mx,my))local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)table.insert(drawing.shapes, drawing.pending)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))elseif drawing.pending.mode == 'square' thenassert(#drawing.pending.vertices <= 2)if #drawing.pending.vertices == 2 thenif mx >= 0 and mx < 256 and my >= 0 and my < drawing.h thenlocal first = drawing.points[drawing.pending.vertices[1]]local second = drawing.points[drawing.pending.vertices[2]]local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)table.insert(drawing.shapes, drawing.pending)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))endendelseif drawing.pending.mode == 'name' then-- drop itelseassert(false)print(drawing.pending.mode)endendendendif chord == 'C-p' and not App.mouse_down(1) thenState.current_drawing_mode = 'freehand'elseif App.mouse_down(1) and chord == 'l' thenif drawing.pending.mode == 'freehand' thenelseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' thendrawing.pending.p1 = drawing.pending.vertices[1]elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' thendrawing.pending.p1 = drawing.pending.centerenddrawing.pending.mode = 'line'elseif chord == 'C-l' and not App.mouse_down(1) thenelseif App.mouse_down(1) and chord == 'm' thenif drawing.pending.mode == 'freehand' thenelseif drawing.pending.mode == 'line' then-- do nothingelseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' thendrawing.pending.p1 = drawing.pending.vertices[1]elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' thendrawing.pending.p1 = drawing.pending.centerenddrawing.pending.mode = 'manhattan'elseif chord == 'C-m' and not App.mouse_down(1) thenelseif chord == 'C-g' and not App.mouse_down(1) thenelseif App.mouse_down(1) and chord == 'g' thenif drawing.pending.mode == 'freehand' thenelseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' thenif drawing.pending.vertices == nil thendrawing.pending.vertices = {drawing.pending.p1}end-- reuse existing verticeselseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' thendrawing.pending.vertices = {drawing.pending.center}enddrawing.pending.mode = 'polygon'while #drawing.pending.vertices >= 2 dotable.remove(drawing.pending.vertices)endtable.insert(drawing.pending.vertices, j)drawing.pending.mode = 'arc'local center = drawing.points[drawing.pending.center]drawing.pending.start_angle = geom.angle(center.x,center.y, mx,my)if drawing.pending.mode == 'freehand' thenelseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' thendrawing.pending.center = drawing.pending.p1drawing.pending.center = drawing.pending.vertices[1]enddrawing.pending.mode = 'circle'if drawing thenendelseif chord == 'C-n' and not App.mouse_down(1) thenlocal drawing_index,drawing,line_cache,point_index,p = Drawing.select_point_at_mouse(State)if drawing thenp.name = ''endif drawing thenfor _,shape in ipairs(drawing.shapes) doif Drawing.contains_point(shape, i) thenif shape.mode == 'polygon' thenlocal idx = table.find(shape.vertices, i)assert(idx)table.remove(shape.vertices, idx)if #shape.vertices < 3 thenshape.mode = 'deleted'endelseshape.mode = 'deleted'endendenddrawing.points[i].deleted = trueendif drawing thenshape.mode = 'deleted'endif drawing thendrawing.show_help = trueendendendif drawing.mode == 'drawing' thenendendendreturn nilendif drawing.mode == 'drawing' thenfor i,shape in ipairs(drawing.shapes) doassert(shape)if geom.on_shape(mx,my, drawing, shape) thenendendendendendendif drawing.mode == 'drawing' thenfor i,point in ipairs(drawing.points) doassert(point)endendendendendendif drawing.mode == 'drawing' thenreturn drawingendendendendfunction Drawing.contains_point(shape, p)if shape.mode == 'freehand' then-- not supportedelseif shape.mode == 'line' or shape.mode == 'manhattan' thenreturn shape.p1 == p or shape.p2 == preturn table.find(shape.vertices, p)elseif shape.mode == 'circle' thenreturn shape.center == pelseif shape.mode == 'arc' thenreturn shape.center == p-- ugh, how to support angleselseif shape.mode == 'deleted' then-- already doneelseprint(shape.mode)assert(false)endendfunction Drawing.insert_point(points, x,y)for i,point in ipairs(points) doreturn iendendtable.insert(points, {x=x, y=y})return #pointsendendendendfunction table.find(h, x)for k,v in pairs(h) doif v == x thenreturn kendendfunction Drawing.coord(n, width) -- pixels to partsreturn math.floor(n*256/width)function Drawing.pixels(n, width) -- parts to pixelsreturn math.floor(n*width/256)return (cx-px)*(cx-px) + (cy-py)*(cy-py) < Same_point_distance*Same_point_distancefunction Drawing.near(point, x,y, width)local px,py = Drawing.pixels(x, width),Drawing.pixels(y, width)local cx,cy = Drawing.pixels(point.x, width), Drawing.pixels(point.y, width)if Drawing.near(point, x,y, width) thentable.insert(points, {x=x, y=y})return #pointsend-- check if UI would snap the two points togetherfunction Drawing.find_or_insert_point(points, x,y, width)function round(num)return math.floor(num+.5)endendendfunction Drawing.smoothen(shape)assert(shape.mode == 'freehand')for _=1,7 dofor i=2,#shape.points-1 dolocal a = shape.points[i-1]local b = shape.points[i]local c = shape.points[i+1]endb.x = round((a.x + b.x + c.x)/3)b.y = round((a.y + b.y + c.y)/3)elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenlocal x, y = App.mouse_x(), App.mouse_y()local line_cache = State.line_cache[drawing_index]if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) thenfunction Drawing.select_drawing_at_mouse(State)for drawing_index,drawing in ipairs(State.lines) doif Drawing.near(point, mx,my, State.width) thenreturn drawing_index,drawing,line_cache,i,pointlocal x, y = App.mouse_x(), App.mouse_y()local line_cache = State.line_cache[drawing_index]if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) thenlocal mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)function Drawing.select_point_at_mouse(State)for drawing_index,drawing in ipairs(State.lines) doreturn drawing,line_cache,i,shapelocal x, y = App.mouse_x(), App.mouse_y()local line_cache = State.line_cache[drawing_index]if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) thenlocal mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)function Drawing.select_shape_at_mouse(State)for drawing_index,drawing in ipairs(State.lines) dolocal line_cache = State.line_cache[drawing_index]if Drawing.in_drawing(drawing, line_cache, x,y, State.left,State.right) thenreturn drawing_index,drawing,line_cachelocal x, y = App.mouse_x(), App.mouse_y()for drawing_index,drawing in ipairs(State.lines) dofunction Drawing.current_drawing(State)local fourthx = firstx+deltaylocal fourthy = firsty-deltaxreturn thirdx,thirdy, fourthx,fourthyendendfunction Drawing.complete_rectangle(firstx,firsty, secondx,secondy, x,y)if firstx == secondx thenendif firsty == secondy thenendlocal first_slope = (secondy-firsty)/(secondx-firstx)-- slope of second edge:-- -1/first_slope-- equation of line containing the second edge:-- y-secondy = -1/first_slope*(x-secondx)-- => 1/first_slope*x + y + (- secondy - secondx/first_slope) = 0-- now we want to find the point on this line that's closest to the mouse pointer.-- https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Line_defined_by_an_equationlocal a = 1/first_slopelocal c = -secondy - secondx/first_slope-- slope of third edge = first_slope-- equation of line containing third edge:-- y - thirdy = first_slope*(x-thirdx)-- => -first_slope*x + y + (-thirdy + thirdx*first_slope) = 0-- now we want to find the point on this line that's closest to the first pointlocal a = -first_slopelocal c = -thirdy + thirdx*first_slopereturn thirdx,thirdy, fourthx,fourthyendfunction Drawing.complete_square(firstx,firsty, secondx,secondy, x,y)-- use x,y only to decide which side of the first edge to complete the square onlocal deltax = secondx-firstxlocal deltay = secondy-firstylocal thirdx = secondx+deltaylocal thirdy = secondy-deltaxif not geom.same_side(firstx,firsty, secondx,secondy, thirdx,thirdy, x,y) thendeltax = -deltaxdeltay = -deltaythirdx = secondx+deltaythirdy = secondy-deltaxlocal fourthx = round(((firstx-a*firsty) - a*c) / (a*a + 1))local fourthy = round((a*(-firstx + a*firsty) - c) / (a*a + 1))local thirdx = round(((x-a*y) - a*c) / (a*a + 1))local thirdy = round((a*(-x + a*y) - c) / (a*a + 1))return secondx,y, firstx,yreturn x,secondy, x,firstyelseif chord == 'escape' and App.mouse_down(1) thendrawing.pending = {}local _,drawing = Drawing.current_drawing(State)elseif chord == 'C-h' and not App.mouse_down(1) thenlocal drawing = Drawing.select_drawing_at_mouse(State)local drawing,_,_,shape = Drawing.select_shape_at_mouse(State)elseif chord == 'C-d' and not App.mouse_down(1) thenlocal _,drawing,_,i,p = Drawing.select_point_at_mouse(State)drawing.pending = {mode=State.current_drawing_mode, target_point=point_index}State.lines.current_drawing_index = drawing_indexState.lines.current_drawing = drawing-- don't clobberendState.current_drawing_mode = 'name'State.previous_drawing_mode = State.current_drawing_modeif State.previous_drawing_mode == nil thenendState.current_drawing_mode = 'move'drawing.pending = {mode=State.current_drawing_mode, target_point=p, target_point_index=i}State.lines.current_drawing_index = drawing_indexState.lines.current_drawing = drawingif State.previous_drawing_mode == nil thenState.previous_drawing_mode = State.current_drawing_modeelseif chord == 'C-u' and not App.mouse_down(1) thenlocal drawing_index,drawing,line_cache,i,p = Drawing.select_point_at_mouse(State)elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' thendrawing.pending.center = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)elseif App.mouse_down(1) and chord == 'o' thenState.current_drawing_mode = 'circle'local _,drawing = Drawing.current_drawing(State)drawing.pending.radius = round(geom.dist(center.x,center.y, mx,my))local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-line_cache.starty, State.width)elseif chord == 'C-o' and not App.mouse_down(1) thenState.current_drawing_mode = 'circle'elseif App.mouse_down(1) and chord == 'a' and State.current_drawing_mode == 'circle' thenlocal _,drawing,line_cache = Drawing.current_drawing(State)elseif App.mouse_down(1) and chord == 'r' thenif drawing.pending.mode == 'freehand' thenelseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' thenif drawing.pending.vertices == nil thendrawing.pending.vertices = {drawing.pending.p1}endelseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' thendrawing.pending.vertices = {drawing.pending.center}enddrawing.pending.mode = 'rectangle'elseif App.mouse_down(1) and chord == 's' thenif drawing.pending.mode == 'freehand' thenelseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' thenif drawing.pending.vertices == nil thendrawing.pending.vertices = {drawing.pending.p1}endelseif drawing.pending.mode == 'polygon' thenwhile #drawing.pending.vertices > 2 dotable.remove(drawing.pending.vertices)endelseif drawing.pending.mode == 'rectangle' then-- reuse existing (1-2) verticeselseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' thendrawing.pending.vertices = {drawing.pending.center}enddrawing.pending.mode = 'square'table.insert(drawing.pending.vertices, j)elseif App.mouse_down(1) and chord == 'p' and (State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square') thenlocal j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)local _,drawing,line_cache = Drawing.current_drawing(State)local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-line_cache.starty, State.width)elseif App.mouse_down(1) and chord == 'p' and State.current_drawing_mode == 'polygon' thenlocal j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)local _,drawing,line_cache = Drawing.current_drawing(State)local mx,my = Drawing.coord(App.mouse_x()-State.left, State.width), Drawing.coord(App.mouse_y()-line_cache.starty, 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 = 'square'local _,drawing = Drawing.current_drawing(State)elseif chord == 'C-s' and not App.mouse_down(1) thenState.current_drawing_mode = 'square'elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'square' then-- reuse existing (1-2) verticesdrawing.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 = 'rectangle'local _,drawing = Drawing.current_drawing(State)elseif chord == 'C-r' and not App.mouse_down(1) thenState.current_drawing_mode = 'rectangle'elseif drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' thendrawing.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 = 'polygon'local _,drawing = Drawing.current_drawing(State)State.current_drawing_mode = 'polygon'State.current_drawing_mode = 'manhattan'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 = 'manhattan'local drawing = Drawing.select_drawing_at_mouse(State)State.current_drawing_mode = 'line'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 = 'line'local _,drawing = Drawing.current_drawing(State)function Drawing.keychord_pressed(State, chord)State.lines.current_drawing.pending = {}State.lines.current_drawing = nilelseif drawing.pending.mode == 'arc' thenif mx >= 0 and mx < 256 and my >= 0 and my < drawing.h thenlocal center = drawing.points[drawing.pending.center]drawing.pending.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, drawing.pending.end_angle)table.insert(drawing.shapes, drawing.pending)local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)elseif drawing.pending.mode == 'rectangle' thenassert(#drawing.pending.vertices <= 2)if #drawing.pending.vertices == 2 thenif mx >= 0 and mx < 256 and my >= 0 and my < drawing.h thenlocal first = drawing.points[drawing.pending.vertices[1]]local second = drawing.points[drawing.pending.vertices[2]]local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)elseif drawing.pending.mode == 'polygon' thenif mx >= 0 and mx < 256 and my >= 0 and my < drawing.h thentable.insert(drawing.shapes, drawing.pending)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-line_cache.starty, State.width)local p2 = drawing.points[drawing.pending.p2]table.insert(drawing.shapes, drawing.pending)App.mouse_move(State.left+Drawing.pixels(p2.x, State.width), line_cache.starty+Drawing.pixels(p2.y, State.width))drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, p1.x, my, State.width)drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, mx, p1.y, State.width)elseif drawing.pending.mode == 'manhattan' thenlocal p1 = drawing.points[drawing.pending.p1]if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h thenlocal mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)Drawing.smoothen(drawing.pending)table.insert(drawing.shapes, drawing.pending)elseif drawing.pending.mode == 'line' thenif mx >= 0 and mx < 256 and my >= 0 and my < drawing.h thentable.insert(drawing.shapes, drawing.pending)drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)local mx,my = Drawing.coord(x-State.left, State.width), Drawing.coord(y-line_cache.starty, State.width)if drawing.pending thenif drawing.pending.mode == nil then-- nothing pendingelseif drawing.pending.mode == 'freehand' thenfunction Drawing.mouse_released(State, x,y, button)if State.current_drawing_mode == 'move' thenState.current_drawing_mode = State.previous_drawing_modeState.previous_drawing_mode = nilif State.lines.current_drawing thenState.lines.current_drawing.pending = {}State.lines.current_drawing = nilelseif State.current_drawing_mode == 'move' thenif Drawing.in_drawing(drawing, line_cache, pmx, pmy, State.left,State.right) thentable.insert(drawing.pending.points, {x=mx, y=my})local pmx, pmy = App.mouse_x(), App.mouse_y()local mx = Drawing.coord(pmx-State.left, State.width)local my = Drawing.coord(pmy-line_cache.starty, State.width)function Drawing.update(State)if State.lines.current_drawing == nil then return endlocal drawing = State.lines.current_drawinglocal line_cache = State.line_cache[State.lines.current_drawing_index]print(State.current_drawing_mode)local cx = Drawing.coord(x-State.left, State.width)if State.current_drawing_mode == 'freehand' thenelseif State.current_drawing_mode == 'line' or State.current_drawing_mode == 'manhattan' thendrawing.pending = {mode=State.current_drawing_mode, p1=j}elseif State.current_drawing_mode == 'polygon' or State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square' thendrawing.pending = {mode=State.current_drawing_mode, vertices={j}}elseif State.current_drawing_mode == 'circle' thendrawing.pending = {mode=State.current_drawing_mode, center=j}elseif State.current_drawing_mode == 'move' thenlocal j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)drawing.pending = {mode=State.current_drawing_mode, points={{x=cx, y=cy}}}local cy = Drawing.coord(y-line_cache.starty, State.width)-- all the action is in mouse_released-- nothingelseif State.current_drawing_mode == 'name' thenfunction Drawing.mouse_pressed(State, drawing_index, x,y, button)local drawing = State.lines[drawing_index]local line_cache = State.line_cache[drawing_index]function Drawing.in_drawing(drawing, line_cache, x,y, left,right)if line_cache.starty == nil then return false end -- outside current pagelocal cx,cy = px(center.x), py(center.y)love.graphics.circle('line', cx,cy, geom.dist(cx,cy, App.mouse_x(),App.mouse_y()))local cx,cy = px(center.x), py(center.y)love.graphics.line(px(first.x),py(first.y), px(second.x),py(second.y))love.graphics.line(px(second.x),py(second.y), px(thirdx),py(thirdy))love.graphics.line(px(thirdx),py(thirdy), px(fourthx),py(fourthy))love.graphics.line(px(fourthx),py(fourthy), px(first.x),py(first.y))love.graphics.line(px(first.x),py(first.y), pmx,pmy)love.graphics.line(px(first.x),py(first.y), px(second.x),py(second.y))love.graphics.line(px(second.x),py(second.y), px(thirdx),py(thirdy))love.graphics.line(px(thirdx),py(thirdy), px(fourthx),py(fourthy))love.graphics.line(px(fourthx),py(fourthy), px(first.x),py(first.y))love.graphics.line(px(first.x),py(first.y), pmx,pmy)love.graphics.line(px(prev.x),py(prev.y), pmx,pmy)love.graphics.line(px(prev.x),py(prev.y), px(curr.x),py(curr.y))love.graphics.line(px(p1.x),py(p1.y), px(p1.x),pmy)love.graphics.line(px(p1.x),py(p1.y), pmx, py(p1.y))local p1 = drawing.points[shape.p1]love.graphics.line(px(p1.x),py(p1.y), pmx,pmy)if shape.mode == nil then-- nothing pendingelseif shape.mode == 'freehand' thenlocal shape_copy = deepcopy(shape)Drawing.smoothen(shape_copy)Drawing.draw_shape(drawing, shape_copy, top, left,right)function Drawing.draw_pending_shape(drawing, top, left,right)local width = right-leftlocal pmx,pmy = App.mouse_x(), App.mouse_y()local mx = Drawing.coord(pmx-left, width)local my = Drawing.coord(pmy-top, width)-- recreate pixels from coords to precisely mimic how the drawing will look-- after mouse_releasedpmx,pmy = px(mx), py(my)local function px(x) return Drawing.pixels(x, width)+left endlocal function py(y) return Drawing.pixels(y, width)+top endlove.graphics.arc('line', 'open', px(center.x),py(center.y), Drawing.pixels(shape.radius, width), shape.start_angle, shape.end_angle, 360)love.graphics.circle('line', px(center.x),py(center.y), Drawing.pixels(shape.radius, width))-- TODO: cliplove.graphics.line(px(prev.x),py(prev.y), px(curr.x),py(curr.y))love.graphics.line(px(prev.x),py(prev.y), px(curr.x),py(curr.y))love.graphics.line(px(p1.x),py(p1.y), px(p2.x),py(p2.y))love.graphics.line(px(prev.x),py(prev.y), px(point.x),py(point.y))function Drawing.draw_shape(drawing, shape, top, left,right)local width = right-leftlocal function px(x) return Drawing.pixels(x, width)+left endlocal function py(y) return Drawing.pixels(y, width)+top endApp.color(Current_stroke_color)Drawing.draw_pending_shape(line, line_cache.starty, State.left,State.right)App.color(Stroke_color)love.graphics.circle('fill', px(p.x),py(p.y), 2)App.color(Focus_stroke_color)love.graphics.circle('line', px(p.x),py(p.y), Same_point_distance)if Drawing.near(p, mx,my, State.width) thenlocal function px(x) return Drawing.pixels(x, State.width)+State.left endlocal function py(y) return Drawing.pixels(y, State.width)+line_cache.starty endfor i,p in ipairs(line.points) doDrawing.draw_shape(line, shape, line_cache.starty, State.left,State.right)App.color(Stroke_color)if geom.on_shape(mx,my, line, shape) thenApp.color(Focus_stroke_color)local mx = Drawing.coord(pmx-State.left, State.width)local my = Drawing.coord(pmy-line_cache.starty, State.width)draw_help_without_mouse_pressed(State, line_index)if App.mouse_down(1) and love.keyboard.isDown('h') thendraw_help_with_mouse_pressed(State, line_index)icon[State.previous_drawing_mode](State.right-22, line_cache.starty+4)-- All drawings span 100% of some conceptual 'page width' and divide it up-- into 256 parts.local pmx,pmy = App.mouse_x(), App.mouse_y()App.color(Icon_color)if icon[State.current_drawing_mode] thenicon[State.current_drawing_mode](State.right-22, line_cache.starty+4)love.graphics.rectangle('line', State.left,line_cache.starty, State.width,Drawing.pixels(line.h, State.width))if pmx < State.right and pmy > line_cache.starty and pmy < line_cache.starty+Drawing.pixels(line.h, State.width) thenfunction Drawing.draw(State, line_index, y)local line = State.lines[line_index]local line_cache = State.line_cache[line_index]line_cache.starty = y
icon = {}function icon.insert_drawing(x, y)love.graphics.rectangle('line', x,y, 12,12)love.graphics.line(4,y+6, 16,y+6)love.graphics.line(10,y, 10,y+12)endfunction icon.freehand(x, y)love.graphics.line(x+4,y+7,x+5,y+5)love.graphics.line(x+5,y+5,x+7,y+4)love.graphics.line(x+7,y+4,x+9,y+3)love.graphics.line(x+9,y+3,x+10,y+5)love.graphics.line(x+10,y+5,x+12,y+6)love.graphics.line(x+12,y+6,x+13,y+8)love.graphics.line(x+13,y+8,x+13,y+10)love.graphics.line(x+13,y+10,x+14,y+12)love.graphics.line(x+14,y+12,x+15,y+14)love.graphics.line(x+15,y+14,x+15,y+16)endfunction icon.line(x, y)love.graphics.line(x+4,y+2, x+16,y+18)endfunction icon.manhattan(x, y)love.graphics.line(x+4,y+20, x+4,y+2)love.graphics.line(x+4,y+2, x+10,y+2)love.graphics.line(x+10,y+2, x+10,y+10)love.graphics.line(x+10,y+10, x+18,y+10)endfunction icon.polygon(x, y)love.graphics.line(x+8,y+2, x+14,y+2)love.graphics.line(x+14,y+2, x+18,y+10)love.graphics.line(x+18,y+10, x+10,y+18)love.graphics.line(x+10,y+18, x+4,y+12)love.graphics.line(x+4,y+12, x+8,y+2)endfunction icon.circle(x, y)love.graphics.circle('line', x+10,y+10, 8)endfunction icon.square(x, y)love.graphics.line(x+6,y+6, x+6,y+16)love.graphics.line(x+6,y+16, x+16,y+16)love.graphics.line(x+16,y+16, x+16,y+6)love.graphics.line(x+16,y+6, x+6,y+6)endendfunction icon.rectangle(x, y)love.graphics.line(x+4,y+8, x+4,y+16)love.graphics.line(x+4,y+16, x+16,y+16)love.graphics.line(x+16,y+16, x+16,y+8)love.graphics.line(x+16,y+8, x+4,y+8)App.color(Icon_color)
love.graphics.print("Things you can do:", State.left+30,y)y = y + State.line_heighty = y + State.line_heighty = y + State.line_heighty = y + State.line_heighty = y + State.line_heighty = y + State.line_heightif State.current_drawing_mode ~= 'freehand' theny = y + State.line_heightendendendendendendendendlove.graphics.print("You're currently drawing a "..current_shape(State, drawing.pending), State.left+30,y)y = y + State.line_heighty = y + State.line_heightif State.current_drawing_mode == 'freehand' theny = y + State.line_heightelseif State.current_drawing_mode == 'line' or State.current_drawing_mode == 'manhattan' theny = y + State.line_heightelseif State.current_drawing_mode == 'circle' thenif drawing.pending.mode == 'circle' thenelseendendendendendendendendendreturn 'freehand stroke'return 'straight line'return 'horizontal/vertical line'return 'arc'elseendend_bullet_indent = nilfunction bullet_indent()if _bullet_indent == nil thenlocal text = love.graphics.newText(love.graphics.getFont(), '* ')_bullet_indent = text:getWidth()endreturn _bullet_indentendreturn State.current_drawing_modeelseif State.current_drawing_mode == 'circle' and shape and shape.start_angle thenelseif State.current_drawing_mode == 'manhattan' thenelseif State.current_drawing_mode == 'line' thenfunction current_shape(State, shape)if State.current_drawing_mode == 'freehand' thenApp.color(Help_background_color)love.graphics.rectangle('fill', State.left,line_cache.starty, State.width, math.max(Drawing.pixels(drawing.h, State.width),y-line_cache.starty))if State.current_drawing_mode ~= 'square' theny = y + State.line_heightlove.graphics.print("* Press 's' to switch to drawing squares", State.left+30,y)if State.current_drawing_mode ~= 'rectangle' theny = y + State.line_heightlove.graphics.print("* Press 'r' to switch to drawing rectangles", State.left+30,y)if State.current_drawing_mode ~= 'polygon' theny = y + State.line_heightlove.graphics.print("* Press 'g' to switch to drawing polygons", State.left+30,y)if State.current_drawing_mode ~= 'circle' theny = y + State.line_heightlove.graphics.print("* Press 'o' to switch to drawing circles/arcs", State.left+30,y)if State.current_drawing_mode ~= 'manhattan' theny = y + State.line_heightlove.graphics.print("* Press 'm' to switch to drawing horizontal/vertical lines", State.left+30,y)y = y + State.line_heighty = y + State.line_heightif State.current_drawing_mode ~= 'line' theny = y + State.line_heightlove.graphics.print("* Press 'l' to switch to drawing lines", State.left+30,y)love.graphics.print("* Press 'esc' then release the mouse button to cancel the current shape", State.left+30,y)if #drawing.pending.vertices < 2 theny = y + State.line_heightelsey = y + State.line_heighty = y + State.line_heightlove.graphics.print("* Press 'p' to replace the second vertex of the rectangle", State.left+30,y)endif #drawing.pending.vertices < 2 theny = y + State.line_heightelsey = y + State.line_heighty = y + State.line_heightlove.graphics.print("* Press 'p' to replace the second vertex of the square", State.left+30,y)endlove.graphics.print('* Release the mouse button to finish drawing the square', State.left+30,y)love.graphics.print("* Press 'p' to add a vertex to the square", State.left+30,y)elseif State.current_drawing_mode == 'square' thenlove.graphics.print('* Release the mouse button to finish drawing the rectangle', State.left+30,y)love.graphics.print("* Press 'p' to add a vertex to the rectangle", State.left+30,y)y = y + State.line_heightelseif State.current_drawing_mode == 'polygon' theny = y + State.line_heighty = y + State.line_heightelseif State.current_drawing_mode == 'rectangle' thenlove.graphics.print("* Press 'p' to add a vertex to the polygon", State.left+30,y)love.graphics.print('* Release the mouse button to finish drawing the polygon', State.left+30,y)love.graphics.print('* Release the mouse button to finish drawing the arc', State.left+30,y)y = y + State.line_heightlove.graphics.print("* Press 'a' to draw just an arc of a circle", State.left+30,y)love.graphics.print('* Release the mouse button to finish drawing the circle', State.left+30,y)love.graphics.print('* Release the mouse button to finish drawing the line', State.left+30,y)love.graphics.print('* Release the mouse button to finish drawing the stroke', State.left+30,y)love.graphics.print('Things you can do now:', State.left+30,y)App.color(Help_color)local y = line_cache.starty+10function draw_help_with_mouse_pressed(State, drawing_index)local drawing = State.lines[drawing_index]local line_cache = State.line_cache[drawing_index]y = y + State.line_heighty = y + State.line_heightlove.graphics.print("Press 'esc' now to hide this message", State.left+30,y)App.color(Help_background_color)love.graphics.rectangle('fill', State.left,line_cache.starty, State.width, math.max(Drawing.pixels(drawing.h, State.width),y-line_cache.starty))love.graphics.print("* Press 'ctrl+=' or 'ctrl+-' to zoom in or out, ctrl+0 to reset zoom", State.left+30,y)if State.current_drawing_mode ~= 'square' theny = y + State.line_heightlove.graphics.print("* Press 'ctrl+s' to switch to drawing squares", State.left+30,y)if State.current_drawing_mode ~= 'rectangle' theny = y + State.line_heightlove.graphics.print("* Press 'ctrl+r' to switch to drawing rectangles", State.left+30,y)if State.current_drawing_mode ~= 'polygon' theny = y + State.line_heightlove.graphics.print("* Press 'ctrl+g' to switch to drawing polygons", State.left+30,y)if State.current_drawing_mode ~= 'circle' theny = y + State.line_heightlove.graphics.print("* Press 'ctrl+o' to switch to drawing circles/arcs", State.left+30,y)if State.current_drawing_mode ~= 'manhattan' theny = y + State.line_heightlove.graphics.print("* Press 'ctrl+m' to switch to drawing horizontal/vertical lines", State.left+30,y)if State.current_drawing_mode ~= 'line' theny = y + State.line_heightlove.graphics.print("* Press 'ctrl+l' to switch to drawing lines", State.left+30,y)love.graphics.print("* Press 'ctrl+p' to switch to drawing freehand strokes", State.left+30,y)love.graphics.print("* Hover on a point or shape and press 'ctrl+d' to delete it", State.left+30,y)love.graphics.print("* Hover on a point and press 'ctrl+n', type a name, then press 'enter'", State.left+30,y)love.graphics.print("then press the mouse button to drop it", State.left+30+bullet_indent(),y)love.graphics.print("* Hover on a point and press 'ctrl+u' to pick it up and start moving it,", State.left+30,y)love.graphics.print("* Press the mouse button to start drawing a "..current_shape(State), State.left+30,y)App.color(Help_color)local y = line_cache.starty+10function draw_help_without_mouse_pressed(State, drawing_index)local drawing = State.lines[drawing_index]local line_cache = State.line_cache[drawing_index]
function geom.on_shape(x,y, drawing, shape)if shape.mode == 'freehand' thenreturn geom.on_freehand(x,y, drawing, shape)elseif shape.mode == 'line' thenreturn geom.on_line(x,y, drawing, shape)elseif shape.mode == 'manhattan' thenreturn geom.on_polygon(x,y, drawing, shape)elseif shape.mode == 'circle' thenlocal center = drawing.points[shape.center]elseif shape.mode == 'arc' thenlocal center = drawing.points[shape.center]if dist < shape.radius*0.95 or dist > shape.radius*1.05 thenreturn falseendreturn geom.angle_between(center.x,center.y, x,y, shape.start_angle,shape.end_angle)elseif shape.mode == 'deleted' thenelseprint(shape.mode)assert(false)endendfunction geom.on_freehand(x,y, drawing, shape)local prevfor _,p in ipairs(shape.points) doif prev thenif geom.on_line(x,y, drawing, {p1=prev, p2=p}) thenreturn trueendendprev = pendreturn falseendfunction geom.on_line(x,y, drawing, shape)local p1,p2if type(shape.p1) == 'number' thenp1 = drawing.points[shape.p1]p2 = drawing.points[shape.p2]elsep1 = shape.p1p2 = shape.p2endif p1.x == p2.x thenreturn falseendlocal y1,y2 = p1.y,p2.yif y1 > y2 theny1,y2 = y2,y1endend-- has the right slope and interceptlocal m = (p2.y - p1.y) / (p2.x - p1.x)local yp = p1.y + m*(x-p1.x)return falseend-- between endpointslocal k = (x-p1.x) / (p2.x-p1.x)endfunction geom.on_polygon(x,y, drawing, shape)local prevfor _,p in ipairs(shape.vertices) doif prev thenif geom.on_line(x,y, drawing, {p1=prev, p2=p}) thenreturn trueendendprev = pendreturn geom.on_line(x,y, drawing, {p1=shape.vertices[1], p2=shape.vertices[#shape.vertices]})endfunction geom.angle_with_hint(x1, y1, x2, y2, hint)local result = geom.angle(x1,y1, x2,y2)if hint then-- Smooth the discontinuity where angle goes from positive to negative.-- The hint is a memory of which way we drew it last time.while result > hint+math.pi/10 doresult = result-math.pi*2endwhile result < hint-math.pi/10 doresult = result+math.pi*2endendreturn resultend-- result is from -π/2 to 3π/2, approximately adding math.atan2 from Lua 5.3-- (LÖVE is Lua 5.1)function geom.angle(x1,y1, x2,y2)local result = math.atan((y2-y1)/(x2-x1))if x2 < x1 thenresult = result+math.piendreturn resultend-- is the line between x,y and cx,cy at an angle between s and e?function geom.angle_between(ox,oy, x,y, s,e)if s > e thens,e = e,send-- I'm not sure this is right or ideal..angle = angle-math.pi*2if s <= angle and angle <= e thenreturn trueendangle = angle+math.pi*2if s <= angle and angle <= e thenreturn trueendangle = angle+math.pi*2return s <= angle and angle <= eendfunction geom.dist(x1,y1, x2,y2) return ((x2-x1)^2+(y2-y1)^2)^0.5 endlocal angle = geom.angle(ox,oy, x,y)end-- are (x3,y3) and (x4,y4) on the same side of the line between (x1,y1) and (x2,y2)function geom.same_side(x1,y1, x2,y2, x3,y3, x4,y4)if x1 == x2 thenreturn math.sign(x3-x1) == math.sign(x4-x1)endif y1 == y2 thenreturn math.sign(y3-y1) == math.sign(y4-y1)endlocal m = (y2-y1)/(x2-x1)return math.sign(m*(x3-x1) + y1-y3) == math.sign(m*(x4-x1) + y1-y4)endfunction math.sign(x)if x > 0 thenreturn 1elseif x == 0 thenreturn 0elseif x < 0 thenreturn -1endreturn k > -0.005 and k < 1.005if yp < y-2 or yp > y+2 thenreturn y >= y1-2 and y <= y2+2if math.abs(p1.x-x) > 2 thenlocal dist = geom.dist(center.x,center.y, x,y)local dist = geom.dist(center.x,center.y, x,y)return dist > shape.radius*0.95 and dist < shape.radius*1.05elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenlocal p1 = drawing.points[shape.p1]local p2 = drawing.points[shape.p2]if p1.x == p2.x thenif x ~= p1.x then return false endlocal y1,y2 = p1.y, p2.yif y1 > y2 theny1,y2 = y2,y1endelseif p1.y == p2.y thenif y ~= p1.y then return false endlocal x1,x2 = p1.x, p2.xif x1 > x2 thenx1,x2 = x2,x1endendreturn x >= x1-2 and x <= x2+2return y >= y1-2 and y <= y2+2geom = {}
if line.mode == 'text' thentable.insert(event.lines, {mode='text', data=line.data})elseif line.mode == 'drawing' thenlocal points=deepcopy(line.points)--? print('copying', line.points, 'with', #line.points, 'points into', points)local shapes=deepcopy(line.shapes)--? print('copying', line.shapes, 'with', #line.shapes, 'shapes into', shapes)table.insert(event.lines, {mode='drawing', h=line.h, points=points, shapes=shapes, pending={}})--? table.insert(event.lines, {mode='drawing', h=line.h, points=deepcopy(line.points), shapes=deepcopy(line.shapes), pending={}})elseprint(line.mode)assert(false)end
table.insert(event.lines, State.lines[i])
endfunction test_click_to_create_drawing()io.write('\ntest_click_to_create_drawing')App.screen.init{width=120, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{}Text.redraw_all(Editor_state)edit.draw(Editor_state)edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1)-- cursor skips drawing to always remain on textcheck_eq(#Editor_state.lines, 2, 'F - test_click_to_create_drawing/#lines')check_eq(Editor_state.cursor1.line, 2, 'F - test_click_to_create_drawing/cursor')endfunction test_backspace_to_delete_drawing()io.write('\ntest_backspace_to_delete_drawing')-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)App.screen.init{width=120, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'```lines', '```', ''}Text.redraw_all(Editor_state)-- cursor is on text as always (outside tests this will get initialized correctly)Editor_state.cursor1.line = 2-- backspacing deletes the drawingedit.run_after_keychord(Editor_state, 'backspace')check_eq(#Editor_state.lines, 1, 'F - test_backspace_to_delete_drawing/#lines')check_eq(Editor_state.cursor1.line, 1, 'F - test_backspace_to_delete_drawing/cursor')
check_eq(Editor_state.lines[1].data, '', 'F - test_insert_newline_at_start_of_line/data:1')check_eq(Editor_state.lines[2].data, 'abc', 'F - test_insert_newline_at_start_of_line/data:2')
check_eq(Editor_state.lines[1], '', 'F - test_insert_newline_at_start_of_line/data:1')check_eq(Editor_state.lines[2], 'abc', 'F - test_insert_newline_at_start_of_line/data:2')
endfunction test_pagedown_skips_drawings()io.write('\ntest_pagedown_skips_drawings')-- some lines of text with a drawing intermixedlocal drawing_width = 50App.screen.init{width=Editor_state.left+drawing_width, height=80}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abc', -- height 15'```lines', '```', -- height 25'def', -- height 15'ghi'} -- height 15Text.redraw_all(Editor_state)check_eq(Editor_state.lines[2].mode, 'drawing', 'F - test_pagedown_skips_drawings/baseline/lines')Editor_state.cursor1 = {line=1, pos=1}Editor_state.screen_top1 = {line=1, pos=1}Editor_state.screen_bottom1 = {}local drawing_height = Drawing_padding_height + drawing_width/2 -- default-- initially the screen displays the first line and the drawing-- 15px margin + 15px line1 + 10px margin + 25px drawing + 10px margin = 75px < screen height 80pxedit.draw(Editor_state)local y = Editor_state.topApp.screen.check(y, 'abc', 'F - test_pagedown_skips_drawings/baseline/screen:1')-- after pagedown the screen draws the drawing up top-- 15px margin + 10px margin + 25px drawing + 10px margin + 15px line3 = 75px < screen height 80pxedit.run_after_keychord(Editor_state, 'pagedown')check_eq(Editor_state.screen_top1.line, 2, 'F - test_pagedown_skips_drawings/screen_top')check_eq(Editor_state.cursor1.line, 3, 'F - test_pagedown_skips_drawings/cursor')y = Editor_state.top + drawing_heightApp.screen.check(y, 'def', 'F - test_pagedown_skips_drawings/screen:1')
check_eq(Editor_state.lines[1].data, 'akl', "F - test_backspace_over_multiple_lines/data:1")check_eq(Editor_state.lines[2].data, 'mno', "F - test_backspace_over_multiple_lines/data:2")
check_eq(Editor_state.lines[1], 'akl', "F - test_backspace_over_multiple_lines/data:1")check_eq(Editor_state.lines[2], 'mno', "F - test_backspace_over_multiple_lines/data:2")
check_eq(Editor_state.lines[1].data, 'a', "F - test_backspace_to_start_of_line/data:1")check_eq(Editor_state.lines[2].data, 'def', "F - test_backspace_to_start_of_line/data:2")
check_eq(Editor_state.lines[1], 'a', "F - test_backspace_to_start_of_line/data:1")check_eq(Editor_state.lines[2], 'def', "F - test_backspace_to_start_of_line/data:2")
check_eq(Editor_state.lines[1].data, 'abc', "F - test_backspace_to_start_of_line/data:1")check_eq(Editor_state.lines[2].data, 'f', "F - test_backspace_to_start_of_line/data:2")
check_eq(Editor_state.lines[1], 'abc', "F - test_backspace_to_start_of_line/data:1")check_eq(Editor_state.lines[2], 'f', "F - test_backspace_to_start_of_line/data:2")
if State.lines[State.cursor1.line].data:sub(State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)-1) == State.search_term then
if State.lines[State.cursor1.line]:sub(State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)-1) == State.search_term then
local byte_offset = Text.offset(State.lines[State.cursor1.line].data, State.cursor1.pos)State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_offset-1)..t..string.sub(State.lines[State.cursor1.line].data, byte_offset)
local byte_offset = Text.offset(State.lines[State.cursor1.line], State.cursor1.pos)State.lines[State.cursor1.line] = string.sub(State.lines[State.cursor1.line], 1, byte_offset-1)..t..string.sub(State.lines[State.cursor1.line], byte_offset)
local byte_start = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos-1)local byte_end = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos)
local byte_start = utf8.offset(State.lines[State.cursor1.line], State.cursor1.pos-1)local byte_end = utf8.offset(State.lines[State.cursor1.line], State.cursor1.pos)
State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_start-1)..string.sub(State.lines[State.cursor1.line].data, byte_end)
State.lines[State.cursor1.line] = string.sub(State.lines[State.cursor1.line], 1, byte_start-1)..string.sub(State.lines[State.cursor1.line], byte_end)
if State.lines[State.cursor1.line-1].mode == 'drawing' thentable.remove(State.lines, State.cursor1.line-1)table.remove(State.line_cache, State.cursor1.line-1)else-- join linesState.cursor1.pos = utf8.len(State.lines[State.cursor1.line-1].data)+1State.lines[State.cursor1.line-1].data = State.lines[State.cursor1.line-1].data..State.lines[State.cursor1.line].datatable.remove(State.lines, State.cursor1.line)table.remove(State.line_cache, State.cursor1.line)end
-- join linesState.cursor1.pos = utf8.len(State.lines[State.cursor1.line-1])+1State.lines[State.cursor1.line-1] = State.lines[State.cursor1.line-1]..State.lines[State.cursor1.line]table.remove(State.lines, State.cursor1.line)table.remove(State.line_cache, State.cursor1.line)
if State.cursor1.pos <= utf8.len(State.lines[State.cursor1.line].data) thenlocal byte_start = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos)local byte_end = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos+1)
if State.cursor1.pos <= utf8.len(State.lines[State.cursor1.line]) thenlocal byte_start = utf8.offset(State.lines[State.cursor1.line], State.cursor1.pos)local byte_end = utf8.offset(State.lines[State.cursor1.line], State.cursor1.pos+1)
State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_start-1)..string.sub(State.lines[State.cursor1.line].data, byte_end)
State.lines[State.cursor1.line] = string.sub(State.lines[State.cursor1.line], 1, byte_start-1)..string.sub(State.lines[State.cursor1.line], byte_end)
if State.lines[State.cursor1.line+1].mode == 'text' then-- join linesState.lines[State.cursor1.line].data = State.lines[State.cursor1.line].data..State.lines[State.cursor1.line+1].dataend
-- join linesState.lines[State.cursor1.line] = State.lines[State.cursor1.line]..State.lines[State.cursor1.line+1]
local byte_offset = Text.offset(State.lines[State.cursor1.line].data, State.cursor1.pos)table.insert(State.lines, State.cursor1.line+1, {mode='text', data=string.sub(State.lines[State.cursor1.line].data, byte_offset)})
local byte_offset = Text.offset(State.lines[State.cursor1.line], State.cursor1.pos)table.insert(State.lines, State.cursor1.line+1, string.sub(State.lines[State.cursor1.line], byte_offset))
State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_offset-1)
State.lines[State.cursor1.line] = string.sub(State.lines[State.cursor1.line], 1, byte_offset-1)
if State.lines[State.screen_top1.line].mode == 'text' theny = y - State.line_heightelseif State.lines[State.screen_top1.line].mode == 'drawing' theny = y - Drawing_padding_height - Drawing.pixels(State.lines[State.screen_top1.line].h, State.width)end
y = y - State.line_height
local new_cursor_line = State.cursor1.linewhile new_cursor_line > 1 donew_cursor_line = new_cursor_line-1if State.lines[new_cursor_line].mode == 'text' then--? print('found previous text line')State.cursor1.line = new_cursor_lineText.populate_screen_line_starting_pos(State, State.cursor1.line)-- previous text line found, pick its final screen line--? print('has multiple screen lines')local screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos--? print(#screen_line_starting_pos)screen_line_starting_pos = screen_line_starting_pos[#screen_line_starting_pos]--? print('previous screen line starts at pos '..tostring(screen_line_starting_pos)..' of its line')if State.screen_top1.line > State.cursor1.line thenState.screen_top1.line = State.cursor1.lineState.screen_top1.pos = screen_line_starting_pos--? print('pos of top of screen is also '..tostring(State.screen_top1.pos)..' of the same line')endlocal screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, screen_line_starting_pos)local s = string.sub(State.lines[State.cursor1.line].data, screen_line_starting_byte_offset)State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1break
if State.cursor1.line > 1 thenlocal new_cursor_line = State.cursor1.line-1--? print('found previous text line')State.cursor1.line = new_cursor_lineText.populate_screen_line_starting_pos(State, State.cursor1.line)-- previous text line found, pick its final screen line--? print('has multiple screen lines')local screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos--? print(#screen_line_starting_pos)screen_line_starting_pos = screen_line_starting_pos[#screen_line_starting_pos]--? print('previous screen line starts at pos '..tostring(screen_line_starting_pos)..' of its line')if State.screen_top1.line > State.cursor1.line thenState.screen_top1.line = State.cursor1.lineState.screen_top1.pos = screen_line_starting_pos--? print('pos of top of screen is also '..tostring(State.screen_top1.pos)..' of the same line')
local screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line], screen_line_starting_pos)local s = string.sub(State.lines[State.cursor1.line], screen_line_starting_byte_offset)State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, new_screen_line_starting_pos)local s = string.sub(State.lines[State.cursor1.line].data, new_screen_line_starting_byte_offset)
local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line], new_screen_line_starting_pos)local s = string.sub(State.lines[State.cursor1.line], new_screen_line_starting_byte_offset)
local new_cursor_line = State.cursor1.linewhile new_cursor_line < #State.lines donew_cursor_line = new_cursor_line+1if State.lines[new_cursor_line].mode == 'text' thenState.cursor1.line = new_cursor_lineState.cursor1.pos = Text.nearest_cursor_pos(State.lines[State.cursor1.line].data, State.cursor_x, State.left)--? print(State.cursor1.pos)breakend
if State.cursor1.line < #State.lines thenlocal new_cursor_line = State.cursor1.line+1State.cursor1.line = new_cursor_lineState.cursor1.pos = Text.nearest_cursor_pos(State.lines[State.cursor1.line], State.cursor_x, State.left)--? print(State.cursor1.pos)
local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, new_screen_line_starting_pos)local s = string.sub(State.lines[State.cursor1.line].data, new_screen_line_starting_byte_offset)
local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line], new_screen_line_starting_pos)local s = string.sub(State.lines[State.cursor1.line], new_screen_line_starting_byte_offset)
elselocal new_cursor_line = State.cursor1.linewhile new_cursor_line > 1 donew_cursor_line = new_cursor_line-1if State.lines[new_cursor_line].mode == 'text' thenState.cursor1.line = new_cursor_lineState.cursor1.pos = utf8.len(State.lines[State.cursor1.line].data) + 1breakendend
elseif State.cursor1.line > 1 thenState.cursor1.line = State.cursor1.line-1State.cursor1.pos = utf8.len(State.lines[State.cursor1.line]) + 1
elselocal new_cursor_line = State.cursor1.linewhile new_cursor_line <= #State.lines-1 donew_cursor_line = new_cursor_line+1if State.lines[new_cursor_line].mode == 'text' thenState.cursor1.line = new_cursor_lineState.cursor1.pos = 1breakendend
elseif State.cursor1.line <= #State.lines-1 thenState.cursor1.line = State.cursor1.line+1State.cursor1.pos = 1
local y = State.topwhile State.cursor1.line <= #State.lines doif State.lines[State.cursor1.line].mode == 'text' thenbreakend--? print('cursor skips', State.cursor1.line)y = y + Drawing_padding_height + Drawing.pixels(State.lines[State.cursor1.line].h, State.width)State.cursor1.line = State.cursor1.line + 1end-- hack: insert a text line at bottom of file if necessaryif State.cursor1.line > #State.lines thenassert(State.cursor1.line == #State.lines+1)table.insert(State.lines, {mode='text', data=''})table.insert(State.line_cache, {})end--? print(y, App.screen.height, App.screen.height-State.line_height)if y > App.screen.height - State.line_height then
if State.top > App.screen.height - State.line_height then
if top2.screen_line > 1 or State.lines[top2.line-1].mode == 'text' thenlocal h = State.line_heightif y - h < State.top thenbreakendy = y - helseassert(top2.line > 1)assert(State.lines[top2.line-1].mode == 'drawing')-- We currently can't draw partial drawings, so either skip it entirely-- or not at all.local h = Drawing_padding_height + Drawing.pixels(State.lines[top2.line-1].h, State.width)if y - h < State.top thenbreakend--? print('skipping drawing of height', h)y = y - h
local h = State.line_heightif y - h < State.top thenbreak
local screen_line_starting_byte_offset = Text.offset(line.data, screen_line_starting_pos)--? print('iter', y, screen_line_index, screen_line_starting_pos, string.sub(line.data, screen_line_starting_byte_offset))
local screen_line_starting_byte_offset = Text.offset(line, screen_line_starting_pos)--? print('iter', y, screen_line_index, screen_line_starting_pos, string.sub(line, screen_line_starting_byte_offset))
local past_end_offset = Text.offset(line.data, past_end_pos)screen_line = string.sub(line.data, start_offset, past_end_offset-1)
local past_end_offset = Text.offset(line, past_end_pos)screen_line = string.sub(line, start_offset, past_end_offset-1)
local lo_offset = Text.offset(line.data, lo)local hi_offset = Text.offset(line.data, hi)local pos_offset = Text.offset(line.data, pos)
local lo_offset = Text.offset(line, lo)local hi_offset = Text.offset(line, hi)local pos_offset = Text.offset(line, pos)
if line.mode == 'text' thenif Text.in_line(State, line_index, x,y) thenreturn line_index, Text.to_pos_on_line(State, line_index, x,y)end
if Text.in_line(State, line_index, x,y) thenreturn line_index, Text.to_pos_on_line(State, line_index, x,y)
local min_offset = Text.offset(State.lines[minl].data, minp)local max_offset = Text.offset(State.lines[maxl].data, maxp)
local min_offset = Text.offset(State.lines[minl], minp)local max_offset = Text.offset(State.lines[maxl], maxp)
if State.lines[i].mode == 'text' thentable.insert(result, State.lines[i].data)end
table.insert(result, State.lines[i])
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')
check_eq(Editor_state.lines[1], 'abc', 'F - test_drop_file/lines:1')check_eq(Editor_state.lines[2], 'def', 'F - test_drop_file/lines:2')check_eq(Editor_state.lines[3], 'ghi', 'F - test_drop_file/lines:3')
if line == '```lines' then -- inflexible with whitespace since these files are always autogeneratedtable.insert(result, load_drawing(infile_next_line))elsetable.insert(result, {mode='text', data=line})end
table.insert(result, line)
json = require 'json'function load_drawing(infile_next_line)local drawing = {mode='drawing', h=256/2, points={}, shapes={}, pending={}}while true dolocal line = infile_next_line()assert(line)if line == '```' then break endlocal shape = json.decode(line)if shape.mode == 'freehand' then-- no changes neededelseif shape.mode == 'line' or shape.mode == 'manhattan' thenlocal name = shape.p1.nameshape.p1 = Drawing.insert_point(drawing.points, shape.p1.x, shape.p1.y)drawing.points[shape.p1].name = namename = shape.p2.nameshape.p2 = Drawing.insert_point(drawing.points, shape.p2.x, shape.p2.y)drawing.points[shape.p2].name = nameelseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenfor i,p in ipairs(shape.vertices) dolocal name = p.nameshape.vertices[i] = Drawing.insert_point(drawing.points, p.x,p.y)drawing.points[shape.vertices[i]].name = nameendelseif shape.mode == 'circle' or shape.mode == 'arc' thenlocal name = shape.center.nameshape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)drawing.points[shape.center].name = nameelseif shape.mode == 'deleted' then-- ignoreelseprint(shape.mode)assert(false)endtable.insert(drawing.shapes, shape)endreturn drawingendfunction store_drawing(outfile, drawing)outfile:write('```lines\n')for _,shape in ipairs(drawing.shapes) doif shape.mode == 'freehand' thenoutfile:write(json.encode(shape), '\n')elseif shape.mode == 'line' or shape.mode == 'manhattan' thenlocal line = json.encode({mode=shape.mode, p1=drawing.points[shape.p1], p2=drawing.points[shape.p2]})outfile:write(line, '\n')elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenlocal obj = {mode=shape.mode, vertices={}}for _,p in ipairs(shape.vertices) dotable.insert(obj.vertices, drawing.points[p])endlocal line = json.encode(obj)outfile:write(line, '\n')elseif shape.mode == 'circle' thenoutfile:write(json.encode({mode=shape.mode, center=drawing.points[shape.center], radius=shape.radius}), '\n')elseif shape.mode == 'arc' thenoutfile:write(json.encode({mode=shape.mode, center=drawing.points[shape.center], radius=shape.radius, start_angle=shape.start_angle, end_angle=shape.end_angle}), '\n')elseif shape.mode == 'deleted' then-- ignoreelseprint(shape.mode)assert(false)endendoutfile:write('```\n')end
--? print(line)if line == '```lines' then -- inflexible with whitespace since these files are always autogenerated--? print('inserting drawing')i, drawing = load_drawing_from_array(next_line, a, i)--? print('i now', i)table.insert(result, drawing)else--? print('inserting text')table.insert(result, {mode='text', data=line})end
table.insert(result, line)
endfunction load_drawing_from_array(iter, a, i)local drawing = {mode='drawing', h=256/2, points={}, shapes={}, pending={}}local linewhile true doi, line = iter(a, i)assert(i)--? print(i)if line == '```' then break endlocal shape = json.decode(line)if shape.mode == 'freehand' then-- no changes neededelseif shape.mode == 'line' or shape.mode == 'manhattan' thenlocal name = shape.p1.nameshape.p1 = Drawing.insert_point(drawing.points, shape.p1.x, shape.p1.y)drawing.points[shape.p1].name = namename = shape.p2.nameshape.p2 = Drawing.insert_point(drawing.points, shape.p2.x, shape.p2.y)drawing.points[shape.p2].name = nameelseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenfor i,p in ipairs(shape.vertices) dolocal name = p.nameshape.vertices[i] = Drawing.insert_point(drawing.points, p.x,p.y)drawing.points[shape.vertices[i]].name = nameendelseif shape.mode == 'circle' or shape.mode == 'arc' thenlocal name = shape.center.nameshape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)drawing.points[shape.center].name = nameelseif shape.mode == 'deleted' then-- ignoreelseprint(shape.mode)assert(false)endtable.insert(drawing.shapes, shape)endreturn i, drawing
Drawing_padding_top = 10Drawing_padding_bottom = 10Drawing_padding_height = Drawing_padding_top + Drawing_padding_bottomSame_point_distance = 4 -- pixel distance at which two points are considered the same
-- a line is either text or a drawing-- a text is a table with:-- mode = 'text',-- string data,-- a drawing is a table with:-- mode = 'drawing'-- a (y) coord in pixels (updated while painting screen),-- a (h)eight,-- an array of points, and-- an array of shapes-- a shape is a table containing:-- a mode-- an array points for mode 'freehand' (raw x,y coords; freehand drawings don't pollute the points array of a drawing)-- an array vertices for mode 'polygon', 'rectangle', 'square'-- p1, p2 for mode 'line'-- center, radius for mode 'circle'-- center, radius, start_angle, end_angle for mode 'arc'-- Unless otherwise specified, coord fields are normalized; a drawing is always 256 units wide-- The field names are carefully chosen so that switching modes in midstream-- remembers previously entered points where that makes sense.lines = {{mode='text', data=''}}, -- array of lines
lines = {''}, -- array of strings
if line.mode == 'text' then--? print('text.draw', y, line_index)local startpos = 1if line_index == State.screen_top1.line thenstartpos = State.screen_top1.posendif line.data == '' then-- button to insert new drawingbutton('draw', {x=4,y=y+4, w=12,h=12, color={1,1,0},icon = icon.insert_drawing,onpress1 = function()Drawing.before = snapshot(State, line_index-1, line_index)table.insert(State.lines, line_index, {mode='drawing', y=y, h=256/2, points={}, shapes={}, pending={}})table.insert(State.line_cache, line_index, {})if State.cursor1.line >= line_index thenState.cursor1.line = State.cursor1.line+1endschedule_save(State)record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)})end,})endy, State.screen_bottom1.pos = Text.draw(State, line_index, y, startpos)y = y + State.line_height--? print('=> y', y)elseif line.mode == 'drawing' theny = y+Drawing_padding_topDrawing.draw(State, line_index, y)y = y + Drawing.pixels(line.h, State.width) + Drawing_padding_bottomelseprint(line.mode)assert(false)
--? print('text.draw', y, line_index)local startpos = 1if line_index == State.screen_top1.line thenstartpos = State.screen_top1.pos
if line.mode == 'text' thenif Text.in_line(State, line_index, x,y) then-- delicate dance between cursor, selection and old cursor/selection-- scenarios:-- regular press+release: sets cursor, clears selection-- shift press+release:-- sets selection to old cursor if not set otherwise leaves it untouched-- sets cursor-- press and hold to start a selection: sets selection on press, cursor on release-- press and hold, then press shift: ignore shift-- i.e. mouse_released should never look at shift stateState.old_cursor1 = State.cursor1State.old_selection1 = State.selection1State.mousepress_shift = App.shift_down()State.selection1 = {line=line_index,pos=Text.to_pos_on_line(State, line_index, x, y),}--? print('selection', State.selection1.line, State.selection1.pos)breakendelseif line.mode == 'drawing' thenlocal line_cache = State.line_cache[line_index]if Drawing.in_drawing(line, line_cache, x, y, State.left,State.right) thenState.lines.current_drawing_index = line_indexState.lines.current_drawing = lineDrawing.before = snapshot(State, line_index)Drawing.mouse_pressed(State, line_index, x,y, mouse_button)breakend
if Text.in_line(State, line_index, x,y) then-- delicate dance between cursor, selection and old cursor/selection-- scenarios:-- regular press+release: sets cursor, clears selection-- shift press+release:-- sets selection to old cursor if not set otherwise leaves it untouched-- sets cursor-- press and hold to start a selection: sets selection on press, cursor on release-- press and hold, then press shift: ignore shift-- i.e. mouse_released should never look at shift stateState.old_cursor1 = State.cursor1State.old_selection1 = State.selection1State.mousepress_shift = App.shift_down()State.selection1 = {line=line_index,pos=Text.to_pos_on_line(State, line_index, x, y),}--? print('selection', State.selection1.line, State.selection1.pos)break
if State.lines.current_drawing thenDrawing.mouse_released(State, x,y, mouse_button)schedule_save(State)if Drawing.before thenrecord_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)})Drawing.before = nilendelsefor line_index,line in ipairs(State.lines) doif line.mode == 'text' thenif Text.in_line(State, line_index, x,y) then--? print('reset selection')State.cursor1 = {line=line_index,pos=Text.to_pos_on_line(State, line_index, x, y),}--? print('cursor', State.cursor1.line, State.cursor1.pos)if State.mousepress_shift thenif State.old_selection1.line == nil thenState.selection1 = State.old_cursor1elseState.selection1 = State.old_selection1endendState.old_cursor1, State.old_selection1, State.mousepress_shift = nilif eq(State.cursor1, State.selection1) thenState.selection1 = {}endbreak
for line_index,line in ipairs(State.lines) doif Text.in_line(State, line_index, x,y) then--? print('reset selection')State.cursor1 = {line=line_index,pos=Text.to_pos_on_line(State, line_index, x, y),}--? print('cursor', State.cursor1.line, State.cursor1.pos)if State.mousepress_shift thenif State.old_selection1.line == nil thenState.selection1 = State.old_cursor1elseState.selection1 = State.old_selection1
elseif State.current_drawing_mode == 'name' thenlocal before = snapshot(State, State.lines.current_drawing_index)local drawing = State.lines.current_drawinglocal p = drawing.points[drawing.pending.target_point]p.name = p.name..trecord_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})
-- dispatch to drawing or textelseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then-- DON'T reset line_cache.starty herelocal drawing_index, drawing = Drawing.current_drawing(State)if drawing_index thenlocal before = snapshot(State, drawing_index)Drawing.keychord_pressed(State, chord)record_undo_event(State, {before=before, after=snapshot(State, drawing_index)})schedule_save(State)endelseif chord == 'escape' and not App.mouse_down(1) thenfor _,line in ipairs(State.lines) doif line.mode == 'drawing' thenline.show_help = falseendendelseif State.current_drawing_mode == 'name' thenif chord == 'return' thenState.current_drawing_mode = State.previous_drawing_modeState.previous_drawing_mode = nilelselocal before = snapshot(State, State.lines.current_drawing_index)local drawing = State.lines.current_drawinglocal p = drawing.points[drawing.pending.target_point]if chord == 'escape' thenp.name = nilrecord_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})elseif chord == 'backspace' thenlocal len = utf8.len(p.name)local byte_offset = Text.offset(p.name, len-1)if len == 1 then byte_offset = 0 endp.name = string.sub(p.name, 1, byte_offset)record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})endendschedule_save(State)
-- dispatch to text
Updates to lines.love can be downloaded from the following mirrors in additionto the website above:* https://github.com/akkartik/lines.love* https://repo.or.cz/lines.love.git* https://codeberg.org/akkartik/lines.love* https://tildegit.org/akkartik/lines.love* https://git.tilde.institute/akkartik/lines.love* https://git.sr.ht/~akkartik/lines.love* https://notabug.org/akkartik/lines.love* https://pagure.io/lines.love
This repo is a fork of lines.love at [http://akkartik.name/lines.html](http://akkartik.name/lines.html).Updates to it can be downloaded from the following mirrors:
Forks of lines.love are encouraged. If you show me your fork, I'll link to ithere.* https://github.com/akkartik/lines-polygon-experiment -- an experiment thatuses separate shortcuts for regular polygons. `ctrl+3` for triangles,`ctrl+4` for squares, etc.## Associated tools
* https://codeberg.org/akkartik/text.love* https://repo.or.cz/text.love.git* https://tildegit.org/akkartik/text.love* https://git.tilde.institute/akkartik/text.love* https://git.sr.ht/~akkartik/text.love* https://notabug.org/akkartik/text.love* https://github.com/akkartik/text.love* https://pagure.io/text.love