diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 3c1562e6a..4cd41cd65 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -45,6 +45,8 @@ namespace Ndk inline const Nz::Vector2f& GetContentSize() const; inline Nz::Vector2f GetSize() const; + void GrabKeyboard(); + virtual void ResizeToContent() = 0; inline void SetContentSize(const Nz::Vector2f& size); @@ -73,6 +75,7 @@ namespace Ndk virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button); virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button); virtual void OnMouseExit(); + virtual void OnTextEntered(char32_t character, bool repeated); private: inline BaseWidget(); diff --git a/SDK/include/NDK/Canvas.hpp b/SDK/include/NDK/Canvas.hpp index 9bf8c8ddd..b88901360 100644 --- a/SDK/include/NDK/Canvas.hpp +++ b/SDK/include/NDK/Canvas.hpp @@ -36,7 +36,11 @@ namespace Ndk void Layout() override; void NotifyWidgetUpdate(std::size_t index); + std::size_t RegisterWidget(BaseWidget* widget); + + inline void SetKeyboardOwner(BaseWidget* widget); + void UnregisterWidget(std::size_t index); private: @@ -44,7 +48,8 @@ namespace Ndk void OnMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event); void OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event); void OnMouseLeft(const Nz::EventHandler* eventHandler); - + void OnTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event); + struct WidgetBox { BaseWidget* widget; @@ -55,9 +60,11 @@ namespace Ndk NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot); NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot); NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot); + NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); std::vector m_widgetBoxes; 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 f9dcc5845..37edcb2e6 100644 --- a/SDK/include/NDK/Canvas.inl +++ b/SDK/include/NDK/Canvas.inl @@ -8,6 +8,7 @@ namespace Ndk { inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler) : m_hoveredWidget(nullptr), + m_keyboardOwner(nullptr), m_world(std::move(world)) { m_canvas = this; @@ -16,10 +17,16 @@ namespace Ndk m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnMouseButtonRelease); m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnMouseMoved); m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnMouseLeft); + m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnTextEntered); } inline const WorldHandle& Canvas::GetWorld() const { return m_world; } + + inline void Ndk::Canvas::SetKeyboardOwner(BaseWidget* widget) + { + m_keyboardOwner = widget; + } } diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index b9e0f6b3c..939fdedfd 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -71,6 +71,11 @@ namespace Ndk m_entities.erase(it); } + void BaseWidget::GrabKeyboard() + { + m_canvas->SetKeyboardOwner(this); + } + void BaseWidget::Layout() { if (m_canvas) @@ -112,4 +117,8 @@ namespace Ndk void BaseWidget::OnMouseExit() { } + + void BaseWidget::OnTextEntered(char32_t character, bool repeated) + { + } } \ No newline at end of file diff --git a/SDK/src/NDK/Canvas.cpp b/SDK/src/NDK/Canvas.cpp index 4f9723146..5aa7cfc4a 100644 --- a/SDK/src/NDK/Canvas.cpp +++ b/SDK/src/NDK/Canvas.cpp @@ -57,6 +57,9 @@ namespace Ndk if (m_hoveredWidget == &entry) m_hoveredWidget = nullptr; + if (m_keyboardOwner == entry.widget) + m_keyboardOwner = nullptr; + entry = std::move(lastEntry); entry.widget->UpdateCanvasIndex(index); m_widgetBoxes.pop_back(); @@ -136,4 +139,10 @@ namespace Ndk m_hoveredWidget = nullptr; } } + + void Canvas::OnTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event) + { + if (m_keyboardOwner) + m_keyboardOwner->OnTextEntered(event.character, event.repeated); + } } \ No newline at end of file