void Camera::keyboardEvent(KeyEvent & e) { //std::cout << "Keyboard Event: " << e.ToString() << "\n"; print = true; switch (e.GetKeyCode()) { case GLFW_KEY_W: m_Position += moveSpeed * m_Forward * m_DeltaTime; break; case GLFW_KEY_S: m_Position -= moveSpeed * m_Forward * m_DeltaTime; break; case GLFW_KEY_A: m_Position -= m_Right * moveSpeed * m_DeltaTime; break; case GLFW_KEY_D: m_Position += m_Right * moveSpeed * m_DeltaTime; break; case GLFW_KEY_E: m_Position += m_Up * moveSpeed * m_DeltaTime; break; case GLFW_KEY_Q: m_Position -= m_Up * moveSpeed * m_DeltaTime; break; case GLFW_KEY_ESCAPE: glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); break; default: break; } print = true; std::cout << "Yaw: " << m_Yaw << " Pitch: " << m_Pitch << "\n"; //std::cout << "Position: " << m_Position.x << " " << m_Position.y << " " << m_Position.z << "\n"; }
bool FocusManager::OnKeyEvent(const KeyEvent& event) { // If the focused view wants to process the key event as is, let it be. // On Linux we always dispatch key events to the focused view first, so // we should not do this check here. See also WidgetGtk::OnKeyEvent(). if(focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event)) { return true; } // Intercept Tab related messages for focus traversal. // Note that we don't do focus traversal if the root window is not part of the // active window hierarchy as this would mean we have no focused view and // would focus the first focusable view. HWND top_window = widget_->GetNativeView(); HWND active_window = ::GetActiveWindow(); if((active_window==top_window || ::IsChild(active_window, top_window)) && IsTabTraversalKeyEvent(event)) { AdvanceFocus(event.IsShiftDown()); return false; } // Intercept arrow key messages to switch between grouped views. KeyboardCode key_code = event.GetKeyCode(); if(focused_view_ && focused_view_->GetGroup()!=-1 && (key_code==VKEY_UP || key_code==VKEY_DOWN || key_code==VKEY_LEFT || key_code==VKEY_RIGHT)) { bool next = (key_code==VKEY_RIGHT || key_code==VKEY_DOWN); std::vector<View*> views; focused_view_->GetParent()->GetViewsWithGroup( focused_view_->GetGroup(), &views); std::vector<View*>::const_iterator iter = std::find(views.begin(), views.end(), focused_view_); DCHECK(iter != views.end()); int index = static_cast<int>(iter - views.begin()); index += next ? 1 : -1; if(index < 0) { index = static_cast<int>(views.size()) - 1; } else if(index >= static_cast<int>(views.size())) { index = 0; } SetFocusedViewWithReason(views[index], kReasonFocusTraversal); return false; } // Process keyboard accelerators. // If the key combination matches an accelerator, the accelerator is // triggered, otherwise the key event is processed as usual. Accelerator accelerator(event.GetKeyCode(), event.IsShiftDown(), event.IsControlDown(), event.IsAltDown()); if(ProcessAccelerator(accelerator)) { // If a shortcut was activated for this keydown message, do not propagate // the event further. return false; } return true; }
// static bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) { return key_event.GetKeyCode() == VKEY_TAB && !key_event.IsControlDown(); }
void SubSectionMenu::HandleEvent(Event* aEvent) { switch(aEvent->GetEventCode()) { case BUTTON_ACTION: { //If the scene isn't active, then we want to ignore all button action events if(ServiceLocator::GetSceneManager()->IsActiveScene(this) == false) { return; } //Get the button pointer from the event data Button* button = (Button*)aEvent->GetEventData(); int index = -1; //Determine the index of the button that was pressed const unsigned int buttonCount = WORLD_NUMBER_OF_SUBSECTIONS.x * WORLD_NUMBER_OF_SUBSECTIONS.y; for(unsigned int i = 0; i < buttonCount; i++) { if(button == m_Buttons[i]) { index = i; break; } } //Safety check the index if(index != -1) { //Check the coordinates for the uvec2 coordinates = uvec2(0,0); coordinates.x = (index % WORLD_NUMBER_OF_SUBSECTIONS.x); coordinates.y = ((index - coordinates.x) / WORLD_NUMBER_OF_SUBSECTIONS.x); //Set the filename, based on the button's coordinates stringstream ss; ss << "SubSection" << coordinates.x << "-" << coordinates.y << ".bin"; //Are we saving OR loading? if(m_SaveSubSection != nullptr) { m_SaveSubSection->Save(ss.str()); m_SaveSubSection = nullptr; } else if(m_LoadSubSection != nullptr) { m_LoadSubSection->Load(ss.str()); m_LoadSubSection = nullptr; } //We the save OR load operation is done, pop the sub-section menu ServiceLocator::GetSceneManager()->Pop(); } } break; case KEYBOARD_EVENT: { KeyEvent* keyEvent = (KeyEvent*)aEvent; if(keyEvent->GetKeyEventType() == KeyUp) { //If the escape key is pressed, pop the sub-section menu if(keyEvent->GetKeyCode() == KEY_CODE_ESCAPE) { ServiceLocator::GetSceneManager()->Pop(); } } } break; } }