|
|
@ -52,42 +52,19 @@ namespace guecs { |
|
|
|
|
|
|
|
|
|
|
|
sprite->setPosition({float(cell.x + padding), float(cell.y + padding)}); |
|
|
|
sprite->setPosition({float(cell.x + padding), float(cell.y + padding)}); |
|
|
|
|
|
|
|
|
|
|
|
sprite->setScale({ |
|
|
|
if(stretch) { |
|
|
|
float(cell.w - padding * 2) / float(bounds.x), |
|
|
|
sprite->setScale({ |
|
|
|
float(cell.h - padding * 2) / float(bounds.y)}); |
|
|
|
float(cell.w - padding * 2) / float(bounds.x), |
|
|
|
} |
|
|
|
float(cell.h - padding * 2) / float(bounds.y)}); |
|
|
|
|
|
|
|
} else { |
|
|
|
void Sprite::render(sf::RenderWindow& window, sf::Shader *shader_ptr) { |
|
|
|
float box_width = float(cell.w - padding * 2); |
|
|
|
window.draw(*sprite, shader_ptr); |
|
|
|
float box_height = float(cell.h - padding * 2); |
|
|
|
} |
|
|
|
float scale = std::min(box_width / float(bounds.x), box_height / float(bounds.y)); |
|
|
|
|
|
|
|
sprite->setScale({scale, scale}); |
|
|
|
void Icon::update(const string& new_name) { |
|
|
|
|
|
|
|
if(new_name != name) { |
|
|
|
|
|
|
|
name = new_name; |
|
|
|
|
|
|
|
auto sprite_texture = BACKEND->get_icon(name); |
|
|
|
|
|
|
|
sprite->setTexture(*sprite_texture.texture); |
|
|
|
|
|
|
|
sprite->setTextureRect({{0,0},sprite_texture.frame_size}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Icon::init(lel::Cell &cell) { |
|
|
|
void Sprite::render(sf::RenderWindow& window, sf::Shader *shader_ptr) { |
|
|
|
auto sprite_texture = BACKEND->get_icon(name); |
|
|
|
|
|
|
|
auto bounds = sprite_texture.frame_size; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::IntRect rect{{0,0}, bounds}; |
|
|
|
|
|
|
|
sprite = make_shared<sf::Sprite>(*sprite_texture.texture, rect); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sprite->setPosition({ float(cell.x + padding), float(cell.y + padding)}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float a_ratio = float(bounds.x) / float(bounds.y); |
|
|
|
|
|
|
|
float x_scale = float(cell.w - padding * 2) / float(bounds.x); |
|
|
|
|
|
|
|
float y_new_size = (float(bounds.x) * x_scale) / a_ratio; |
|
|
|
|
|
|
|
float y_scale = float(cell.h - padding * 2) / y_new_size; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sprite->setScale({x_scale, y_scale}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Icon::render(sf::RenderWindow& window, sf::Shader *shader_ptr) { |
|
|
|
|
|
|
|
window.draw(*sprite, shader_ptr); |
|
|
|
window.draw(*sprite, shader_ptr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|