Exemplo n.º 1
0
int
gp2xCtrlPeekBufferPositive(gp2xCtrlData* c, int v)
{
  SDL_Event SDLEvent;

  int Event         = 0;
  int ButtonPress   = 0;
  int ButtonRelease = 0;
  int Mask = 0;

  memset(c, 0x0, sizeof(gp2xCtrlData));
  loc_CurrTimeStamp = SDL_GetTicks() * 1000;

  if (SDL_PollEvent(&SDLEvent)) {
#if defined(GP2X_MODE) || defined(WIZ_MODE)
    Event = SDLEvent.jbutton.button;
    if (SDLEvent.type==SDL_JOYBUTTONDOWN) ButtonPress = 1;
    else
    if (SDLEvent.type==SDL_JOYBUTTONUP) ButtonRelease = 1;
#else
    Event=((SDL_KeyboardEvent*)(&SDLEvent))->keysym.scancode;
    if (SDLEvent.type==SDL_KEYDOWN) {
      ButtonPress = 1;
    } else
    if (SDLEvent.type==SDL_KEYUP) {
      ButtonRelease = 1;
    }
#endif

    switch (Event) {
      case GP2X_UP        : Mask = GP2X_CTRL_UP;
      break;
      case GP2X_DOWN      : Mask = GP2X_CTRL_DOWN;
      break;
      case GP2X_LEFT      : Mask = GP2X_CTRL_LEFT;
      break;
      case GP2X_RIGHT     : Mask = GP2X_CTRL_RIGHT;
      break;
      case GP2X_UPLEFT    : Mask = GP2X_CTRL_UPLEFT;
      break;
      case GP2X_UPRIGHT   : Mask = GP2X_CTRL_UPRIGHT;
      break;
      case GP2X_DOWNLEFT  : Mask = GP2X_CTRL_DOWNLEFT;
      break;
      case GP2X_DOWNRIGHT : Mask = GP2X_CTRL_DOWNRIGHT;
      break;
      case GP2X_A         : Mask = GP2X_CTRL_SQUARE;
      break;
      case GP2X_B         : Mask = GP2X_CTRL_CIRCLE;
      break;
      case GP2X_X         : Mask = GP2X_CTRL_CROSS;
      break;
      case GP2X_Y         : Mask = GP2X_CTRL_TRIANGLE;
      break;
      case GP2X_L         : Mask = GP2X_CTRL_LTRIGGER;
      break;
      case GP2X_R         : Mask = GP2X_CTRL_RTRIGGER;
      break;
      case GP2X_FIRE      : Mask = GP2X_CTRL_FIRE;
      break;
      case GP2X_START     : Mask = GP2X_CTRL_START;
      break;
      case GP2X_SELECT    : Mask = GP2X_CTRL_SELECT;
      break;
      case GP2X_VOLUP     : Mask = GP2X_CTRL_VOLUP;
      break;
      case GP2X_VOLDOWN   : Mask = GP2X_CTRL_VOLDOWN;
      break;
    }
    loc_LastEventMask = loc_CurrEventMask;
    if (ButtonPress) {
      loc_CurrEventMask |= Mask;
    } else
    if (ButtonRelease) {
      loc_CurrEventMask &= ~Mask;
    }
    loc_CurrEventButtons = gp2xConvertMaskToButtons(loc_CurrEventMask);
    c->Buttons   = loc_CurrEventButtons;
    c->TimeStamp = loc_CurrTimeStamp;

    loc_LastTimeStamp = loc_CurrTimeStamp;

  } else {
    c->Buttons   = loc_CurrEventButtons;
    c->TimeStamp = loc_CurrTimeStamp;
  }

  gp2xTreatVolume(c);

  return (c->Buttons != 0);
}
Exemplo n.º 2
0
int  
gp2xCtrlPeekBufferPositive(gp2xCtrlData* c, int v)
{
  SDL_Event SDLEvent;    

  int cx			= 0;
  int cy			= 0;
  int Event         = 0;
  int ButtonPress   = 0;
  int ButtonRelease = 0;
  int Mask = 0;

  memset(c, 0x0, sizeof(gp2xCtrlData));
  loc_CurrTimeStamp = SDL_GetTicks() * 1000;

  if (SDL_PollEvent(&SDLEvent)) {
	Event = SDLEvent.key.keysym.sym;
    
    if (SDLEvent.type==SDL_KEYDOWN)			ButtonPress = 1;		else
    if (SDLEvent.type==SDL_KEYUP)			ButtonRelease = 1;		else
    if (SDLEvent.type==SDL_MOUSEBUTTONDOWN)	ButtonPress = 1;		else
    if (SDLEvent.type==SDL_MOUSEBUTTONUP)	ButtonRelease = 1;
    
    if(SDLEvent.button.button==SDL_BUTTON_LEFT) {
    	// Touched Screen
    	cx=SDLEvent.button.x;
    	cy=SDLEvent.button.y;
    	if(PointOver(cx, cy,   0,   0, 100, 120))		Mask = GP2X_CTRL_VOLUP;		else
    	if(PointOver(cx, cy,   0, 120, 100, 120))		Mask = GP2X_CTRL_VOLDOWN;	else
    	if(PointOver(cx, cy, 210,   0, 110,  80))		Mask = GP2X_CTRL_SQUARE;	else
    	if(PointOver(cx, cy, 210,  80, 110,  80))		Mask = GP2X_CTRL_CIRCLE;	else
    	if(PointOver(cx, cy, 210, 160, 110,  80))		Mask = GP2X_CTRL_CROSS;		else
    	if(PointOver(cx, cy, 100,   0, 110, 240))		Mask = GP2X_CTRL_TRIANGLE;
    }
    
    	// Check pressed button
		switch (Event) {
		  			  case SDLK_UP       	: Mask = GP2X_CTRL_UP;			// UP
		  break;      case SDLK_DOWN      	: Mask = GP2X_CTRL_DOWN;		// DOWN
		  break;      case SDLK_LEFT      	: Mask = GP2X_CTRL_LEFT;		// LEFT
		  break;      case SDLK_RIGHT     	: Mask = GP2X_CTRL_RIGHT;		// RIGHT
//		  break;      case SDLK_3    		: Mask = GP2X_CTRL_UPLEFT;		// XXX
//		  break;      case SDLK_9   		: Mask = GP2X_CTRL_UPRIGHT;		// XXX
//		  break;      case SDLK_1  			: Mask = GP2X_CTRL_DOWNLEFT;	// XXX
//		  break;      case SDLK_7 			: Mask = GP2X_CTRL_DOWNRIGHT;	// XXX
		  break;      case SDLK_MINUS 	    : Mask = GP2X_CTRL_LTRIGGER;	// -
		  break;      case SDLK_PLUS  		: Mask = GP2X_CTRL_RTRIGGER;	// +
		  break;      case SDLK_RETURN      : Mask = GP2X_CTRL_FIRE;		// OK
		  break;      case SDLK_PAUSE     	: Mask = GP2X_CTRL_START;		// HANGUP
		  break;      case SDLK_SPACE		: Mask = GP2X_CTRL_SELECT;		// CALL
		  break;
		}
	
    loc_LastEventMask = loc_CurrEventMask;
    if (ButtonPress) {
      loc_CurrEventMask |= Mask;
    } else 
    if (ButtonRelease) {
      loc_CurrEventMask &= ~Mask;
    }
    loc_CurrEventButtons = gp2xConvertMaskToButtons(loc_CurrEventMask);
    c->Buttons   = loc_CurrEventButtons;
    c->TimeStamp = loc_CurrTimeStamp;

    loc_LastTimeStamp = loc_CurrTimeStamp;

  } else {
    c->Buttons   = loc_CurrEventButtons;
    c->TimeStamp = loc_CurrTimeStamp;
  }

  gp2xTreatVolume(c);

  return (c->Buttons != 0);
}