diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-07-13 08:21:07 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-07-13 08:24:16 -0700 |
commit | 6659de60f365cf31290790a9d84f46c16eb6301b (patch) | |
tree | 8ef6c916ce33f7fbe2240f35758aa5741b13a3d8 | |
parent | 3b1f2cf9def925619b109fb969aff82fede09cfd (diff) | |
download | text.love-6659de60f365cf31290790a9d84f46c16eb6301b.tar.gz |
hoist couple of variables out
This seems to uncover a corner case I'd never run into until now.
-rw-r--r-- | drawing.lua | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/drawing.lua b/drawing.lua index 664bf6c..71595a8 100644 --- a/drawing.lua +++ b/drawing.lua @@ -241,13 +241,17 @@ function Drawing.update(State) if State.lines.current_drawing == nil then return end local drawing = State.lines.current_drawing assert(drawing.mode == 'drawing') + if drawing.y == nil then + return -- first draw? + end local pmx, pmy = App.mouse_x(), App.mouse_y() + local mx = Drawing.coord(pmx-State.left, State.width) + local my = Drawing.coord(pmy-drawing.y, State.width) if App.mouse_down(1) then if Drawing.in_drawing(drawing, pmx,pmy, State.left,State.right) then if drawing.pending.mode == 'freehand' then - table.insert(drawing.pending.points, {x=Drawing.coord(pmx-State.left, State.width), y=Drawing.coord(pmy-drawing.y, State.width)}) + table.insert(drawing.pending.points, {x=mx, y=my}) elseif drawing.pending.mode == 'move' then - local mx,my = Drawing.coord(pmx-State.left, State.width), Drawing.coord(pmy-drawing.y, State.width) drawing.pending.target_point.x = mx drawing.pending.target_point.y = my Drawing.relax_constraints(drawing, drawing.pending.target_point_index) @@ -255,7 +259,6 @@ function Drawing.update(State) end elseif State.current_drawing_mode == 'move' then if Drawing.in_drawing(drawing, pmx, pmy, State.left,State.right) then - local mx,my = Drawing.coord(pmx-State.left, State.width), Drawing.coord(pmy-drawing.y, State.width) drawing.pending.target_point.x = mx drawing.pending.target_point.y = my Drawing.relax_constraints(drawing, drawing.pending.target_point_index) |