world(game& g) : m_entity_handler{g} { on_key_pressed(key::D) += [this]{this->c_player();}; on_btn_pressed(btn::Left) += [this](const vec2f& pos){this->c_ent(pos);}; on_btn_pressed(btn::Right) += [this](const vec2f& pos){this->c_ent_death(pos);}; on_key_pressed(key::A) += [this]{this->c_world();}; }
void GUIManager::update(const Input::Event& event) { switch (event.type) { case Input::POINTER_EVENT_TYPE: mouse_pos.x = int(event.pointer.x); mouse_pos.y = int(event.pointer.y); on_pointer_move(mouse_pos.x, mouse_pos.y); break; case Input::BUTTON_EVENT_TYPE: if (event.button.name == PRIMARY_BUTTON) { if (event.button.state == Input::BUTTON_PRESSED) on_primary_button_press(mouse_pos.x, mouse_pos.y); else if (event.button.state == Input::BUTTON_RELEASED) on_primary_button_release(mouse_pos.x, mouse_pos.y); } else if (event.button.name == SECONDARY_BUTTON) { if (event.button.state == Input::BUTTON_PRESSED) on_secondary_button_press(mouse_pos.x, mouse_pos.y); else if (event.button.state == Input::BUTTON_RELEASED) on_secondary_button_release(mouse_pos.x, mouse_pos.y); } break; case Input::AXIS_EVENT_TYPE: // AxisEvents can be ignored in the GUI, they are handled elsewhere log_debug("GUIManager: AxisEvent: %1%", event.axis.dir); break; case Input::KEYBOARD_EVENT_TYPE: if (event.keyboard.state) { on_key_pressed(event.keyboard); } else { //FIXME: implement this on_key_release(event.keyboard); } break; case Input::SCROLLER_EVENT_TYPE: on_scroller_move(event.scroll.x_delta, event.scroll.y_delta); break; default: log_warn("unhandled event type %1%", event.type); break; } }
void GUIManager::update(const Input::Event& event) { switch (event.type) { case Input::POINTER_EVENT_TYPE: mouse_pos.x = int(event.pointer.x); mouse_pos.y = int(event.pointer.y); on_pointer_move(mouse_pos.x, mouse_pos.y); break; case Input::BUTTON_EVENT_TYPE: if (event.button.name == PRIMARY_BUTTON) { if (event.button.state == Input::BUTTON_PRESSED) on_primary_button_press(mouse_pos.x, mouse_pos.y); else if (event.button.state == Input::BUTTON_RELEASED) on_primary_button_release(mouse_pos.x, mouse_pos.y); } else if (event.button.name == SECONDARY_BUTTON) { if (event.button.state == Input::BUTTON_PRESSED) on_secondary_button_press(mouse_pos.x, mouse_pos.y); else if (event.button.state == Input::BUTTON_RELEASED) on_secondary_button_release(mouse_pos.x, mouse_pos.y); } break; case Input::AXIS_EVENT_TYPE: // AxisEvents can be ignored in the GUI, they are handled elsewhere pout(PINGUS_DEBUG_GUI) << "GUIManager: AxisEvent: " << event.axis.dir << std::endl; break; case Input::KEYBOARD_EVENT_TYPE: on_key_pressed(event.keyboard.key); break; case Input::SCROLLER_EVENT_TYPE: on_scroller_move(event.scroll.x_delta, event.scroll.y_delta); break; default: pwarn (PINGUS_DEBUG_GUI) << "GUIManager: unhandled event type " << event.type << std::endl; break; } }
int menu(void* scrbuf, const char* menuentries[]) { int selecteditem = 1; int lastitem; int blockarrow = 0; int inputpause = INPUTPAUSE; while (1) { sleep(10); //results in around 63 fps lastitem = dispMenu(scrbuf, 0, 0, menuentries, selecteditem); showBuffer(scrbuf); //closing menu: if (isKeyPressed(KEY_NSPIRE_ESC) || on_key_pressed()) return 0; //choosing an option: if (isKeyPressed(KEY_NSPIRE_ENTER)) return selecteditem; //navigating: if (isKeyPressed(KEY_NSPIRE_UP) && (blockarrow != 0x1 || inputpause <= 0)) { inputpause = INPUTPAUSE; blockarrow = 0x1; selecteditem--; if (selecteditem == 0) selecteditem = lastitem; } else if (isKeyPressed(KEY_NSPIRE_DOWN) && (blockarrow != 0x2 || inputpause <= 0)) { inputpause = INPUTPAUSE; blockarrow = 0x2; selecteditem++; if (selecteditem > lastitem) selecteditem = 1; } if (!isKeyPressed(KEY_NSPIRE_UP) && !isKeyPressed(KEY_NSPIRE_DOWN)) blockarrow = 0; else inputpause--; } }
/** * @brief Calls an input callback method of the object on top of the stack. * @param event The input event to forward. * @return \c true if the event was handled and should stop being propagated. */ bool LuaContext::on_input(InputEvent& event) { // Call the Lua function(s) corresponding to this input event. bool handled = false; if (event.is_keyboard_event()) { // Keyboard. if (event.is_keyboard_key_pressed()) { handled = on_key_pressed(event) || handled;/* if (event.is_character_pressed()) { handled = on_character_pressed(event) || handled; }*/ } /* else if (event.is_keyboard_key_released()) { handled = on_key_released(event) || handled; } */ } //TODO Change this to mouse input events /* else if (event.is_joypad_event()) { // Joypad. if (event.is_joypad_button_pressed()) { handled = on_joypad_button_pressed(event) || handled; } else if (event.is_joypad_button_released()) { handled = on_joypad_button_released(event) || handled; } else if (event.is_joypad_axis_moved()) { handled = on_joypad_axis_moved(event) || handled; } else if (event.is_joypad_hat_moved()) { handled = on_joypad_hat_moved(event) || handled; } }*/ return handled; }
state_handler(game_window& window, game& g, main_menu& menu) : m_game_window{window}, m_game{g}, m_menu{menu}, m_debug_info{m_game} { // m_current_state |= state::main_menu; m_current_state |= state::game; m_states[state::game] += [this](dur duration){m_game.update(duration); m_game.render();}; m_states[state::main_menu] += [this](dur duration){m_menu.update(duration);}; m_game_window.get_updater().on_update += [this](dur duration){this->update(duration);}; m_game_window.get_updater().on_render += [this]{this->render();}; on_key_pressed(key::P) += [this] { if(m_current_state & state::game) {this->set_only_state(state::game_menu); return;} if(m_current_state & state::game_menu) {this->set_only_state(state::game); return;} }; }
void Screen::process_event (const SDL_Event& event) { Control* under_cursor; Control* par; switch (event.type) { case SDL_KEYDOWN: on_key_pressed (event.key); break; case SDL_MOUSEBUTTONDOWN: under_cursor = control_at_pos (event.button.x, event.button.y); on_mouse_button (event.button); if (event.button.button == SDL_BUTTON_LEFT) { be_clicked = under_cursor; if (be_clicked->is_focusable ()) be_clicked->grab_focus (); } break; case SDL_MOUSEBUTTONUP: under_cursor = control_at_pos (event.button.x, event.button.y); on_mouse_button (event.button); if (event.button.button == SDL_BUTTON_LEFT) { par = under_cursor; while (par != popup && par != NULL) { par = par->get_parent (); } if (under_cursor == be_clicked) { be_clicked->on_clicked (); } if (par == NULL) { remove_popup (!(under_cursor->is_focusable () && under_cursor->is_focused ())); } be_clicked = NULL; } break; case SDL_MOUSEMOTION: under_cursor = control_at_pos (event.motion.x, event.motion.y); set_mouse_target (under_cursor); on_mouse_move (event.motion); break; case SDL_ACTIVEEVENT: switch (event.active.state) { case SDL_APPMOUSEFOCUS: if (event.active.gain) { int x, y; SDL_GetMouseState (&x, &y); under_cursor = control_at_pos (x, y); set_mouse_target (under_cursor); } else { set_mouse_target (NULL); } break; } break; case E_SHOW_POPUP: remove_popup (false); add_popup (static_cast<Control*> (event.user.data1), static_cast<Control*> (event.user.data2)); break; case E_HIDE_POPUP: remove_popup (true); break; } }