|
|
|
@ -13,90 +13,53 @@ |
|
|
|
|
#include <any> |
|
|
|
|
|
|
|
|
|
namespace guecs { |
|
|
|
|
using std::shared_ptr, std::make_shared; |
|
|
|
|
|
|
|
|
|
struct Label { |
|
|
|
|
std::string label; |
|
|
|
|
unsigned int size = GUECS_FONT_SIZE; |
|
|
|
|
sf::Color color = GUECS_TEXT_COLOR; |
|
|
|
|
shared_ptr<sf::Font> font = nullptr; |
|
|
|
|
shared_ptr<sf::Text> text = nullptr; |
|
|
|
|
|
|
|
|
|
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) { |
|
|
|
|
dbc::check(font_ptr != nullptr, "you failed to initialize this Label"); |
|
|
|
|
if(font == nullptr) font = font_ptr; |
|
|
|
|
if(text == nullptr) text = make_shared<sf::Text>(*font, label, size); |
|
|
|
|
text->setFillColor(color); |
|
|
|
|
auto bounds = text->getLocalBounds(); |
|
|
|
|
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell); |
|
|
|
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
|
|
|
|
text->setPosition({float(text_cell.x), float(text_cell.y) - text_cell.h / 2}); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct WideLabel { |
|
|
|
|
std::wstring label; |
|
|
|
|
unsigned int size = GUECS_FONT_SIZE; |
|
|
|
|
sf::Color color = GUECS_TEXT_COLOR; |
|
|
|
|
shared_ptr<sf::Font> font = nullptr; |
|
|
|
|
shared_ptr<sf::Text> text = nullptr; |
|
|
|
|
|
|
|
|
|
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) { |
|
|
|
|
dbc::check(font_ptr != nullptr, "you failed to initialize this WideLabel"); |
|
|
|
|
if(font == nullptr) font = font_ptr; |
|
|
|
|
if(text == nullptr) text = make_shared<sf::Text>(*font, label, size); |
|
|
|
|
text->setFillColor(color); |
|
|
|
|
auto bounds = text->getLocalBounds(); |
|
|
|
|
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell); |
|
|
|
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
|
|
|
|
text->setPosition({float(text_cell.x), float(text_cell.y) - text_cell.h / 2}); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
using std::shared_ptr, std::make_shared, std::wstring, std::string; |
|
|
|
|
|
|
|
|
|
struct Textual { |
|
|
|
|
std::string content; |
|
|
|
|
std::wstring content; |
|
|
|
|
unsigned int size = GUECS_FONT_SIZE; |
|
|
|
|
sf::Color color = GUECS_TEXT_COLOR; |
|
|
|
|
int padding = GUECS_PADDING; |
|
|
|
|
bool centered = false; |
|
|
|
|
shared_ptr<sf::Font> font = nullptr; |
|
|
|
|
shared_ptr<sf::Text> text = nullptr; |
|
|
|
|
|
|
|
|
|
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) { |
|
|
|
|
dbc::check(font_ptr != nullptr, "you failed to initialize this Text"); |
|
|
|
|
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText"); |
|
|
|
|
if(font == nullptr) font = font_ptr; |
|
|
|
|
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size); |
|
|
|
|
text->setFillColor(color); |
|
|
|
|
text->setPosition({float(cell.x + padding * 2), float(cell.y + padding * 2)}); |
|
|
|
|
|
|
|
|
|
if(centered) { |
|
|
|
|
dbc::log("TEXTUAL IS CENTERED"); |
|
|
|
|
auto bounds = text->getLocalBounds(); |
|
|
|
|
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell); |
|
|
|
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
|
|
|
|
text->setPosition({float(text_cell.x), float(text_cell.y) - text_cell.h / 2}); |
|
|
|
|
} else { |
|
|
|
|
text->setPosition({float(cell.x + padding * 2), float(cell.y + padding * 2)}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
text->setCharacterSize(size); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void update(std::string& new_content) { |
|
|
|
|
void update(std::wstring& new_content) { |
|
|
|
|
content = new_content; |
|
|
|
|
text->setString(content); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct WideText { |
|
|
|
|
std::wstring content; |
|
|
|
|
unsigned int size = GUECS_FONT_SIZE; |
|
|
|
|
sf::Color color = GUECS_TEXT_COLOR; |
|
|
|
|
int padding = GUECS_PADDING; |
|
|
|
|
shared_ptr<sf::Font> font = nullptr; |
|
|
|
|
shared_ptr<sf::Text> text = nullptr; |
|
|
|
|
struct Label : public Textual { |
|
|
|
|
|
|
|
|
|
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) { |
|
|
|
|
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText"); |
|
|
|
|
if(font == nullptr) font = font_ptr; |
|
|
|
|
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size); |
|
|
|
|
text->setFillColor(color); |
|
|
|
|
text->setPosition({float(cell.x + padding * 2), float(cell.y + padding * 2)}); |
|
|
|
|
text->setCharacterSize(size); |
|
|
|
|
template<typename... Args> |
|
|
|
|
Label(Args... args) : Textual(args...) |
|
|
|
|
{ |
|
|
|
|
centered = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void update(std::wstring& new_content) { |
|
|
|
|
content = new_content; |
|
|
|
|
text->setString(content); |
|
|
|
|
} |
|
|
|
|
Label() { |
|
|
|
|
centered = true; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct Clickable { |
|
|
|
@ -259,10 +222,10 @@ namespace guecs { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void show_sprite(string region, string sprite_name); |
|
|
|
|
void show_text(string region, string content); |
|
|
|
|
void update_text(string region, string content); |
|
|
|
|
void update_label(string region, string content); |
|
|
|
|
void show_label(string region, string content); |
|
|
|
|
void show_text(string region, wstring content); |
|
|
|
|
void update_text(string region, wstring content); |
|
|
|
|
void update_label(string region, wstring content); |
|
|
|
|
void show_label(string region, wstring content); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Clickable make_action(DinkyECS::World& target, Events::GUI event); |
|
|
|
|