2012-06-25 19:13:30 -03:00
|
|
|
-- @docclass
|
2012-07-13 18:31:05 +12:00
|
|
|
function g_mouse.bindAutoPress(widget, callback, delay, button)
|
2021-07-19 19:24:59 -03:00
|
|
|
local button = button or MouseLeftButton
|
|
|
|
|
connect(widget, {
|
|
|
|
|
onMousePress = function(widget, mousePos, mouseButton)
|
2022-08-17 12:51:56 -03:00
|
|
|
if mouseButton ~= button then
|
|
|
|
|
return false
|
|
|
|
|
end
|
2021-07-19 19:24:59 -03:00
|
|
|
local startTime = g_clock.millis()
|
|
|
|
|
callback(widget, mousePos, mouseButton, 0)
|
|
|
|
|
periodicalEvent(function()
|
2022-04-29 23:14:24 -03:00
|
|
|
callback(widget, g_window.getMousePosition(), mouseButton, g_clock.millis() - startTime)
|
2022-08-17 12:51:56 -03:00
|
|
|
end, function()
|
|
|
|
|
return g_mouse.isPressed(mouseButton)
|
|
|
|
|
end, 30, delay)
|
2021-07-19 19:24:59 -03:00
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
})
|
2012-03-25 11:10:15 -03:00
|
|
|
end
|
|
|
|
|
|
2022-04-27 22:54:09 -03:00
|
|
|
function g_mouse.bindPressMove(widget, callback)
|
|
|
|
|
connect(widget, {
|
|
|
|
|
onMouseMove = function(widget, mousePos, mouseMoved)
|
|
|
|
|
if widget:isPressed() then
|
|
|
|
|
callback(mousePos, mouseMoved)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2022-04-27 22:50:53 -03:00
|
|
|
function g_mouse.bindMove(widget, callback)
|
2021-07-19 19:24:59 -03:00
|
|
|
connect(widget, {
|
|
|
|
|
onMouseMove = function(widget, mousePos, mouseMoved)
|
2022-04-27 22:50:53 -03:00
|
|
|
callback(mousePos, mouseMoved)
|
|
|
|
|
return true
|
2021-07-19 19:24:59 -03:00
|
|
|
end
|
|
|
|
|
})
|
2012-03-25 11:10:15 -03:00
|
|
|
end
|
2013-01-16 14:20:17 -02:00
|
|
|
|
2013-02-13 05:14:16 +13:00
|
|
|
function g_mouse.bindPress(widget, callback, button)
|
2021-07-19 19:24:59 -03:00
|
|
|
connect(widget, {
|
|
|
|
|
onMousePress = function(widget, mousePos, mouseButton)
|
|
|
|
|
if not button or button == mouseButton then
|
|
|
|
|
callback(mousePos, mouseButton)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
})
|
2013-01-16 14:20:17 -02:00
|
|
|
end
|
2022-07-25 10:30:27 -04:00
|
|
|
|
|
|
|
|
function g_mouse.bindOnDrop(widget, callback)
|
|
|
|
|
connect(widget, {
|
|
|
|
|
onDrop = function(widget, mousePos)
|
|
|
|
|
callback(mousePos, mouseButton)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end
|