Refactoring the GUECS UI::render and the components so that it's just calling a .render on each one. This will then let me allow registering any components people want.
This commit is contained in:
parent
a9e219ea96
commit
4d71f552aa
7 changed files with 108 additions and 69 deletions
|
@ -21,6 +21,7 @@ namespace guecs {
|
|||
|
||||
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr);
|
||||
void update(const std::wstring& new_content);
|
||||
void render(sf::RenderWindow& window, sf::Shader *shader_ptr);
|
||||
};
|
||||
|
||||
struct Label : public Textual {
|
||||
|
@ -49,6 +50,7 @@ namespace guecs {
|
|||
|
||||
void init(lel::Cell &cell);
|
||||
void update(const string& new_name);
|
||||
void render(sf::RenderWindow& window, sf::Shader *shader_ptr);
|
||||
};
|
||||
|
||||
struct Rectangle {
|
||||
|
@ -59,6 +61,7 @@ namespace guecs {
|
|||
shared_ptr<sf::RectangleShape> shape = nullptr;
|
||||
|
||||
void init(lel::Cell& cell);
|
||||
void render(sf::RenderWindow& window, sf::Shader *shader_ptr);
|
||||
};
|
||||
|
||||
struct Meter {
|
||||
|
@ -67,7 +70,8 @@ namespace guecs {
|
|||
Rectangle bar;
|
||||
|
||||
void init(lel::Cell& cell);
|
||||
void render(lel::Cell& cell);
|
||||
void init(lel::Cell& cell, Rectangle& bg);
|
||||
void render(lel::Cell& cell, sf::RenderWindow& window, sf::Shader *shader_ptr);
|
||||
};
|
||||
|
||||
struct Effect {
|
||||
|
@ -82,8 +86,9 @@ namespace guecs {
|
|||
void init(lel::Cell &cell);
|
||||
void run();
|
||||
void stop();
|
||||
void step();
|
||||
shared_ptr<sf::Shader> checkout_ptr();
|
||||
void render();
|
||||
sf::Shader* get_shader(bool is_shape);
|
||||
|
||||
};
|
||||
|
||||
struct Sound {
|
||||
|
@ -111,5 +116,6 @@ namespace guecs {
|
|||
Background() {}
|
||||
|
||||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -209,20 +209,11 @@ namespace guecs {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void render_helper(sf::RenderWindow& window, Entity ent, bool is_shape, T& target) {
|
||||
sf::Shader *shader_ptr = nullptr;
|
||||
void render_helper(sf::RenderWindow& window, T& target, sf::Shader *shader_ptr) {
|
||||
window.draw(*target, shader_ptr);
|
||||
}
|
||||
|
||||
if(auto shader = get_if<Effect>(ent)) {
|
||||
if(shader->$active) {
|
||||
auto ptr = shader->checkout_ptr();
|
||||
ptr->setUniform("is_shape", is_shape);
|
||||
// NOTE: this is needed because SFML doesn't handle shared_ptr
|
||||
shader_ptr = ptr.get();
|
||||
}
|
||||
}
|
||||
|
||||
window.draw(*target, shader_ptr);
|
||||
}
|
||||
sf::Shader* find_shader(Entity ent, bool is_shape);
|
||||
|
||||
void show_sprite(const string& region, const string& sprite_name);
|
||||
void show_text(const string& region, const wstring& content);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue