Update Events & docs
This commit is contained in:
parent
1c923ca76d
commit
fad362f1aa
2
Doxyfile
2
Doxyfile
|
|
@ -53,7 +53,7 @@ EXCLUDE = src/3rd-party
|
||||||
|
|
||||||
ENABLE_PREPROCESSING = YES
|
ENABLE_PREPROCESSING = YES
|
||||||
MACRO_EXPANSION = YES
|
MACRO_EXPANSION = YES
|
||||||
PREDEFINED = KGE_API=
|
PREDEFINED = KGE_API=
|
||||||
|
|
||||||
# The INCLUDE_PATH tag can be used to specify one or more directories that
|
# The INCLUDE_PATH tag can be used to specify one or more directories that
|
||||||
# contain include files that are not input files but should be processed by the
|
# contain include files that are not input files but should be processed by the
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,17 @@
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
namespace event
|
|
||||||
{
|
|
||||||
EventType event::ContactBegin = EventType(L"ContactBegin");
|
|
||||||
EventType event::ContactEnd = EventType(L"ContactEnd");
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace physics
|
namespace physics
|
||||||
{
|
{
|
||||||
|
namespace events
|
||||||
|
{
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(ContactBegin, physics::ContactBeginEvent);
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(ContactEnd, physics::ContactEndEvent);
|
||||||
|
}
|
||||||
|
|
||||||
ContactBeginEvent::ContactBeginEvent()
|
ContactBeginEvent::ContactBeginEvent()
|
||||||
: Event(event::ContactBegin)
|
: Event(events::ContactBegin)
|
||||||
, body_a(nullptr)
|
, body_a(nullptr)
|
||||||
, body_b(nullptr)
|
, body_b(nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -47,7 +47,7 @@ namespace kiwano
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactEndEvent::ContactEndEvent()
|
ContactEndEvent::ContactEndEvent()
|
||||||
: Event(event::ContactEnd)
|
: Event(events::ContactEnd)
|
||||||
, body_a(nullptr)
|
, body_a(nullptr)
|
||||||
, body_b(nullptr)
|
, body_b(nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,37 +26,46 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
namespace physics
|
namespace physics
|
||||||
{
|
{
|
||||||
// 接触开始事件
|
namespace events
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* \addtogroup EventTypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
KGE_DECLARE_EVENT_TYPE(ContactBegin); ///< 接触开始
|
||||||
|
KGE_DECLARE_EVENT_TYPE(ContactEnd); ///< 接触结束
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 接触开始事件
|
||||||
class KGE_API ContactBeginEvent
|
class KGE_API ContactBeginEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Contact contact;
|
Contact contact; ///< 产生的接触
|
||||||
Body* body_a;
|
Body* body_a; ///< 产生接触的物体A
|
||||||
Body* body_b;
|
Body* body_b; ///< 产生接触的物体B
|
||||||
|
|
||||||
ContactBeginEvent();
|
ContactBeginEvent();
|
||||||
ContactBeginEvent(Contact const& contact);
|
ContactBeginEvent(Contact const& contact);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 接触结束事件
|
/// \~chinese
|
||||||
|
/// @brief 接触结束事件
|
||||||
class KGE_API ContactEndEvent
|
class KGE_API ContactEndEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Contact contact;
|
Contact contact; ///< 产生的接触
|
||||||
Body* body_a;
|
Body* body_a; ///< 产生接触的物体A
|
||||||
Body* body_b;
|
Body* body_b; ///< 产生接触的物体B
|
||||||
|
|
||||||
ContactEndEvent();
|
ContactEndEvent();
|
||||||
ContactEndEvent(Contact const& contact);
|
ContactEndEvent(Contact const& contact);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace event
|
|
||||||
{
|
|
||||||
extern EventType ContactBegin; // 接触开始
|
|
||||||
extern EventType ContactEnd; // 接触结束
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -169,21 +169,21 @@ namespace kiwano
|
||||||
|
|
||||||
if (responsible_)
|
if (responsible_)
|
||||||
{
|
{
|
||||||
if (evt.type == event::MouseMove)
|
if (evt.IsType<MouseMoveEvent>())
|
||||||
{
|
{
|
||||||
auto mouse_evt = evt.SafeCast<MouseMoveEvent>();
|
auto& mouse_evt = evt.SafeCast<MouseMoveEvent>();
|
||||||
if (!mouse_evt->target && ContainsPoint(mouse_evt->pos))
|
if (!mouse_evt.target && ContainsPoint(mouse_evt.pos))
|
||||||
{
|
{
|
||||||
mouse_evt->target = this;
|
mouse_evt.target = this;
|
||||||
|
|
||||||
if (!hover_)
|
if (!hover_)
|
||||||
{
|
{
|
||||||
hover_ = true;
|
hover_ = true;
|
||||||
|
|
||||||
MouseHoverEvent hover;
|
MouseHoverEvent hover;
|
||||||
hover.pos = mouse_evt->pos;
|
hover.pos = mouse_evt.pos;
|
||||||
hover.left_btn_down = mouse_evt->left_btn_down;
|
hover.left_btn_down = mouse_evt.left_btn_down;
|
||||||
hover.right_btn_down = mouse_evt->right_btn_down;
|
hover.right_btn_down = mouse_evt.right_btn_down;
|
||||||
hover.target = this;
|
hover.target = this;
|
||||||
EventDispatcher::Dispatch(hover);
|
EventDispatcher::Dispatch(hover);
|
||||||
}
|
}
|
||||||
|
|
@ -194,33 +194,33 @@ namespace kiwano
|
||||||
pressed_ = false;
|
pressed_ = false;
|
||||||
|
|
||||||
MouseOutEvent out;
|
MouseOutEvent out;
|
||||||
out.pos = mouse_evt->pos;
|
out.pos = mouse_evt.pos;
|
||||||
out.left_btn_down = mouse_evt->left_btn_down;
|
out.left_btn_down = mouse_evt.left_btn_down;
|
||||||
out.right_btn_down = mouse_evt->right_btn_down;
|
out.right_btn_down = mouse_evt.right_btn_down;
|
||||||
out.target = this;
|
out.target = this;
|
||||||
EventDispatcher::Dispatch(out);
|
EventDispatcher::Dispatch(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.type == event::MouseDown && hover_)
|
if (evt.IsType<MouseDownEvent>() && hover_)
|
||||||
{
|
{
|
||||||
pressed_ = true;
|
pressed_ = true;
|
||||||
evt.SafeCast<MouseDownEvent>()->target = this;
|
evt.SafeCast<MouseDownEvent>().target = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.type == event::MouseUp && pressed_)
|
if (evt.IsType<MouseUpEvent>() && pressed_)
|
||||||
{
|
{
|
||||||
pressed_ = false;
|
pressed_ = false;
|
||||||
|
|
||||||
auto mouse_up_evt = evt.SafeCast<MouseUpEvent>();
|
auto mouse_up_evt = evt.SafeCast<MouseUpEvent>();
|
||||||
mouse_up_evt->target = this;
|
mouse_up_evt.target = this;
|
||||||
|
|
||||||
MouseClickEvent click;
|
MouseClickEvent click;
|
||||||
click.pos = mouse_up_evt->pos;
|
click.pos = mouse_up_evt.pos;
|
||||||
click.left_btn_down = mouse_up_evt->left_btn_down;
|
click.left_btn_down = mouse_up_evt.left_btn_down;
|
||||||
click.right_btn_down = mouse_up_evt->right_btn_down;
|
click.right_btn_down = mouse_up_evt.right_btn_down;
|
||||||
click.target = this;
|
click.target = this;
|
||||||
click.button = mouse_up_evt->button;
|
click.button = mouse_up_evt.button;
|
||||||
EventDispatcher::Dispatch(click);
|
EventDispatcher::Dispatch(click);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,8 @@ namespace kiwano
|
||||||
style.line_spacing = 20.f;
|
style.line_spacing = 20.f;
|
||||||
debug_text_->SetStyle(style);
|
debug_text_->SetStyle(style);
|
||||||
|
|
||||||
AddListener(event::MouseHover, [=](Event&) { SetOpacity(0.4f); });
|
AddListener(events::MouseHover, [=](Event&) { SetOpacity(0.4f); });
|
||||||
AddListener(event::MouseOut, [=](Event&) { SetOpacity(1.f); });
|
AddListener(events::MouseOut, [=](Event&) { SetOpacity(1.f); });
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugActor::~DebugActor()
|
DebugActor::~DebugActor()
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
auto handler = Closure(this, &Layer::HandleMessages);
|
auto handler = Closure(this, &Layer::HandleMessages);
|
||||||
|
|
||||||
AddListener(event::MouseDown, handler);
|
AddListener(events::MouseDown, handler);
|
||||||
AddListener(event::MouseUp, handler);
|
AddListener(events::MouseUp, handler);
|
||||||
AddListener(event::MouseMove, handler);
|
AddListener(events::MouseMove, handler);
|
||||||
AddListener(event::MouseWheel, handler);
|
AddListener(events::MouseWheel, handler);
|
||||||
|
|
||||||
AddListener(event::KeyDown, handler);
|
AddListener(events::KeyDown, handler);
|
||||||
AddListener(event::KeyUp, handler);
|
AddListener(events::KeyUp, handler);
|
||||||
AddListener(event::KeyChar, handler);
|
AddListener(events::KeyChar, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer::~Layer()
|
Layer::~Layer()
|
||||||
|
|
@ -93,40 +93,40 @@ namespace kiwano
|
||||||
|
|
||||||
void Layer::HandleMessages(Event& evt)
|
void Layer::HandleMessages(Event& evt)
|
||||||
{
|
{
|
||||||
if (evt.type == event::MouseDown)
|
if (evt.IsType<MouseDownEvent>())
|
||||||
{
|
{
|
||||||
auto real_evt = evt.SafeCast<MouseDownEvent>();
|
const auto& real_evt = evt.SafeCast<MouseDownEvent>();
|
||||||
OnMouseButtonDown(real_evt->button, real_evt->pos);
|
OnMouseButtonDown(real_evt.button, real_evt.pos);
|
||||||
}
|
}
|
||||||
else if (evt.type == event::MouseUp)
|
else if (evt.IsType<MouseUpEvent>())
|
||||||
{
|
{
|
||||||
auto real_evt = evt.SafeCast<MouseUpEvent>();
|
const auto& real_evt = evt.SafeCast<MouseUpEvent>();
|
||||||
OnMouseButtonUp(real_evt->button, real_evt->pos);
|
OnMouseButtonUp(real_evt.button, real_evt.pos);
|
||||||
}
|
}
|
||||||
else if (evt.type == event::MouseMove)
|
else if (evt.IsType<MouseMoveEvent>())
|
||||||
{
|
{
|
||||||
auto real_evt = evt.SafeCast<MouseMoveEvent>();
|
const auto& real_evt = evt.SafeCast<MouseMoveEvent>();
|
||||||
OnMouseMoved(real_evt->pos);
|
OnMouseMoved(real_evt.pos);
|
||||||
}
|
}
|
||||||
else if (evt.type == event::MouseWheel)
|
else if (evt.IsType<MouseWheelEvent>())
|
||||||
{
|
{
|
||||||
auto real_evt = evt.SafeCast<MouseWheelEvent>();
|
const auto& real_evt = evt.SafeCast<MouseWheelEvent>();
|
||||||
OnMouseWheel(real_evt->wheel);
|
OnMouseWheel(real_evt.wheel);
|
||||||
}
|
}
|
||||||
else if (evt.type == event::KeyDown)
|
else if (evt.IsType<KeyDownEvent>())
|
||||||
{
|
{
|
||||||
auto real_evt = evt.SafeCast<KeyDownEvent>();
|
const auto& real_evt = evt.SafeCast<KeyDownEvent>();
|
||||||
OnKeyDown(real_evt->code);
|
OnKeyDown(real_evt.code);
|
||||||
}
|
}
|
||||||
else if (evt.type == event::KeyUp)
|
else if (evt.IsType<KeyUpEvent>())
|
||||||
{
|
{
|
||||||
auto real_evt = evt.SafeCast<KeyUpEvent>();
|
const auto& real_evt = evt.SafeCast<KeyUpEvent>();
|
||||||
OnKeyUp(real_evt->code);
|
OnKeyUp(real_evt.code);
|
||||||
}
|
}
|
||||||
else if (evt.type == event::KeyChar)
|
else if (evt.IsType<KeyCharEvent>())
|
||||||
{
|
{
|
||||||
auto real_evt = evt.SafeCast<KeyCharEvent>();
|
const auto& real_evt = evt.SafeCast<KeyCharEvent>();
|
||||||
OnChar(real_evt->value);
|
OnChar(real_evt.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,26 +31,46 @@ namespace kiwano
|
||||||
typedef Function<void()> AsyncTaskFunc;
|
typedef Function<void()> AsyncTaskFunc;
|
||||||
typedef Function<void()> AsyncTaskCallback;
|
typedef Function<void()> AsyncTaskCallback;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 异步任务
|
||||||
|
/// @details 在多线程下执行任务并返回
|
||||||
|
/// @code
|
||||||
|
/// AsyncTaskPtr task = new AsyncTask;
|
||||||
|
/// task->Then(DoSomething);
|
||||||
|
/// task->Start();
|
||||||
|
/// @endcode
|
||||||
class AsyncTask
|
class AsyncTask
|
||||||
: public ObjectBase
|
: public ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 构造异步任务
|
||||||
AsyncTask();
|
AsyncTask();
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 构造异步任务
|
||||||
|
/// @param func 异步回调函数
|
||||||
AsyncTask(
|
AsyncTask(
|
||||||
AsyncTaskFunc func
|
AsyncTaskFunc func
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~AsyncTask();
|
virtual ~AsyncTask();
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 添加异步任务链
|
||||||
AsyncTask& Then(
|
AsyncTask& Then(
|
||||||
AsyncTaskFunc func
|
AsyncTaskFunc func
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 设置任务执行完成后的回调函数
|
||||||
|
/// @note 该函数在 Kiwano 主线程中执行
|
||||||
AsyncTask& SetCallback(
|
AsyncTask& SetCallback(
|
||||||
AsyncTaskCallback callback
|
AsyncTaskCallback callback
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 启动异步任务
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,29 @@
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
EventType event::MouseMove = EventType(L"MouseMove");
|
namespace events
|
||||||
EventType event::MouseDown = EventType(L"MouseDown");
|
{
|
||||||
EventType event::MouseUp = EventType(L"MouseUp");
|
KGE_IMPLEMENT_EVENT_TYPE(MouseMove, MouseMoveEvent);
|
||||||
EventType event::MouseWheel = EventType(L"MouseWheel");
|
KGE_IMPLEMENT_EVENT_TYPE(MouseDown, MouseDownEvent);
|
||||||
EventType event::MouseHover = EventType(L"MouseHover");
|
KGE_IMPLEMENT_EVENT_TYPE(MouseUp, MouseUpEvent);
|
||||||
EventType event::MouseOut = EventType(L"MouseOut");
|
KGE_IMPLEMENT_EVENT_TYPE(MouseWheel, MouseWheelEvent);
|
||||||
EventType event::MouseClick = EventType(L"MouseClick");
|
KGE_IMPLEMENT_EVENT_TYPE(MouseHover, MouseHoverEvent);
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(MouseOut, MouseOutEvent);
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(MouseClick, MouseClickEvent);
|
||||||
|
|
||||||
EventType event::KeyDown = EventType(L"KeyDown");
|
KGE_IMPLEMENT_EVENT_TYPE(KeyDown, KeyDownEvent);
|
||||||
EventType event::KeyUp = EventType(L"KeyUp");
|
KGE_IMPLEMENT_EVENT_TYPE(KeyUp, KeyUpEvent);
|
||||||
EventType event::KeyChar = EventType(L"KeyChar");
|
KGE_IMPLEMENT_EVENT_TYPE(KeyChar, KeyCharEvent);
|
||||||
|
|
||||||
EventType event::WindowMoved = EventType(L"WindowMoved");
|
|
||||||
EventType event::WindowResized = EventType(L"WindowResized");
|
|
||||||
EventType event::WindowFocusChanged = EventType(L"WindowFocusChanged");
|
|
||||||
EventType event::WindowTitleChanged = EventType(L"WindowTitleChanged");
|
|
||||||
EventType event::WindowClosed = EventType(L"WindowClosed");
|
|
||||||
|
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(WindowMoved, WindowMovedEvent);
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(WindowResized, WindowResizedEvent);
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(WindowFocusChanged, WindowFocusChangedEvent);
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(WindowTitleChanged, WindowTitleChangedEvent);
|
||||||
|
KGE_IMPLEMENT_EVENT_TYPE(WindowClosed, WindowClosedEvent);
|
||||||
|
}
|
||||||
|
|
||||||
Event::Event(EventType const& type)
|
Event::Event(EventType const& type)
|
||||||
: type(type)
|
: type_(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,91 +42,91 @@ namespace kiwano
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseMoveEvent::MouseMoveEvent()
|
MouseMoveEvent::MouseMoveEvent()
|
||||||
: MouseEvent(event::MouseMove)
|
: MouseEvent(events::MouseMove)
|
||||||
, button(0)
|
, button(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseDownEvent::MouseDownEvent()
|
MouseDownEvent::MouseDownEvent()
|
||||||
: MouseEvent(event::MouseDown)
|
: MouseEvent(events::MouseDown)
|
||||||
, button(0)
|
, button(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseUpEvent::MouseUpEvent()
|
MouseUpEvent::MouseUpEvent()
|
||||||
: MouseEvent(event::MouseUp)
|
: MouseEvent(events::MouseUp)
|
||||||
, button(0)
|
, button(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseClickEvent::MouseClickEvent()
|
MouseClickEvent::MouseClickEvent()
|
||||||
: MouseEvent(event::MouseClick)
|
: MouseEvent(events::MouseClick)
|
||||||
, button(0)
|
, button(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseHoverEvent::MouseHoverEvent()
|
MouseHoverEvent::MouseHoverEvent()
|
||||||
: MouseEvent(event::MouseHover)
|
: MouseEvent(events::MouseHover)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseOutEvent::MouseOutEvent()
|
MouseOutEvent::MouseOutEvent()
|
||||||
: MouseEvent(event::MouseOut)
|
: MouseEvent(events::MouseOut)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseWheelEvent::MouseWheelEvent()
|
MouseWheelEvent::MouseWheelEvent()
|
||||||
: MouseEvent(event::MouseWheel)
|
: MouseEvent(events::MouseWheel)
|
||||||
, wheel(0.f)
|
, wheel(0.f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyDownEvent::KeyDownEvent()
|
KeyDownEvent::KeyDownEvent()
|
||||||
: Event(event::KeyDown)
|
: Event(events::KeyDown)
|
||||||
, code(0)
|
, code(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyUpEvent::KeyUpEvent()
|
KeyUpEvent::KeyUpEvent()
|
||||||
: Event(event::KeyUp)
|
: Event(events::KeyUp)
|
||||||
, code(0)
|
, code(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyCharEvent::KeyCharEvent()
|
KeyCharEvent::KeyCharEvent()
|
||||||
: Event(event::KeyChar)
|
: Event(events::KeyChar)
|
||||||
, value()
|
, value()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowMovedEvent::WindowMovedEvent()
|
WindowMovedEvent::WindowMovedEvent()
|
||||||
: Event(event::WindowMoved)
|
: Event(events::WindowMoved)
|
||||||
, x(0)
|
, x(0)
|
||||||
, y(0)
|
, y(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowResizedEvent::WindowResizedEvent()
|
WindowResizedEvent::WindowResizedEvent()
|
||||||
: Event(event::WindowResized)
|
: Event(events::WindowResized)
|
||||||
, width(0)
|
, width(0)
|
||||||
, height(0)
|
, height(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowFocusChangedEvent::WindowFocusChangedEvent()
|
WindowFocusChangedEvent::WindowFocusChangedEvent()
|
||||||
: Event(event::WindowFocusChanged)
|
: Event(events::WindowFocusChanged)
|
||||||
, focus(false)
|
, focus(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowTitleChangedEvent::WindowTitleChangedEvent()
|
WindowTitleChangedEvent::WindowTitleChangedEvent()
|
||||||
: Event(event::WindowTitleChanged)
|
: Event(events::WindowTitleChanged)
|
||||||
, title()
|
, title()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowClosedEvent::WindowClosedEvent()
|
WindowClosedEvent::WindowClosedEvent()
|
||||||
: Event(event::WindowClosed)
|
: Event(events::WindowClosed)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,144 +23,209 @@
|
||||||
#include <kiwano/math/math.h>
|
#include <kiwano/math/math.h>
|
||||||
#include <kiwano/core/keys.h>
|
#include <kiwano/core/keys.h>
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <typeindex>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
class Actor;
|
class Actor;
|
||||||
|
|
||||||
// 事件类型
|
/// \~chinese
|
||||||
struct EventType
|
/// @brief 事件类型
|
||||||
|
class EventType
|
||||||
|
: public std::type_index
|
||||||
{
|
{
|
||||||
inline EventType() : hash(0), type()
|
class Dummy { };
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline EventType(String const& type) : hash(0), type(type)
|
public:
|
||||||
{
|
/// \~chinese
|
||||||
hash = type.hash();
|
/// @brief 构建事件类型
|
||||||
}
|
EventType() : std::type_index(typeid(EventType::Dummy)) {}
|
||||||
|
|
||||||
inline bool operator==(const EventType& rhs) const
|
/// \~chinese
|
||||||
{
|
/// @brief 构建事件类型
|
||||||
return hash == rhs.hash && type == rhs.type;
|
/// @param info 事件标识符
|
||||||
}
|
EventType(const type_info& info) : std::type_index(info) {}
|
||||||
|
|
||||||
size_t hash;
|
/// \~chinese
|
||||||
String type;
|
/// @brief 构建事件类型
|
||||||
|
/// @param index 事件标识符
|
||||||
|
EventType(const std::type_index& index) : std::type_index(index) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace event
|
#define KGE_EVENT(EVENT_TYPE) ::kiwano::EventType(typeid(EVENT_TYPE))
|
||||||
|
|
||||||
|
#define KGE_DECLARE_EVENT_TYPE(EVENT_NAME) extern ::kiwano::EventType EVENT_NAME;
|
||||||
|
|
||||||
|
#define KGE_IMPLEMENT_EVENT_TYPE(EVENT_NAME, EVENT_TYPE) ::kiwano::EventType EVENT_NAME = KGE_EVENT(EVENT_TYPE);
|
||||||
|
|
||||||
|
|
||||||
|
namespace events
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* \~chinese
|
||||||
|
* \defgroup EventTypes 事件类型
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup EventTypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
// 鼠标事件
|
// 鼠标事件
|
||||||
extern EventType MouseMove; // 移动
|
KGE_DECLARE_EVENT_TYPE(MouseMove); ///< 鼠标移动
|
||||||
extern EventType MouseDown; // 鼠标按下
|
KGE_DECLARE_EVENT_TYPE(MouseDown); ///< 鼠标按下
|
||||||
extern EventType MouseUp; // 鼠标抬起
|
KGE_DECLARE_EVENT_TYPE(MouseUp); ///< 鼠标抬起
|
||||||
extern EventType MouseWheel; // 滚轮滚动
|
KGE_DECLARE_EVENT_TYPE(MouseWheel); ///< 滚轮滚动
|
||||||
extern EventType MouseHover; // 鼠标移入
|
KGE_DECLARE_EVENT_TYPE(MouseHover); ///< 鼠标移入
|
||||||
extern EventType MouseOut; // 鼠标移出
|
KGE_DECLARE_EVENT_TYPE(MouseOut); ///< 鼠标移出
|
||||||
extern EventType MouseClick; // 鼠标点击
|
KGE_DECLARE_EVENT_TYPE(MouseClick); ///< 鼠标点击
|
||||||
|
|
||||||
// 按键事件
|
// 按键事件
|
||||||
extern EventType KeyDown; // 按键按下
|
KGE_DECLARE_EVENT_TYPE(KeyDown); ///< 按键按下
|
||||||
extern EventType KeyUp; // 按键抬起
|
KGE_DECLARE_EVENT_TYPE(KeyUp); ///< 按键抬起
|
||||||
extern EventType KeyChar; // 输出字符
|
KGE_DECLARE_EVENT_TYPE(KeyChar); ///< 输出字符
|
||||||
|
|
||||||
// 窗口消息
|
// 窗口消息
|
||||||
extern EventType WindowMoved; // 窗口移动
|
KGE_DECLARE_EVENT_TYPE(WindowMoved); ///< 窗口移动
|
||||||
extern EventType WindowResized; // 窗口大小变化
|
KGE_DECLARE_EVENT_TYPE(WindowResized); ///< 窗口大小变化
|
||||||
extern EventType WindowFocusChanged; // 获得或失去焦点
|
KGE_DECLARE_EVENT_TYPE(WindowFocusChanged); ///< 获得或失去焦点
|
||||||
extern EventType WindowTitleChanged; // 标题变化
|
KGE_DECLARE_EVENT_TYPE(WindowTitleChanged); ///< 标题变化
|
||||||
extern EventType WindowClosed; // 窗口被关闭
|
KGE_DECLARE_EVENT_TYPE(WindowClosed); ///< 窗口被关闭
|
||||||
|
|
||||||
|
/** @} */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \~chinese
|
||||||
|
* \defgroup Events 事件
|
||||||
|
*/
|
||||||
|
|
||||||
// 事件
|
/**
|
||||||
|
* \addtogroup Events
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 事件
|
||||||
class KGE_API Event
|
class KGE_API Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const EventType type;
|
/// \~chinese
|
||||||
|
/// @brief 构造事件
|
||||||
Event(EventType const& type);
|
Event(EventType const& type);
|
||||||
|
|
||||||
virtual ~Event();
|
virtual ~Event();
|
||||||
|
|
||||||
template <
|
/// \~chinese
|
||||||
typename _Ty,
|
/// @brief 获取类型事件
|
||||||
typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type
|
inline const EventType& GetType() const
|
||||||
>
|
|
||||||
inline const _Ty* SafeCast() const
|
|
||||||
{
|
{
|
||||||
const _Ty* ptr = dynamic_cast<const _Ty*>(this);
|
return type_;
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 判断事件类型
|
||||||
|
/// @return 是否是指定事件类型
|
||||||
template <
|
template <
|
||||||
typename _Ty,
|
typename _Ty,
|
||||||
typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type
|
typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type
|
||||||
>
|
>
|
||||||
inline _Ty* SafeCast()
|
inline bool IsType() const
|
||||||
{
|
{
|
||||||
return const_cast<_Ty*>(const_cast<const Event*>(this)->SafeCast<_Ty>());
|
return type_ == KGE_EVENT(_Ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 安全转换为其他类型事件
|
||||||
|
/// @throw std::bad_cast 无法转换的类型
|
||||||
|
template <
|
||||||
|
typename _Ty,
|
||||||
|
typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type
|
||||||
|
>
|
||||||
|
inline const _Ty& SafeCast() const
|
||||||
|
{
|
||||||
|
if (!IsType<_Ty>()) throw std::bad_cast();
|
||||||
|
return *dynamic_cast<const _Ty*>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 安全转换为其他类型事件
|
||||||
|
/// @throw std::bad_cast 无法转换的类型
|
||||||
|
template <
|
||||||
|
typename _Ty,
|
||||||
|
typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type
|
||||||
|
>
|
||||||
|
inline _Ty& SafeCast()
|
||||||
|
{
|
||||||
|
return const_cast<_Ty&>(const_cast<const Event*>(this)->SafeCast<_Ty>());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const EventType type_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标事件
|
||||||
class KGE_API MouseEvent
|
class KGE_API MouseEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Point pos;
|
Point pos; ///< 鼠标位置
|
||||||
bool left_btn_down; // 左键是否按下
|
bool left_btn_down; ///< 鼠标左键是否按下
|
||||||
bool right_btn_down; // 右键是否按下
|
bool right_btn_down; ///< 鼠标右键是否按下
|
||||||
Actor* target;
|
Actor* target; ///< 目标
|
||||||
|
|
||||||
MouseEvent(EventType const& type);
|
MouseEvent(EventType const& type);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标移动事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标移动事件
|
||||||
class KGE_API MouseMoveEvent
|
class KGE_API MouseMoveEvent
|
||||||
: public MouseEvent
|
: public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButton::Value button;
|
MouseButton::Value button; ///< 鼠标键值
|
||||||
|
|
||||||
MouseMoveEvent();
|
MouseMoveEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标按键按下事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标按键按下事件
|
||||||
class KGE_API MouseDownEvent
|
class KGE_API MouseDownEvent
|
||||||
: public MouseEvent
|
: public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButton::Value button;
|
MouseButton::Value button; ///< 鼠标键值
|
||||||
|
|
||||||
MouseDownEvent();
|
MouseDownEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标按键抬起事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标按键抬起事件
|
||||||
class KGE_API MouseUpEvent
|
class KGE_API MouseUpEvent
|
||||||
: public MouseEvent
|
: public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButton::Value button;
|
MouseButton::Value button; ///< 鼠标键值
|
||||||
|
|
||||||
MouseUpEvent();
|
MouseUpEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标点击事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标点击事件
|
||||||
class KGE_API MouseClickEvent
|
class KGE_API MouseClickEvent
|
||||||
: public MouseEvent
|
: public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MouseButton::Value button;
|
MouseButton::Value button; ///< 鼠标键值
|
||||||
|
|
||||||
MouseClickEvent();
|
MouseClickEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标移入事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标移入事件
|
||||||
class KGE_API MouseHoverEvent
|
class KGE_API MouseHoverEvent
|
||||||
: public MouseEvent
|
: public MouseEvent
|
||||||
{
|
{
|
||||||
|
|
@ -168,7 +233,8 @@ namespace kiwano
|
||||||
MouseHoverEvent();
|
MouseHoverEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标移出事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标移出事件
|
||||||
class KGE_API MouseOutEvent
|
class KGE_API MouseOutEvent
|
||||||
: public MouseEvent
|
: public MouseEvent
|
||||||
{
|
{
|
||||||
|
|
@ -176,89 +242,98 @@ namespace kiwano
|
||||||
MouseOutEvent();
|
MouseOutEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 鼠标滚轮事件
|
/// \~chinese
|
||||||
|
/// @brief 鼠标滚轮事件
|
||||||
class KGE_API MouseWheelEvent
|
class KGE_API MouseWheelEvent
|
||||||
: public MouseEvent
|
: public MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float wheel;
|
float wheel; ///< 滚轮值
|
||||||
|
|
||||||
MouseWheelEvent();
|
MouseWheelEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 键盘按下事件
|
/// \~chinese
|
||||||
|
/// @brief 键盘按下事件
|
||||||
class KGE_API KeyDownEvent
|
class KGE_API KeyDownEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyCode::Value code;
|
KeyCode::Value code; ///< 键值
|
||||||
|
|
||||||
KeyDownEvent();
|
KeyDownEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 键盘抬起事件
|
/// \~chinese
|
||||||
|
/// @brief 键盘抬起事件
|
||||||
class KGE_API KeyUpEvent
|
class KGE_API KeyUpEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyCode::Value code;
|
KeyCode::Value code; ///< 键值
|
||||||
|
|
||||||
KeyUpEvent();
|
KeyUpEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 键盘字符事件
|
/// \~chinese
|
||||||
|
/// @brief 键盘字符事件
|
||||||
class KGE_API KeyCharEvent
|
class KGE_API KeyCharEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char value;
|
char value; ///< 字符
|
||||||
|
|
||||||
KeyCharEvent();
|
KeyCharEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 窗口移动事件
|
/// \~chinese
|
||||||
|
/// @brief 窗口移动事件
|
||||||
class KGE_API WindowMovedEvent
|
class KGE_API WindowMovedEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int x;
|
int x; ///< 窗口左上角 x 坐标
|
||||||
int y;
|
int y; ///< 窗口左上角 y 坐标
|
||||||
|
|
||||||
WindowMovedEvent();
|
WindowMovedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 窗口大小变化事件
|
/// \~chinese
|
||||||
|
/// @brief 窗口大小变化事件
|
||||||
class KGE_API WindowResizedEvent
|
class KGE_API WindowResizedEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int width;
|
int width; ///< 窗口宽度
|
||||||
int height;
|
int height; ///< 窗口高度
|
||||||
|
|
||||||
WindowResizedEvent();
|
WindowResizedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 窗口焦点变化事件
|
/// \~chinese
|
||||||
|
/// @brief 窗口焦点变化事件
|
||||||
class KGE_API WindowFocusChangedEvent
|
class KGE_API WindowFocusChangedEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool focus;
|
bool focus; ///< 是否获取到焦点
|
||||||
|
|
||||||
WindowFocusChangedEvent();
|
WindowFocusChangedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 窗口标题更改事件
|
/// \~chinese
|
||||||
|
/// @brief 窗口标题更改事件
|
||||||
class KGE_API WindowTitleChangedEvent
|
class KGE_API WindowTitleChangedEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
String title;
|
String title; ///< 标题
|
||||||
|
|
||||||
WindowTitleChangedEvent();
|
WindowTitleChangedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 窗口关闭事件
|
/// \~chinese
|
||||||
|
/// @brief 窗口关闭事件
|
||||||
class KGE_API WindowClosedEvent
|
class KGE_API WindowClosedEvent
|
||||||
: public Event
|
: public Event
|
||||||
{
|
{
|
||||||
|
|
@ -266,4 +341,6 @@ namespace kiwano
|
||||||
WindowClosedEvent();
|
WindowClosedEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
next = listener->next_item();
|
next = listener->next_item();
|
||||||
|
|
||||||
if (listener->IsRunning() && listener->type_ == evt.type)
|
if (listener->IsRunning() && listener->type_ == evt.GetType())
|
||||||
{
|
{
|
||||||
listener->callback_(evt);
|
listener->callback_(evt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,18 @@ namespace kiwano
|
||||||
* @brief 时间段
|
* @brief 时间段
|
||||||
* @details
|
* @details
|
||||||
* 时间段表示法:
|
* 时间段表示法:
|
||||||
* 5 秒: time::Second * 5
|
* @code
|
||||||
* 1.5 小时: time::Hour * 1.5
|
* time::Second * 5 // 5 秒
|
||||||
* 3 小时 45 分 15 秒: time::Hour * 3 + time::Minute * 45 + time::Second * 15
|
* time::Hour * 1.5 // 1.5 小时
|
||||||
|
* time::Hour * 3 + time::Minute * 45 + time::Second * 15 // 3 小时 45 分 15 秒
|
||||||
|
* @endcode
|
||||||
* 在 VS2015 及更高版本可以使用 time literals:
|
* 在 VS2015 及更高版本可以使用 time literals:
|
||||||
* 5 秒: 5_s
|
* @code
|
||||||
* 1.5 小时: 1.5_h
|
* using namespace kiwano;
|
||||||
* 3 小时 45 分 15 秒: 3_h + 45_m + 15_s
|
* 5_sec // 5 秒
|
||||||
|
* 1.5_hour // 1.5 小时
|
||||||
|
* 3_hour + 45_min + 15_sec // 3 小时 45 分 15 秒
|
||||||
|
* @endcode
|
||||||
*/
|
*/
|
||||||
struct KGE_API Duration
|
struct KGE_API Duration
|
||||||
{
|
{
|
||||||
|
|
@ -217,48 +222,48 @@ namespace kiwano
|
||||||
inline bool Time::IsZero() const { return dur_ == 0; }
|
inline bool Time::IsZero() const { return dur_ == 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#if KGE_VS_VER > KGE_VS_2013
|
#if defined(KGE_VS_VER) && KGE_VS_VER > KGE_VS_2013
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
inline namespace literals
|
inline namespace literals
|
||||||
{
|
{
|
||||||
inline const kiwano::Duration operator "" _ms(long double val)
|
inline const kiwano::Duration operator "" _msec(long double val)
|
||||||
{
|
{
|
||||||
return kiwano::Duration::Ms * val;
|
return kiwano::Duration::Ms * val;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const kiwano::Duration operator "" _s(long double val)
|
inline const kiwano::Duration operator "" _msec(unsigned long long val)
|
||||||
|
{
|
||||||
|
return kiwano::Duration::Ms * val;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const kiwano::Duration operator "" _sec(long double val)
|
||||||
{
|
{
|
||||||
return kiwano::Duration::Second * val;
|
return kiwano::Duration::Second * val;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const kiwano::Duration operator "" _m(long double val)
|
inline const kiwano::Duration operator "" _sec(unsigned long long val)
|
||||||
|
{
|
||||||
|
return kiwano::Duration::Second * val;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const kiwano::Duration operator "" _min(long double val)
|
||||||
{
|
{
|
||||||
return kiwano::Duration::Minute * val;
|
return kiwano::Duration::Minute * val;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const kiwano::Duration operator "" _h(long double val)
|
inline const kiwano::Duration operator "" _min(unsigned long long val)
|
||||||
|
{
|
||||||
|
return kiwano::Duration::Minute * val;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const kiwano::Duration operator "" _hour(long double val)
|
||||||
{
|
{
|
||||||
return kiwano::Duration::Hour * val;
|
return kiwano::Duration::Hour * val;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const kiwano::Duration operator "" _ms(unsigned long long val)
|
inline const kiwano::Duration operator "" _hour(unsigned long long val)
|
||||||
{
|
|
||||||
return kiwano::Duration::Ms * val;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const kiwano::Duration operator "" _s(unsigned long long val)
|
|
||||||
{
|
|
||||||
return kiwano::Duration::Second * val;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const kiwano::Duration operator "" _m(unsigned long long val)
|
|
||||||
{
|
|
||||||
return kiwano::Duration::Minute * val;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const kiwano::Duration operator "" _h(unsigned long long val)
|
|
||||||
{
|
{
|
||||||
return kiwano::Duration::Hour * val;
|
return kiwano::Duration::Hour * val;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,10 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
SetResponsible(true);
|
SetResponsible(true);
|
||||||
|
|
||||||
AddListener(event::MouseHover, Closure(this, &Button::UpdateStatus));
|
AddListener(events::MouseHover, Closure(this, &Button::UpdateStatus));
|
||||||
AddListener(event::MouseOut, Closure(this, &Button::UpdateStatus));
|
AddListener(events::MouseOut, Closure(this, &Button::UpdateStatus));
|
||||||
AddListener(event::MouseDown, Closure(this, &Button::UpdateStatus));
|
AddListener(events::MouseDown, Closure(this, &Button::UpdateStatus));
|
||||||
AddListener(event::MouseUp, Closure(this, &Button::UpdateStatus));
|
AddListener(events::MouseUp, Closure(this, &Button::UpdateStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Button(const Callback& click)
|
Button::Button(const Callback& click)
|
||||||
|
|
@ -105,12 +105,12 @@ namespace kiwano
|
||||||
|
|
||||||
void Button::UpdateStatus(Event& evt)
|
void Button::UpdateStatus(Event& evt)
|
||||||
{
|
{
|
||||||
auto mouse_evt = evt.SafeCast<MouseEvent>();
|
auto mouse_evt = dynamic_cast<MouseEvent*>(&evt);
|
||||||
KGE_ASSERT(mouse_evt);
|
KGE_ASSERT(mouse_evt != nullptr);
|
||||||
|
|
||||||
if (enabled_ && (mouse_evt->target == this))
|
if (enabled_ && (mouse_evt->target == this))
|
||||||
{
|
{
|
||||||
if (evt.type == event::MouseHover)
|
if (evt.IsType<MouseHoverEvent>())
|
||||||
{
|
{
|
||||||
SetStatus(Status::Hover);
|
SetStatus(Status::Hover);
|
||||||
Window::instance().SetCursor(CursorType::Hand);
|
Window::instance().SetCursor(CursorType::Hand);
|
||||||
|
|
@ -118,7 +118,7 @@ namespace kiwano
|
||||||
if (mouse_over_callback_)
|
if (mouse_over_callback_)
|
||||||
mouse_over_callback_();
|
mouse_over_callback_();
|
||||||
}
|
}
|
||||||
else if (evt.type == event::MouseOut)
|
else if (evt.IsType<MouseOutEvent>())
|
||||||
{
|
{
|
||||||
SetStatus(Status::Normal);
|
SetStatus(Status::Normal);
|
||||||
Window::instance().SetCursor(CursorType::Arrow);
|
Window::instance().SetCursor(CursorType::Arrow);
|
||||||
|
|
@ -126,14 +126,14 @@ namespace kiwano
|
||||||
if (mouse_out_callback_)
|
if (mouse_out_callback_)
|
||||||
mouse_out_callback_();
|
mouse_out_callback_();
|
||||||
}
|
}
|
||||||
else if (evt.type == event::MouseDown && status_ == Status::Hover)
|
else if (evt.IsType<MouseDownEvent>() && status_ == Status::Hover)
|
||||||
{
|
{
|
||||||
SetStatus(Status::Pressed);
|
SetStatus(Status::Pressed);
|
||||||
|
|
||||||
if (pressed_callback_)
|
if (pressed_callback_)
|
||||||
pressed_callback_();
|
pressed_callback_();
|
||||||
}
|
}
|
||||||
else if (evt.type == event::MouseUp && status_ == Status::Pressed)
|
else if (evt.IsType<MouseUpEvent>() && status_ == Status::Pressed)
|
||||||
{
|
{
|
||||||
SetStatus(Status::Hover);
|
SetStatus(Status::Hover);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue