about summary refs log tree commit diff stats
path: root/drawing.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-17 23:10:58 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-17 23:10:58 -0700
commit10bc32e2f002d67a8b336b58cebeae5ce2b6e9a5 (patch)
treede2eafc32cdd42f0995a9e0d198a4fbff2f69167 /drawing.lua
parent4818672c1116ee0cebcdd3bbeca969b7b07adaf4 (diff)
downloadtext.love-10bc32e2f002d67a8b336b58cebeae5ce2b6e9a5.tar.gz
DRY some code
Diffstat (limited to 'drawing.lua')
-rw-r--r--drawing.lua12
1 files changed, 6 insertions, 6 deletions
diff --git a/drawing.lua b/drawing.lua
index 02dd909..5ea47f9 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -286,7 +286,7 @@ function Drawing.current_drawing()
   local x, y = love.mouse.getX(), love.mouse.getY()
   for _,drawing in ipairs(Lines) do
     if drawing.mode == 'drawing' then
-      if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
+      if Drawing.in_drawing(drawing, x,y) then
         return drawing
       end
     end
@@ -298,8 +298,8 @@ 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()
-      if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
-        local mx,my = Drawing.coord(love.mouse.getX()-16), Drawing.coord(love.mouse.getY()-drawing.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
           assert(shape)
           if geom.on_shape(mx,my, drawing, shape) then
@@ -315,8 +315,8 @@ function Drawing.select_point_at_mouse()
   for _,drawing in ipairs(Lines) do
     if drawing.mode == 'drawing' then
       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
-        local mx,my = Drawing.coord(love.mouse.getX()-16), Drawing.coord(love.mouse.getY()-drawing.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
           assert(point)
           if Drawing.near(point, mx,my) then
@@ -332,7 +332,7 @@ 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()
-      if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
+      if Drawing.in_drawing(drawing, x,y) then
         return drawing
       end
     end