2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 26.03.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_BUTTON_H
|
|
|
|
#define ENGINE_BUTTON_H
|
|
|
|
|
2021-11-10 14:14:10 +03:00
|
|
|
#include <functional>
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
struct tPos final {
|
|
|
|
const int tx;
|
|
|
|
const int ty;
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class Button final {
|
2021-10-03 07:47:05 +03:00
|
|
|
private:
|
2021-10-28 16:58:02 +03:00
|
|
|
const int _x{};
|
|
|
|
const int _y{};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
const int _w{};
|
|
|
|
const int _h{};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
const std::function<void()> _click;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
const std::string _textString;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
const double _sx{};
|
|
|
|
const double _sy{};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
const std::string _texture;
|
|
|
|
const tPos _usualState{};
|
|
|
|
const tPos _selectedState{};
|
|
|
|
const tPos _pressedState{};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
const std::string _font;
|
|
|
|
const sf::Color _textColor;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-03 07:47:05 +03:00
|
|
|
sf::Sprite _button;
|
|
|
|
sf::Text _text;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-03 07:47:05 +03:00
|
|
|
bool _selected = false;
|
|
|
|
bool _pressed = false;
|
|
|
|
bool _checkBox = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Button() = default;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
Button(int x, int y, int width, int height, std::function<void()> click, std::string text, double sx, double sy,
|
|
|
|
std::string texture, tPos usualState, tPos selectedState, tPos pressedState, std::string font,
|
|
|
|
sf::Color textColor);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
void select();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void unSelect();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void press();
|
|
|
|
|
|
|
|
void init();
|
2021-10-03 07:47:05 +03:00
|
|
|
|
|
|
|
[[nodiscard]] int x() const { return _x; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-03 07:47:05 +03:00
|
|
|
[[nodiscard]] int y() const { return _y; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-03 07:47:05 +03:00
|
|
|
[[nodiscard]] int w() const { return _w; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-03 07:47:05 +03:00
|
|
|
[[nodiscard]] int h() const { return _h; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-03 07:47:05 +03:00
|
|
|
[[nodiscard]] double sx() const { return _sx; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-03 07:47:05 +03:00
|
|
|
[[nodiscard]] double sy() const { return _sy; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
[[nodiscard]] sf::Sprite const &sprite() const { return _button; }
|
|
|
|
|
|
|
|
[[nodiscard]] sf::Text const &text() const { return _text; }
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //MINECRAFT_3DZAVR_BUTTON_H
|