bool CompositeWidget::HitTest(Vector2n ParentPosition, std::list<Widget *> * Hits) const { #if 1 for (auto & Widget : reverse(GetWidgets())) { auto Result = Widget->HitTest(ParentToLocal(ParentPosition), Hits); #if DECISION_POINTER_MAPPING_CONTAINS_SINGLE_TOPMOST_WIDGET if (Result) return true; #endif } if (Widget::HitTest(ParentPosition, Hits)) return true; return false; #else bool HitInside = false; // HACK, TESTING: Swapped order of inner widgets and this widget for testing //>> FIX: Make clicking inside text area work... for (auto & Widget : reverse(GetWidgets())) { auto Result = Widget->HitTest(ParentToLocal(ParentPosition), nullptr); #if DECISION_POINTER_MAPPING_CONTAINS_SINGLE_TOPMOST_WIDGET if (Result) return true; #endif if (Result) HitInside = true; } if (Widget::HitTest(ParentPosition, Hits)) //return true; HitInside = true; if (HitInside && nullptr != Hits) { Hits->push_back(const_cast<CompositeWidget *>(this)); //return true; } for (auto & Widget : reverse(GetWidgets())) { auto Result = Widget->HitTest(ParentToLocal(ParentPosition), Hits); #if DECISION_POINTER_MAPPING_CONTAINS_SINGLE_TOPMOST_WIDGET if (Result) return true; #endif } if (HitInside) return true; return false; #endif }
bool HistogramWindow::Initialize() { GetWidgets(); AttachSignals(); // Load the PGR icon LoadIcon(); set_default_icon( m_iconPixBuf ); set_default_size( 400, 400 ); // Set up initial state for row col plot m_pRadioRowColModeColumn->set_active( true ); m_pCheckbuttonRowColDisplayGrey->set_active( true ); m_pCheckbuttonRowColDisplayRed->set_active( false ); m_pCheckbuttonRowColDisplayGreen->set_active( false ); m_pCheckbuttonRowColDisplayBlue->set_active( false ); m_pCheckbuttonRowColFunctionMax->set_active( true ); m_pCheckbuttonRowColFunctionMean->set_active( true ); m_pCheckbuttonRowColFunctionMin->set_active( true ); return true; }
void CompositeWidget::ProcessTimePassed(const double TimePassed) { for (auto & Widget : GetWidgets()) { Widget->ProcessTimePassed(TimePassed); } }
void CPDFSDK_InterForm::GetWidgets( const CFX_WideString& sFieldName, std::vector<CPDFSDK_Widget*>* widgets) const { for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); ASSERT(pFormField); GetWidgets(pFormField, widgets); } }
CompositeWidget::CompositeWidget(Vector2n Position, Vector2n Dimensions, std::initializer_list<std::shared_ptr<Widget>> Widgets, std::vector<std::shared_ptr<Behavior>> Behaviors) : Widget(Position, Dimensions, Behaviors), m_Widgets(Widgets) { for (auto & Widget : GetWidgets()) { Widget->SetParent(*this); } }
void FlowLayoutWidget::Render() { // HACK: This doesn't belong in Render, etc. // TODO: Support for invisible widgets (i.e. they shouldn't add 2 points of space) for (auto WidgetToLayout = 0; WidgetToLayout < GetWidgets().size(); ++WidgetToLayout) { if (0 == WidgetToLayout) { GetWidgets()[WidgetToLayout]->SetPosition(Vector2n::ZERO); } else { GetWidgets()[WidgetToLayout]->SetPosition(Vector2n(GetWidgets()[WidgetToLayout - 1]->GetPosition().X() + GetWidgets()[WidgetToLayout - 1]->GetDimensions().X() + 2, 0)); } } CompositeWidget::Render(); }
LiveFunctionWidget::LiveFunctionWidget(Vector2n Position, TypingModule & TypingModule, Project & Project) : CompositeWidget(Position, { std::shared_ptr<Widget>(m_ToggleWidget = new ToggleWidget(Vector2n(-1, -18), [=](bool State) { m_LiveProgramWidget->m_SourceWidget->m_Visible = State; }, true)), std::shared_ptr<Widget>(new FlowLayoutWidget(Vector2n::ZERO, { std::shared_ptr<Widget>(m_InputWidget = new TextFieldWidget(Vector2n::ZERO, TypingModule)), std::shared_ptr<Widget>(m_SourceWidget = new TextFieldWidget(Vector2n::ZERO, TypingModule)), std::shared_ptr<Widget>(m_LiveProgramWidget = new LiveProgramWidget(Vector2n::ZERO, TypingModule, Project)) }, { })) }, { std::shared_ptr<Behavior>(new DraggablePositionBehavior(*this)) }) { m_LiveProgramWidget->RemoveAllBehaviors(); // With live test execution and all m_SourceWidget->m_OnChange = [=, &Project]() { std::ostringstream GenProgram; Project.GenerateProgramForFunction(GenProgram, m_InputWidget->GetContent(), m_SourceWidget->GetContent()); m_LiveProgramWidget->m_SourceWidget->SetContent(GenProgram.str()); }; m_InputWidget->m_OnChange = m_SourceWidget->m_OnChange; { auto ImportList = new ListWidget<ConceptId>(Vector2n::ZERO, Project.GetStdIncludes(), TypingModule); auto pTypingModule = &TypingModule; ImportList->m_TapAction = [=](Vector2n LocalPosition, std::vector<ConceptId> & m_List) { auto Entry = pTypingModule->TakeString(); if (!Entry.empty()) { auto ConceptId = FindOrCreateConcept(Entry); //Insert(ConceptId); // TEST auto Spot = m_List.begin() + (LocalPosition.Y() / lineHeight); m_List.insert(Spot, ConceptId); } else { auto ListEntry = static_cast<decltype(m_List.size())>(LocalPosition.Y() / lineHeight); if (ListEntry < m_List.size()) { pTypingModule->SetString(GetConcept(m_List[ListEntry]).GetContent()); m_List.erase(m_List.begin() + ListEntry); } } }; auto LabelledImportList = new FlowLayoutWidget(Vector2n(-280, -100), { std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string("import (\""), LabelWidget::Background::None)), std::shared_ptr<Widget>(ImportList), std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string("\")"), LabelWidget::Background::None)) }, {}); static_cast<FlowLayoutWidget *>(GetWidgets()[1].get())->AddWidget(LabelledImportList); } }
void WidgetOwner::CallWidgets_AppendVertices(std::vector<Vertex_2f_2f_4f_1f>& vertices) { const std::vector<Widget*>& widgets = GetWidgets(); for (auto i = widgets.rbegin(); i != widgets.rend(); ++i) { Widget* widget = *i; if (widget->IsVisible()) widget->RenderVertices(vertices); } }
void CompositeWidget::Render() { glPushMatrix(); glTranslated(GetPosition().X(), GetPosition().Y(), 0); { for (auto & Widget : GetWidgets()) { Widget->Render(); } } glPopMatrix(); }
Widget *Container::GetWidgetAt(const Point &pos) { if (!Contains(pos)) return 0; for (RefCountedPtr<Widget> widget : GetWidgets()) { const Point relpos = pos - widget->GetPosition() - widget->GetDrawOffset(); if (widget->IsContainer()) { Widget* w = static_cast<Container*>(widget.Get())->GetWidgetAt(relpos); if (w) return w; } else if (widget->Contains(relpos)) return widget.Get(); } return this; }
const Vector2n CompositeWidget::GetDimensions() const { auto Dimensions = Widget::GetDimensions(); // TODO: Figure out if this is what I want to do... and make it proper, etc. for (auto & Widget : GetWidgets()) { auto FarCorner = Widget->GetPosition() + Widget->GetDimensions(); if (FarCorner.X() > Dimensions.X()) Dimensions.X() = FarCorner.X(); if (FarCorner.Y() > Dimensions.Y()) Dimensions.Y() = FarCorner.Y(); } return Dimensions; }
void Container::CollectShortcuts(std::map<KeySym,Widget*> &shortcuts) { { const std::set<KeySym> &widgetShortcuts = GetShortcuts(); if (!widgetShortcuts.empty()) for (std::set<KeySym>::const_iterator j = widgetShortcuts.begin(); j != widgetShortcuts.end(); ++j) shortcuts[*j] = this; } for (RefCountedPtr<Widget> widget : GetWidgets()) { if (widget->IsContainer()) static_cast<Container*>(widget.Get())->CollectShortcuts(shortcuts); else { const std::set<KeySym> &widgetShortcuts = widget->GetShortcuts(); if (!widgetShortcuts.empty()) for (std::set<KeySym>::const_iterator j = widgetShortcuts.begin(); j != widgetShortcuts.end(); ++j) shortcuts[*j] = widget.Get(); } } }
DebugOverlayWidget::DebugOverlayWidget(CanvasWidget * MainCanvas) : CanvasWidget(Vector2n::ZERO, false, false) { { auto Content = []() -> std::string { std::ostringstream out; out << "Mouse.PntrMppng.m_Entries.size(): " << g_InputManager->m_MousePointer->ModifyPointerMapping().m_Entries.size(); for (auto & i : g_InputManager->m_MousePointer->ModifyPointerMapping().m_Entries) { PrintName(out, i); auto LocalPosition = dynamic_cast<Widget *>(&i->GetOwner())->GlobalToLocal(Vector2n(g_InputManager->m_MousePointer->GetPointerState().GetAxisState(0).GetPosition(), g_InputManager->m_MousePointer->GetPointerState().GetAxisState(1).GetPosition())); out << " [" << static_cast<Widget *>(&i->GetOwner())->GetDimensions().X() << ", " << static_cast<Widget *>(&i->GetOwner())->GetDimensions().Y() << "]"; out << " (" << LocalPosition.X() << ", " << LocalPosition.Y() << ")"; out << " <" << static_cast<Widget *>(&i->GetOwner())->m_DebugDescription << ">"; } out << "\nKB.PntrMppng.m_Entries.size(): " << g_InputManager->m_TypingPointer->ModifyPointerMapping().m_Entries.size(); for (auto & i : g_InputManager->m_TypingPointer->ModifyPointerMapping().m_Entries) { PrintName(out, i); } return out.str(); }; AddWidget(new LabelWidget(Vector2n(0, 18), Content)); } { auto Content = []() -> std::string { std::ostringstream out; out << "InputManager.m_IEQueue.m_Queue" << std::endl; for (auto & i : g_InputManager->m_InputEventQueue.m_Queue) { out << i.ToString() << std::endl; } return out.str(); }; AddWidget(new LabelWidget(Vector2n(0, 240), Content)); } // Visualizer of currently available shortcuts { auto Content = []() -> std::string { std::ostringstream out; std::map<GestureRecognizer::ShortcutEntry::Key, GestureRecognizer::ShortcutEntry &> AvailShortcuts; // Find all non-overlapping available shortcuts for (auto & i : g_InputManager->m_TypingPointer->ModifyPointerMapping().m_Entries) { for (auto & S : i->m_Shortcuts) { // TODO: Highlight shortcuts that can be activated in current state (e.g. Cmd+O does nothing when a folder is selected, etc.) // Only add this shortcut if there isn't any other overlapping one (i.e., with the same signature <Modifier, InputId>) auto Key = decltype(AvailShortcuts)::key_type(S.InputId, S.Modifiers); if (AvailShortcuts.end() == AvailShortcuts.find(Key)) AvailShortcuts.insert(decltype(AvailShortcuts)::value_type(Key, S)); } } // Print out all available shortcuts (in some sorted order) for (auto & aS : AvailShortcuts) { auto & S = aS.second; if (PointerState::Modifiers::Super == S.Modifiers) // TODO: Make this more general (Modifier -> string) out << "Cmd+"; switch (S.InputId) { case GLFW_KEY_F3: out << "F3"; break; default: out << static_cast<char>(S.InputId); break; } out << " - " << S.Description; out << endl; } return out.str(); }; // TODO: Make it right aligned to edge of screen AddWidget(new LabelWidget(Vector2n(1536 - 19 * charWidth, lineHeight + 2), Content)); } // Time in top right corner // TODO: Add support for reference frames other than top left corner as origin auto TimeWidget = new class TimeWidget(Vector2n(1536 - 13 * charWidth - 1, 1)); //TimeWidget->SetPosition(TimeWidget->GetPosition() - Vector2n(TimeWidget->GetDimensions().X(), 0)); // This doesn't work because its dimensions are updated after render... AddWidget(TimeWidget); // Visibility toggle { auto ToggleWidget = new class ToggleWidget(Vector2n(1, 1), [=](bool State) { // Toggle visibility of all widgets but the last one (i.e. this toggle) // TODO: Fix problem where upon initialize, OnChange is called before this widget has been added, so 2nd last widget is not hidden for (auto Widget = GetWidgets().begin(); GetWidgets().end() != Widget && GetWidgets().end() - 3 != Widget; ++Widget) { (*Widget)->m_Visible = State; } }, false); AddWidget(ToggleWidget); ProcessTimePassed(0); // HACK: Get all the widgets actually added ToggleWidget->UpdateHACK(); } }
void InformationPane::Initialize() { GetWidgets(); }