diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-07-12 16:25:29 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-07-12 16:25:29 -0700 |
commit | 2307cb3ded17013fcea56ed77ca23dc1a136382d (patch) | |
tree | 72cd04b14b74759e8125fc57f19428afaa5d6b93 | |
parent | 93aca28cb3e86f2b65d7ae4d62f0ed695470c6fc (diff) | |
download | view.love-2307cb3ded17013fcea56ed77ca23dc1a136382d.tar.gz |
add state arg to Drawing.draw
-rw-r--r-- | drawing.lua | 30 | ||||
-rw-r--r-- | edit.lua | 2 |
2 files changed, 16 insertions, 16 deletions
diff --git a/drawing.lua b/drawing.lua index ac879f8..5a4fc85 100644 --- a/drawing.lua +++ b/drawing.lua @@ -4,15 +4,15 @@ require 'drawing_tests' -- All drawings span 100% of some conceptual 'page width' and divide it up -- into 256 parts. -function Drawing.draw(line) +function Drawing.draw(State, line) local pmx,pmy = App.mouse_x(), App.mouse_y() - if pmx < App.screen.width-Editor_state.margin_right and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then + if pmx < App.screen.width-State.margin_right and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then App.color(Icon_color) - love.graphics.rectangle('line', Editor_state.margin_left,line.y, App.screen.width-Editor_state.margin_width,Drawing.pixels(line.h)) - if icon[Editor_state.current_drawing_mode] then - icon[Editor_state.current_drawing_mode](App.screen.width-Editor_state.margin_right-22, line.y+4) + love.graphics.rectangle('line', State.margin_left,line.y, App.screen.width-State.margin_width,Drawing.pixels(line.h)) + if icon[State.current_drawing_mode] then + icon[State.current_drawing_mode](App.screen.width-State.margin_right-22, line.y+4) else - icon[Editor_state.previous_drawing_mode](App.screen.width-Editor_state.margin_right-22, line.y+4) + icon[State.previous_drawing_mode](App.screen.width-State.margin_right-22, 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-Editor_state.margin_left), Drawing.coord(pmy-line.y) + local mx,my = Drawing.coord(pmx-State.margin_left), Drawing.coord(pmy-line.y) for _,shape in ipairs(line.shapes) do assert(shape) @@ -35,38 +35,38 @@ function Drawing.draw(line) else App.color(Stroke_color) end - Drawing.draw_shape(Editor_state.margin_left,line.y, line, shape) + Drawing.draw_shape(State.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 App.color(Focus_stroke_color) - love.graphics.circle('line', Drawing.pixels(p.x)+Editor_state.margin_left,Drawing.pixels(p.y)+line.y, 4) + love.graphics.circle('line', Drawing.pixels(p.x)+State.margin_left,Drawing.pixels(p.y)+line.y, 4) else App.color(Stroke_color) - love.graphics.circle('fill', Drawing.pixels(p.x)+Editor_state.margin_left,Drawing.pixels(p.y)+line.y, 2) + love.graphics.circle('fill', Drawing.pixels(p.x)+State.margin_left,Drawing.pixels(p.y)+line.y, 2) end if p.name then -- TODO: clip - local x,y = Drawing.pixels(p.x)+Editor_state.margin_left+5, Drawing.pixels(p.y)+line.y+5 + local x,y = Drawing.pixels(p.x)+State.margin_left+5, Drawing.pixels(p.y)+line.y+5 love.graphics.print(p.name, x,y) - if Editor_state.current_drawing_mode == 'name' and i == line.pending.target_point then + if State.current_drawing_mode == 'name' and i == line.pending.target_point then -- create a faint red box for the name App.color(Current_name_background_color) local name_text -- TODO: avoid computing name width on every repaint if p.name == '' then - name_text = Editor_state.em + name_text = State.em else name_text = App.newText(love.graphics.getFont(), p.name) end - love.graphics.rectangle('fill', x,y, App.width(name_text), Editor_state.line_height) + love.graphics.rectangle('fill', x,y, App.width(name_text), State.line_height) end end end end App.color(Current_stroke_color) - Drawing.draw_pending_shape(Editor_state.margin_left,line.y, line) + Drawing.draw_pending_shape(State.margin_left,line.y, line) end function Drawing.draw_shape(left,top, drawing, shape) diff --git a/edit.lua b/edit.lua index 6ca8eb1..0e303bb 100644 --- a/edit.lua +++ b/edit.lua @@ -152,7 +152,7 @@ function edit.draw(State) elseif line.mode == 'drawing' then y = y+State.drawing_padding_top line.y = y - Drawing.draw(line) + Drawing.draw(State, line) y = y + Drawing.pixels(line.h) + State.drawing_padding_bottom else line.starty = y |