diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 2c3b6df7b..cff9b1a9e 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -56,6 +56,8 @@ namespace Ndk inline const Nz::Vector2f& GetContentSize() const; inline Nz::Vector2f GetSize() const; + bool HasFocus() const; + inline bool IsVisible() const; virtual void ResizeToContent() = 0; diff --git a/SDK/include/NDK/Canvas.hpp b/SDK/include/NDK/Canvas.hpp index 44e377aa2..2f81e3520 100644 --- a/SDK/include/NDK/Canvas.hpp +++ b/SDK/include/NDK/Canvas.hpp @@ -35,7 +35,9 @@ namespace Ndk protected: inline void ClearKeyboardOwner(std::size_t canvasIndex); - + + inline bool IsKeyboardOwner(std::size_t canvasIndex) const; + inline void NotifyWidgetBoxUpdate(std::size_t index); inline void NotifyWidgetCursorUpdate(std::size_t index); diff --git a/SDK/include/NDK/Canvas.inl b/SDK/include/NDK/Canvas.inl index a70a0edb1..f1f1daec6 100644 --- a/SDK/include/NDK/Canvas.inl +++ b/SDK/include/NDK/Canvas.inl @@ -52,6 +52,11 @@ namespace Ndk SetKeyboardOwner(InvalidCanvasIndex); } + inline bool Canvas::IsKeyboardOwner(std::size_t canvasIndex) const + { + return m_keyboardOwner == canvasIndex; + } + inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index) { WidgetBox& entry = m_widgetBoxes[index]; diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index 8af1ef19c..61bc9b13c 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -79,7 +79,7 @@ namespace Ndk { m_backgroundSprite = Nz::Sprite::New(); m_backgroundSprite->SetColor(m_backgroundColor); - m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D")); + m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D")); //< TODO: Use a shared material instead of creating one everytime m_backgroundEntity = CreateEntity(); m_backgroundEntity->AddComponent().Attach(m_backgroundSprite, -1); @@ -94,6 +94,18 @@ namespace Ndk } } + /*! + * \brief Checks if this widget has keyboard focus + * \return true if widget has keyboard focus, false otherwhise + */ + bool BaseWidget::HasFocus() const + { + if (!IsRegisteredToCanvas()) + return false; + + return m_canvas->IsKeyboardOwner(m_canvasIndex); + } + void BaseWidget::SetBackgroundColor(const Nz::Color& color) { m_backgroundColor = color;