SDK/Widgets: Add OnKeyPressed/OnKeyReleased callbacks
This commit is contained in:
parent
e3daf7ef1f
commit
cfa9b4bf2f
|
|
@ -12,6 +12,7 @@
|
||||||
#include <NDK/EntityOwner.hpp>
|
#include <NDK/EntityOwner.hpp>
|
||||||
#include <NDK/World.hpp>
|
#include <NDK/World.hpp>
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
|
#include <Nazara/Utility/Event.hpp>
|
||||||
#include <Nazara/Utility/Mouse.hpp>
|
#include <Nazara/Utility/Mouse.hpp>
|
||||||
#include <Nazara/Utility/Node.hpp>
|
#include <Nazara/Utility/Node.hpp>
|
||||||
|
|
||||||
|
|
@ -70,6 +71,8 @@ namespace Ndk
|
||||||
virtual void Layout();
|
virtual void Layout();
|
||||||
void InvalidateNode() override;
|
void InvalidateNode() override;
|
||||||
|
|
||||||
|
virtual void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
|
||||||
|
virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key);
|
||||||
virtual void OnMouseEnter();
|
virtual void OnMouseEnter();
|
||||||
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
|
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
|
||||||
virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button);
|
virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button);
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Ndk
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
|
||||||
void NotifyWidgetUpdate(std::size_t index);
|
void NotifyWidgetUpdate(std::size_t index);
|
||||||
|
|
||||||
std::size_t RegisterWidget(BaseWidget* widget);
|
std::size_t RegisterWidget(BaseWidget* widget);
|
||||||
|
|
||||||
inline void SetKeyboardOwner(BaseWidget* widget);
|
inline void SetKeyboardOwner(BaseWidget* widget);
|
||||||
|
|
@ -48,6 +48,8 @@ namespace Ndk
|
||||||
void OnMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
void OnMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||||
void OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
void OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||||
void OnMouseLeft(const Nz::EventHandler* eventHandler);
|
void OnMouseLeft(const Nz::EventHandler* eventHandler);
|
||||||
|
void OnKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||||
|
void OnKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||||
void OnTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
void OnTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
||||||
|
|
||||||
struct WidgetBox
|
struct WidgetBox
|
||||||
|
|
@ -56,6 +58,8 @@ namespace Ndk
|
||||||
Nz::Boxf box;
|
Nz::Boxf box;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
|
||||||
|
NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot);
|
||||||
NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
|
NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
|
||||||
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
|
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
|
||||||
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
|
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
m_canvas = this;
|
m_canvas = this;
|
||||||
|
|
||||||
|
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnKeyPressed);
|
||||||
|
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnKeyReleased);
|
||||||
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnMouseButtonPressed);
|
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnMouseButtonPressed);
|
||||||
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnMouseButtonRelease);
|
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnMouseButtonRelease);
|
||||||
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnMouseMoved);
|
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnMouseMoved);
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,14 @@ namespace Ndk
|
||||||
m_canvas->NotifyWidgetUpdate(m_canvasIndex);
|
m_canvas->NotifyWidgetUpdate(m_canvasIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseEnter()
|
void BaseWidget::OnMouseEnter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -121,4 +129,4 @@ namespace Ndk
|
||||||
void BaseWidget::OnTextEntered(char32_t character, bool repeated)
|
void BaseWidget::OnTextEntered(char32_t character, bool repeated)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event)
|
void Canvas::OnMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
|
||||||
{
|
{
|
||||||
if (m_hoveredWidget)
|
if (m_hoveredWidget)
|
||||||
{
|
{
|
||||||
|
|
@ -77,7 +77,7 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnMouseButtonRelease(const Nz::EventHandler * eventHandler, const Nz::WindowEvent::MouseButtonEvent & event)
|
void Canvas::OnMouseButtonRelease(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent & event)
|
||||||
{
|
{
|
||||||
if (m_hoveredWidget)
|
if (m_hoveredWidget)
|
||||||
{
|
{
|
||||||
|
|
@ -88,7 +88,7 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event)
|
void Canvas::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||||
{
|
{
|
||||||
const WidgetBox* bestEntry = nullptr;
|
const WidgetBox* bestEntry = nullptr;
|
||||||
float bestEntryArea = std::numeric_limits<float>::infinity();
|
float bestEntryArea = std::numeric_limits<float>::infinity();
|
||||||
|
|
@ -131,7 +131,7 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnMouseLeft(const Nz::EventHandler* eventHandler)
|
void Canvas::OnMouseLeft(const Nz::EventHandler* /*eventHandler*/)
|
||||||
{
|
{
|
||||||
if (m_hoveredWidget)
|
if (m_hoveredWidget)
|
||||||
{
|
{
|
||||||
|
|
@ -140,9 +140,21 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event)
|
void Canvas::OnKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||||
|
{
|
||||||
|
if (m_keyboardOwner)
|
||||||
|
m_keyboardOwner->OnKeyPressed(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||||
|
{
|
||||||
|
if (m_keyboardOwner)
|
||||||
|
m_keyboardOwner->OnKeyReleased(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event)
|
||||||
{
|
{
|
||||||
if (m_keyboardOwner)
|
if (m_keyboardOwner)
|
||||||
m_keyboardOwner->OnTextEntered(event.character, event.repeated);
|
m_keyboardOwner->OnTextEntered(event.character, event.repeated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue