#define GP2X_BUTTON_START (8)
int main()
{
// SDL Init code here
bool QuitFlag = false;
while(!QuitFlag)
{
SDL_JoystickUpdate();
if ( SDL_JoystickGetButton(joystick, GP2X_BUTTON_START) != 0 )
{
// Do something
}
// Draw stuff here
// Flip buffers
}
// SDL cleanup
}
Uint8* kbarray;
// grab the keyboard state
kbarray[SDL_a] == 1)
{
// The A is down
}
#ifdef GP2X
#define GP2X_EVENT_DOWN SDL_JOYBUTTONDOWN
#define GP2X_EVENT_UP SDL_JOYBUTTONUP
#define GP2X_EVENT_VAR jbutton.button
//Numbers because some sources say some SDL headers are wrong in the button layout.
#define GP2X_KEY_UP 0
#define GP2X_KEY_UPLEFT 1
#define GP2X_KEY_LEFT 2
#define GP2X_KEY_DOWNLEFT 3
#define GP2X_KEY_DOWN 4
#define GP2X_KEY_DOWNRIGHT 5
#define GP2X_KEY_RIGHT 6
#define GP2X_KEY_UPRIGHT 7
#define GP2X_KEY_START 8
#define GP2X_KEY_SELECT 9
#define GP2X_KEY_TOPL 10
#define GP2X_KEY_TOPR 11
#define GP2X_KEY_A 12
#define GP2X_KEY_B 13
#define GP2X_KEY_X 14
#define GP2X_KEY_Y 15
#define GP2X_KEY_VOLUP 16
#define GP2X_KEY_VOLDOWN 17
#define GP2X_KEY_JOYBUT 18
#else
#define GP2X_EVENT_DOWN SDL_KEYDOWN
#define GP2X_EVENT_UP SDL_KEYUP
#define GP2X_EVENT_VAR key.keysym.sym
#define GP2X_KEY_UP SDLK_KP8
#define GP2X_KEY_UPLEFT SDLK_KP7
#define GP2X_KEY_LEFT SDLK_KP4
#define GP2X_KEY_DOWNLEFT SDLK_KP1
#define GP2X_KEY_DOWN SDLK_KP2
#define GP2X_KEY_DOWNRIGHT SDLK_KP3
#define GP2X_KEY_RIGHT SDLK_KP6
#define GP2X_KEY_UPRIGHT SDLK_KP9
#define GP2X_KEY_START SDLK_ESCAPE
#define GP2X_KEY_SELECT SDLK_TAB
#define GP2X_KEY_TOPL SDLK_q
#define GP2X_KEY_TOPR SDLK_w
#define GP2X_KEY_A SDLK_a
#define GP2X_KEY_B SDLK_b
#define GP2X_KEY_X SDLK_x
#define GP2X_KEY_Y SDLK_y
#define GP2X_KEY_VOLUP SDLK_EQUALS
#define GP2X_KEY_VOLDOWN SDLK_MINUS
#define GP2X_KEY_JOYBUT SDLK_SPACE
#endif
//Loop all the time it's not set to 1
while (!done)
{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent (&event))
{
//What sort of event is it?
switch (event.type)
//Something being pressed?
case GP2X_EVENT_DOWN:
//Yep, what was it?
switch( event.GP2X_EVENT_VAR )
{
case GP2X_KEY_START
/* if press Start button, terminate program */
printf("User pressed Start, exiting\n");
done=1;
break;
case GP2X_KEY_UP:
/* Funky coding here */
break;
}
}
}