shooter/engine/gui/Button.h

72 lines
1.6 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 26.03.2021.
//
#ifndef ENGINE_BUTTON_H
#define ENGINE_BUTTON_H
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <functional>
struct tPos {
int tx;
int ty;
};
2021-10-03 07:47:05 +03:00
class Button {
private:
int _x{};
int _y{};
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
int _w{};
int _h{};
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
std::function<void()> _click;
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
std::string _textString;
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
double _sx{};
double _sy{};
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
std::string _texture;
tPos _usualState{};
tPos _selectedState{};
tPos _pressedState{};
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
std::string _font;
sf::Color _textColor;
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
std::string _clickSoundName;
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
sf::Sprite _button;
sf::Text _text;
sf::Sound _clickSound;
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;
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, std::string clickSound);
2021-09-13 15:53:43 +03:00
void select();
void unSelect();
void press();
void init();
2021-10-03 07:47:05 +03:00
[[nodiscard]] int x() const { return _x; }
[[nodiscard]] int y() const { return _y; }
[[nodiscard]] int w() const { return _w; }
[[nodiscard]] int h() const { return _h; }
[[nodiscard]] double sx() const { return _sx; }
[[nodiscard]] double sy() const { return _sy; }
[[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