Page 1 of 1

problem too Show mouse position in SDL

Posted: Tue Jan 13, 2009 2:44 pm
by Vortex
Hello im currently learning SDL and i want to make a function in my program that shows the current position of the mouse ( x and y ) but when i try it it sais i cannot send in a string into the function that blits the surface :( i hope you understand what i mean im kinda tired and im not sitting by the computer that i got my source on so i cannot really explain so good.


how do you guys do it? :)

Re: problem too Show mouse position in SDL

Posted: Tue Jan 13, 2009 3:01 pm
by Chaos Clown
Well, to get the current mouse position, you'd use an event.
For example:

Code: Select all

int MouseX, MouseY;
SDL_Event event;

while (SDL_PollEvent( &event))
{
   if (event.type == SDL_MOUSEMOTION)
   {
      MouseX = event.motion.x;
      MouseY = event.motion.y;
   }
}
Although, it sounds more like the error you're having is to do with the image blitting function, are you trying to pass a string where you should be passing an SDL_Surface?

Re: problem too Show mouse position in SDL

Posted: Tue Jan 13, 2009 3:09 pm
by KuramaYoko10
Hey dude,


I am learning C and SDL too...

And about your problem, I don't know if I understood right but you have several comands to manipulate the mouse, you have to look the SDL_mouse.h file!
One of them to look the exact position when this command is executed is this:

Code: Select all

int x;
int y;

SDL_GetMouseState(&x, &y);
Now if you want to display every position of mouse on screen as you move it, you can go by where ChaosClown have pointed xD

Hope it helps!!

Re: problem too Show mouse position in SDL

Posted: Tue Jan 13, 2009 3:13 pm
by M_D_K
you can also do:

Code: Select all

//mouse_x and mouse_y are int
//mouseButtons are unsigned int
SDL_PumpEvents();
mouseButtons = SDL_GetMouseState(&mouse_x, &mouse_y);
I prefer this cause you get all mouse button states at the same time.
To check whech buttons are pressed you can use this

Code: Select all

//button is stuff like SDL_BUTTON_LEFT, SDL_BUTTON_WHEELDOWN, etc
//the & is a bitwise and
//not to be confused with logical and which is &&
bool MouseBtnDown(int button)
{
    return (mouseButtons&SDL_BUTTON(button))!=0; 
};

Re: problem too Show mouse position in SDL

Posted: Wed Jan 14, 2009 11:20 am
by Vortex
Thanks for your anwsers, i havent been able to try it cause my computer is fucked wich my stuff is on :oops:
i just wanted to let you know that i have recived your anwsers :)