SDL_events.h has this struct for mouse actions >
Code:
typedef struct SDL_MouseButtonEvent {
Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
Uint8 which; /* The mouse device index */
Uint8 button; /* The mouse button index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
Uint16 x, y; /* The X/Y coordinates of the mouse at press time */
} SDL_MouseButtonEvent;
I am trying to use the members x and y so i can return my pointing device co-ordinates,
By using another struct in the header i have got event polling working for simple button down/up events, eg 'click on the window to close' actions, but these events test conditions rather than store new values in a variable for me to pass on, and this is where i am stuck, i have tried >
Code:
int done = 0;
int startx = 0;
while(done == 0)
{
SDL_Event testEvent;
SDL_MouseButtonEvent newXY;
while ( SDL_PollEvent(&testEvent) )
{
if ( testEvent.type == SDL_QUIT ) { done = 1; }
if ( testEvent.type == SDL_KEYDOWN )
{
if ( testEvent.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
if ( testEvent.type == SDL_MOUSEBUTTONDOWN )
{
startx = newXY.x;
}
}
// Continue working here...
}
a watch on startx shows a random value 20013, so this is wrong so far. Wrong i think because the member 'x' value is unassigned to start with so i need to get the mouse co-ordinates from somewhere else because this struct is not like a function that returns the value of 'x'... so how is it used in any useful way?