static int joyx,joyy;
static int move,dirn;
static void handle_events(void)
{
SDL_Event events[10],event1;
const int n_max_events = sizeof(events) / sizeof(events[0]);
int n_events;
int widthx=640;
int widthy=480;
while ((n_events = SDL_PeepEvents(events, n_max_events, SDL_GETEVENT, sdl_eventmask)) > 0) {
// printf ("handle events: PeepEvents\n");
for (int i = 0; i < n_events; i++)
{
SDL_Event const & event = events[i];
switch (event.type)
{
case SDL_JOYBUTTONDOWN:{
printf ("handle events: joybuttondown move=%i\n",move);
switch( event.jbutton.button )
{
case GP2X_BUTTON_CLICK:
// printf("Joystick BUTTON\n");
break;
case GP2X_BUTTON_START:
// printf("Button START\n");
break;
case GP2X_BUTTON_SELECT:
break;
case GP2X_BUTTON_VOLUP:
break;
case GP2X_BUTTON_VOLDOWN:
break;
case GP2X_BUTTON_LEFT :
joyx--;
if (joyx<0) joyx=0;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_LEFT;
break;
case GP2X_BUTTON_RIGHT :
joyx++;
if (joyx>widthx) joyx=widthx;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_RIGHT;
break;
case GP2X_BUTTON_UP :
joyy--;
if (joyy<0) joyy=0;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_UP;
break;
case GP2X_BUTTON_DOWN :
joyy++;
if (joyy>widthy) joyy=widthy;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_DOWN;
break;
case GP2X_BUTTON_UPLEFT :
joyx--;
joyy--;
if (joyx<0) joyx=0;
if (joyy<0) joyy=0;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_UPLEFT;
break;
case GP2X_BUTTON_DOWNRIGHT :
joyx++;
joyy++;
if (joyy>widthy) joyy=widthy;
if (joyx>widthx) joyx=widthx;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_DOWNRIGHT;
break;
case GP2X_BUTTON_UPRIGHT :
joyy--;
joyx++;
if (joyx>widthx) joyx=widthx;
if (joyy<0) joyy=0;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_UPRIGHT;
break;
case GP2X_BUTTON_DOWNLEFT :
joyy++;
joyx--;
if (joyx<0) joyx=0;
if (joyy>widthy) joyy=widthy;
//printf("mouse_moved %i, %i\n",joyx,joyy);
drv->mouse_moved(joyx, joyy);
move=1;
dirn=GP2X_BUTTON_DOWNLEFT;
break;
case GP2X_BUTTON_Y:
break;
case GP2X_BUTTON_B:
{
ADBMouseDown(0);
break;
}
case GP2X_BUTTON_X :
break;
case GP2X_BUTTON_A :
break;
case GP2X_BUTTON_L :
break;
case GP2X_BUTTON_R :
break;
default:
break;
}
}
case SDL_JOYBUTTONUP:{
printf ("handle events: joybuttonup move=%i\n",move);
// printf ("handle events: joybuttonup\n");
switch( event.jbutton.button ){
case GP2X_BUTTON_CLICK:
break;
case GP2X_BUTTON_START:
break;
case GP2X_BUTTON_SELECT:
break;
case GP2X_BUTTON_VOLUP:
break;
case GP2X_BUTTON_VOLDOWN:
break;
case GP2X_BUTTON_LEFT :
move=0;
break;
case GP2X_BUTTON_RIGHT :
move=0;
break;
case GP2X_BUTTON_UP :
move=0;
break;
case GP2X_BUTTON_DOWN :
move=0;
break;
case GP2X_BUTTON_UPLEFT :
move=0;
break;
case GP2X_BUTTON_DOWNRIGHT :
move=0;
break;
case GP2X_BUTTON_UPRIGHT :
move=0;
break;
case GP2X_BUTTON_DOWNLEFT :
move=0;
break;
case GP2X_BUTTON_Y:
break;
case GP2X_BUTTON_B:
{
ADBMouseUp(0);
break;
}
case GP2X_BUTTON_X :
break;
case GP2X_BUTTON_A :
break;
case GP2X_BUTTON_L :
break;
case GP2X_BUTTON_R :
break;
default:
break;
}
}
}
// printf("move = %i\n",move);
if (move==1) {
switch (dirn){
case GP2X_BUTTON_LEFT :
joyx--;
if (joyx<0) joyx=0;
drv->mouse_moved(joyx, joyy);
break;
case GP2X_BUTTON_RIGHT :
joyx++;
if (joyx>widthx) joyx=widthx;
drv->mouse_moved(joyx, joyy);
break;
case GP2X_BUTTON_UP :
joyy--;
if (joyy<0) joyy=0;
drv->mouse_moved(joyx, joyy);
break;
case GP2X_BUTTON_DOWN :
joyy++;
if (joyy>widthy) joyy=widthy;
drv->mouse_moved(joyx, joyy);
break;
case GP2X_BUTTON_UPLEFT :
joyx--;
joyy--;
if (joyx<0) joyx=0;
if (joyy<0) joyy=0;
drv->mouse_moved(joyx, joyy);
break;
case GP2X_BUTTON_DOWNRIGHT :
joyx++;
joyy++;
if (joyy>widthy) joyy=widthy;
if (joyx>widthx) joyx=widthx;
drv->mouse_moved(joyx, joyy);
break;
case GP2X_BUTTON_UPRIGHT :
joyy--;
joyx++;
if (joyx>widthx) joyx=widthx;
if (joyy<0) joyy=0;
drv->mouse_moved(joyx, joyy);
break;
case GP2X_BUTTON_DOWNLEFT :
joyy++;
joyx--;
if (joyx<0) joyx=0;
if (joyy>widthy) joyy=widthy;
drv->mouse_moved(joyx, joyy);
break;
}
}
}