Widgets/BaseWidget: Fix background position and render mask

This commit is contained in:
Jérôme Leclercq 2021-11-21 17:14:59 +01:00
parent 2a8568f2ac
commit 1b271a29ef
2 changed files with 6 additions and 3 deletions

View File

@ -7,7 +7,7 @@
namespace Nz namespace Nz
{ {
inline void LabelWidget::UpdateText(const Nz::AbstractTextDrawer& drawer, float scale) inline void LabelWidget::UpdateText(const AbstractTextDrawer& drawer, float scale)
{ {
m_textSprite->Update(drawer, scale); m_textSprite->Update(drawer, scale);

View File

@ -82,12 +82,12 @@ namespace Nz
auto material = std::make_shared<Material>(); auto material = std::make_shared<Material>();
material->AddPass("ForwardPass", std::make_shared<MaterialPass>(BasicMaterial::GetSettings())); material->AddPass("ForwardPass", std::make_shared<MaterialPass>(BasicMaterial::GetSettings()));
m_backgroundSprite = std::make_shared<Nz::Sprite>(std::move(material)); m_backgroundSprite = std::make_shared<Sprite>(std::move(material));
m_backgroundSprite->SetColor(m_backgroundColor); m_backgroundSprite->SetColor(m_backgroundColor);
//m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D")); //< TODO: Use a shared material instead of creating one everytime //m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D")); //< TODO: Use a shared material instead of creating one everytime
entt::entity backgroundEntity = CreateEntity(); entt::entity backgroundEntity = CreateEntity();
m_registry->emplace<GraphicsComponent>(backgroundEntity).AttachRenderable(m_backgroundSprite); m_registry->emplace<GraphicsComponent>(backgroundEntity).AttachRenderable(m_backgroundSprite, GetCanvas()->GetRenderMask());
m_registry->emplace<NodeComponent>(backgroundEntity).SetParent(this); m_registry->emplace<NodeComponent>(backgroundEntity).SetParent(this);
m_backgroundEntity = backgroundEntity; m_backgroundEntity = backgroundEntity;
@ -242,7 +242,10 @@ namespace Nz
void BaseWidget::Layout() void BaseWidget::Layout()
{ {
if (m_backgroundSprite) if (m_backgroundSprite)
{
m_registry->get<NodeComponent>(*m_backgroundEntity).SetPosition(0.f, m_size.y);
m_backgroundSprite->SetSize({ m_size.x, m_size.y }); m_backgroundSprite->SetSize({ m_size.x, m_size.y });
}
UpdatePositionAndSize(); UpdatePositionAndSize();
} }