Page 1 of 1

Suggestion: mousemoved() callback

Posted: Tue Oct 14, 2008 8:09 pm
by surtic
There seems to be a small problem with having to poll to find the position of the mouse. For example, if I want to drag something (see file attached), then the object doesn't move together with the mouse.

My suggestion is to have a mousemoved(x, y) callback to allow the application to deal with this event as it happens. In most cases the callback will not be implemented, but sometimes it can be quite useful.

Of course, I can draw the cursor myself, but that's not always the best solution (in a windowed application the user might expect to see the standard cursor).

Re: Suggestion: mousemoved() callback

Posted: Tue Oct 14, 2008 8:42 pm
by Xfcn
I'm not entirely certain what your problem is? The example works perfectly for me with no noticeable lag or anything. I click the square and drag it and the cursor remains and the square is dragged around. WFM.

Re: Suggestion: mousemoved() callback

Posted: Tue Oct 14, 2008 8:52 pm
by surtic
I must have a slow computer (or graphics card)... didn't think that was the case, it was great when I bought it...

I can certainly see a lag - if I grab the rectangle by the corner and then move it in that direction (the corner's direction) the mouse is outside the rectangle most of the time.

In any case, for a fast computer it won't make a difference if mousemoved() was implemented (the performance hit would be minimal, especially if it's not actually used), whereas for a slow computer it would be very useful.

I'm wondering if I'm the only one with this problem, though...

Re: Suggestion: mousemoved() callback

Posted: Wed Oct 15, 2008 3:54 am
by Xfcn
This breaks the "drag from the original click point" portion of the code, but purely for testing purposes see if this doesn't help:

Code: Select all

function update(dt)
   if drag.active then
      local x, y = love.mouse.getPosition()
      rect.x = x - drag.dx * dt
      rect.y = y - drag.dy * dt
   end
end

Re: Suggestion: mousemoved() callback

Posted: Wed Oct 15, 2008 7:01 pm
by surtic
Thanks for the suggestion. Unfortunately it doesn't help - the cursor is still outside the rectangle most of the time.

I guess for now I'll have to draw the cursor myself - not a big deal, but maybe something to think about for the next version of LÖVE.

Re: Suggestion: mousemoved() callback

Posted: Thu Oct 16, 2008 6:00 pm
by rude
The lag is probably due to vertical sync, which can be disabled by setting vsync = false in game.conf. (Unless you've specified "always sync" in your graphics driver settings). Adding mousemoved() will not solve this problem, since events aren't processed while waiting for vertical sync.

Future solutions may involve multi-threading, or setting the actual mouse cursor itself.

Re: Suggestion: mousemoved() callback

Posted: Thu Oct 16, 2008 9:35 pm
by surtic
Thank you very much! It solved the problem immediately...

Now I'm happy again :)