2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
2012-07-13 08:31:05 +02:00
|
|
|
function g_mouse.bindAutoPress(widget, callback, delay, button)
|
|
|
|
local button = button or MouseLeftButton
|
2012-03-25 16:10:15 +02:00
|
|
|
connect(widget, { onMousePress = function(widget, mousePos, mouseButton)
|
2012-07-15 13:49:28 +02:00
|
|
|
if mouseButton ~= button then
|
2012-07-13 08:31:05 +02:00
|
|
|
return false
|
|
|
|
end
|
2012-07-13 01:40:55 +02:00
|
|
|
local startTime = g_clock.millis()
|
|
|
|
callback(widget, mousePos, mouseButton, 0)
|
2012-03-25 16:10:15 +02:00
|
|
|
periodicalEvent(function()
|
2012-07-13 01:40:55 +02:00
|
|
|
callback(widget, g_window.getMousePosition(), mouseButton, g_clock.millis() - startTime)
|
2012-03-25 16:10:15 +02:00
|
|
|
end, function()
|
2012-07-13 08:31:05 +02:00
|
|
|
return g_mouse.isPressed(mouseButton)
|
2012-07-13 01:40:55 +02:00
|
|
|
end, 30, delay)
|
2012-03-25 16:10:15 +02:00
|
|
|
return true
|
|
|
|
end })
|
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_mouse.bindPressMove(widget, callback)
|
2012-03-25 16:10:15 +02:00
|
|
|
connect(widget, { onMouseMove = function(widget, mousePos, mouseMoved)
|
|
|
|
if widget:isPressed() then
|
|
|
|
callback(mousePos, mouseMoved)
|
2013-02-10 06:24:51 +01:00
|
|
|
return true
|
2012-03-25 16:10:15 +02:00
|
|
|
end
|
|
|
|
end })
|
|
|
|
end
|
2013-01-16 17:20:17 +01:00
|
|
|
|
2013-02-12 17:14:16 +01:00
|
|
|
function g_mouse.bindPress(widget, callback, button)
|
2013-01-16 17:20:17 +01:00
|
|
|
connect(widget, { onMousePress = function(widget, mousePos, mouseButton)
|
2013-02-12 17:14:16 +01:00
|
|
|
if not button or button == mouseButton then
|
|
|
|
callback(mousePos, mouseButton)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2013-01-16 17:20:17 +01:00
|
|
|
end })
|
|
|
|
end
|