2023-02-25 04:46:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
|
|
|
class Button
|
|
|
|
{
|
|
|
|
|
|
|
|
protected:
|
2023-03-02 02:37:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// TODO / JankMode: setter & getter for these three fields
|
|
|
|
// were protected, but directly changing them should be...fine?
|
2023-02-25 04:46:34 +00:00
|
|
|
sf::RectangleShape rect;
|
|
|
|
sf::Text caption;
|
|
|
|
std::string action;
|
|
|
|
|
|
|
|
Button() {};
|
|
|
|
Button(int x, int y, int w, int h,
|
|
|
|
sf::Color _background, sf::Color _textcolor,
|
|
|
|
const char * _caption, sf::Font & font,
|
|
|
|
const char * _action);
|
|
|
|
void setPosition(sf::Vector2f v) { rect.setPosition(v); caption.setPosition(v); }
|
|
|
|
void setSize(sf::Vector2f & v) { rect.setSize(v); }
|
|
|
|
void setBackground(sf::Color c) { rect.setFillColor(c); }
|
|
|
|
void setCaption(std::string & s) { caption.setString(s); }
|
|
|
|
void setTextColor(sf::Color c) { caption.setFillColor(c); }
|
|
|
|
void render(sf::RenderWindow & window);
|
|
|
|
auto contains(sf::Vector2i p) { return rect.getGlobalBounds().contains(p.x, p.y); }
|
2023-03-08 01:03:09 +00:00
|
|
|
auto contains(sf::Vector2f rel, sf::Vector2i p) {
|
|
|
|
return rect.getGlobalBounds().contains(p.x - rel.x, p.y - rel.y);
|
|
|
|
}
|
2023-02-25 04:46:34 +00:00
|
|
|
auto getAction() { return action; }
|
2023-03-02 02:37:42 +00:00
|
|
|
|
2023-02-25 04:46:34 +00:00
|
|
|
private:
|
|
|
|
};
|