Sdk/Widget: Add Canvas system, mouse movement event for widgets (buttons react to hovering)

Former-commit-id: 685295853d1f0edf28c36b2f698eca881da25ea2 [formerly f65f951ed3d2edfd9c12d390837cd13e5691eaa3] [formerly 5e239f37c28bf5e93a71cba29a94f0de680a79a2 [formerly 38346fa5d68c7bf79ddebc1990959e7c56617640]]
Former-commit-id: 92da4ed40fb63fe0b02c7543ea64cebda0575623 [formerly 2db1fe5fca87a1461ceb8314709d764af079a7be]
Former-commit-id: 77d61a99fd5a2bb21701fbe4a4b4451c3655663a
This commit is contained in:
Lynix
2016-09-15 13:16:37 +02:00
parent 136fb65a6d
commit 72206a3ca3
10 changed files with 285 additions and 15 deletions

View File

@@ -9,8 +9,8 @@
namespace Ndk
{
ButtonWidget::ButtonWidget(const WorldHandle& world, BaseWidget* parent) :
BaseWidget(world, parent)
ButtonWidget::ButtonWidget(BaseWidget* parent) :
BaseWidget(parent)
{
m_gradientSprite = Nz::Sprite::New();
m_gradientSprite->SetColor(Nz::Color(74, 74, 74));
@@ -21,13 +21,14 @@ namespace Ndk
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);
Layout();
}
void ButtonWidget::ResizeToContent()
@@ -37,6 +38,8 @@ namespace Ndk
void ButtonWidget::Layout()
{
BaseWidget::Layout();
const Nz::Vector2f& contentSize = GetContentSize();
m_gradientSprite->SetSize(contentSize);
@@ -44,4 +47,19 @@ namespace Ndk
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);
}
void ButtonWidget::OnMouseEnter()
{
m_gradientSprite->SetColor(Nz::Color(128, 128, 128));
}
void ButtonWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
{
NazaraDebug(Nz::String::Number(x) + ", " + Nz::String::Number(y));
}
void ButtonWidget::OnMouseExit()
{
m_gradientSprite->SetColor(Nz::Color(74, 74, 74));
}
}

View File

@@ -9,14 +9,16 @@
namespace Ndk
{
LabelWidget::LabelWidget(const WorldHandle& world, BaseWidget* parent) :
BaseWidget(world, parent)
LabelWidget::LabelWidget(BaseWidget* parent) :
BaseWidget(parent)
{
m_textSprite = Nz::TextSprite::New();
m_textEntity = CreateEntity();
m_textEntity->AddComponent<GraphicsComponent>().Attach(m_textSprite);
m_textEntity->AddComponent<NodeComponent>().SetParent(this);
Layout();
}
void LabelWidget::ResizeToContent()