Widgets: Add ImageWidget

This commit is contained in:
Jérôme Leclercq
2021-11-24 22:24:57 +01:00
parent 6c97f538a1
commit 643b1a2b15
4 changed files with 138 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
// Copyright (C) 2021 Samy Bensaid
// This file is part of the "Nazara Engine - Widgets module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Widgets/ImageWidget.hpp>
#include <Nazara/Graphics/Components/GraphicsComponent.hpp>
#include <Nazara/Utility/Components/NodeComponent.hpp>
#include <Nazara/Widgets/Canvas.hpp>
#include <Nazara/Widgets/Widgets.hpp>
#include <Nazara/Widgets/Debug.hpp>
namespace Nz
{
ImageWidget::ImageWidget(BaseWidget* parent) :
BaseWidget(parent)
{
m_sprite = std::make_shared<Sprite>(Widgets::Instance()->GetTransparentMaterial());
auto& registry = GetRegistry();
m_entity = CreateEntity();
auto& gfxComponent = registry.emplace<GraphicsComponent>(m_entity, IsVisible());
gfxComponent.AttachRenderable(m_sprite, GetCanvas()->GetRenderMask());
auto& nodeComponent = registry.emplace<NodeComponent>(m_entity);
nodeComponent.SetParent(this);
}
void ImageWidget::Layout()
{
BaseWidget::Layout();
m_sprite->SetSize(GetSize());
}
}