about summary refs log tree commit diff stats
path: root/button.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-10 21:17:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-11 13:01:13 -0700
commit475bbd70efec08f4279f42b044dfe3bb9f35d63e (patch)
tree82434df44d4754cc3235d41414fff7a4a282d78f /button.lua
parent3019442c02bd301dd9ce61f76c2a007aed202577 (diff)
downloadlines.love-475bbd70efec08f4279f42b044dfe3bb9f35d63e.tar.gz
intermingle freehand line drawings with text
Diffstat (limited to 'button.lua')
-rw-r--r--button.lua18
1 files changed, 18 insertions, 0 deletions
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 x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
+      if ev.onpress1 and button == 1 then ev.onpress1() end
+    end
+  end
+end