Added generic button
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#ifndef GUIELEMENTS
|
||||
#define GUIELEMENTS
|
||||
|
||||
#include "../../sdlpp/sdlpp.hpp"
|
||||
#include "../global_vars.hpp"
|
||||
#include "../objectids.hpp"
|
||||
|
||||
class Button : public SDLPP::TextRenderer {
|
||||
public:
|
||||
Button() = delete;
|
||||
Button(double x, double y, double w, double h,
|
||||
std::shared_ptr<SDLPP::Renderer> &r, const std::string &text,
|
||||
const std::string &color, const std::string &outline_color,
|
||||
const std::string &background_color,
|
||||
std::function<void(void *)> click_fun, void *input)
|
||||
: TextRenderer(x, y, w, h, r, g_text_config->getFont(), text, color,
|
||||
outline_color, 0.2),
|
||||
click_fun(click_fun), func_input(input) {
|
||||
setColor(background_color);
|
||||
setId(BUTTON_ID);
|
||||
addCollision(SDLPP::RectColider(0, 0, 1, 1));
|
||||
}
|
||||
void setBackgroundColor(const std::string &color) {
|
||||
setColor(color);
|
||||
}
|
||||
void performFunction() const {
|
||||
click_fun(func_input);
|
||||
}
|
||||
// TODO highlight visit
|
||||
private:
|
||||
std::function<void(void *)> click_fun;
|
||||
void *func_input;
|
||||
};
|
||||
|
||||
std::shared_ptr<SDLPP::RectangleRender>
|
||||
createButton(double x, double y, double w, double h,
|
||||
std::shared_ptr<SDLPP::Renderer> &r, const std::string &text,
|
||||
const std::string &color, const std::string &outline_color,
|
||||
const std::string &background_color,
|
||||
std::function<void(void *)> click_fun, void *input);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user