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.
This commit is contained in:
Matthias Richter 2013-11-04 21:52:36 +01:00
parent 935c91f042
commit ffd187dc17
4 changed files with 14 additions and 5 deletions

View file

@ -72,6 +72,6 @@ return function(w)
core.registerDraw(id, w.draw or core.style.Button, core.registerDraw(id, w.draw or core.style.Button,
w.text, pos[1],pos[2], size[1],size[2]) 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 end

View file

@ -74,5 +74,5 @@ return function(w)
core.registerDraw(id, w.draw or core.style.Input, core.registerDraw(id, w.draw or core.style.Input,
w.info.text, w.info.cursor, pos[1],pos[2], size[1],size[2]) 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 end

View file

@ -70,6 +70,10 @@ local function makeCyclable(id)
lastwidget = id lastwidget = id
end end
local function pressedOn(id, k)
return (k or 'return') == key and hasFocus(id) and k
end
local function beginFrame() local function beginFrame()
-- for future use? -- for future use?
end end
@ -88,6 +92,7 @@ return setmetatable({
clearFocus = clearFocus, clearFocus = clearFocus,
hasFocus = hasFocus, hasFocus = hasFocus,
makeCyclable = makeCyclable, makeCyclable = makeCyclable,
pressedOn = pressedOn,
disable = disable, disable = disable,
enable = clearFocus, enable = clearFocus,

View file

@ -27,7 +27,7 @@ THE SOFTWARE.
local _M -- holds the module. needed to make widgetHit overridable local _M -- holds the module. needed to make widgetHit overridable
local x,y = 0,0 local x,y = 0,0
local down = false local down, downLast = false, false
local hot, active = nil, nil local hot, active = nil, nil
local NO_WIDGET = {} local NO_WIDGET = {}
local function _NOP_() end local function _NOP_() end
@ -55,13 +55,17 @@ local function updateWidget(id, pos, size, hit)
end end
local function releasedOn(id) 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 end
local function beginFrame() local function beginFrame()
hot = nil hot = nil
x,y = love.mouse.getPosition() 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 end
local function endFrame() local function endFrame()