// DEBUG: Not sure if I should make such a distinction as "topmost" widget, or better to avoid it, or have a "request/accept focus" system so then it's topmost-widget-that-requested-focus bool Widget::HasTopmostTypingFocus() const { auto TypingPointerIterator = GetGestureRecognizer().GetConnected().find(g_InputManager->m_TypingPointer.get()); if (GetGestureRecognizer().GetConnected().end() != TypingPointerIterator) { return (&GetGestureRecognizer() == (*TypingPointerIterator)->GetPointerMapping().GetHoverer()); } else return false; }
bool Widget::CheckActive() const { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if ( &GetGestureRecognizer() == Pointer->GetPointerMapping().GetHoverer() // Pointer was hovering this very widged when pointer went active && true == Pointer->GetPointerState().GetButtonState(0)) // Pointer button 0 is down { return true; } } return false; }
bool Widget::CheckHover() const { // DEBUG: Why only loop over the connected pointers? If I'm using m_CurrentPointerMappingTEST, then it may not be connected at all... Doesn't make sense, I should fix this inconsistency for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (&GetGestureRecognizer() == Pointer->m_CurrentPointerMappingTEST.GetHoverer()) { return true; } } return false; }
void MultitouchTestBoxWidget::ProcessTimePassed(const double TimePassed) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::TYPING == Pointer->GetVirtualCategory()) { const PointerState & PointerState = Pointer->GetPointerState(); const double SpeedMultiplier = 250; if (PointerState.GetButtonState(GLFW_KEY_LEFT) && !PointerState.GetButtonState(GLFW_KEY_RIGHT)) { ModifyPosition().X() += -SpeedMultiplier * TimePassed; } else if (PointerState.GetButtonState(GLFW_KEY_RIGHT) && !PointerState.GetButtonState(GLFW_KEY_LEFT)) { ModifyPosition().X() += SpeedMultiplier * TimePassed; } if (PointerState.GetButtonState(GLFW_KEY_UP) && !PointerState.GetButtonState(GLFW_KEY_DOWN)) { ModifyPosition().Y() += -SpeedMultiplier * TimePassed; } else if (PointerState.GetButtonState(GLFW_KEY_DOWN) && !PointerState.GetButtonState(GLFW_KEY_UP)) { ModifyPosition().Y() += SpeedMultiplier * TimePassed; } } } Widget::ProcessTimePassed(TimePassed); }
template <typename T> void ListWidget<T>::UpdateDimensions() { Vector2n Dimensions; for (auto & Entry : m_List) { Dimensions.X() = std::max<sint32>(Dimensions.X(), Concept::GetDimensions(Entry).X()); Dimensions.Y() += Concept::GetDimensions(Entry).Y(); } // TEST if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Dimensions.X() = std::max<sint32>(Dimensions.X(), static_cast<sint32>(m_TypingModule.GetString().length() * charWidth)); Dimensions.Y() += 1 * lineHeight; break; } } } Vector2n MinDimensions(3 * charWidth, lineHeight); Dimensions.X() = std::max<sint32>(Dimensions.X(), MinDimensions.X()); Dimensions.Y() = std::max<sint32>(Dimensions.Y(), MinDimensions.Y()); SetDimensions(Dimensions); }
template <typename T> void ListWidget<T>::ProcessManipulationUpdated(const PointerState & PointerState) { if (!HasTypingFocus()) { auto ParentLocalPosition = GlobalToParent(Vector2n(PointerState.GetAxisState(0).GetPosition(), PointerState.GetAxisState(1).GetPosition())); ModifyPosition() = GetGestureRecognizer().m_ManipulationOffset + ParentLocalPosition; } }
void MultitouchTestBoxWidget::ProcessManipulationUpdate(const InputEvent & InputEvent) { const PointerState & PointerState = InputEvent.m_PostEventState; //printf("MultitouchTestBoxWidget::ProcessManipulationUpdate()\n"); /*Vector2d PositionDouble = GetParent()->GlobalToCanvas(Vector2n(PointerState.GetAxisState(0).GetPosition(), PointerState.GetAxisState(1).GetPosition())); Vector2n PositionInt(std::lround(PositionDouble.X()), std::lround(PositionDouble.Y())); // TODO: Loss of accuracy? Fix it if needed.*/ auto ParentLocalPosition = GlobalToParent(Vector2n(PointerState.GetAxisState(0).GetPosition(), PointerState.GetAxisState(1).GetPosition())); ModifyPosition() = GetGestureRecognizer().m_ManipulationOffset + ParentLocalPosition; }
template <typename T> void ListWidget<T>::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ // TODO: Think if I should outsource the entire rendering code for more generality // Draw list { UpdateDimensions(); // LATER: Optimize by not repeating this calculation each time, only when something changes? if (m_List.empty()) { BackgroundColor[0] = 234 / 255.0; BackgroundColor[1] = 233 / 255.0; BackgroundColor[2] = 190 / 255.0; } DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TODO: This part is not general std::string Description[2] = { "#include <", ">" }; glColor3d(0, 0, 0); OglUtilsPrint(GetPosition().X(), GetPosition().Y(), 0, RIGHT, Description[0].c_str()); glColor3d(0, 0, 0); OglUtilsPrint(GetPosition().X() + GetDimensions().X(), GetPosition().Y(), 0, LEFT, Description[1].c_str()); // TEST auto Spot = m_List.end(); if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); Spot = m_List.begin() + (LocalPosition.Y() / lineHeight); } } } OpenGLStream OpenGLStream(GetPosition()); for (auto ListEntry = m_List.begin(); m_List.end() != ListEntry; ++ListEntry) { if (ListEntry == Spot) OpenGLStream << endl; OpenGLStream << *ListEntry << endl; } } CompositeWidget::Render(); }
void ConceptStringBoxWidget::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ //if (CheckHover()) // HACK if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } /*glBegin(GL_QUADS); glVertex2d(m_Position.X(), m_Position.Y()); glVertex2d(m_Position.X(), m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y()); glEnd();*/ DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); glColor3d(0, 0, 0); OpenGLStream OpenGLStream(GetPosition()); //OpenGLStream << m_Content.substr(0, m_CaretPosition); // TODO: Optimize this somehow? OpenGLStream << decltype(m_Content)(m_Content.begin(), m_Content.begin() + m_CaretPosition); // TEST if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { //Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); //Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); //auto ConceptId = FindOrCreateConcept(Entry); OpenGLStream << m_TypingModule.GetString(); } } } Vector2n CaretPosition = OpenGLStream.GetCaretPosition(); //OpenGLStream << m_Content.substr(m_CaretPosition); // TODO: Optimize this somehow? OpenGLStream << decltype(m_Content)(m_Content.begin() + m_CaretPosition, m_Content.end()); //if (CheckHover()) // HACK if (HasTypingFocus()) { // Draw caret //if (static_cast<int>(glfwGetTime() * 2) % 2) { glPushMatrix(); glTranslated(CaretPosition.X(), CaretPosition.Y(), 0); glColor3d(0, 0, 0); glBegin(GL_QUADS); glVertex2d(-1, 0); glVertex2d(-1, lineHeight); glVertex2d(+1, lineHeight); glVertex2d(+1, 0); glEnd(); glPopMatrix(); } } }
template <typename T> void MenuWidget<T>::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ // HACK, TODO: Make this a single DRY const if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } // TODO: Think if I should outsource the entire rendering code for more generality // Draw list { UpdateDimensions(); // LATER: Optimize by not repeating this calculation each time, only when something changes? if (m_Entries.empty()) { BackgroundColor[0] = 234 / 255.0; BackgroundColor[1] = 233 / 255.0; BackgroundColor[2] = 190 / 255.0; } DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TEST auto Spot = m_Entries.end(); if ( nullptr != m_TypingModule && !m_TypingModule->GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); Spot = m_Entries.begin() + (LocalPosition.Y() / lineHeight); } } } OpenGLStream OpenGLStream(GetPosition()); //for (auto & Entry : m_Entries) for (auto Entry = m_Entries.begin(); m_Entries.end() != Entry; ++Entry) { if (Entry == Spot) OpenGLStream << endl; if (Entry - m_Entries.begin() == m_SelectedEntryId) { if (HasTypingFocus()) DrawBox(GetPosition() + Vector2n(0, static_cast<sint32>((Entry - m_Entries.begin() + (Entry >= Spot)) * lineHeight)), Vector2n(GetDimensions().X(), lineHeight), m_SelectedColor, m_SelectedColor); else DrawBox(GetPosition() + Vector2n(0, static_cast<sint32>((Entry - m_Entries.begin() + (Entry >= Spot)) * lineHeight)), Vector2n(GetDimensions().X(), lineHeight), m_UnfocusedSelectedColor, m_UnfocusedSelectedColor); } OpenGLStream << *Entry << endl; } } }
bool Widget::HasAnyTypingFocus() const { return (GetGestureRecognizer().GetConnected().end() != GetGestureRecognizer().GetConnected().find(g_InputManager->m_TypingPointer.get())); }
template <typename T> void ListWidget<T>::Render() { Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ // TODO: Think if I should outsource the entire rendering code for more generality // Draw list { UpdateDimensions(); // LATER: Optimize by not repeating this calculation each time, only when something changes? if (m_Entries.empty()) { BackgroundColor[0] = 234 / 255.0; BackgroundColor[1] = 233 / 255.0; BackgroundColor[2] = 190 / 255.0; } DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TEST auto Spot = m_Entries.end(); if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); Spot = m_Entries.begin() + (LocalPosition.Y() / lineHeight); } } } OpenGLStream OpenGLStream(GetPosition()); for (auto Entry = m_Entries.begin(); m_Entries.end() != Entry; ++Entry) { if (Entry == Spot) OpenGLStream << endl; OpenGLStream << *Entry << endl; } } #if DECISION_LIST_WIDGET_IS_COMPOSITE CompositeWidget::Render(); #endif }
void TextFieldWidget::Render() { //Color BackgroundColor(1.0, 1.0, 1.0); Color BackgroundColor = m_BackgroundColor; Color BorderColor(0.3, 0.3, 0.3); /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager)) { } else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager))) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } else { }*/ //if (CheckHover()) // HACK if (HasTypingFocus()) { BorderColor[0] = 0.898; BorderColor[1] = 0.765; BorderColor[2] = 0.396; } /*glBegin(GL_QUADS); glVertex2d(m_Position.X(), m_Position.Y()); glVertex2d(m_Position.X(), m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y() + 30); glVertex2d(m_Position.X() + 30, m_Position.Y()); glEnd();*/ DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); // TEST auto ContentWithInsertion = m_Content; if (!m_TypingModule.GetString().empty()) { for (auto & Pointer : GetGestureRecognizer().GetConnected()) { if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory()) { Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition()); Vector2n LocalPosition(GlobalToLocal(GlobalPosition)); LocalPosition = m_TypingModule.GetInsertionPosition(LocalPosition); auto InsertionPosition = GetNearestCaretPosition(LocalPosition); ContentWithInsertion.insert(InsertionPosition, m_TypingModule.GetString()); } } } glColor3d(0, 0, 0); OpenGLStream OpenGLStream(GetPosition()); OpenGLStream << ContentWithInsertion.substr(0, std::min(m_CaretPosition, m_SelectionPosition)); Vector2n CaretPosition; // Remember caret position at selection front if (std::min(m_CaretPosition, m_SelectionPosition) == m_CaretPosition) { CaretPosition = OpenGLStream.GetCaretPosition(); } // Draw selected text as highlighted if (HasTypingFocus()) { OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(195), 212, 242)); } else { OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(212), 212, 212)); } auto SelectionLength = std::max(m_CaretPosition, m_SelectionPosition) - std::min(m_CaretPosition, m_SelectionPosition); OpenGLStream << ContentWithInsertion.substr(std::min(m_CaretPosition, m_SelectionPosition), SelectionLength); OpenGLStream.SetBackgroundColor(Color(1.0, 1.0, 1.0)); // Remember caret position at selection back if (std::max(m_CaretPosition, m_SelectionPosition) == m_CaretPosition) { CaretPosition = OpenGLStream.GetCaretPosition(); } OpenGLStream << ContentWithInsertion.substr(std::max(m_CaretPosition, m_SelectionPosition)); //if (CheckHover()) // HACK if (HasTypingFocus()) { // Draw caret //if (static_cast<int>(glfwGetTime() * 2) % 2) { glPushMatrix(); glTranslated(CaretPosition.X(), CaretPosition.Y(), 0); glColor3d(0, 0, 0); glBegin(GL_QUADS); glVertex2d(-1, 0); glVertex2d(-1, lineHeight); glVertex2d(+1, lineHeight); glVertex2d(+1, 0); glEnd(); glPopMatrix(); } } }