project-kyoku/src/gui/widgets/widget.h

42 lines
1.2 KiB
C
Raw Normal View History

2021-07-26 18:44:10 -04:00
#pragma once
#include <vector>
#include <memory>
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/Drawable.hpp>
2021-07-27 14:18:37 -04:00
#include <SFML/Graphics/RenderTarget.hpp>
2021-07-26 18:44:10 -04:00
2021-07-27 14:18:37 -04:00
class Widget : public sf::Drawable, public std::enable_shared_from_this<Widget>
2021-07-26 18:44:10 -04:00
{
public:
virtual ~Widget() = default;
virtual void input(const sf::Event& event) = 0;
virtual void update(const sf::Time& dt) = 0;
2021-07-26 18:44:10 -04:00
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
virtual void move(const sf::Vector2f& delta) = 0;
2021-07-27 14:18:37 -04:00
virtual bool isUnderMouse(int mouse_x, int mouse_y) const = 0;
2021-07-26 18:44:10 -04:00
virtual void setRect(const sf::FloatRect& rect) = 0;
virtual sf::FloatRect rect() const = 0;
virtual void setPosition(const sf::Vector2f& position) = 0;
virtual sf::Vector2f position() const = 0;
virtual void setVisibility(bool is_visible = true);
2021-08-26 14:36:09 -04:00
bool isVisible() const;
2021-07-26 18:44:10 -04:00
void addChild(const std::shared_ptr<Widget>& child);
void setParent(const std::shared_ptr<Widget>& parent);
2021-08-26 14:36:09 -04:00
void blockBy(const std::shared_ptr<Widget>& blocker);
void unblock();
2021-07-26 18:44:10 -04:00
2021-07-27 14:18:37 -04:00
protected:
2021-07-26 18:44:10 -04:00
std::vector<std::shared_ptr<Widget>> _children;
2021-07-27 14:18:37 -04:00
std::shared_ptr<Widget> _parent;
std::shared_ptr<Widget> _blocker;
2021-08-03 14:42:58 -04:00
bool _is_visible = true;
2021-07-26 18:44:10 -04:00
};