Added ImageWidget (#139)

* Added ImageWidget

* Remove useless ResizeToContent function

* Add ResizeToContent function

* Forgot operators

* Added textures & colors functions

* oops
This commit is contained in:
S6066
2017-11-06 16:50:52 +01:00
committed by Jérôme Leclercq
parent 078641aa23
commit 2ed9691c80
4 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Widgets/ImageWidget.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
namespace Ndk
{
ImageWidget::ImageWidget(BaseWidget* parent) :
BaseWidget(parent)
{
m_entity = CreateEntity();
m_entity->AddComponent<NodeComponent>();
auto& gfx = m_entity->AddComponent<GraphicsComponent>();
m_sprite = Nz::Sprite::New();
gfx.Attach(m_sprite);
}
void ImageWidget::ResizeToContent()
{
Nz::Vector3ui textureSize = m_sprite->GetMaterial()->GetDiffuseMap()->GetSize();
SetSize({ static_cast<float>(textureSize.x), static_cast<float>(textureSize.y) });
}
void ImageWidget::Layout()
{
BaseWidget::Layout();
Nz::Vector2f origin = GetContentOrigin();
Nz::Vector2f contentSize = GetContentSize();
m_entity->GetComponent<NodeComponent>().SetPosition(origin);
m_sprite->SetSize(contentSize);
}
}