2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
|
|
|
g_mouse = {}
|
2012-01-08 16:42:23 +01:00
|
|
|
|
2012-03-29 00:42:02 +02:00
|
|
|
local cursorChanged = false
|
2012-03-29 00:25:00 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_mouse.setTargetCursor()
|
2012-06-19 10:46:49 +02:00
|
|
|
g_window.setMouseCursor('/cursors/targetcursor.png', {x=9,y=9})
|
2012-03-29 00:25:00 +02:00
|
|
|
cursorChanged = true
|
2012-02-06 05:39:52 +01:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_mouse.setHorizontalCursor()
|
2012-06-19 10:46:49 +02:00
|
|
|
g_window.setMouseCursor('/cursors/horizontal.png', {x=9,y=4})
|
2012-03-29 00:25:00 +02:00
|
|
|
cursorChanged = true
|
2012-03-23 02:52:31 +01:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_mouse.setVerticalCursor()
|
2012-06-19 10:46:49 +02:00
|
|
|
g_window.setMouseCursor('/cursors/vertical.png', {x=4,y=9})
|
2012-03-29 00:25:00 +02:00
|
|
|
cursorChanged = true
|
2012-03-23 02:52:31 +01:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_mouse.restoreCursor()
|
2012-02-06 05:39:52 +01:00
|
|
|
g_window.restoreMouseCursor()
|
2012-03-29 00:25:00 +02:00
|
|
|
cursorChanged = false
|
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_mouse.isCursorChanged()
|
2012-03-29 00:25:00 +02:00
|
|
|
return cursorChanged
|
2012-02-06 05:39:52 +01:00
|
|
|
end
|
2012-03-25 16:10:15 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_mouse.isPressed(button)
|
2012-03-29 15:45:40 +02:00
|
|
|
if not button then button = MouseLeftButton end
|
|
|
|
return g_window.isMouseButtonPressed(button)
|
2012-03-26 00:14:00 +02:00
|
|
|
end
|
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end })
|
|
|
|
end
|