From 475bbd70efec08f4279f42b044dfe3bb9f35d63e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 10 May 2022 21:17:50 -0700 Subject: [PATCH] intermingle freehand line drawings with text --- button.lua | 18 +++++++++++++ main.lua | 76 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 button.lua diff --git a/button.lua b/button.lua new file mode 100644 index 0000000..c495b5f --- /dev/null +++ b/button.lua @@ -0,0 +1,18 @@ +button_handlers = {} + +-- draw button and queue up event handlers +function button(name, params) + love.graphics.setColor(params.color[1], params.color[2], params.color[3]) + love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5) + if params.icon then params.icon(params.x, params.y) end + table.insert(button_handlers, params) +end + +-- process button event handlers +function propagate_to_button_handers(x, y, button) + for _,ev in ipairs(button_handlers) do + if x>ev.x and xev.y and y= line.y and y < line.y + line.h then + lines.current = line + process_drag(line,love.mouse.getX(),love.mouse.getY()) + end + end + end + end +end + +function process_drag(drawing, x,y) + table.insert(drawing.pending, {x=x, y=y}) +end + +function love.mousereleased(x,y, button) + if lines.current then + if lines.current.pending then + table.insert(lines.current.shapes, lines.current.pending) + lines.current.pending = {} + lines.current = nil + end + end end function love.textinput(t) @@ -62,9 +126,7 @@ function love.keyreleased(key, scancode) end function love.mousepressed(x, y, button) -end - -function love.mousereleased(x, y, button) + propagate_to_button_handers(x, y, button) end function eval(buf)