about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-17 22:53:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-17 22:53:09 -0700
commit92bd6839c769b70e75c37c363a13789c8c0823e6 (patch)
treed3b2b7bbbd1429ff6a044c9723e942c197ae45c7 /main.lua
parent222a11a8dd0c8b5b68b5628928a38f05d0a3d13c (diff)
downloadtext.love-92bd6839c769b70e75c37c363a13789c8c0823e6.tar.gz
split mouse_pressed events between Text and Drawing
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua24
1 files changed, 4 insertions, 20 deletions
diff --git a/main.lua b/main.lua
index 36ff345..17c5e4f 100644
--- a/main.lua
+++ b/main.lua
@@ -158,28 +158,12 @@ function love.mousepressed(x,y, button)
 
   for line_index,line in ipairs(Lines) do
     if line.mode == 'text' then
-      -- move cursor
-      if x >= 16 and y >= line.y and y < line.y+15*Zoom then
-        Cursor_line = line_index
-        Cursor_pos = Text.nearest_cursor_pos(line.data, x, 1)
+      if Text.in_line(line, x,y) then
+        Text.move_cursor(line_index, line, x)
       end
     elseif line.mode == 'drawing' then
-      local drawing = line
-      local x, y = love.mouse.getX(), love.mouse.getY()
-      if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
-        if Current_drawing_mode == 'freehand' then
-          drawing.pending = {mode=Current_drawing_mode, points={{x=Drawing.coord(x-16), y=Drawing.coord(y-drawing.y)}}}
-        elseif Current_drawing_mode == 'line' or Current_drawing_mode == 'manhattan' then
-          local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
-          drawing.pending = {mode=Current_drawing_mode, p1=j}
-        elseif Current_drawing_mode == 'polygon' then
-          local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
-          drawing.pending = {mode=Current_drawing_mode, vertices={j}}
-        elseif Current_drawing_mode == 'circle' then
-          local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y))
-          drawing.pending = {mode=Current_drawing_mode, center=j}
-        end
-        Lines.current = drawing
+      if Drawing.in_drawing(line, x, y) then
+        Drawing.mouse_pressed(line, x,y, button)
       end
     end
   end