From bb3f39531915a8362456fae3f602b7b34aeef218 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 20 Jan 2017 19:40:54 +0100 Subject: [PATCH 1/3] Revert "Spoilers.." This reverts commit e00d00931c0e4bca55d4a4894e98e77df2eba2fd. --- SDK/src/NDK/BaseWidget.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index 4d7f12fa8..c4ef2d1f8 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -76,6 +76,14 @@ namespace Ndk } } + void BaseWidget::SetCursor(Nz::SystemCursor systemCursor) + { + m_cursor = systemCursor; + + if (IsRegisteredToCanvas()) + m_canvas->NotifyWidgetCursorUpdate(m_canvasIndex); + } + void BaseWidget::SetSize(const Nz::Vector2f& size) { SetContentSize({std::max(size.x - m_padding.left - m_padding.right, 0.f), std::max(size.y - m_padding.top - m_padding.bottom, 0.f)}); @@ -120,7 +128,7 @@ namespace Ndk void BaseWidget::Layout() { if (IsRegisteredToCanvas()) - m_canvas->NotifyWidgetUpdate(m_canvasIndex); + m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex); if (m_backgroundEntity) m_backgroundSprite->SetSize(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom); @@ -131,7 +139,7 @@ namespace Ndk Node::InvalidateNode(); if (IsRegisteredToCanvas()) - m_canvas->NotifyWidgetUpdate(m_canvasIndex); + m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex); } void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) From cf286e0413decd613ffed8a45be3dd9fca2256d9 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 20 Jan 2017 20:03:00 +0100 Subject: [PATCH 2/3] Sdk/Widgets: Add possibility to set cursor when mouse hover a widget --- SDK/include/NDK/BaseWidget.hpp | 4 ++++ SDK/include/NDK/BaseWidget.inl | 6 ++++++ SDK/include/NDK/Canvas.hpp | 8 ++++++-- SDK/include/NDK/Canvas.inl | 23 ++++++++++++++++++++++- SDK/src/NDK/Canvas.cpp | 19 ++++++++----------- SDK/src/NDK/Widgets/TextAreaWidget.cpp | 2 ++ 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 5022ade61..723e93e80 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ namespace Ndk inline const Nz::Color& GetBackgroundColor() const; inline Canvas* GetCanvas(); + inline Nz::SystemCursor GetCursor() const; inline const Padding& GetPadding() const; inline Nz::Vector2f GetContentOrigin() const; inline const Nz::Vector2f& GetContentSize() const; @@ -58,6 +60,7 @@ namespace Ndk virtual void ResizeToContent() = 0; void SetBackgroundColor(const Nz::Color& color); + void SetCursor(Nz::SystemCursor systemCursor); inline void SetContentSize(const Nz::Vector2f& size); inline void SetPadding(float left, float top, float right, float bottom); void SetSize(const Nz::Vector2f& size); @@ -113,6 +116,7 @@ namespace Ndk WorldHandle m_world; Nz::Color m_backgroundColor; Nz::SpriteRef m_backgroundSprite; + Nz::SystemCursor m_cursor; Nz::Vector2f m_contentSize; BaseWidget* m_widgetParent; bool m_visible; diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index 9134b3c32..63b71a942 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -12,6 +12,7 @@ namespace Ndk m_canvasIndex(InvalidCanvasIndex), m_backgroundColor(Nz::Color(230, 230, 230, 255)), m_canvas(nullptr), + m_cursor(Nz::SystemCursor_Default), m_contentSize(50.f, 50.f), m_widgetParent(nullptr), m_visible(true) @@ -54,6 +55,11 @@ namespace Ndk return m_canvas; } + inline Nz::SystemCursor BaseWidget::GetCursor() const + { + return m_cursor; + } + inline const BaseWidget::Padding& BaseWidget::GetPadding() const { return m_padding; diff --git a/SDK/include/NDK/Canvas.hpp b/SDK/include/NDK/Canvas.hpp index f3ba31705..0cc314b73 100644 --- a/SDK/include/NDK/Canvas.hpp +++ b/SDK/include/NDK/Canvas.hpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace Ndk @@ -20,7 +21,7 @@ namespace Ndk public: struct Padding; - inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler); + inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController); Canvas(const Canvas&) = delete; Canvas(Canvas&&) = delete; inline ~Canvas(); @@ -33,7 +34,8 @@ namespace Ndk Canvas& operator=(Canvas&&) = delete; protected: - void NotifyWidgetUpdate(std::size_t index); + inline void NotifyWidgetBoxUpdate(std::size_t index); + inline void NotifyWidgetCursorUpdate(std::size_t index); std::size_t RegisterWidget(BaseWidget* widget); @@ -54,6 +56,7 @@ namespace Ndk { BaseWidget* widget; Nz::Boxf box; + Nz::SystemCursor cursor; }; NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); @@ -65,6 +68,7 @@ namespace Ndk NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); std::vector m_widgetBoxes; + Nz::CursorControllerHandle m_cursorController; const WidgetBox* m_hoveredWidget; BaseWidget* m_keyboardOwner; WorldHandle m_world; diff --git a/SDK/include/NDK/Canvas.inl b/SDK/include/NDK/Canvas.inl index 9ad38b852..3dd5de87f 100644 --- a/SDK/include/NDK/Canvas.inl +++ b/SDK/include/NDK/Canvas.inl @@ -3,10 +3,12 @@ // For conditions of distribution and use, see copyright notice in Prerequesites.hpp #include +#include namespace Ndk { - inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler) : + inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) : + m_cursorController(cursorController), m_hoveredWidget(nullptr), m_keyboardOwner(nullptr), m_world(std::move(world)) @@ -44,6 +46,25 @@ namespace Ndk return m_world; } + inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index) + { + WidgetBox& entry = m_widgetBoxes[index]; + + Nz::Vector3f pos = entry.widget->GetPosition(); + Nz::Vector2f size = entry.widget->GetContentSize(); + + entry.box.Set(pos.x, pos.y, pos.z, size.x, size.y, 1.f); + } + + inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index) + { + WidgetBox& entry = m_widgetBoxes[index]; + + entry.cursor = entry.widget->GetCursor(); + if (m_cursorController && m_hoveredWidget == &entry) + m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor)); + } + inline void Ndk::Canvas::SetKeyboardOwner(BaseWidget* widget) { m_keyboardOwner = widget; diff --git a/SDK/src/NDK/Canvas.cpp b/SDK/src/NDK/Canvas.cpp index 4f72e73b1..84e4b5bd8 100644 --- a/SDK/src/NDK/Canvas.cpp +++ b/SDK/src/NDK/Canvas.cpp @@ -14,25 +14,16 @@ namespace Ndk { } - void Canvas::NotifyWidgetUpdate(std::size_t index) - { - WidgetBox& entry = m_widgetBoxes[index]; - - Nz::Vector3f pos = entry.widget->GetPosition(); - Nz::Vector2f size = entry.widget->GetContentSize(); - - entry.box.Set(pos.x, pos.y, pos.z, size.x, size.y, 1.f); - } - std::size_t Canvas::RegisterWidget(BaseWidget* widget) { WidgetBox box; + box.cursor = widget->GetCursor(); box.widget = widget; std::size_t index = m_widgetBoxes.size(); m_widgetBoxes.emplace_back(box); - NotifyWidgetUpdate(index); + NotifyWidgetBoxUpdate(index); return index; } @@ -109,6 +100,9 @@ namespace Ndk m_hoveredWidget = bestEntry; m_hoveredWidget->widget->OnMouseEnter(); + + if (m_cursorController) + m_cursorController->UpdateCursor(Nz::Cursor::Get(m_hoveredWidget->cursor)); } int x = static_cast(std::round(event.x - m_hoveredWidget->box.x)); @@ -120,6 +114,9 @@ namespace Ndk { m_hoveredWidget->widget->OnMouseExit(); m_hoveredWidget = nullptr; + + if (m_cursorController) + m_cursorController->UpdateCursor(Nz::Cursor::Get(Nz::SystemCursor_Default)); } } diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index a5a557f9f..53a9ffdb4 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -32,6 +32,8 @@ namespace Ndk m_textEntity->AddComponent().Attach(m_textSprite); m_textEntity->AddComponent().SetParent(this); + SetCursor(Nz::SystemCursor_Text); + Layout(); } From 174feda1e9cbbbace8a5f68cb4c8f03fcc872065 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 20 Jan 2017 20:03:17 +0100 Subject: [PATCH 3/3] Sdk/TextAreaWidget: Make cursor sprite black --- SDK/src/NDK/Widgets/TextAreaWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index 53a9ffdb4..932757621 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -18,7 +18,7 @@ namespace Ndk m_readOnly(false) { m_cursorSprite = Nz::Sprite::New(); - m_cursorSprite->SetColor(Nz::Color(192, 192, 192)); + m_cursorSprite->SetColor(Nz::Color::Black); m_cursorSprite->SetSize(1.f, float(m_drawer.GetFont()->GetSizeInfo(m_drawer.GetCharacterSize()).lineHeight)); m_cursorEntity = CreateEntity();