Exemplo n.º 1
0
bool DEV_EventConsumer::processEvent(GHOST_IEvent *event)
{
	GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
	switch (event->getType()) {
		case GHOST_kEventButtonDown:
		{
			HandleButtonEvent(eventData, true);
			break;
		}

		case GHOST_kEventButtonUp:
		{
			HandleButtonEvent(eventData, false);
			break;
		}

		case GHOST_kEventWheel:
		{
			HandleWheelEvent(eventData);
			break;
		}

		case GHOST_kEventCursorMove:
		{
			HandleCursorEvent(eventData, event->getWindow());
			break;
		}

		case GHOST_kEventKeyDown:
		{
			HandleKeyEvent(eventData, true);
			break;
		}
		case GHOST_kEventKeyUp:
		{
			HandleKeyEvent(eventData, false);
			break;
		}
		case GHOST_kEventWindowSize:
		case GHOST_kEventWindowClose:
		case GHOST_kEventQuit:
		{
			HandleWindowEvent(event->getType());
			break;
		}
		default:
			break;
	}

	return true;
}
Exemplo n.º 2
0
/** Process an event. */
void ProcessEvent(XEvent *event)
{
   switch(event->type) {
   case ButtonPress:
   case ButtonRelease:
      HandleButtonEvent(&event->xbutton);
      break;
   case KeyPress:
      HandleKeyPress(&event->xkey);
      break;
   case KeyRelease:
      HandleKeyRelease(&event->xkey);
      break;
   case EnterNotify:
      HandleEnterNotify(&event->xcrossing);
      break;
   case MotionNotify:
      while(JXCheckTypedEvent(display, MotionNotify, event));
      UpdateTime(event);
      HandleMotionNotify(&event->xmotion);
      break;
   case LeaveNotify:
   case DestroyNotify:
   case Expose:
   case ConfigureNotify:
      break;
   default:
      Debug("Unknown event type: %d", event->type);
      break;
   }
}
Exemplo n.º 3
0
/*! Changes the state variable associated with the button specified
 *
 * The purpose of the state change being a function call is so that there is a
 * consistent place to determine a state change.  State changes normally cause
 * an event, so we want only one place that does that.
 *
 * \param btnIndex index of the button ( 0 to 7 )
 * \param btnState the button state to change to
 *
 */
static void ChangeButtonState(unsigned char btnIndex, unsigned char btnState)
{

  /* pressing and releasing the button will cause menu change
   *
   * but holding the button will cause execution
   *
   */
  if (   btnState == BUTTON_STATE_PRESSED
      && ButtonData[btnIndex].BtnState == BUTTON_STATE_DEBOUNCE
      && GetButtonImmediateModeMask(btnIndex) == 0)
  {
    HandleButtonEvent(btnIndex,BUTTON_STATE_IMMEDIATE);

    /* need to know that we are in the immediate state, but go to the
     * button pressed state
     */
    btnState = BUTTON_STATE_PRESSED;
  }
  else if (   btnState == BUTTON_STATE_OFF
           && ButtonData[btnIndex].BtnState == BUTTON_STATE_PRESSED )
  {
    HandleButtonEvent(btnIndex,BUTTON_STATE_PRESSED);
  }
  else if (   btnState == BUTTON_STATE_OFF
           && ButtonData[btnIndex].BtnState == BUTTON_STATE_HOLD )
  {
    HandleButtonEvent(btnIndex,BUTTON_STATE_HOLD);
  }
  else if (   btnState == BUTTON_STATE_OFF
           && ButtonData[btnIndex].BtnState == BUTTON_STATE_LONG_HOLD )
  {
    HandleButtonEvent(btnIndex,BUTTON_STATE_LONG_HOLD);
  }

  /* Update the state of the specified button after we have detected
   * a possible edge
   */
  ButtonData[btnIndex].BtnState = btnState;

}
Exemplo n.º 4
0
bool JSInput::ReadEvents()
{
  if(js_FD_ == -1)
  {
    return false;
  }

  int read_return = 0;

  //js event struct to read joystick input into
  struct js_event event;
  memset(&event,0, sizeof(js_event));

  do
  {
    read_return = read(js_FD_, &event, sizeof(struct js_event));
    if(read_return>0)
    {
      switch (event.type) {
        case JS_EVENT_AXIS:
          HandleAxisEvent(event);
          break;
        case JS_EVENT_BUTTON:
          HandleButtonEvent(event);
          break;
        case JS_EVENT_INIT:
          HandleInitEvent(event);
          break;
        default:
          //std::cout << "Unable to handle JS Event type: " << int(event.type) << std::endl;
          break;
      }

    }
  }
  while (read_return > 0);

  return true;
}
Exemplo n.º 5
0
void EventLoop(void)
{
  while (1)
  {
    if (PendingEvent())		/* got event */
    {
      Event event;

      while (NextValidEvent(&event))
      {
  	switch (event.type)
  	{
  	  case EVENT_BUTTONPRESS:
  	  case EVENT_BUTTONRELEASE:
  	    HandleButtonEvent((ButtonEvent *) &event);
  	    break;
  
  	  case EVENT_MOTIONNOTIFY:
  	    HandleMotionEvent((MotionEvent *) &event);
  	    break;
  
  	  case EVENT_KEYPRESS:
  	  case EVENT_KEYRELEASE:
  	    HandleKeyEvent((KeyEvent *) &event);
  	    break;
  
  	  default:
  	    HandleOtherEvents(&event);
  	    break;
  	}
      }
    }
    else
    {
      /* when playing, display a special mouse pointer inside the playfield */
      if (game_status == GAME_MODE_PLAYING && !tape.pausing)
      {
	if (!playfield_cursor_set && cursor_inside_playfield &&
	    DelayReached(&playfield_cursor_delay, 1000))
	{
	  SetMouseCursor(CURSOR_PLAYFIELD);
	  playfield_cursor_set = TRUE;
	}
      }
      else if (playfield_cursor_set)
      {
	SetMouseCursor(CURSOR_DEFAULT);
	playfield_cursor_set = FALSE;
      }

      HandleNoEvent();
    }

    /* don't use all CPU time when idle; the main loop while playing
       has its own synchronization and is CPU friendly, too */

    if (game_status == GAME_MODE_PLAYING)
    {
      HandleGameActions();
    }
    else
    {
      SyncDisplay();
      if (!PendingEvent())	/* delay only if no pending events */
	Delay(10);
    }

    /* refresh window contents from drawing buffer, if needed */
    BackToFront();

    if (game_status == GAME_MODE_QUIT)
      return;
  }
}