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