SDL mouse event coordinates

Moderator
Posts: 435
Joined: 2002.09
Post: #1
I was playing with SDL mouse motion/button coordinates for the first time last night.

It seems that the mouse coordinates are relative to the entire screen, even though I'm in windowed mode. I'm hoping it's not hard to get the window position and offset the mouse coordinates with it, but window-local coordinates are such a basic need that I thought maybe I was missing something. Is there a built-in SDL method that I missed?

Thanks!

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Member
Posts: 89
Joined: 2005.06
Post: #2
relx, rely. should get you what you want.

http://www.libsdl.org/cgi/docwiki.cgi/SDL_20API

or more specifically:

http://www.libsdl.org/cgi/docwiki.cgi/SD...otionEvent
Quote this message in a reply
Moderator
Posts: 435
Joined: 2002.09
Post: #3
relx & rely are the delta since the last mouse move event. This is certainly useful but what I'm looking for are absolute coordinates, relative to the window's origin. (Simple example, someone clicks in the window and I want to figure out what they clicked on.)

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Moderator
Posts: 700
Joined: 2002.04
Post: #4
@MattDiamond: which version of SDL are you linking against? As I get window-relative coordinates (although Y-flipped) in windowed-OpenGL mode here, linking against a slightly older (I believe only one version behind, but I can't check at the moment...) version.

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Moderator
Posts: 435
Joined: 2002.09
Post: #5
I'm using the current stable build: 1.2.9

If your coords are working the way I would have expected mine to work, then perhaps I have a bug. I guess I'll build the Atlantis demo again and see what the mouse coordinates look like in there. But my initialization code is basically the same as the Atlantis demo, haven't souped it up at all yet.

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Moderator
Posts: 435
Joined: 2002.09
Post: #6
Finally played with this a little more. The local mouse coordinates appear to be correct after all. For some reason my game is interpretting them as offset a ways. Even weirder, if I use full-screen instead, my game interprets the coordinates as if the Y-axis were reversed. So there's something weird going on with my game's event handling but there's no reason to believe it's SDL's fault at this point.

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Moderator
Posts: 700
Joined: 2002.04
Post: #7
The inversion of the y coordinates is SDL's fault, and has been known to be for some time; although it is odd that you mention it only occurs for you in fullscreen mode - I get inverted y coordinates in windowed mode as well...

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Moderator
Posts: 435
Joined: 2002.09
Post: #8
sealfin Wrote:The inversion of the y coordinates is SDL's fault, and has been known to be for some time; although it is odd that you mention it only occurs for you in fullscreen mode - I get inverted y coordinates in windowed mode as well...

I could have sworn I saw a note that a Mac y-axis problem had been fixed recently. Now of course I can't find it.... But maybe they fixed one of the modes (and not the other) in 1.2.9?

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #9
My solution was to have a configure file for each system with different defines in each one, in the mac os x one I put #define INVERT_MOUSE_Y_AXIS
I also put
// WHY did apple make the y axis inverted????????
// Its so annoying and causes so so many problems???

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #10
The inverted y-axis happened only in one of the modes (fullscreen or windowed, I don't recall which right now), but it was "supposedly" fixed already... Annoyed
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  openal coordinates vs. opengl coordinates gerald 1 6,134 Feb 3, 2011 10:04 PM
Last Post: OneSadCookie
  SDL and the event queue WhatMeWorry 5 3,589 Sep 28, 2006 10:56 AM
Last Post: WhatMeWorry
  Tip: Fullscreen mouse event gotcha Fenris 3 3,143 Feb 13, 2006 07:41 PM
Last Post: AnotherJake
  Mouse coordinates in fullscreen TomorrowPlusX 9 5,751 Aug 26, 2005 09:03 PM
Last Post: arekkusu