Mouse Coordinate Problems

Code:

SDL_Event mouseEvent;
if (SDL_PollEvent(&mouseEvent))
if (mouseEvent.type == SDL_MOUSEBUTTONDOWN)
if(mouseEvent.button.button == SDL_BUTTON_LEFT)
{
int xMousePosTemp = mouseEvent.button.x;
int yMousePosTemp = mouseEvent.button.y;

                std::stringstream sstr;

                sstr << xMousePosTemp;
                std::string xMousePosStringTemp = sstr.str();

                sstr << yMousePosTemp;
                std::string yMousePosStringTemp = sstr.str();

                const char* xMousePos = xMousePosStringTemp.c_str();
                const char* yMousePos = yMousePosStringTemp.c_str();

                fprintf(stderr, "(%x,%y)\n", xMousePos, yMousePos);

This is part of a larger program. The basics, is that I should click on the
screen, and the coordinates of where I clicked will be posted. Problem is,
the coordinates I’m given are completly wrong. Eg. (3e27ac,y)

Uh, I think you mean “(%d,%d)”, not “(%x,%y)” :)On Tue, Oct 07, 2008 at 02:14:28PM -0500, Adamski wrote:

                     fprintf(stderr, "(%x,%y)\n", xMousePos, yMousePos);

This is part of a larger program. The basics, is that I should click on
the screen, and the coordinates of where I clicked will be posted. Problem
is, the coordinates I’m given are completly wrong. Eg. (3e27ac,y)


-bill!
“Tux Paint” - free children’s drawing software for Windows / Mac OS X / Linux!
Download it today! http://www.tuxpaint.org/

The coordinates are very likely to be OK, but your display is completly wrong, replace:
fprintf(stderr, “(%x,%y)\n”, xMousePos, yMousePos);

By:
fprintf(stderr, “(%d,%d)\n”, xMousePos, yMousePos);

Moreover why are you displaying the mouse coordinates on stderr and not stdout ?
Have a look to “man printf” if you’re not used to printf functions. But maybe it was a simple error.

Cheers

— En date de?: Mar 7.10.08, Adamski a ?crit?:de: Adamski
Objet: [SDL] Mouse Coordinate Problems
?: sdl at lists.libsdl.org
Date: Mardi 7 Octobre 2008, 21h14

Code:
SDL_Event mouseEvent;
??? if (SDL_PollEvent(&mouseEvent))

??? if (mouseEvent.type == SDL_MOUSEBUTTONDOWN)
??? if(mouseEvent.button.button == SDL_BUTTON_LEFT)
??? {
??? int xMousePosTemp = mouseEvent.button.x;
??? int yMousePosTemp = mouseEvent.button.y;

??? std::stringstream sstr;

??? sstr << xMousePosTemp;
??? std::string xMousePosStringTemp = sstr.str();

??? sstr << yMousePosTemp;

??? std::string yMousePosStringTemp = sstr.str();

??? const char* xMousePos = xMousePosStringTemp.c_str();
??? const char* yMousePos = yMousePosStringTemp.c_str();

??? fprintf(stderr, “(%x,%y)\n”, xMousePos, yMousePos);
This is part of a larger program. The basics, is that I should click on the screen, and the coordinates of where I clicked will be posted. Problem is, the coordinates I’m given are completly wrong. Eg. (3e27ac,y)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Or better yet, use %s since the parameters seem to be char pointers. Like so:
fprintf(stderr, “(%s,%s)\n”, xMousePos, yMousePos);

  • Aki -On Wednesday 08 October 2008, julien CLEMENT wrote:

The coordinates are very likely to be OK, but your display is completly
wrong, replace: fprintf(stderr, “(%x,%y)\n”, xMousePos, yMousePos);

By:
fprintf(stderr, “(%d,%d)\n”, xMousePos, yMousePos);

— En date de?: Mar 7.10.08, Adamski a ?crit?:
De: Adamski
Objet: [SDL] Mouse Coordinate Problems
?: sdl at lists.libsdl.org
Date: Mardi 7 Octobre 2008, 21h14
??? const char* xMousePos = xMousePosStringTemp.c_str();
??? const char* yMousePos = yMousePosStringTemp.c_str();

??? fprintf(stderr, “(%x,%y)\n”, xMousePos, yMousePos);

Aki Koskinen
http://www.akikoskinen.info/