Fixed Icon vs. Sprite and now Icon is just a subclass of Sprite. Closes #12.
This commit is contained in:
parent
a22342cd7e
commit
3752522597
3 changed files with 26 additions and 5 deletions
|
@ -93,7 +93,7 @@ struct ClickerUI {
|
|||
if(name != "clicker") {
|
||||
$gui.set<guecs::Rectangle>(id, {});
|
||||
$gui.set<guecs::Effect>(id, {});
|
||||
$gui.set<guecs::Icon>(id, { "clicker_treat_bone" });
|
||||
$gui.set<guecs::Sprite>(id, { "clicker_treat_bone" });
|
||||
$gui.set<guecs::Clickable>(id, {
|
||||
[&](auto, auto) { handle_button(Event::A_BUTTON); }
|
||||
});
|
||||
|
@ -101,7 +101,7 @@ struct ClickerUI {
|
|||
}
|
||||
|
||||
$clicker = $gui.entity("clicker");
|
||||
$gui.set<guecs::Sprite>($clicker, {"clicker_the_dog", 0, true});
|
||||
$gui.set<guecs::Sprite>($clicker, {"clicker_the_dog"});
|
||||
$gui.set<guecs::Sound>($clicker, {"clicker_bark"});
|
||||
$gui.set<guecs::Clickable>($clicker, {
|
||||
[&](auto, auto) { handle_button(Event::CLICKER); }
|
||||
|
|
|
@ -40,7 +40,8 @@ namespace guecs {
|
|||
struct Sprite {
|
||||
string name;
|
||||
int padding = THEME.PADDING;
|
||||
bool stretch = false;
|
||||
bool stretch = true;
|
||||
bool is_icon = false;
|
||||
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
||||
|
||||
void init(lel::Cell &cell);
|
||||
|
@ -48,7 +49,19 @@ namespace guecs {
|
|||
void render(sf::RenderWindow& window, sf::Shader *shader_ptr);
|
||||
};
|
||||
|
||||
struct Icon : public Sprite { };
|
||||
struct Icon : public Sprite {
|
||||
template<typename... Args>
|
||||
Icon(Args... args) : Sprite(args...)
|
||||
{
|
||||
stretch = false;
|
||||
is_icon = true;
|
||||
}
|
||||
|
||||
Icon() {
|
||||
// BUG: why do I have to do this again?
|
||||
stretch = false;
|
||||
};
|
||||
};
|
||||
|
||||
struct Rectangle {
|
||||
int padding = THEME.PADDING;
|
||||
|
|
|
@ -43,8 +43,16 @@ namespace guecs {
|
|||
}
|
||||
}
|
||||
|
||||
inline SpriteTexture load_texture(const string& name, bool is_icon) {
|
||||
if(is_icon) {
|
||||
return BACKEND->get_icon(name);
|
||||
} else {
|
||||
return BACKEND->get_sprite(name);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::init(lel::Cell &cell) {
|
||||
auto sprite_texture = BACKEND->get_sprite(name);
|
||||
auto sprite_texture = load_texture(name, is_icon);
|
||||
auto bounds = sprite_texture.frame_size;
|
||||
|
||||
sf::IntRect rect{{0,0}, bounds};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue