Converted almost everything to use wstring so that it works better with SFML and the unicode/utf8 usage in the system.
This commit is contained in:
parent
47c6bfd531
commit
72951f308f
17 changed files with 156 additions and 162 deletions
97
guecs.hpp
97
guecs.hpp
|
@ -13,74 +13,14 @@
|
|||
#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;
|
||||
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;
|
||||
|
||||
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
||||
dbc::check(font_ptr != nullptr, "you failed to initialize this Text");
|
||||
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);
|
||||
}
|
||||
|
||||
void update(std::string& 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;
|
||||
bool centered = false;
|
||||
shared_ptr<sf::Font> font = nullptr;
|
||||
shared_ptr<sf::Text> text = nullptr;
|
||||
|
||||
|
@ -89,7 +29,17 @@ namespace guecs {
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -99,6 +49,19 @@ namespace guecs {
|
|||
}
|
||||
};
|
||||
|
||||
struct Label : public Textual {
|
||||
|
||||
template<typename... Args>
|
||||
Label(Args... args) : Textual(args...)
|
||||
{
|
||||
centered = true;
|
||||
}
|
||||
|
||||
Label() {
|
||||
centered = true;
|
||||
};
|
||||
};
|
||||
|
||||
struct Clickable {
|
||||
/* This is actually called by UI::mouse and passed the entity ID of the
|
||||
* button pressed so you can interact with it in the event handler.
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue