mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-18 18:06:44 +00:00
add mouse wheel events and scroll attribute
This commit is contained in:
@@ -47,6 +47,7 @@ local callback = {
|
||||
keypressed = function () end,
|
||||
keyreleased = function () end,
|
||||
textinput = function () end,
|
||||
wheelmoved = function () end,
|
||||
}
|
||||
|
||||
Backend.run = function ()
|
||||
@@ -79,6 +80,9 @@ Backend.run = function ()
|
||||
callback.keyreleased(key, event.key['repeat'])
|
||||
elseif event.type == sdl.TEXTINPUT then
|
||||
callback.textinput(ffi.string(event.text.text))
|
||||
elseif event.type == sdl.MOUSEWHEEL then
|
||||
local wheel = event.wheel
|
||||
callback.wheelmoved(wheel.x, wheel.y)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -269,8 +273,10 @@ local stack = {}
|
||||
|
||||
Backend.pop = function ()
|
||||
local history = stack[#stack]
|
||||
Backend.setColor(history.color or { 0, 0, 0, 255 })
|
||||
Backend.setScissor(history.scissor)
|
||||
local color = history.color or { 0, 0, 0, 255 }
|
||||
sdl.setRenderDrawColor(renderer,
|
||||
color[1], color[2], color[3], color[4] or 255)
|
||||
sdl.renderSetClipRect(renderer, history.scissor) -- Backend.setScissor(history.scissor)
|
||||
stack[#stack] = nil
|
||||
end
|
||||
|
||||
@@ -316,6 +322,9 @@ function Backend.show (layout)
|
||||
hook(layout, 'textinput', function (text)
|
||||
return input:handleTextInput(layout, text, Backend.getMousePosition())
|
||||
end)
|
||||
hook(layout, 'wheelmoved', function (x, y)
|
||||
return input:handleWheelMove(layout, x, y)
|
||||
end)
|
||||
end
|
||||
|
||||
return Backend
|
||||
|
||||
@@ -115,6 +115,9 @@ function Backend.show (layout)
|
||||
return input:handleReshape(layout, width, height)
|
||||
end)
|
||||
hook(layout, 'mousepressed', function (x, y, button)
|
||||
if love._version_minor < 10 and button == 'wu' or button == 'wd' then
|
||||
return input:handleWheelMove(layout, 0, button == 'wu' and 1 or -1)
|
||||
end
|
||||
return input:handlePressStart(layout, getMouseButtonId(button), x, y)
|
||||
end)
|
||||
hook(layout, 'mousereleased', function (x, y, button)
|
||||
@@ -136,6 +139,11 @@ function Backend.show (layout)
|
||||
hook(layout, 'textinput', function (text)
|
||||
return input:handleTextInput(layout, text, Backend.getMousePosition())
|
||||
end)
|
||||
if love._version_minor > 9 then
|
||||
hook(layout, 'wheelmoved', function (x, y)
|
||||
return input:handleWheelMove(layout, x, y)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return Backend
|
||||
|
||||
Reference in New Issue
Block a user