diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-17 22:55:45 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-17 22:55:45 -0700 |
commit | 4818672c1116ee0cebcdd3bbeca969b7b07adaf4 (patch) | |
tree | 8eb9ca26fdd6edd06c528e2666f2c22a9334682a /drawing.lua | |
parent | 92bd6839c769b70e75c37c363a13789c8c0823e6 (diff) | |
download | lines.love-4818672c1116ee0cebcdd3bbeca969b7b07adaf4.tar.gz |
move mouse_released events to Drawing
Diffstat (limited to 'drawing.lua')
-rw-r--r-- | drawing.lua | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/drawing.lua b/drawing.lua index fad062f..02dd909 100644 --- a/drawing.lua +++ b/drawing.lua @@ -69,6 +69,66 @@ function Drawing.mouse_pressed(drawing, x,y, button) Lines.current = drawing end +function Drawing.mouse_released(x,y, button) + if Current_drawing_mode == 'move' then + Current_drawing_mode = Previous_drawing_mode + Previous_drawing_mode = nil + elseif Lines.current then + if Lines.current.pending then + if Lines.current.pending.mode == 'freehand' then + -- the last point added during update is good enough + table.insert(Lines.current.shapes, Lines.current.pending) + elseif Lines.current.pending.mode == 'line' then + local mx,my = Drawing.coord(x-16), Drawing.coord(y-Lines.current.y) + if mx >= 0 and mx < 256 and my >= 0 and my < Lines.current.h then + local j = Drawing.insert_point(Lines.current.points, mx,my) + Lines.current.pending.p2 = j + table.insert(Lines.current.shapes, Lines.current.pending) + end + elseif Lines.current.pending.mode == 'manhattan' then + local p1 = Lines.current.points[Lines.current.pending.p1] + local mx,my = Drawing.coord(x-16), Drawing.coord(y-Lines.current.y) + if mx >= 0 and mx < 256 and my >= 0 and my < Lines.current.h then + if math.abs(mx-p1.x) > math.abs(my-p1.y) then + local j = Drawing.insert_point(Lines.current.points, mx, p1.y) + Lines.current.pending.p2 = j + else + local j = Drawing.insert_point(Lines.current.points, p1.x, my) + Lines.current.pending.p2 = j + end + local p2 = Lines.current.points[Lines.current.pending.p2] + love.mouse.setPosition(16+Drawing.pixels(p2.x), Lines.current.y+Drawing.pixels(p2.y)) + table.insert(Lines.current.shapes, Lines.current.pending) + end + elseif Lines.current.pending.mode == 'polygon' then + local mx,my = Drawing.coord(x-16), Drawing.coord(y-Lines.current.y) + if mx >= 0 and mx < 256 and my >= 0 and my < Lines.current.h then + local j = Drawing.insert_point(Lines.current.points, mx,my) + table.insert(Lines.current.shapes, Lines.current.pending) + end + table.insert(Lines.current.shapes, Lines.current.pending) + elseif Lines.current.pending.mode == 'circle' then + local mx,my = Drawing.coord(x-16), Drawing.coord(y-Lines.current.y) + if mx >= 0 and mx < 256 and my >= 0 and my < Lines.current.h then + local center = Lines.current.points[Lines.current.pending.center] + Lines.current.pending.radius = geom.dist(center.x,center.y, mx,my) + table.insert(Lines.current.shapes, Lines.current.pending) + end + elseif Lines.current.pending.mode == 'arc' then + local mx,my = Drawing.coord(x-16), Drawing.coord(y-Lines.current.y) + if mx >= 0 and mx < 256 and my >= 0 and my < Lines.current.h then + local center = Lines.current.points[Lines.current.pending.center] + Lines.current.pending.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, Lines.current.pending.end_angle) + table.insert(Lines.current.shapes, Lines.current.pending) + end + end + Lines.current.pending = {} + Lines.current = nil + end + end + save_to_disk(Lines, Filename) +end + function Drawing.keychord_pressed(chord) if chord == 'C-=' then Drawing_width = Drawing_width/Zoom |