예제 #1
0
void Widget::addChild(Widget::Ptr child) {
	if (child->parent().get() != this) {
		return child->setParent(shared_from_this());
	}

	m_children.push_back(child);
}
예제 #2
0
void Alignment::UpdateChild() {
	Widget::Ptr child = GetChild();

	if( !child ) {
		return;
	}

	sf::FloatRect allocation( GetAllocation() );

	sf::Vector2f spare_space( allocation.width, allocation.height );
	spare_space -= child->GetRequisition();
	spare_space.x *= 1.f - GetScale().x;
	spare_space.y *= 1.f - GetScale().y;

	if( ( spare_space.x < 0 ) || ( spare_space.y < 0 ) ) {
#ifdef SFGUI_DEBUG
		std::cerr << "SFGUI warning: Alignment got a smaller allocation than it requested." << std::endl;
		return;
#endif
	}

	allocation.left = spare_space.x * GetAlignment().x;
	allocation.top = spare_space.y * GetAlignment().y;
	allocation.width -= spare_space.x;
	allocation.height -= spare_space.y;

	child->SetAllocation( allocation );
}
예제 #3
0
sf::Vector2f Alignment::CalculateRequisition() {
	Widget::Ptr child = GetChild();

	if( !child ) {
		return sf::Vector2f( 0.f, 0.f );
	}

	return child->GetRequisition();
}
예제 #4
0
void Widget::removeChild(Widget::Ptr child) {
	if (child->parent() != 0) {
		return child->setParent(0);
	}

	auto it = std::find(m_children.begin(), m_children.end(), child);
	if (it != m_children.begin()) {
		m_children.erase(it);
	}
}
예제 #5
0
void Container::RemoveAll() {
	while( !m_children.empty() ) {
		Widget::Ptr widget = m_children.back();

		m_children.pop_back();
		widget->SetParent( Widget::Ptr() );
		HandleRemove( widget );
	}

	RequestResize();
}
예제 #6
0
bool Instrumenter::handleUnconditionalExitInstrumentation(RelocBlock *trace, RelocGraph *, instPoint *exit) {
  // Easy
  RelocBlock::WidgetList &elements = trace->elements();
  // For now, we're inserting this instrumentation immediately before the last instruction
  // in the list of elements. 
  
  Widget::Ptr inst = makeInstrumentation(exit);
  if (!inst) return false;
  
  inst.swap(elements.back());
  elements.push_back(inst);
  return true;
}
예제 #7
0
void Widget::setParent(Widget::Ptr parent) {
	if (m_parent == parent)
		return;

	if (m_parent) {
		std::cout << m_parent << std::endl;
		Widget::Ptr old = m_parent;
		m_parent = 0;
		old->removeChild(shared_from_this());
	}

	if (parent) {
		m_parent = parent;
		parent->addChild(shared_from_this());
	}
}
예제 #8
0
파일: container.cpp 프로젝트: Lo-X/hammer
void Container::pack(Widget::Ptr widget)
{
    mChildren.push_back(widget);

    if(!hasSelection() && widget->isSelectable())
        select(mChildren.size() -1);
}
예제 #9
0
파일: Widget.cpp 프로젝트: Cruel/SFGUI
void Widget::SetParent( Widget::Ptr parent ) {
	auto cont = std::dynamic_pointer_cast<Container>( parent );
	auto oldparent = m_parent.lock();

	if( cont == oldparent ) {
		return;
	}

	if( oldparent ) {
		oldparent->Remove( shared_from_this() );
	}

	m_parent = cont;

	auto iter = std::find( root_widgets.begin(), root_widgets.end(), this );

	if( parent ) {
		// If this widget has a parent, it is no longer a root widget.
		if( iter != root_widgets.end() ) {
			root_widgets.erase( iter );
		}

		SetHierarchyLevel( parent->GetHierarchyLevel() + 1 );
	}
	else {
		// If this widget does not have a parent, it becomes a root widget.
		if( iter == root_widgets.end() ) {
			root_widgets.push_back( this );
		}

		SetHierarchyLevel( 0 );
	}

	HandleAbsolutePositionChange();
}
예제 #10
0
    bool ScrollablePanel::remove(const Widget::Ptr& widget)
    {
        const sf::Vector2f bottomRight = widget->getPosition() + widget->getFullSize();

        const bool ret = Panel::remove(widget);

        if (m_contentSize == sf::Vector2f{0, 0})
        {
            if ((bottomRight.x == m_mostBottomRightPosition.x) || (bottomRight.y == m_mostBottomRightPosition.y))
            {
                recalculateMostBottomRightPosition();
                updateScrollbars();
            }
        }

        return ret;
    }
예제 #11
0
void Container::Remove( const Widget::Ptr& widget ) {
	WidgetsList::iterator iter( std::find( m_children.begin(), m_children.end(), widget ) );

	if( iter != m_children.end() ) {
		m_children.erase( iter );
		widget->SetParent( Widget::Ptr() );
		HandleRemove( widget );

		RequestResize();
	}
}
예제 #12
0
void Container::Add( const Widget::Ptr& widget ) {
	if( IsChild( widget ) ) {
		return;
	}

	m_children.push_back( widget );
	HandleAdd( widget );

	// Check if HandleAdd still wants the little boy.
	if( IsChild( widget ) ) {
		widget->SetParent( shared_from_this() );
		RequestResize();
	}
}
예제 #13
0
파일: WidgetLoader.cpp 프로젝트: wpbest/XPF
    TGUI_API Widget::Ptr loadWidget(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget)
    {
        assert(widget != nullptr);

        if (node->propertyValuePairs["visible"])
        {
            bool visible = parseBoolean(node->propertyValuePairs["visible"]->value);
            if (visible)
                widget->show();
            else
                widget->hide();
        }
        if (node->propertyValuePairs["enabled"])
        {
            bool enabled = parseBoolean(node->propertyValuePairs["enabled"]->value);
            if (enabled)
                widget->enable();
            else
                widget->disable();
        }
        if (node->propertyValuePairs["position"])
            widget->setPosition(parseLayout(node->propertyValuePairs["position"]->value));
        if (node->propertyValuePairs["size"])
            widget->setSize(parseLayout(node->propertyValuePairs["size"]->value));
        if (node->propertyValuePairs["opacity"])
            widget->setOpacity(tgui::stof(node->propertyValuePairs["opacity"]->value));

        /// TODO: Font and ToolTip (and Theme?)

        for (auto& childNode : node->children)
        {
            if (toLower(childNode->name) == "renderer")
            {
                for (auto& pair : childNode->propertyValuePairs)
                    widget->getRenderer()->setProperty(pair.first, pair.second->value);
            }
        }
        REMOVE_CHILD("renderer");

        return widget;
    }
예제 #14
0
파일: Widget.cpp 프로젝트: ksandison/sfgui
void Widget::SetParent( const Widget::Ptr& parent ) {
	Container::Ptr cont( DynamicPointerCast<Container>( parent ) );

	if( !cont ) {
		return;
	}

	Container::Ptr oldparent = m_parent.lock();

	if( oldparent ) {
		oldparent->Remove( shared_from_this() );
	}

	m_parent = cont;

	SetHierarchyLevel( parent->GetHierarchyLevel() + 1 );

	HandleAbsolutePositionChange();
}
예제 #15
0
파일: Grid.cpp 프로젝트: texus/TGUI
    void Grid::addWidget(const Widget::Ptr& widget, unsigned int row, unsigned int col,
                         const Borders& borders, Alignment alignment)
    {
        // If the widget hasn't already been added then add it now
        if (std::find(getWidgets().begin(), getWidgets().end(), widget) == getWidgets().end())
            add(widget);

        // Create the row if it did not exist yet
        if (m_gridWidgets.size() < row + 1)
        {
            m_gridWidgets.resize(row + 1);
            m_objBorders.resize(row + 1);
            m_objAlignment.resize(row + 1);
        }

        // Create the column if it did not exist yet
        if (m_gridWidgets[row].size() < col + 1)
        {
            m_gridWidgets[row].resize(col + 1, nullptr);
            m_objBorders[row].resize(col + 1);
            m_objAlignment[row].resize(col + 1);
        }

        // If this is a new row then reserve some space for it
        if (m_rowHeight.size() < row + 1)
            m_rowHeight.resize(row + 1, 0);

        // If this is the first row to have so many columns then reserve some space for it
        if (m_columnWidth.size() < col + 1)
            m_columnWidth.resize(col + 1, 0);

        // Add the widget to the grid
        m_gridWidgets[row][col] = widget;
        m_objBorders[row][col] = borders;
        m_objAlignment[row][col] = alignment;

        // Update the widgets
        updateWidgets();

        // Automatically update the widgets when their size changes
        m_connectedCallbacks[widget] = widget->connect("SizeChanged", &Grid::updateWidgets, this);
    }
예제 #16
0
파일: CFWidget.C 프로젝트: Zirkon/dyninst
// Case 2: wrap a CF-category instruction
CFWidget::Ptr CFWidget::create(Widget::Ptr atom) {
   CFWidget::Ptr ptr = Ptr(new CFWidget(atom->insn(), atom->addr()));
   return ptr;
}
예제 #17
0
void Container::HandleAdd( const Widget::Ptr& child ) {
	child->SetViewport( GetViewport() );
}
예제 #18
0
    bool EventManager::handleEvent(sf::Event& event)
    {
        // Check if a mouse button has moved
        if (event.type == sf::Event::MouseMoved)
        {
            // Loop through all widgets
            for (unsigned int i=0; i<m_Widgets.size(); ++i)
            {
                // Check if the mouse went down on the widget
                if (m_Widgets[i]->m_MouseDown)
                {
                    // Some widgets should always receive mouse move events while dragging them, even if the mouse is no longer on top of them.
                    if ((m_Widgets[i]->m_DraggableWidget) || (m_Widgets[i]->m_ContainerWidget))
                    {
                        m_Widgets[i]->mouseMoved(static_cast<float>(event.mouseMove.x), static_cast<float>(event.mouseMove.y));
                        return true;
                    }
                }
            }

            // Check if the mouse is on top of an widget
            Widget::Ptr widget = mouseOnWidget(static_cast<float>(event.mouseMove.x), static_cast<float>(event.mouseMove.y));
            if (widget != nullptr)
            {
                // Send the event to the widget
                widget->mouseMoved(static_cast<float>(event.mouseMove.x), static_cast<float>(event.mouseMove.y));
                return true;
            }

            return false;
        }

        // Check if a mouse button was pressed
        else if (event.type == sf::Event::MouseButtonPressed)
        {
            // Check if the left mouse was pressed
            if (event.mouseButton.button == sf::Mouse::Left)
            {
                // Check if the mouse is on top of an widget
                Widget::Ptr widget = mouseOnWidget(static_cast<float>(event.mouseButton.x), static_cast<float>(event.mouseButton.y));
                if (widget != nullptr)
                {
                    // Focus the widget
                    focusWidget(widget.get());

                    // Check if the widget is a container
                    if (widget->m_ContainerWidget)
                    {
                        // If another widget was focused then unfocus it now
                        if ((m_FocusedWidget) && (m_Widgets[m_FocusedWidget-1] != widget))
                        {
                            m_Widgets[m_FocusedWidget-1]->m_Focused = false;
                            m_Widgets[m_FocusedWidget-1]->widgetUnfocused();
                            m_FocusedWidget = 0;
                        }
                    }

                    widget->leftMousePressed(static_cast<float>(event.mouseButton.x), static_cast<float>(event.mouseButton.y));
                    return true;
                }
                else // The mouse didn't went down on an widget, so unfocus the focused widget
                    unfocusAllWidgets();
            }

            return false;
        }

        // Check if a mouse button was released
        else if (event.type == sf::Event::MouseButtonReleased)
        {
            // Check if the left mouse was released
            if (event.mouseButton.button == sf::Mouse::Left)
            {
                // Check if the mouse is on top of an widget
                Widget::Ptr widget = mouseOnWidget(static_cast<float>(event.mouseButton.x), static_cast<float>(event.mouseButton.y));
                if (widget != nullptr)
                    widget->leftMouseReleased(static_cast<float>(event.mouseButton.x), static_cast<float>(event.mouseButton.y));

                // Tell all the other widgets that the mouse has gone up
                for (std::vector<Widget::Ptr>::iterator it = m_Widgets.begin(); it != m_Widgets.end(); ++it)
                {
                    if (*it != widget)
                        (*it)->mouseNoLongerDown();
                }

                if (widget != nullptr)
                    return true;
            }

            return false;
        }

        // Check if a key was pressed
        else if (event.type == sf::Event::KeyPressed)
        {
            // Only continue when the character was recognised
            if (event.key.code != sf::Keyboard::Unknown)
            {
                // Check if there is a focused widget
                if (m_FocusedWidget)
                {
                    // Check the pressed key
                    if ((event.key.code == sf::Keyboard::Left)
                     || (event.key.code == sf::Keyboard::Right)
                     || (event.key.code == sf::Keyboard::Up)
                     || (event.key.code == sf::Keyboard::Down)
                     || (event.key.code == sf::Keyboard::BackSpace)
                     || (event.key.code == sf::Keyboard::Delete)
                     || (event.key.code == sf::Keyboard::Space)
                     || (event.key.code == sf::Keyboard::Return))
                    {
                        // Tell the widget that the key was pressed
                        m_Widgets[m_FocusedWidget-1]->keyPressed(event.key.code);
                    }

                    return true;
                }
            }

            return false;
        }

        // Check if a key was released
        else if (event.type == sf::Event::KeyReleased)
        {
            // Change the focus to another widget when the tab key was pressed
            if (event.key.code == sf::Keyboard::Tab)
                return tabKeyPressed();
            else
                return false;
        }

        // Also check if text was entered (not a special key)
        else if (event.type == sf::Event::TextEntered)
        {
            // Check if the character that we pressed is allowed
            if ((event.text.unicode >= 30) && (event.text.unicode != 127))
            {
                // Tell the widget that the key was pressed
                if (m_FocusedWidget)
                {
                    m_Widgets[m_FocusedWidget-1]->textEntered(event.text.unicode);
                    return true;
                }
            }

            return false;
        }

        // Check for mouse wheel scrolling
        else if (event.type == sf::Event::MouseWheelMoved)
        {
            // Find the widget under the mouse
            Widget::Ptr widget = mouseOnWidget(static_cast<float>(event.mouseWheel.x), static_cast<float>(event.mouseWheel.y));
            if (widget != nullptr)
            {
                // Send the event to the widget
                widget->mouseWheelMoved(event.mouseWheel.delta, event.mouseWheel.x,  event.mouseWheel.y);
                return true;
            }

            return false;
        }
        else // Event is ignored
            return false;
    }
예제 #19
0
파일: WidgetSaver.cpp 프로젝트: wpbest/XPF
    TGUI_API std::shared_ptr<DataIO::Node> saveWidget(Widget::Ptr widget)
    {
        std::string widgetName;
        if (widget->getParent())
            widget->getParent()->getWidgetName(widget, widgetName);

        auto node = std::make_shared<DataIO::Node>();
        if (widgetName.empty())
            node->name = widget->getWidgetType();
        else
            node->name = widget->getWidgetType() + "." + widgetName;

        if (!widget->isVisible())
            SET_PROPERTY("Visible", "false");
        if (!widget->isEnabled())
            SET_PROPERTY("Enabled", "false");
        if (widget->getPosition() != sf::Vector2f{})
            SET_PROPERTY("Position", emitLayout(widget->getPositionLayout()));
        if (widget->getSize() != sf::Vector2f{})
            SET_PROPERTY("Size", emitLayout(widget->getSizeLayout()));
        if (widget->getOpacity() != 255)
            SET_PROPERTY("Opacity", tgui::to_string(widget->getOpacity()));

        /// TODO: Font and ToolTip

        if (widget->getRenderer())
        {
            node->children.emplace_back(std::make_shared<DataIO::Node>());
            node->children.back()->name = "Renderer";
            for (auto& pair : widget->getRenderer()->getPropertyValuePairs())
                node->children.back()->propertyValuePairs[pair.first] = std::make_shared<DataIO::ValueNode>(node->children.back().get(), Serializer::serialize(std::move(pair.second)));
        }

        return node;
    }
예제 #20
0
파일: Grid.cpp 프로젝트: DalikarFT/dndgame
 void Grid::remove(const Widget::Ptr& widget)
 {
     remove(widget.get());
 }