diff options
-rw-r--r-- | drawing.lua | 46 | ||||
-rw-r--r-- | main.lua | 8 | ||||
-rw-r--r-- | select.lua | 2 | ||||
-rw-r--r-- | text.lua | 2 | ||||
-rw-r--r-- | text_tests.lua | 32 |
5 files changed, 45 insertions, 45 deletions
diff --git a/drawing.lua b/drawing.lua index 13faf49..4a9d77d 100644 --- a/drawing.lua +++ b/drawing.lua @@ -15,7 +15,7 @@ function Drawing.draw(line) icon[Previous_drawing_mode](16+Line_width-20, line.y+4) end - if App.mouse_down('1') and love.keyboard.isDown('h') then + if App.mouse_down(1) and love.keyboard.isDown('h') then draw_help_with_mouse_pressed(line) return end @@ -233,7 +233,7 @@ function Drawing.update() local drawing = Lines.current_drawing assert(drawing.mode == 'drawing') local x, y = App.mouse_x(), App.mouse_y() - if App.mouse_down('1') then + if App.mouse_down(1) then if Drawing.in_drawing(drawing, x,y) then if drawing.pending.mode == 'freehand' then table.insert(drawing.pending.points, {x=Drawing.coord(App.mouse_x()-16), y=Drawing.coord(App.mouse_y()-drawing.y)}) @@ -349,11 +349,11 @@ function Drawing.mouse_released(x,y, button) end function Drawing.keychord_pressed(chord) - if chord == 'C-p' and not App.mouse_down('1') then + if chord == 'C-p' and not App.mouse_down(1) then Current_drawing_mode = 'freehand' - elseif chord == 'C-g' and not App.mouse_down('1') then + elseif chord == 'C-g' and not App.mouse_down(1) then Current_drawing_mode = 'polygon' - elseif App.mouse_down('1') and chord == 'g' then + elseif App.mouse_down(1) and chord == 'g' then Current_drawing_mode = 'polygon' local _,drawing = Drawing.current_drawing() if drawing.pending.mode == 'freehand' then @@ -368,9 +368,9 @@ function Drawing.keychord_pressed(chord) drawing.pending.vertices = {drawing.pending.center} end drawing.pending.mode = 'polygon' - elseif chord == 'C-r' and not App.mouse_down('1') then + elseif chord == 'C-r' and not App.mouse_down(1) then Current_drawing_mode = 'rectangle' - elseif App.mouse_down('1') and chord == 'r' then + elseif App.mouse_down(1) and chord == 'r' then Current_drawing_mode = 'rectangle' local _,drawing = Drawing.current_drawing() if drawing.pending.mode == 'freehand' then @@ -385,9 +385,9 @@ function Drawing.keychord_pressed(chord) -- reuse existing (1-2) vertices end drawing.pending.mode = 'rectangle' - elseif chord == 'C-s' and not App.mouse_down('1') then + elseif chord == 'C-s' and not App.mouse_down(1) then Current_drawing_mode = 'square' - elseif App.mouse_down('1') and chord == 's' then + elseif App.mouse_down(1) and chord == 's' then Current_drawing_mode = 'square' local _,drawing = Drawing.current_drawing() if drawing.pending.mode == 'freehand' then @@ -406,14 +406,14 @@ function Drawing.keychord_pressed(chord) end end drawing.pending.mode = 'square' - elseif App.mouse_down('1') and chord == 'p' and (Current_drawing_mode == 'polygon' or Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square') then + elseif App.mouse_down(1) and chord == 'p' and (Current_drawing_mode == 'polygon' or Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square') then local _,drawing = Drawing.current_drawing() local mx,my = Drawing.coord(App.mouse_x()-16), Drawing.coord(App.mouse_y()-drawing.y) local j = Drawing.insert_point(drawing.points, mx,my) table.insert(drawing.pending.vertices, j) - elseif chord == 'C-o' and not App.mouse_down('1') then + elseif chord == 'C-o' and not App.mouse_down(1) then Current_drawing_mode = 'circle' - elseif App.mouse_down('1') and chord == 'a' and Current_drawing_mode == 'circle' then + elseif App.mouse_down(1) and chord == 'a' and Current_drawing_mode == 'circle' then local _,drawing = Drawing.current_drawing() drawing.pending.mode = 'arc' local mx,my = Drawing.coord(App.mouse_x()-16), Drawing.coord(App.mouse_y()-drawing.y) @@ -421,7 +421,7 @@ function Drawing.keychord_pressed(chord) local center = drawing.points[drawing.pending.center] drawing.pending.radius = geom.dist(center.x,center.y, mx,my) drawing.pending.start_angle = geom.angle(center.x,center.y, mx,my) - elseif App.mouse_down('1') and chord == 'o' then + elseif App.mouse_down(1) and chord == 'o' then Current_drawing_mode = 'circle' local _,drawing = Drawing.current_drawing() if drawing.pending.mode == 'freehand' then @@ -432,7 +432,7 @@ function Drawing.keychord_pressed(chord) drawing.pending.center = drawing.pending.vertices[1] end drawing.pending.mode = 'circle' - elseif App.mouse_down('1') and chord == 'l' then + elseif App.mouse_down(1) and chord == 'l' then Current_drawing_mode = 'line' local _,drawing = Drawing.current_drawing() if drawing.pending.mode == 'freehand' then @@ -443,9 +443,9 @@ function Drawing.keychord_pressed(chord) drawing.pending.p1 = drawing.pending.vertices[1] end drawing.pending.mode = 'line' - elseif chord == 'C-l' and not App.mouse_down('1') then + elseif chord == 'C-l' and not App.mouse_down(1) then Current_drawing_mode = 'line' - elseif App.mouse_down('1') and chord == 'm' then + elseif App.mouse_down(1) and chord == 'm' then Current_drawing_mode = 'manhattan' local drawing = Drawing.select_drawing_at_mouse() if drawing.pending.mode == 'freehand' then @@ -458,14 +458,14 @@ function Drawing.keychord_pressed(chord) drawing.pending.p1 = drawing.pending.center end drawing.pending.mode = 'manhattan' - elseif chord == 'C-m' and not App.mouse_down('1') then + elseif chord == 'C-m' and not App.mouse_down(1) then Current_drawing_mode = 'manhattan' - elseif chord == 'C-s' and not App.mouse_down('1') then + elseif chord == 'C-s' and not App.mouse_down(1) then local drawing,_,shape = Drawing.select_shape_at_mouse() if drawing then smoothen(shape) end - elseif chord == 'C-u' and not App.mouse_down('1') then + elseif chord == 'C-u' and not App.mouse_down(1) then local drawing_index,drawing,_,p = Drawing.select_point_at_mouse() if drawing then if Previous_drawing_mode == nil then @@ -476,7 +476,7 @@ function Drawing.keychord_pressed(chord) Lines.current_drawing_index = drawing_index Lines.current_drawing = drawing end - elseif App.mouse_down('1') and chord == 'v' then + elseif App.mouse_down(1) and chord == 'v' then local drawing_index,drawing,_,p = Drawing.select_point_at_mouse() if drawing then if Previous_drawing_mode == nil then @@ -487,7 +487,7 @@ function Drawing.keychord_pressed(chord) Lines.current_drawing_index = drawing_index Lines.current_drawing = drawing end - elseif chord == 'C-n' and not App.mouse_down('1') then + elseif chord == 'C-n' and not App.mouse_down(1) then local drawing_index,drawing,point_index,p = Drawing.select_point_at_mouse() if drawing then if Previous_drawing_mode == nil then @@ -500,7 +500,7 @@ function Drawing.keychord_pressed(chord) Lines.current_drawing_index = drawing_index Lines.current_drawing = drawing end - elseif chord == 'C-d' and not App.mouse_down('1') then + elseif chord == 'C-d' and not App.mouse_down(1) then local _,drawing,i,p = Drawing.select_point_at_mouse() if drawing then for _,shape in ipairs(drawing.shapes) do @@ -523,7 +523,7 @@ function Drawing.keychord_pressed(chord) if drawing then shape.mode = 'deleted' end - elseif chord == 'C-h' and not App.mouse_down('1') then + elseif chord == 'C-h' and not App.mouse_down(1) then local drawing = Drawing.select_drawing_at_mouse() if drawing then drawing.show_help = true diff --git a/main.lua b/main.lua index bc5d45a..db5d1ba 100644 --- a/main.lua +++ b/main.lua @@ -55,7 +55,7 @@ Cursor1 = {line=1, pos=1} -- position of cursor Screen_bottom1 = {line=1, pos=1} -- position of start of screen line at bottom of screen Selection1 = {} -Old_cursor1, Old_selection1, Mousepress_shift = nil -- some extra state to compute selection between mousepress and mouserelease +Old_cursor1, Old_selection1, Mousepress_shift = nil -- some extra state to compute selection between mouse press and release Recent_mouse = {} -- when selecting text, avoid recomputing some state on every single frame Cursor_x, Cursor_y = 0, 0 -- in pixels @@ -450,7 +450,7 @@ function App.keychord_pressed(chord) save_to_disk(Lines, Filename) record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)}) -- dispatch to drawing or text - elseif App.mouse_down('1') or chord:sub(1,2) == 'C-' then + elseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then -- DON'T reset line.y here local drawing_index, drawing = Drawing.current_drawing() if drawing_index then @@ -459,12 +459,12 @@ function App.keychord_pressed(chord) record_undo_event({before=before, after=snapshot(drawing_index)}) save_to_disk(Lines, Filename) end - elseif chord == 'escape' and App.mouse_down('1') then + elseif chord == 'escape' and App.mouse_down(1) then local _,drawing = Drawing.current_drawing() if drawing then drawing.pending = {} end - elseif chord == 'escape' and not App.mouse_down('1') then + elseif chord == 'escape' and not App.mouse_down(1) then for _,line in ipairs(Lines) do if line.mode == 'drawing' then line.show_help = false diff --git a/select.lua b/select.lua index 6425b06..839e770 100644 --- a/select.lua +++ b/select.lua @@ -13,7 +13,7 @@ function Text.clip_selection(line_index, apos, bpos) -- min,max = sorted(Selection1,Cursor1) local minl,minp = Selection1.line,Selection1.pos local maxl,maxp - if App.mouse_down('1') then + if App.mouse_down(1) then maxl,maxp = Text.mouse_pos() else maxl,maxp = Cursor1.line,Cursor1.pos diff --git a/text.lua b/text.lua index a31f07c..0940776 100644 --- a/text.lua +++ b/text.lua @@ -138,7 +138,7 @@ function Text.compute_fragments(line, line_width) end function Text.textinput(t) - if App.mouse_down('1') then return end + if App.mouse_down(1) then return end if App.ctrl_down() or App.alt_down() or App.cmd_down() then return end if Selection1.line then Text.delete_selection() diff --git a/text_tests.lua b/text_tests.lua index 4fcd584..c75458d 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -35,7 +35,7 @@ function test_click_with_mouse() -- click on the other line local screen_left_margin = 25 -- pixels App.draw() - App.run_after_mouse_click(screen_left_margin+8,Margin_top+5, '1') + App.run_after_mouse_click(screen_left_margin+8,Margin_top+5, 1) -- cursor moves check_eq(Cursor1.line, 1, 'F - test_click_with_mouse/cursor') end @@ -147,7 +147,7 @@ function test_click_on_wrapping_line_containing_non_ascii() y = y + Line_height -- click past the end of it App.draw() - App.run_after_mouse_click(App.screen.width-2,y-2, '1') + App.run_after_mouse_click(App.screen.width-2,y-2, 1) -- cursor moves to end of line check_eq(Cursor1.pos, 15, 'F - test_click_on_wrapping_line_containing_non_ascii/cursor') -- one more than the number of UTF-8 code-points end @@ -243,7 +243,7 @@ function test_move_cursor_using_mouse() Selection1 = {} App.draw() -- populate line.y for each line in Lines local screen_left_margin = 25 -- pixels - App.run_after_mouse_release(screen_left_margin+8,Margin_top+5, '1') + App.run_after_mouse_release(screen_left_margin+8,Margin_top+5, 1) check_eq(Cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line') check_eq(Cursor1.pos, 2, 'F - test_move_cursor_using_mouse/cursor:pos') check_nil(Selection1.line, 'F - test_move_cursor_using_mouse/selection:line') @@ -262,9 +262,9 @@ function test_select_text_using_mouse() App.draw() -- populate line.y for each line in Lines local screen_left_margin = 25 -- pixels -- press and hold on first location - App.run_after_mouse_press(screen_left_margin+8,Margin_top+5, '1') + App.run_after_mouse_press(screen_left_margin+8,Margin_top+5, 1) -- drag and release somewhere else - App.run_after_mouse_release(screen_left_margin+20,Margin_top+Line_height+5, '1') + App.run_after_mouse_release(screen_left_margin+20,Margin_top+Line_height+5, 1) check_eq(Selection1.line, 1, 'F - test_select_text_using_mouse/selection:line') check_eq(Selection1.pos, 2, 'F - test_select_text_using_mouse/selection:pos') check_eq(Cursor1.line, 2, 'F - test_select_text_using_mouse/cursor:line') @@ -283,12 +283,12 @@ function test_select_text_using_mouse_and_shift() App.draw() -- populate line.y for each line in Lines local screen_left_margin = 25 -- pixels -- click on first location - App.run_after_mouse_press(screen_left_margin+8,Margin_top+5, '1') - App.run_after_mouse_release(screen_left_margin+8,Margin_top+5, '1') + App.run_after_mouse_press(screen_left_margin+8,Margin_top+5, 1) + App.run_after_mouse_release(screen_left_margin+8,Margin_top+5, 1) -- hold down shift and click somewhere else App.fake_key_press('lshift') - App.run_after_mouse_press(screen_left_margin+20,Margin_top+5, '1') - App.run_after_mouse_release(screen_left_margin+20,Margin_top+Line_height+5, '1') + App.run_after_mouse_press(screen_left_margin+20,Margin_top+5, 1) + App.run_after_mouse_release(screen_left_margin+20,Margin_top+Line_height+5, 1) App.fake_key_release('lshift') check_eq(Selection1.line, 1, 'F - test_select_text_using_mouse_and_shift/selection:line') check_eq(Selection1.pos, 2, 'F - test_select_text_using_mouse_and_shift/selection:pos') @@ -308,16 +308,16 @@ function test_select_text_repeatedly_using_mouse_and_shift() App.draw() -- populate line.y for each line in Lines local screen_left_margin = 25 -- pixels -- click on first location - App.run_after_mouse_press(screen_left_margin+8,Margin_top+5, '1') - App.run_after_mouse_release(screen_left_margin+8,Margin_top+5, '1') + App.run_after_mouse_press(screen_left_margin+8,Margin_top+5, 1) + App.run_after_mouse_release(screen_left_margin+8,Margin_top+5, 1) -- hold down shift and click on a second location App.fake_key_press('lshift') - App.run_after_mouse_press(screen_left_margin+20,Margin_top+5, '1') - App.run_after_mouse_release(screen_left_margin+20,Margin_top+Line_height+5, '1') + App.run_after_mouse_press(screen_left_margin+20,Margin_top+5, 1) + App.run_after_mouse_release(screen_left_margin+20,Margin_top+Line_height+5, 1) -- hold down shift and click at a third location App.fake_key_press('lshift') - App.run_after_mouse_press(screen_left_margin+20,Margin_top+5, '1') - App.run_after_mouse_release(screen_left_margin+8,Margin_top+Line_height+5, '1') + App.run_after_mouse_press(screen_left_margin+20,Margin_top+5, 1) + App.run_after_mouse_release(screen_left_margin+8,Margin_top+Line_height+5, 1) App.fake_key_release('lshift') -- selection is between first and third location. forget the second location, not the first. check_eq(Selection1.line, 1, 'F - test_select_text_repeatedly_using_mouse_and_shift/selection:line') @@ -955,7 +955,7 @@ function test_position_cursor_on_recently_edited_wrapping_line() App.screen.check(y, 'stu', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:3') -- try to move the cursor earlier in the third screen line by clicking the mouse local screen_left_margin = 25 -- pixels - App.run_after_mouse_release(screen_left_margin+8,Margin_top+Line_height*2+5, '1') + App.run_after_mouse_release(screen_left_margin+8,Margin_top+Line_height*2+5, 1) -- cursor should move check_eq(Cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line') check_eq(Cursor1.pos, 26, 'F - test_move_cursor_using_mouse/cursor:pos') |