Example #1
0
/**
 * @brief This function is called when there is an input event.
 *
 * It handles the events common to all screens:
 * closing the window, pressing F5 or a debug key.
 * The notify_event() method of the current screen
 * is then called.
 */
void Solarus::notify_event(InputEvent& event) {

  // handle the common events
  InputEvent::KeyboardKey key = event.get_keyboard_key();

  if (event.is_window_closing()) {
    exiting = true;
  }
  else if (event.is_keyboard_key_pressed()) {
    // a key is pressed
    if (key == InputEvent::KEY_F5) {
      // F5: change the video mode
      VideoManager::get_instance()->switch_video_mode();
    }
    else if (key == InputEvent::KEY_RETURN
        && (event.is_alt_down() || event.is_control_down())) {
      // Alt + Return or Ctrl + Return: switch fullscreen
      VideoManager::get_instance()->switch_fullscreen();
    }
    else if (key == InputEvent::KEY_F4 && event.is_alt_down()) {
      // Alt + F4: quit the program
      exiting = true;
    }
#if defined(PANDORA)
    else if (key == InputEvent::KEY_ESCAPE) {
      exiting = true;
    }
#endif
    else {
      debug_keys->key_pressed(key);
    }
  }
  else if (event.is_keyboard_key_released()) {
    // a key is released
    debug_keys->key_released(key);
  }

  // send the event to the current screen
  current_screen->notify_event(event);
}