Skip to content

Commit

Permalink
True fix panel borders
Browse files Browse the repository at this point in the history
  • Loading branch information
autosquash committed Feb 25, 2024
1 parent 4539ffa commit b971b07
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/vista/paneles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ namespace medidas {
constexpr float GROSOR_BORDE_PANEL = 3;
} // namespace medidas

namespace {
std::shared_ptr<sf::RenderTexture>
crear_render_texture_interior(const sf::Shape &forma) {
const auto thickness = forma.getOutlineThickness();
const auto bounds = forma.getGlobalBounds();
auto texture = std::make_shared<sf::RenderTexture>();
assert(texture->create(
bounds.width - thickness * 2, //
bounds.height - thickness * 2 //
));
return texture;
}

sf::Sprite crear_sprite_interior(
std::shared_ptr<sf::RenderTexture> render_texture,
const sf::Shape &forma
) {
const auto thickness = forma.getOutlineThickness();
const auto bounds = forma.getGlobalBounds();
// Crea un sprite con la textura de la renderTexture
sf::Sprite sprite(render_texture->getTexture());
sprite.setPosition(
bounds.left + thickness, //
bounds.top + thickness //
);
return sprite;
}
} // namespace

const std::map<IndicePanel, std::string> texto_titulos_paneles = {
{IndicePanel::PANEL_ENCARGAR, "Encargar"},
{IndicePanel::PANEL_EN_PREPARACION, "En preparaci%on"},
Expand Down Expand Up @@ -71,11 +100,7 @@ PanelEncargar::PanelEncargar(
for (auto [_, btn] : encargar) {
add_child(btn);
}
render_texture = std::make_shared<sf::RenderTexture>();
assert(render_texture->create(
forma.getGlobalBounds().width - forma.getOutlineThickness(),
forma.getGlobalBounds().height - forma.getOutlineThickness()
));
render_texture = crear_render_texture_interior(forma);
}

void PanelEncargar::draw(
Expand All @@ -92,11 +117,8 @@ void PanelEncargar::draw(
render_texture->draw(*boton_ptr);
}
render_texture->display();
// Crea un sprite con la textura de la renderTexture
sf::Sprite sprite(render_texture->getTexture());
sprite.setPosition(
forma.getGlobalBounds().left, forma.getGlobalBounds().top
); // Posiciona el sprite en el render target segun sea necesario

sf::Sprite sprite = crear_sprite_interior(render_texture, forma);
target.draw(sprite);
}

Expand Down Expand Up @@ -185,11 +207,7 @@ PanelPedidos::PanelPedidos(
tarjetas_pedidos = std::make_shared<TarjetasPedidos>();
add_child(tarjetas_pedidos);

render_texture = std::make_shared<sf::RenderTexture>();
assert(render_texture->create(
forma.getGlobalBounds().width - forma.getOutlineThickness(),
forma.getGlobalBounds().height - forma.getOutlineThickness()
));
render_texture = crear_render_texture_interior(forma);
}

void PanelPedidos::actualizar(const VistaPedidos &presentacion_pedidos //
Expand All @@ -206,10 +224,7 @@ void PanelPedidos::draw(
render_texture->clear(sf::Color::Transparent);
render_texture->draw(*tarjetas_pedidos);
render_texture->display();
sf::Sprite sprite(render_texture->getTexture());
sprite.setPosition(
forma.getGlobalBounds().left, forma.getGlobalBounds().top
);
sf::Sprite sprite = crear_sprite_interior(render_texture, forma);
target.draw(sprite);
}

Expand Down

0 comments on commit b971b07

Please sign in to comment.