diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-14 13:57:19 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-14 13:57:19 -0700 |
commit | d2d7e30c319f3ddc3457fa72408e4754861ac325 (patch) | |
tree | e2f78c54b1a62b469d9e16c3279d30e2c0cac490 /main.lua | |
parent | 361d80b55ff0b84b916546b9ccb383c2babbeb63 (diff) | |
download | lines.love-d2d7e30c319f3ddc3457fa72408e4754861ac325.tar.gz |
experimental approach to combining keyboard and mouse while drawing
Desired properties: - fluently draw lots of precise drawings - requires expressing lots of different kinds of constraints - always know what pressing a key is going to do - when typing, don't care where the mouse pointer is Less important: - discoverability, learnability. Provide a hotkey for help. Current plan: - chorded keys to modify drawings while mouse button is not pressed - unchorded keys to modify drawings only while mouse button is pressed - make changes while drawing a shape by pressing a key while mouse button is pressed - make changes to a drawing by hovering mouse pointer at a shape and pressing a key (unary operators) - add constraints after drawing by hovering mouse pointer at a shape, pressing a key and moving mouse pointer to a second shape (binary operators) - almost any change can be made to a shape after it's drawn (inspired by Sketchpad) - keys pressed while drawing a shape act as abbreviations to performing the action after drawing First example in this PR: - you press mouse button, start drawing freehand - you realize you want a simple line, not a freehand stroke - without releasing the mouse button, you press 'l' - now you're drawing a straight line You could also release the mouse button and finish the stroke, then press 'ctrl-l' while hovering the mouse pointer on the stroke to turn it into a line. There's an asymmetry here. Strokes require a lot more information, so while you can turn a stroke into a line, you can't turn a line into a stroke. Strokes are an exception where you can't switch to freehand mode after you start drawing. You have to press C-f before drawing.
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/main.lua b/main.lua index 234ac2a..aa1053b 100644 --- a/main.lua +++ b/main.lua @@ -229,6 +229,8 @@ function on_line(x,y, shape) end function love.textinput(t) + if love.mouse.isDown('1') then return end + if in_drawing() then return end lines[#lines] = lines[#lines]..t end @@ -250,7 +252,17 @@ function keychord_pressed(chord) lines[#lines+1] = '' elseif chord == 'C-d' then parse_into_exec_payload(lines[#lines]) + elseif chord == 'C-f' then + current_mode = 'freehand' + elseif love.mouse.isDown('1') and chord == 'l' then + current_mode = 'line' + local drawing = current_drawing() + assert(drawing.pending.mode == 'freehand') + drawing.pending.mode = 'line' + drawing.pending.x1 = drawing.pending.points[1].x + drawing.pending.y1 = drawing.pending.points[1].y elseif chord == 'C-l' then + current_mode = 'line' local drawing,i,shape = select_shape_at_mouse() if drawing then convert_line(shape) @@ -268,6 +280,30 @@ function keychord_pressed(chord) end end +function in_drawing() + local x, y = love.mouse.getX(), love.mouse.getY() + for _,drawing in ipairs(lines) do + if type(drawing) == 'table' then + if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 12 and x < 12+drawingw then + return true + end + end + end + return false +end + +function current_drawing() + local x, y = love.mouse.getX(), love.mouse.getY() + for _,drawing in ipairs(lines) do + if type(drawing) == 'table' then + if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 12 and x < 12+drawingw then + return drawing + end + end + end + return nil +end + function select_shape_at_mouse() for _,drawing in ipairs(lines) do if type(drawing) == 'table' then |