forked from NaiJi/project-kyoku
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.3 KiB
C++
71 lines
1.3 KiB
C++
#include "widget.h"
|
|
|
|
void Widget::input(const sf::Event &event)
|
|
{
|
|
if (_blocker)
|
|
_blocker->input(event);
|
|
else
|
|
{
|
|
for (auto& child : _children)
|
|
child->input(event);
|
|
}
|
|
}
|
|
|
|
void Widget::update(const sf::Time& dt)
|
|
{
|
|
for (auto& child : _children)
|
|
child->update(dt);
|
|
}
|
|
|
|
void Widget::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|
{
|
|
for (auto& child : _children)
|
|
child->draw(target, states);
|
|
}
|
|
|
|
void Widget::move(const sf::Vector2f &delta)
|
|
{
|
|
for (auto& child : _children)
|
|
child->move(delta);
|
|
}
|
|
|
|
void Widget::setVisibility(bool is_visible)
|
|
{
|
|
_is_visible = is_visible;
|
|
for (auto& child : _children)
|
|
child->setVisibility(_is_visible);
|
|
}
|
|
|
|
bool Widget::isVisible() const
|
|
{
|
|
return _is_visible;
|
|
}
|
|
|
|
void Widget::addChild(const std::shared_ptr<Widget>& child)
|
|
{
|
|
child->setParent(shared_from_this());
|
|
|
|
const auto iterator = std::find(_children.begin(), _children.end(), child);
|
|
if (iterator == _children.end())
|
|
_children.emplace_back(child);
|
|
}
|
|
|
|
void Widget::setParent(const std::shared_ptr<Widget>& parent)
|
|
{
|
|
if (_parent != parent)
|
|
{
|
|
_parent = parent;
|
|
_parent->addChild(shared_from_this());
|
|
}
|
|
}
|
|
|
|
void Widget::blockBy(const std::shared_ptr<Widget>& blocker)
|
|
{
|
|
_blocker = blocker;
|
|
}
|
|
|
|
void Widget::unblock()
|
|
{
|
|
_blocker = nullptr;
|
|
}
|