From ffd187dc177f4a15fa2e87579b9cbabee38b8245 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Mon, 4 Nov 2013 21:52:36 +0100 Subject: Fix #11: Right click support. When clicked, Button() and Input() return the respective mouse button constant ('l', 'r', 'm') instead of just true. When activated by keyboard, Button() and Input() return 'return'. Otherwise Button() and Input() return false. --- button.lua | 2 +- input.lua | 2 +- keyboard.lua | 5 +++++ mouse.lua | 10 +++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/button.lua b/button.lua index 2e2b310..a1f0589 100644 --- a/button.lua +++ b/button.lua @@ -72,6 +72,6 @@ return function(w) core.registerDraw(id, w.draw or core.style.Button, w.text, pos[1],pos[2], size[1],size[2]) - return mouse.releasedOn(id) or (keyboard.key == 'return' and keyboard.hasFocus(id)) + return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') end diff --git a/input.lua b/input.lua index dd5e3aa..ad0683f 100644 --- a/input.lua +++ b/input.lua @@ -74,5 +74,5 @@ return function(w) core.registerDraw(id, w.draw or core.style.Input, w.info.text, w.info.cursor, pos[1],pos[2], size[1],size[2]) - return mouse.releasedOn(id) or (keyboard.key == 'return' and keyboard.hasFocus(id)) + return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') end diff --git a/keyboard.lua b/keyboard.lua index 50323ff..4850df3 100644 --- a/keyboard.lua +++ b/keyboard.lua @@ -70,6 +70,10 @@ local function makeCyclable(id) lastwidget = id end +local function pressedOn(id, k) + return (k or 'return') == key and hasFocus(id) and k +end + local function beginFrame() -- for future use? end @@ -88,6 +92,7 @@ return setmetatable({ clearFocus = clearFocus, hasFocus = hasFocus, makeCyclable = makeCyclable, + pressedOn = pressedOn, disable = disable, enable = clearFocus, diff --git a/mouse.lua b/mouse.lua index 83a150f..a7d6d6c 100644 --- a/mouse.lua +++ b/mouse.lua @@ -27,7 +27,7 @@ THE SOFTWARE. local _M -- holds the module. needed to make widgetHit overridable local x,y = 0,0 -local down = false +local down, downLast = false, false local hot, active = nil, nil local NO_WIDGET = {} local function _NOP_() end @@ -55,13 +55,17 @@ local function updateWidget(id, pos, size, hit) end local function releasedOn(id) - return not down and isHot(id) and isActive(id) + return not down and isHot(id) and isActive(id) and downLast end local function beginFrame() hot = nil x,y = love.mouse.getPosition() - down = love.mouse.isDown('l') + downLast = down + down = false + for _,btn in ipairs{'l', 'm', 'r'} do + down = down or (love.mouse.isDown(btn) and btn) + end end local function endFrame() -- cgit v1.2.3-54-g00ecf