Page 1 of 1
Is retrieving non-relative mouse position possible?
Posted: Tue May 31, 2016 4:46 pm
by Pixelguru26
I'm working on a borderless application, since I would like to add my own sort of "custom border" with all of the same options.
However, I'm having a problem making the window draggable or resizeable since I cannot get absolute, system-wide mouse position; only mouse position relative to the window. Does anyone know of a way to retrieve this information via built-in features or an elegant workaround?
Re: Is retrieving non-relative mouse position possible?
Posted: Tue May 31, 2016 5:33 pm
by zorg
Yes, since i had this exact same problem beforehand (Dragging the window too fast made the mouse cursor intermittently exit the application's window, hence it slowed the dragging to a crawl after a certain point...)
I solved this by using FFI, and SDL's
SDL_GetGlobalMouseState that Löve
sadly doesn't expose.
I may have a working snippet too somewhere... not online, sorry; either you wait till i get home tomorrow, and then i might find it on my computer, or someone else could help with it in the mean time.
Re: Is retrieving non-relative mouse position possible?
Posted: Tue May 31, 2016 6:20 pm
by Pixelguru26
This sounds perfect! I will look into this while I await your snippets. Thank you for the help!
Re: Is retrieving non-relative mouse position possible?
Posted: Wed Jun 01, 2016 11:42 am
by zorg
Okay, so we both lucky, since i did have the relevant .love file in my dropbox.
Here's the
gist of it
(har har)
Edit: Just a bit more info on usage. (Yes, it supports multiple displays, and hopefully even non-entirely convex layouts as well.)
Code: Select all
local desktop = require 'path.to.file.name.without.lua.extension' -- a bit more realistic, of course.
local coordsys = desktop() -- creates a new instance, totally a byproduct of how i coded the library, but whatever.
-- 3 functions you can use
-- Gives you back the current (primary) mouse cursor position in desktop coordinates.
local gx, gy = coordsys:getGlobalMousePosition() -- or coordsys.getGlobalMousePosition(coordsys), similarly applies to the 2 below functions
-- Gives you back desktop coordinates of the display-local coordinates of one specific display
-- This works independently of what display Löve's window is actually, but it's still a neat byproduct of how the library works.
local gx, gy = coordsys:toGlobalPosition(screenX, screenY, display)
-- Gives you back the display-local coordinates and the display index from desktop-coordinates
-- This again works independently of Löve's window.
local screenX, screenY, display = coordsys:toScreenPosition(gx, gy)
Re: Is retrieving non-relative mouse position possible?
Posted: Wed Jun 01, 2016 6:02 pm
by Pixelguru26
Oh, this is perfect, and extremely robust! Thank you so much, this'll be a great help!
Re: Is retrieving non-relative mouse position possible?
Posted: Wed Jun 01, 2016 6:17 pm
by zorg
No problem, though fair warning, i sadly didn't have time to really test it out, despite it seemingly working, it might have some flaws; i'll try to get some time later so i can really release it as a lib, instead of just a gist.