SDK/Widgets: Add buttons (not clickable atm)
Former-commit-id: 8c37250acd7bf5123674f1d83d4d55d7125f080e [formerly 6705a2a453bb8c1e441a5008beb9a4ac60847fa2] [formerly a391c49c98f003cfcb8409d67052ce7998329f9b [formerly a8440703ccade130b116dc51246cd3ec0e16e6ae]] Former-commit-id: 7f0f4bd7353768e7e0440ef41ce24c8035d7ee83 [formerly 6d3310e1488bbea850e17257da5588f9f0d0ec03] Former-commit-id: 1ef3f72963ba3df19e789aae2a2e263e104a2e94
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Ndk
|
||||
delete child;
|
||||
}
|
||||
|
||||
inline void Ndk::BaseWidget::EnableBackground(bool enable)
|
||||
inline void BaseWidget::EnableBackground(bool enable)
|
||||
{
|
||||
if (m_backgroundEntity.IsValid() == enable)
|
||||
return;
|
||||
@@ -30,7 +30,7 @@ namespace Ndk
|
||||
m_backgroundEntity->AddComponent<GraphicsComponent>().Attach(m_backgroundSprite, -1);
|
||||
m_backgroundEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
|
||||
UpdateBackground();
|
||||
BaseWidget::Layout(); // Only layout background
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace Ndk
|
||||
m_entities.erase(it);
|
||||
}
|
||||
|
||||
void BaseWidget::UpdateBackground()
|
||||
void BaseWidget::Layout()
|
||||
{
|
||||
if (m_backgroundEntity)
|
||||
{
|
||||
|
||||
47
SDK/src/NDK/Widgets/ButtonWidget.cpp
Normal file
47
SDK/src/NDK/Widgets/ButtonWidget.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Widgets/ButtonWidget.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ButtonWidget::ButtonWidget(const WorldHandle& world, BaseWidget* parent) :
|
||||
BaseWidget(world, parent)
|
||||
{
|
||||
m_gradientSprite = Nz::Sprite::New();
|
||||
m_gradientSprite->SetColor(Nz::Color(74, 74, 74));
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, Nz::Color(180, 180, 180));
|
||||
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, Nz::Color(180, 180, 180));
|
||||
m_gradientSprite->SetMaterial(Nz::Material::New("Basic2D"));
|
||||
|
||||
m_gradientEntity = CreateEntity();
|
||||
m_gradientEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_gradientEntity->AddComponent<GraphicsComponent>().Attach(m_gradientSprite);
|
||||
m_gradientEntity->GetComponent<GraphicsComponent>().Attach(m_borderSprite, Nz::Matrix4f::Translate(Nz::Vector2f(-1.f, -1.f)), -1);
|
||||
|
||||
m_textSprite = Nz::TextSprite::New();
|
||||
|
||||
m_textEntity = CreateEntity();
|
||||
m_textEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||
m_textEntity->AddComponent<GraphicsComponent>().Attach(m_textSprite, 1);
|
||||
}
|
||||
|
||||
void ButtonWidget::ResizeToContent()
|
||||
{
|
||||
SetContentSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()));
|
||||
}
|
||||
|
||||
void ButtonWidget::Layout()
|
||||
{
|
||||
const Nz::Vector2f& contentSize = GetContentSize();
|
||||
|
||||
m_gradientSprite->SetSize(contentSize);
|
||||
|
||||
Nz::Boxf textBox = m_textEntity->GetComponent<GraphicsComponent>().GetBoundingVolume().aabb;
|
||||
m_textEntity->GetComponent<NodeComponent>().SetPosition(contentSize.x / 2 - textBox.width / 2, contentSize.y / 2 - textBox.height / 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user