override mouse state lookups in tests
If I'd had this stuff in my test harness earlier, two recent commits would have failed tests and given me early warning:ff88238ff1
ff88a2a927
This commit is contained in:
parent
9ada7cf833
commit
059efba79d
57
app.lua
57
app.lua
|
@ -132,6 +132,8 @@ function App.initialize_for_test()
|
|||
App.screen.init({width=100, height=50})
|
||||
App.screen.contents = {} -- clear screen
|
||||
App.filesystem = {}
|
||||
App.fake_key_pressed = {}
|
||||
App.fake_mouse_state = {x=-1, y=-1}
|
||||
if App.initialize_globals then App.initialize_globals() end
|
||||
end
|
||||
|
||||
|
@ -186,16 +188,40 @@ function App.setClipboardText(s)
|
|||
App.clipboard = s
|
||||
end
|
||||
|
||||
App.modifier_keys = {}
|
||||
function App.keypress(key)
|
||||
App.modifier_keys[key] = true
|
||||
App.fake_key_pressed = {}
|
||||
function App.fake_key_press(key)
|
||||
App.fake_key_pressed[key] = true
|
||||
end
|
||||
function App.keyrelease(key)
|
||||
App.modifier_keys[key] = nil
|
||||
function App.fake_key_release(key)
|
||||
App.fake_key_pressed[key] = nil
|
||||
end
|
||||
function App.modifier_down(key)
|
||||
return App.fake_key_pressed[key]
|
||||
end
|
||||
|
||||
function App.modifier_down(key)
|
||||
return App.modifier_keys[key]
|
||||
App.fake_mouse_state = {x=-1, y=-1} -- x,y always set
|
||||
function App.fake_mouse_press(x,y, button)
|
||||
App.fake_mouse_state.x = x
|
||||
App.fake_mouse_state.y = y
|
||||
App.fake_mouse_state[button] = true
|
||||
end
|
||||
function App.fake_mouse_release(x,y, button)
|
||||
App.fake_mouse_state.x = x
|
||||
App.fake_mouse_state.y = y
|
||||
App.fake_mouse_state[button] = nil
|
||||
end
|
||||
function App.mouse_move(x,y)
|
||||
App.fake_mouse_state.x = x
|
||||
App.fake_mouse_state.y = y
|
||||
end
|
||||
function App.mouse_down(button)
|
||||
return App.fake_mouse_state[button]
|
||||
end
|
||||
function App.mouse_x()
|
||||
return App.fake_mouse_state.x
|
||||
end
|
||||
function App.mouse_y()
|
||||
return App.fake_mouse_state.y
|
||||
end
|
||||
|
||||
function App.run_after_textinput(t)
|
||||
|
@ -210,13 +236,15 @@ function App.run_after_keychord(key)
|
|||
App.draw()
|
||||
end
|
||||
|
||||
function App.run_after_mousepress(x,y, button)
|
||||
function App.run_after_mouse_press(x,y, button)
|
||||
App.fake_mouse_press(x,y, button)
|
||||
App.mousepressed(x,y, button)
|
||||
App.screen.contents = {}
|
||||
App.draw()
|
||||
end
|
||||
|
||||
function App.run_after_mouserelease(x,y, button)
|
||||
function App.run_after_mouse_release(x,y, button)
|
||||
App.fake_mouse_release(x,y, button)
|
||||
App.mousereleased(x,y, button)
|
||||
App.screen.contents = {}
|
||||
App.draw()
|
||||
|
@ -283,7 +311,12 @@ function App.disable_tests()
|
|||
App.run_after_keychord = nil
|
||||
App.keypress = nil
|
||||
App.keyrelease = nil
|
||||
App.modifier_keys = nil
|
||||
App.fake_key_pressed = nil
|
||||
App.fake_key_press = nil
|
||||
App.fake_key_release = nil
|
||||
App.fake_mouse_state = nil
|
||||
App.fake_mouse_press = nil
|
||||
App.fake_mouse_release = nil
|
||||
-- other methods dispatch to real hardware
|
||||
App.screen.print = love.graphics.print
|
||||
App.newText = love.graphics.newText
|
||||
|
@ -293,4 +326,8 @@ function App.disable_tests()
|
|||
App.getClipboardText = love.system.getClipboardText
|
||||
App.setClipboardText = love.system.setClipboardText
|
||||
App.modifier_down = love.keyboard.isDown
|
||||
App.mouse_move = love.mouse.setPosition
|
||||
App.mouse_down = love.mouse.isDown
|
||||
App.mouse_x = love.mouse.getX
|
||||
App.mouse_y = love.mouse.getY
|
||||
end
|
||||
|
|
82
drawing.lua
82
drawing.lua
|
@ -5,7 +5,7 @@ geom = require 'geom'
|
|||
-- All drawings span 100% of some conceptual 'page width' and divide it up
|
||||
-- into 256 parts.
|
||||
function Drawing.draw(line)
|
||||
local pmx,pmy = love.mouse.getX(), love.mouse.getY()
|
||||
local pmx,pmy = App.mouse_x(), App.mouse_y()
|
||||
if pmx < 16+Line_width and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then
|
||||
love.graphics.setColor(0.75,0.75,0.75)
|
||||
love.graphics.rectangle('line', 16,line.y, Line_width,Drawing.pixels(line.h))
|
||||
|
@ -15,7 +15,7 @@ function Drawing.draw(line)
|
|||
icon[Previous_drawing_mode](16+Line_width-20, line.y+4)
|
||||
end
|
||||
|
||||
if love.mouse.isDown('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
|
||||
|
@ -116,14 +116,14 @@ function Drawing.draw_pending_shape(left,top, drawing)
|
|||
elseif shape.mode == 'freehand' then
|
||||
Drawing.draw_shape(left,top, drawing, shape)
|
||||
elseif shape.mode == 'line' then
|
||||
local mx,my = Drawing.coord(love.mouse.getX()-left), Drawing.coord(love.mouse.getY()-top)
|
||||
local mx,my = Drawing.coord(App.mouse_x()-left), Drawing.coord(App.mouse_y()-top)
|
||||
if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
|
||||
return
|
||||
end
|
||||
local p1 = drawing.points[shape.p1]
|
||||
love.graphics.line(Drawing.pixels(p1.x)+left,Drawing.pixels(p1.y)+top, Drawing.pixels(mx)+left,Drawing.pixels(my)+top)
|
||||
elseif shape.mode == 'manhattan' then
|
||||
local mx,my = Drawing.coord(love.mouse.getX()-left), Drawing.coord(love.mouse.getY()-top)
|
||||
local mx,my = Drawing.coord(App.mouse_x()-left), Drawing.coord(App.mouse_y()-top)
|
||||
if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
|
||||
return
|
||||
end
|
||||
|
@ -143,9 +143,9 @@ function Drawing.draw_pending_shape(left,top, drawing)
|
|||
end
|
||||
prev = curr
|
||||
end
|
||||
love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, love.mouse.getX(),love.mouse.getY())
|
||||
love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, App.mouse_x(),App.mouse_y())
|
||||
elseif shape.mode == 'rectangle' then
|
||||
local pmx,pmy = love.mouse.getX(), love.mouse.getY()
|
||||
local pmx,pmy = App.mouse_x(), App.mouse_y()
|
||||
local first = drawing.points[shape.vertices[1]]
|
||||
if #shape.vertices == 1 then
|
||||
love.graphics.line(Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top, pmx,pmy)
|
||||
|
@ -159,7 +159,7 @@ function Drawing.draw_pending_shape(left,top, drawing)
|
|||
love.graphics.line(Drawing.pixels(thirdx)+left,Drawing.pixels(thirdy)+top, Drawing.pixels(fourthx)+left,Drawing.pixels(fourthy)+top)
|
||||
love.graphics.line(Drawing.pixels(fourthx)+left,Drawing.pixels(fourthy)+top, Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top)
|
||||
elseif shape.mode == 'square' then
|
||||
local pmx,pmy = love.mouse.getX(), love.mouse.getY()
|
||||
local pmx,pmy = App.mouse_x(), App.mouse_y()
|
||||
local first = drawing.points[shape.vertices[1]]
|
||||
if #shape.vertices == 1 then
|
||||
love.graphics.line(Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top, pmx,pmy)
|
||||
|
@ -174,15 +174,15 @@ function Drawing.draw_pending_shape(left,top, drawing)
|
|||
love.graphics.line(Drawing.pixels(fourthx)+left,Drawing.pixels(fourthy)+top, Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top)
|
||||
elseif shape.mode == 'circle' then
|
||||
local center = drawing.points[shape.center]
|
||||
local mx,my = Drawing.coord(love.mouse.getX()-left), Drawing.coord(love.mouse.getY()-top)
|
||||
local mx,my = Drawing.coord(App.mouse_x()-left), Drawing.coord(App.mouse_y()-top)
|
||||
if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
|
||||
return
|
||||
end
|
||||
local cx,cy = Drawing.pixels(center.x)+left, Drawing.pixels(center.y)+top
|
||||
love.graphics.circle('line', cx,cy, geom.dist(cx,cy, love.mouse.getX(),love.mouse.getY()))
|
||||
love.graphics.circle('line', cx,cy, geom.dist(cx,cy, App.mouse_x(),App.mouse_y()))
|
||||
elseif shape.mode == 'arc' then
|
||||
local center = drawing.points[shape.center]
|
||||
local mx,my = Drawing.coord(love.mouse.getX()-left), Drawing.coord(love.mouse.getY()-top)
|
||||
local mx,my = Drawing.coord(App.mouse_x()-left), Drawing.coord(App.mouse_y()-top)
|
||||
if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
|
||||
return
|
||||
end
|
||||
|
@ -232,11 +232,11 @@ function Drawing.update()
|
|||
if Lines.current_drawing == nil then return end
|
||||
local drawing = Lines.current_drawing
|
||||
assert(drawing.mode == 'drawing')
|
||||
local x, y = love.mouse.getX(), love.mouse.getY()
|
||||
if love.mouse.isDown('1') then
|
||||
local x, y = App.mouse_x(), App.mouse_y()
|
||||
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(love.mouse.getX()-16), y=Drawing.coord(love.mouse.getY()-drawing.y)})
|
||||
table.insert(drawing.pending.points, {x=Drawing.coord(App.mouse_x()-16), y=Drawing.coord(App.mouse_y()-drawing.y)})
|
||||
elseif drawing.pending.mode == 'move' then
|
||||
local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
|
||||
drawing.pending.target_point.x = mx
|
||||
|
@ -283,7 +283,7 @@ function Drawing.mouse_released(x,y, button)
|
|||
drawing.pending.p2 = j
|
||||
end
|
||||
local p2 = drawing.points[drawing.pending.p2]
|
||||
love.mouse.setPosition(16+Drawing.pixels(p2.x), drawing.y+Drawing.pixels(p2.y))
|
||||
App.mouse_move(16+Drawing.pixels(p2.x), drawing.y+Drawing.pixels(p2.y))
|
||||
table.insert(drawing.shapes, drawing.pending)
|
||||
end
|
||||
elseif drawing.pending.mode == 'polygon' then
|
||||
|
@ -349,11 +349,11 @@ function Drawing.mouse_released(x,y, button)
|
|||
end
|
||||
|
||||
function Drawing.keychord_pressed(chord)
|
||||
if chord == 'C-p' and not love.mouse.isDown('1') then
|
||||
if chord == 'C-p' and not App.mouse_down('1') then
|
||||
Current_drawing_mode = 'freehand'
|
||||
elseif chord == 'C-g' and not love.mouse.isDown('1') then
|
||||
elseif chord == 'C-g' and not App.mouse_down('1') then
|
||||
Current_drawing_mode = 'polygon'
|
||||
elseif love.mouse.isDown('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 love.mouse.isDown('1') then
|
||||
elseif chord == 'C-r' and not App.mouse_down('1') then
|
||||
Current_drawing_mode = 'rectangle'
|
||||
elseif love.mouse.isDown('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 love.mouse.isDown('1') then
|
||||
elseif chord == 'C-s' and not App.mouse_down('1') then
|
||||
Current_drawing_mode = 'square'
|
||||
elseif love.mouse.isDown('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,22 +406,22 @@ function Drawing.keychord_pressed(chord)
|
|||
end
|
||||
end
|
||||
drawing.pending.mode = 'square'
|
||||
elseif love.mouse.isDown('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(love.mouse.getX()-16), Drawing.coord(love.mouse.getY()-drawing.y)
|
||||
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 love.mouse.isDown('1') then
|
||||
elseif chord == 'C-o' and not App.mouse_down('1') then
|
||||
Current_drawing_mode = 'circle'
|
||||
elseif love.mouse.isDown('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(love.mouse.getX()-16), Drawing.coord(love.mouse.getY()-drawing.y)
|
||||
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)
|
||||
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 love.mouse.isDown('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 love.mouse.isDown('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 love.mouse.isDown('1') then
|
||||
elseif chord == 'C-l' and not App.mouse_down('1') then
|
||||
Current_drawing_mode = 'line'
|
||||
elseif love.mouse.isDown('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 love.mouse.isDown('1') then
|
||||
elseif chord == 'C-m' and not App.mouse_down('1') then
|
||||
Current_drawing_mode = 'manhattan'
|
||||
elseif chord == 'C-s' and not love.mouse.isDown('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 love.mouse.isDown('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 love.mouse.isDown('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 love.mouse.isDown('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 love.mouse.isDown('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 love.mouse.isDown('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
|
||||
|
@ -580,7 +580,7 @@ function Drawing.complete_square(firstx,firsty, secondx,secondy, x,y)
|
|||
end
|
||||
|
||||
function Drawing.current_drawing()
|
||||
local x, y = love.mouse.getX(), love.mouse.getY()
|
||||
local x, y = App.mouse_x(), App.mouse_y()
|
||||
for drawing_index,drawing in ipairs(Lines) do
|
||||
if drawing.mode == 'drawing' then
|
||||
if Drawing.in_drawing(drawing, x,y) then
|
||||
|
@ -594,7 +594,7 @@ end
|
|||
function Drawing.select_shape_at_mouse()
|
||||
for _,drawing in ipairs(Lines) do
|
||||
if drawing.mode == 'drawing' then
|
||||
local x, y = love.mouse.getX(), love.mouse.getY()
|
||||
local x, y = App.mouse_x(), App.mouse_y()
|
||||
if Drawing.in_drawing(drawing, x,y) then
|
||||
local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
|
||||
for i,shape in ipairs(drawing.shapes) do
|
||||
|
@ -611,7 +611,7 @@ end
|
|||
function Drawing.select_point_at_mouse()
|
||||
for drawing_index,drawing in ipairs(Lines) do
|
||||
if drawing.mode == 'drawing' then
|
||||
local x, y = love.mouse.getX(), love.mouse.getY()
|
||||
local x, y = App.mouse_x(), App.mouse_y()
|
||||
if Drawing.in_drawing(drawing, x,y) then
|
||||
local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
|
||||
for i,point in ipairs(drawing.points) do
|
||||
|
@ -628,7 +628,7 @@ end
|
|||
function Drawing.select_drawing_at_mouse()
|
||||
for _,drawing in ipairs(Lines) do
|
||||
if drawing.mode == 'drawing' then
|
||||
local x, y = love.mouse.getX(), love.mouse.getY()
|
||||
local x, y = App.mouse_x(), App.mouse_y()
|
||||
if Drawing.in_drawing(drawing, x,y) then
|
||||
return drawing
|
||||
end
|
||||
|
|
6
main.lua
6
main.lua
|
@ -446,7 +446,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 love.mouse.isDown('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
|
||||
|
@ -455,12 +455,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 love.mouse.isDown('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 love.mouse.isDown('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
|
||||
|
|
|
@ -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 love.mouse.isDown('1') then
|
||||
if App.mouse_down('1') then
|
||||
maxl,maxp = Text.mouse_pos()
|
||||
else
|
||||
maxl,maxp = Cursor1.line,Cursor1.pos
|
||||
|
@ -84,7 +84,7 @@ function Text.mouse_pos()
|
|||
return Recent_mouse.line, Recent_mouse.pos
|
||||
end
|
||||
Recent_mouse.time = time
|
||||
local line,pos = Text.to_pos(love.mouse.getX(), love.mouse.getY())
|
||||
local line,pos = Text.to_pos(App.mouse_x(), App.mouse_y())
|
||||
if line then
|
||||
Recent_mouse.line = line
|
||||
Recent_mouse.pos = pos
|
||||
|
|
2
text.lua
2
text.lua
|
@ -136,7 +136,7 @@ function Text.compute_fragments(line, line_width)
|
|||
end
|
||||
|
||||
function Text.textinput(t)
|
||||
if love.mouse.isDown('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()
|
||||
|
|
|
@ -171,7 +171,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_mouserelease(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')
|
||||
|
@ -190,9 +190,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_mousepress(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_mouserelease(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')
|
||||
|
@ -211,13 +211,13 @@ 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_mousepress(screen_left_margin+8,Margin_top+5, '1')
|
||||
App.run_after_mouserelease(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.keypress('lshift')
|
||||
App.run_after_mousepress(screen_left_margin+20,Margin_top+5, '1')
|
||||
App.run_after_mouserelease(screen_left_margin+20,Margin_top+Line_height+5, '1')
|
||||
App.keyrelease('lshift')
|
||||
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.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')
|
||||
check_eq(Cursor1.line, 2, 'F - test_select_text_using_mouse_and_shift/cursor:line')
|
||||
|
@ -236,17 +236,17 @@ 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_mousepress(screen_left_margin+8,Margin_top+5, '1')
|
||||
App.run_after_mouserelease(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.keypress('lshift')
|
||||
App.run_after_mousepress(screen_left_margin+20,Margin_top+5, '1')
|
||||
App.run_after_mouserelease(screen_left_margin+20,Margin_top+Line_height+5, '1')
|
||||
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')
|
||||
-- hold down shift and click at a third location
|
||||
App.keypress('lshift')
|
||||
App.run_after_mousepress(screen_left_margin+20,Margin_top+5, '1')
|
||||
App.run_after_mouserelease(screen_left_margin+8,Margin_top+Line_height+5, '1')
|
||||
App.keyrelease('lshift')
|
||||
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.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')
|
||||
check_eq(Selection1.pos, 2, 'F - test_select_text_repeatedly_using_mouse_and_shift/selection:pos')
|
||||
|
@ -884,7 +884,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_mouserelease(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')
|
||||
|
|
Loading…
Reference in New Issue