diff options
Diffstat (limited to 'drawing.lua')
-rw-r--r-- | drawing.lua | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/drawing.lua b/drawing.lua index 4a9d77d..1790953 100644 --- a/drawing.lua +++ b/drawing.lua @@ -6,13 +6,13 @@ geom = require 'geom' -- into 256 parts. function Drawing.draw(line) local pmx,pmy = App.mouse_x(), App.mouse_y() - if pmx < 16+Line_width and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then + if pmx < Margin_left+Line_width and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then love.graphics.setColor(0.75,0.75,0.75) - love.graphics.rectangle('line', 16,line.y, Line_width,Drawing.pixels(line.h)) + love.graphics.rectangle('line', Margin_left,line.y, Line_width,Drawing.pixels(line.h)) if icon[Current_drawing_mode] then - icon[Current_drawing_mode](16+Line_width-20, line.y+4) + icon[Current_drawing_mode](Margin_left+Line_width-20, line.y+4) else - icon[Previous_drawing_mode](16+Line_width-20, line.y+4) + icon[Previous_drawing_mode](Margin_left+Line_width-20, line.y+4) end if App.mouse_down(1) and love.keyboard.isDown('h') then @@ -26,7 +26,7 @@ function Drawing.draw(line) return end - local mx,my = Drawing.coord(pmx-16), Drawing.coord(pmy-line.y) + local mx,my = Drawing.coord(pmx-Margin_left), Drawing.coord(pmy-line.y) for _,shape in ipairs(line.shapes) do assert(shape) @@ -35,20 +35,20 @@ function Drawing.draw(line) else love.graphics.setColor(0,0,0) end - Drawing.draw_shape(16,line.y, line, shape) + Drawing.draw_shape(Margin_left,line.y, line, shape) end for i,p in ipairs(line.points) do if p.deleted == nil then if Drawing.near(p, mx,my) then love.graphics.setColor(1,0,0) - love.graphics.circle('line', Drawing.pixels(p.x)+16,Drawing.pixels(p.y)+line.y, 4) + love.graphics.circle('line', Drawing.pixels(p.x)+Margin_left,Drawing.pixels(p.y)+line.y, 4) else love.graphics.setColor(0,0,0) - love.graphics.circle('fill', Drawing.pixels(p.x)+16,Drawing.pixels(p.y)+line.y, 2) + love.graphics.circle('fill', Drawing.pixels(p.x)+Margin_left,Drawing.pixels(p.y)+line.y, 2) end if p.name then -- todo: clip - local x,y = Drawing.pixels(p.x)+16+5, Drawing.pixels(p.y)+line.y+5 + local x,y = Drawing.pixels(p.x)+Margin_left+5, Drawing.pixels(p.y)+line.y+5 love.graphics.print(p.name, x,y) if Current_drawing_mode == 'name' and i == line.pending.target_point then -- create a faint red box for the name @@ -66,7 +66,7 @@ function Drawing.draw(line) end end love.graphics.setColor(0.75,0.75,0.75) - Drawing.draw_pending_shape(16,line.y, line) + Drawing.draw_pending_shape(Margin_left,line.y, line) end function Drawing.draw_shape(left,top, drawing, shape) @@ -207,15 +207,15 @@ end function Drawing.mouse_pressed(drawing, x,y, button) if Current_drawing_mode == 'freehand' then - drawing.pending = {mode=Current_drawing_mode, points={{x=Drawing.coord(x-16), y=Drawing.coord(y-drawing.y)}}} + drawing.pending = {mode=Current_drawing_mode, points={{x=Drawing.coord(x-Margin_left), 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)) + local j = Drawing.insert_point(drawing.points, Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y)) drawing.pending = {mode=Current_drawing_mode, p1=j} elseif Current_drawing_mode == 'polygon' or Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square' then - local j = Drawing.insert_point(drawing.points, Drawing.coord(x-16), Drawing.coord(y-drawing.y)) + local j = Drawing.insert_point(drawing.points, Drawing.coord(x-Margin_left), 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)) + local j = Drawing.insert_point(drawing.points, Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y)) drawing.pending = {mode=Current_drawing_mode, center=j} elseif Current_drawing_mode == 'move' then -- all the action is in mouse_released @@ -236,16 +236,16 @@ function Drawing.update() if App.mouse_down(1) then if Drawing.in_drawing(drawing, x,y) then if drawing.pending.mode == 'freehand' then - table.insert(drawing.pending.points, {x=Drawing.coord(App.mouse_x()-16), y=Drawing.coord(App.mouse_y()-drawing.y)}) + table.insert(drawing.pending.points, {x=Drawing.coord(App.mouse_x()-Margin_left), y=Drawing.coord(App.mouse_y()-drawing.y)}) elseif drawing.pending.mode == 'move' then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) drawing.pending.target_point.x = mx drawing.pending.target_point.y = my end end elseif Current_drawing_mode == 'move' then if Drawing.in_drawing(drawing, x, y) then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) drawing.pending.target_point.x = mx drawing.pending.target_point.y = my end @@ -265,7 +265,7 @@ function Drawing.mouse_released(x,y, button) -- the last point added during update is good enough table.insert(drawing.shapes, drawing.pending) elseif drawing.pending.mode == 'line' then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then local j = Drawing.insert_point(drawing.points, mx,my) drawing.pending.p2 = j @@ -273,7 +273,7 @@ function Drawing.mouse_released(x,y, button) end elseif drawing.pending.mode == 'manhattan' then local p1 = drawing.points[drawing.pending.p1] - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then if math.abs(mx-p1.x) > math.abs(my-p1.y) then local j = Drawing.insert_point(drawing.points, mx, p1.y) @@ -283,11 +283,11 @@ function Drawing.mouse_released(x,y, button) drawing.pending.p2 = j end local p2 = drawing.points[drawing.pending.p2] - App.mouse_move(16+Drawing.pixels(p2.x), drawing.y+Drawing.pixels(p2.y)) + App.mouse_move(Margin_left+Drawing.pixels(p2.x), drawing.y+Drawing.pixels(p2.y)) table.insert(drawing.shapes, drawing.pending) end elseif drawing.pending.mode == 'polygon' then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then table.insert(drawing.pending.vertices, Drawing.insert_point(drawing.points, mx,my)) table.insert(drawing.shapes, drawing.pending) @@ -295,7 +295,7 @@ function Drawing.mouse_released(x,y, button) elseif drawing.pending.mode == 'rectangle' then assert(#drawing.pending.vertices <= 2) if #drawing.pending.vertices == 2 then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then local first = drawing.points[drawing.pending.vertices[1]] local second = drawing.points[drawing.pending.vertices[2]] @@ -310,7 +310,7 @@ function Drawing.mouse_released(x,y, button) elseif drawing.pending.mode == 'square' then assert(#drawing.pending.vertices <= 2) if #drawing.pending.vertices == 2 then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then local first = drawing.points[drawing.pending.vertices[1]] local second = drawing.points[drawing.pending.vertices[2]] @@ -321,14 +321,14 @@ function Drawing.mouse_released(x,y, button) end end elseif drawing.pending.mode == 'circle' then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then local center = drawing.points[drawing.pending.center] drawing.pending.radius = geom.dist(center.x,center.y, mx,my) table.insert(drawing.shapes, drawing.pending) end elseif drawing.pending.mode == 'arc' then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then local center = drawing.points[drawing.pending.center] drawing.pending.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, drawing.pending.end_angle) @@ -408,7 +408,7 @@ function Drawing.keychord_pressed(chord) drawing.pending.mode = 'square' elseif App.mouse_down(1) and chord == 'p' and (Current_drawing_mode == 'polygon' or Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square') then local _,drawing = Drawing.current_drawing() - local mx,my = Drawing.coord(App.mouse_x()-16), Drawing.coord(App.mouse_y()-drawing.y) + local mx,my = Drawing.coord(App.mouse_x()-Margin_left), Drawing.coord(App.mouse_y()-drawing.y) local j = Drawing.insert_point(drawing.points, mx,my) table.insert(drawing.pending.vertices, j) elseif chord == 'C-o' and not App.mouse_down(1) then @@ -416,7 +416,7 @@ function Drawing.keychord_pressed(chord) elseif App.mouse_down(1) and chord == 'a' and Current_drawing_mode == 'circle' then local _,drawing = Drawing.current_drawing() drawing.pending.mode = 'arc' - local mx,my = Drawing.coord(App.mouse_x()-16), Drawing.coord(App.mouse_y()-drawing.y) + local mx,my = Drawing.coord(App.mouse_x()-Margin_left), Drawing.coord(App.mouse_y()-drawing.y) local j = Drawing.insert_point(drawing.points, mx,my) local center = drawing.points[drawing.pending.center] drawing.pending.radius = geom.dist(center.x,center.y, mx,my) @@ -596,7 +596,7 @@ function Drawing.select_shape_at_mouse() if drawing.mode == 'drawing' then local x, y = App.mouse_x(), App.mouse_y() if Drawing.in_drawing(drawing, x,y) then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) for i,shape in ipairs(drawing.shapes) do assert(shape) if geom.on_shape(mx,my, drawing, shape) then @@ -613,7 +613,7 @@ function Drawing.select_point_at_mouse() if drawing.mode == 'drawing' then local x, y = App.mouse_x(), App.mouse_y() if Drawing.in_drawing(drawing, x,y) then - local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y) + local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y) for i,point in ipairs(drawing.points) do assert(point) if Drawing.near(point, mx,my) then @@ -709,7 +709,7 @@ end function Drawing.near(point, x,y) local px,py = Drawing.pixels(x),Drawing.pixels(y) local cx,cy = Drawing.pixels(point.x), Drawing.pixels(point.y) - return (cx-px)*(cx-px) + (cy-py)*(cy-py) < 16 + return (cx-px)*(cx-px) + (cy-py)*(cy-py) < Margin_left end function Drawing.pixels(n) -- parts to pixels |