void TypingModule::ProcessEvent(InputEvent & InputEvent) { if (InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT)) { if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory()) { auto ButtonId = InputEvent.m_InputId; bool Pressed = InputEvent.m_Buttons[0]; // TODO: Check if there are >1 buttons if (Pressed) { switch (ButtonId) { case GLFW_KEY_BACKSPACE: { // Erase the last character in string if (!m_Typed.empty()) { m_Typed.erase(m_Typed.end() - 1); } InputEvent.m_Handled = true; } break; case GLFW_KEY_DEL: { // Erase the entire string m_Typed.clear(); InputEvent.m_Handled = true; } break; case GLFW_KEY_ESC: if (!m_Typed.empty()) { // Erase the entire string m_Typed.clear(); InputEvent.m_Handled = true; } break; default: break; } } } } }
void GestureRecognizer::ProcessEvent(InputEvent & InputEvent) { // DEBUG: This check is probably not needed anymore... it should always pass, due to new architecture if (true == InputEvent.m_Handled) { printf("Exception in void GestureRecognizer::ProcessEvent(InputEvent & InputEvent), InputEvent.m_Handled is not false!"); throw 0; return; } // DECISION /*#if 1 // TEST: Capture the pointer if the pointer is activated (via primary button) if ( InputEvent.HasType(InputEvent::EventType::POINTER_ACTIVATION) && ( InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT) && 0 == InputEvent.m_InputId && true == InputEvent.m_Buttons[0])) { InputEvent.m_Pointer->ModifyPointerMapping().RequestPointerCapture(this); } // Release the pointer capture if the pointer is deactivated if (InputEvent.HasType(InputEvent::EventType::POINTER_DEACTIVATION)) { InputEvent.m_Pointer->ModifyPointerMapping().RequestPointerRelease(this); } #endif*/ // EXPERIMENTAL /*if ( m_RecognizeDoubleTap && !InputEvent.m_Handled) { if ( InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT) && 0 == InputEvent.m_InputId && false == InputEvent.m_Buttons[0] && std::fabs(InputEvent.m_Pointer->GetPointerState().GetTimestamp() - m_LastTapCompletedStateTEST.GetTimestamp()) <= 0.400 && (Vector2n(InputEvent.m_Pointer->GetPointerState().GetAxisState(0).GetPosition(), InputEvent.m_Pointer->GetPointerState().GetAxisState(1).GetPosition()) - Vector2n(m_LastTapStateTEST.GetAxisState(0).GetPosition(), m_LastTapStateTEST.GetAxisState(1).GetPosition())).LengthSquared() <= (3 * 3)) { printf("Recognized a double tap of %f ms.\n", std::fabs(InputEvent.m_Pointer->GetPointerState().GetTimestamp() - m_LastTapCompletedStateTEST.GetTimestamp()) * 1000); InputEvent.m_Handled = true; m_Owner.ProcessDoubleTap(InputEvent, Vector2n(m_LastTapStateTEST.GetAxisState(0).GetPosition(), m_LastTapStateTEST.GetAxisState(1).GetPosition())); m_LastTapCompletedStateTEST.InvalidateTEST(); } }*/ // TODO: Fix bug where dragging the object out of down-event range and then bringing it back still activates the tap (it shouldn't) /*if ( m_RecognizeTap && !InputEvent.m_Handled) { if ( InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT) && 0 == InputEvent.m_InputId && true == InputEvent.m_Buttons[0]) { m_LastTapStateTEST = InputEvent.m_Pointer->GetPointerState(); } else if ( InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT) && 0 == InputEvent.m_InputId && false == InputEvent.m_Buttons[0] //&& std::fabs(InputEvent.m_Timestamp - m_LastTapEventTEST.m_Timestamp) <= 1.0) && (Vector2n(InputEvent.m_Pointer->GetPointerState().GetAxisState(0).GetPosition(), InputEvent.m_Pointer->GetPointerState().GetAxisState(1).GetPosition()) - Vector2n(m_LastTapStateTEST.GetAxisState(0).GetPosition(), m_LastTapStateTEST.GetAxisState(1).GetPosition())).LengthSquared() <= (3 * 3)) { printf("Recognized a tap.\n"); InputEvent.m_Handled = true; m_Owner.ProcessTap(InputEvent, Vector2n(m_LastTapStateTEST.GetAxisState(0).GetPosition(), m_LastTapStateTEST.GetAxisState(1).GetPosition())); m_LastTapCompletedStateTEST = m_LastTapStateTEST; } }*/ //if (m_RecognizeDrag) /*{ if ( InputEvent.HasType(InputEvent::EventType::AXIS_EVENT) && 0 == InputEvent.m_InputId && true == InputEvent.GetPointerState().GetButtonState(0)) { //printf("Recognized a drag by (%d, %d).\n", InputEvent.m_Sliders[0], InputEvent.m_Sliders[1]); //double Scaler = GetAttached().size(); //printf("GetAttached().size() %d\n", GetAttached().size()); //m_Owner.ProcessDrag(Vector2d(InputEvent.m_Sliders[0] / Scaler, InputEvent.m_Sliders[1] / Scaler)); m_Owner.ProcessDrag(Vector2d(InputEvent.m_Sliders[0], InputEvent.m_Sliders[1])); // TODO: Figure out this GetAttached() stuff } }*/ if ( m_RecognizeScroll && !InputEvent.m_Handled) { if ( InputEvent.HasType(InputEvent::EventType::AXIS_EVENT) && 2 == InputEvent.m_InputId) { //printf("Recognized a wheel move by %d.\n", InputEvent.m_Sliders[0]); m_Owner.ProcessScroll(InputEvent, Vector2n(InputEvent.m_Sliders[0], InputEvent.m_Sliders[1])); InputEvent.m_Handled = true; } } // TODO: Support for manipulation with >1 pointer simultaneously (including translation, as well as rotation/scale) /*if ( m_RecognizeManipulationTranslate && !InputEvent.m_Handled) { if ( InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT) && 0 == InputEvent.m_InputId && true == InputEvent.m_Buttons[0]) { m_InManipulation = true; m_Owner.ProcessManipulationBegin(InputEvent.m_Pointer->GetPointerState()); // DECISION //InputEvent.m_Pointer->ModifyPointerMapping().RequestPointerCapture(this); // TEST InputEvent.m_Handled = true; } if ( InputEvent.HasType(InputEvent::EventType::AXIS_EVENT) && 0 == InputEvent.m_InputId && true == InputEvent.m_Pointer->GetPointerState().GetButtonState(0)) { //double Scaler = GetAttached().size(); m_Owner.ProcessManipulationUpdate(InputEvent.m_Pointer->GetPointerState()); // DECISION //InputEvent.m_Pointer->ModifyPointerMapping().RequestPointerCapture(this); // TEST InputEvent.m_Handled = true; } if ( InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT) && 0 == InputEvent.m_InputId && false == InputEvent.m_Buttons[0]) { m_InManipulation = false; m_Owner.ProcessManipulationEnd(InputEvent.m_Pointer->GetPointerState()); // DECISION //InputEvent.m_Pointer->ModifyPointerMapping().RequestPointerRelease(this); // TEST InputEvent.m_Handled = true; } }*/ //if ( m_RecognizeCharacters if ( true && !InputEvent.m_Handled) { if (InputEvent.HasType(InputEvent::EventType::CHARACTER_EVENT)) { m_Owner.ProcessCharacter(InputEvent, InputEvent.m_InputId); //InputEvent.m_Handled = true; } } // TODO: There might be duplication here this way, I think I should eliminate it (by providing a complete alternative gesture-level api for all events // Low-level event passthrough if (!InputEvent.m_Handled) { m_Owner.ProcessEvent(InputEvent); } }
bool IsPointerPointingDeactivationEvent(const InputEvent & InputEvent) { return ( nullptr != InputEvent.m_Pointer && Pointer::VirtualCategory::POINTING == InputEvent.m_Pointer->GetVirtualCategory() && InputEvent.HasType(InputEvent::EventType::POINTER_DEACTIVATION)); }
void ConceptStringBoxWidget::ProcessEvent(InputEvent & InputEvent) { if (InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT)) { auto ButtonId = InputEvent.m_InputId; bool Pressed = InputEvent.m_Buttons[0]; // TODO: Check if there are >1 buttons if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory()) { if (Pressed) { bool HandledEvent = true; // Assume true at first switch (ButtonId) { case GLFW_KEY_BACKSPACE: /*{ // Erase the last concept if (false == m_Content.empty()) { m_Content.pop_back(); } InputEvent.m_Handled = true; }*/ break; case GLFW_KEY_ENTER: { } break; case GLFW_KEY_TAB: { } break; case GLFW_KEY_LEFT: { MoveCaretTry(-1, true); } break; case GLFW_KEY_RIGHT: { MoveCaretTry(+1, true); } break; default: HandledEvent = false; break; } if (HandledEvent) { InputEvent.m_Handled = true; } } } else if (Pointer::VirtualCategory::POINTING == InputEvent.m_Pointer->GetVirtualCategory()) { if (HasTypingFocus()) { if (Pressed) { bool HandledEvent = true; // Assume true at first switch (ButtonId) { case 0: { auto Entry = m_TypingModule.TakeString(); if (!Entry.empty()) { auto ConceptId = FindOrCreateConcept(Entry); m_Content.push_back(ConceptId); } else { if (!m_Content.empty()) { if (m_CaretPosition >= m_Content.size()) { MoveCaretTry(-1, true); } m_TypingModule.SetString(GetConcept(m_Content.back()).GetContent()); m_Content.pop_back(); } } } break; default: HandledEvent = false; break; } if (HandledEvent) { InputEvent.m_Handled = true; } } } } } }
void ConceptionApp::ProcessEvent(InputEvent & InputEvent) { // DEBUG, TEST: System key handling if (false == InputEvent.m_Handled) { if (InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT)) { if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory()) { auto ButtonId = InputEvent.m_InputId; bool Pressed = InputEvent.m_Buttons[0]; // TODO: Check if there are >1 buttons if (Pressed) { switch (ButtonId) { //case GLFW_KEY_F5: /*case 'R': if ( InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LSUPER) || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RSUPER)) { / *m_CurrentProject.GenerateProgram(m_SourceWidget->GetContent()); m_OutputWidget->SetContent(m_CurrentProject.RunProgram(m_OutputWidget));* / m_SourceWidget->m_OnChange(); InputEvent.m_Handled = true; } break;*/ // TEST /*case 'B': //if (glfwGetKey(GLFW_KEY_LCTRL) || glfwGetKey(GLFW_KEY_RCTRL)) { m_CurrentProject.GetStdIncludes().push_back(FindOrCreateConcept("test")); InputEvent.m_Handled = true; } break;*/ default: break; } } } } } App::ProcessEvent(InputEvent); // TODO, LOWER_PRIORITY: Perhaps generalize and standardize this back into App, removing need for overloaded ProcessEvent() if (false == InputEvent.m_Handled) { if (InputEvent.HasType(InputEvent::EventType::CHARACTER_EVENT)) { if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory()) { auto Character = InputEvent.m_InputId; m_TypingModule.ProcessCharacter(InputEvent, Character); } } m_TypingModule.ProcessEvent(InputEvent); } }
template <typename T> void MenuWidget<T>::ProcessEvent(InputEvent & InputEvent) { if (InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT)) { auto ButtonId = InputEvent.m_InputId; bool Pressed = InputEvent.m_Buttons[0]; // TODO: Check if there are >1 buttons if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory()) { if (Pressed) { const auto ControlActive = ( InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LCTRL) || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RCTRL)); const auto ShiftActive = ( InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LSHIFT) || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RSHIFT)); const auto SuperActive = ( InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LSUPER) || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RSUPER)); const auto AltActive = ( InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LALT) || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RALT)); bool HandledEvent = true; // Assume true at first switch (ButtonId) { case GLFW_KEY_UP: { if (!SuperActive) { if (m_SelectedEntryId > 0) SetSelectedEntryId(m_SelectedEntryId - 1); } else { SetSelectedEntryId(0); } } break; case GLFW_KEY_DOWN: { if (!SuperActive) { if (m_SelectedEntryId < m_Entries.size() - 1) SetSelectedEntryId(m_SelectedEntryId + 1); } else { SetSelectedEntryId(m_Entries.size() - 1); } } break; default: HandledEvent = false; break; } if (HandledEvent) { InputEvent.m_Handled = true; } } } } if (HasTypingFocus()) { if ( InputEvent.HasType(InputEvent::EventType::AXIS_EVENT) || InputEvent.HasType(InputEvent::EventType::CANVAS_MOVED_TEST)) { if (Pointer::VirtualCategory::POINTING == InputEvent.m_Pointer->GetVirtualCategory()) { if (true == InputEvent.m_Pointer->GetPointerState().GetButtonState(0)) { if (!( nullptr != m_TypingModule && !m_TypingModule->GetString().empty())) { Vector2n GlobalPosition(InputEvent.m_Pointer->GetPointerState().GetAxisState(0).GetPosition(), InputEvent.m_Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition = GlobalToLocal(GlobalPosition); SetSelectedEntryId(LocalPosition); } } } } } }