diff --git a/src/gui/button.cpp b/src/gui/button.cpp new file mode 100644 index 0000000..49cc11c --- /dev/null +++ b/src/gui/button.cpp @@ -0,0 +1,48 @@ +#include "button.h" + +Button::Button(const std::string &text) +{ + _button_text.setString(text); + _button_text.setFillColor(sf::Color::Black); + _button_content.setFillColor(sf::Color::White); +} + +void Button::input(const sf::Event& event) +{ + switch (event.type) + { + case sf::Event::MouseButtonPressed: + break; + } +} + +void Button::update() +{ + +} + +void Button::draw(sf::RenderTarget& target, sf::RenderStates states) const +{ + +} + +void Button::setRect(const sf::IntRect& rect) +{ + +} + +void Button::setPosition(const sf::Vector2f& position) +{ + +} + +void Button::setText(const std::string& text) +{ + +} + +void Button::setCallback(std::function callback) +{ + +} + diff --git a/src/gui/button.h b/src/gui/button.h new file mode 100644 index 0000000..e85e8e3 --- /dev/null +++ b/src/gui/button.h @@ -0,0 +1,26 @@ +#pragma once + +#include "widget.h" +#include +#include +#include + +class Button : public Widget +{ +public: + Button(const std::string& text); + + virtual void input(const sf::Event& event) override; + virtual void update() override; + virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override; + virtual void setRect(const sf::IntRect& rect) override; + virtual void setPosition(const sf::Vector2f& position) override; + + void setText(const std::string& text); + void setCallback(std::function callback); + +private: + sf::RectangleShape _button_content; + sf::Text _button_text; +}; + diff --git a/src/gui/widget.cpp b/src/gui/widget.cpp new file mode 100644 index 0000000..1de6e3c --- /dev/null +++ b/src/gui/widget.cpp @@ -0,0 +1,13 @@ +#include "widget.h" + +Widget::Widget(const std::shared_ptr& parent) : + _parent(parent) +{ + if (_parent) + _parent->addChild(shared_from_this()); +} + +void Widget::addChild(const std::shared_ptr &child) +{ + _children.emplace_back(child); +} diff --git a/src/gui/widget.h b/src/gui/widget.h new file mode 100644 index 0000000..3c3c265 --- /dev/null +++ b/src/gui/widget.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include + +class Widget : public sf::Drawable, std::enable_shared_from_this +{ +public: + Widget(const std::shared_ptr& parent = nullptr); + + virtual ~Widget() = default; + + virtual void input(const sf::Event& event) = 0; + virtual void update() = 0; + virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const = 0; + virtual void setRect(const sf::FloatRect& rect) = 0; + virtual void setPosition(const sf::Vector2f& position) = 0; + +protected: + void addChild(const std::shared_ptr& child); + + std::vector> _children; + const std::shared_ptr _parent; +}; +