diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index e7b30047..eab6029a 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -12,7 +12,11 @@ - + + + + + @@ -107,9 +111,12 @@ - + + + + @@ -239,4 +246,4 @@ - + \ No newline at end of file diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index 20d6b9e6..dce7c87c 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -31,6 +31,9 @@ {e84dcf9a-e650-473e-8c9c-193804ab9e76} + + {c629aedd-ffb9-4bc1-82c3-f50e77c82e77} + @@ -228,9 +231,6 @@ core - - core - platform @@ -273,6 +273,21 @@ platform\win32 + + core\event + + + core\event + + + core\event + + + core\event + + + core\event + @@ -431,9 +446,6 @@ core - - core - platform @@ -461,5 +473,17 @@ platform\win32 + + core\event + + + core\event + + + core\event + + + core\event + \ No newline at end of file diff --git a/src/kiwano/core/Event.cpp b/src/kiwano/core/Event.cpp deleted file mode 100644 index 0bf249b6..00000000 --- a/src/kiwano/core/Event.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include - -namespace kiwano -{ - Event::Event(EventType const& type) - : type_(type) - { - } - - Event::~Event() - { - } - - MouseEvent::MouseEvent(EventType const& type) - : Event(type) - , pos() - , left_btn_down(false) - , right_btn_down(false) - , target(nullptr) - { - } - - MouseMoveEvent::MouseMoveEvent() - : MouseEvent(KGE_EVENT(MouseMoveEvent)) - { - } - - MouseDownEvent::MouseDownEvent() - : MouseEvent(KGE_EVENT(MouseDownEvent)) - , button(0) - { - } - - MouseUpEvent::MouseUpEvent() - : MouseEvent(KGE_EVENT(MouseUpEvent)) - , button(0) - { - } - - MouseClickEvent::MouseClickEvent() - : MouseEvent(KGE_EVENT(MouseClickEvent)) - , button(0) - { - } - - MouseHoverEvent::MouseHoverEvent() - : MouseEvent(KGE_EVENT(MouseHoverEvent)) - { - } - - MouseOutEvent::MouseOutEvent() - : MouseEvent(KGE_EVENT(MouseOutEvent)) - { - } - - MouseWheelEvent::MouseWheelEvent() - : MouseEvent(KGE_EVENT(MouseWheelEvent)) - , wheel(0.f) - { - } - - KeyDownEvent::KeyDownEvent() - : Event(KGE_EVENT(KeyDownEvent)) - , code(0) - { - } - - KeyUpEvent::KeyUpEvent() - : Event(KGE_EVENT(KeyUpEvent)) - , code(0) - { - } - - KeyCharEvent::KeyCharEvent() - : Event(KGE_EVENT(KeyCharEvent)) - , value() - { - } - - WindowMovedEvent::WindowMovedEvent() - : Event(KGE_EVENT(WindowMovedEvent)) - , x(0) - , y(0) - { - } - - WindowResizedEvent::WindowResizedEvent() - : Event(KGE_EVENT(WindowResizedEvent)) - , width(0) - , height(0) - { - } - - WindowFocusChangedEvent::WindowFocusChangedEvent() - : Event(KGE_EVENT(WindowFocusChangedEvent)) - , focus(false) - { - } - - WindowTitleChangedEvent::WindowTitleChangedEvent() - : Event(KGE_EVENT(WindowTitleChangedEvent)) - , title() - { - } - - WindowClosedEvent::WindowClosedEvent() - : Event(KGE_EVENT(WindowClosedEvent)) - { - } - -} diff --git a/src/kiwano/core/Event.h b/src/kiwano/core/Event.h deleted file mode 100644 index 322385d8..00000000 --- a/src/kiwano/core/Event.h +++ /dev/null @@ -1,333 +0,0 @@ -// Copyright (c) 2016-2018 Kiwano - Nomango -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#pragma once -#include -#include -#include -#include -#include - -namespace kiwano -{ - class Actor; - - /// \~chinese - /// @brief 事件类型 - class EventType - : public std::type_index - { - class Dummy { }; - - public: - /// \~chinese - /// @brief 构建事件类型 - EventType() : std::type_index(typeid(EventType::Dummy)) {} - - /// \~chinese - /// @brief 构建事件类型 - /// @param info 事件标识符 - EventType(const type_info& info) : std::type_index(info) {} - - /// \~chinese - /// @brief 构建事件类型 - /// @param index 事件标识符 - EventType(const std::type_index& index) : std::type_index(index) {} - }; - -#define KGE_EVENT(EVENT_TYPE) ::kiwano::EventType(typeid(EVENT_TYPE)) - - - /** - * \~chinese - * \defgroup Events 事件 - */ - - /** - * \addtogroup Events - * @{ - */ - - /// \~chinese - /// @brief 事件 - class KGE_API Event - { - public: - /// \~chinese - /// @brief 构造事件 - Event(EventType const& type); - - virtual ~Event(); - - /// \~chinese - /// @brief 获取类型事件 - inline const EventType& GetType() const - { - return type_; - } - - /// \~chinese - /// @brief 判断事件类型 - /// @return 是否是指定事件类型 - template < - typename _Ty, - typename = typename std::enable_if::value, int>::type - > - inline bool IsType() const - { - 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& Cast() const - { - return dynamic_cast(*this); - } - - /// \~chinese - /// @brief 转换为其他类型事件 - /// @throw std::bad_cast 类型无法转换时抛出 - template < - typename _Ty, - typename = typename std::enable_if::value, int>::type - > - inline _Ty& Cast() - { - return dynamic_cast<_Ty&>(*this); - } - - /// \~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 Cast<_Ty>(); - } - - /// \~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>()); - } - - private: - const EventType type_; - }; - - /// \~chinese - /// @brief 事件特性:判断是否是事件类型 - template - class IsEvent : public std::bool_constant::value || std::is_same::value> {}; - - - /// \~chinese - /// @brief 鼠标事件 - class KGE_API MouseEvent - : public Event - { - public: - 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: - MouseMoveEvent(); - }; - - /// \~chinese - /// @brief 鼠标按键按下事件 - class KGE_API MouseDownEvent - : public MouseEvent - { - public: - MouseButton::Value button; ///< 鼠标键值 - - MouseDownEvent(); - }; - - /// \~chinese - /// @brief 鼠标按键抬起事件 - class KGE_API MouseUpEvent - : public MouseEvent - { - public: - MouseButton::Value button; ///< 鼠标键值 - - MouseUpEvent(); - }; - - /// \~chinese - /// @brief 鼠标点击事件 - class KGE_API MouseClickEvent - : public MouseEvent - { - public: - MouseButton::Value button; ///< 鼠标键值 - - MouseClickEvent(); - }; - - /// \~chinese - /// @brief 鼠标移入事件 - class KGE_API MouseHoverEvent - : public MouseEvent - { - public: - MouseHoverEvent(); - }; - - /// \~chinese - /// @brief 鼠标移出事件 - class KGE_API MouseOutEvent - : public MouseEvent - { - public: - MouseOutEvent(); - }; - - /// \~chinese - /// @brief 鼠标滚轮事件 - class KGE_API MouseWheelEvent - : public MouseEvent - { - public: - float wheel; ///< 滚轮值 - - MouseWheelEvent(); - }; - - /// \~chinese - /// @brief 键盘按下事件 - class KGE_API KeyDownEvent - : public Event - { - public: - KeyCode::Value code; ///< 键值 - - KeyDownEvent(); - }; - - /// \~chinese - /// @brief 键盘抬起事件 - class KGE_API KeyUpEvent - : public Event - { - public: - KeyCode::Value code; ///< 键值 - - KeyUpEvent(); - }; - - /// \~chinese - /// @brief 键盘字符事件 - class KGE_API KeyCharEvent - : public Event - { - public: - char value; ///< 字符 - - KeyCharEvent(); - }; - - /// \~chinese - /// @brief 窗口移动事件 - class KGE_API WindowMovedEvent - : public Event - { - public: - int x; ///< 窗口左上角 x 坐标 - int y; ///< 窗口左上角 y 坐标 - - WindowMovedEvent(); - }; - - /// \~chinese - /// @brief 窗口大小变化事件 - class KGE_API WindowResizedEvent - : public Event - { - public: - int width; ///< 窗口宽度 - int height; ///< 窗口高度 - - WindowResizedEvent(); - }; - - /// \~chinese - /// @brief 窗口焦点变化事件 - class KGE_API WindowFocusChangedEvent - : public Event - { - public: - bool focus; ///< 是否获取到焦点 - - WindowFocusChangedEvent(); - }; - - /// \~chinese - /// @brief 窗口标题更改事件 - class KGE_API WindowTitleChangedEvent - : public Event - { - public: - String title; ///< 标题 - - WindowTitleChangedEvent(); - }; - - /// \~chinese - /// @brief 窗口关闭事件 - class KGE_API WindowClosedEvent - : public Event - { - public: - WindowClosedEvent(); - }; - - /** @} */ - -} diff --git a/src/kiwano/core/EventListener.h b/src/kiwano/core/EventListener.h index a0795530..6014e9f0 100644 --- a/src/kiwano/core/EventListener.h +++ b/src/kiwano/core/EventListener.h @@ -22,7 +22,10 @@ #include #include #include -#include +#include +#include +#include +#include namespace kiwano { diff --git a/src/kiwano/core/event/Event.cpp b/src/kiwano/core/event/Event.cpp new file mode 100644 index 00000000..e8ddc6bb --- /dev/null +++ b/src/kiwano/core/event/Event.cpp @@ -0,0 +1,14 @@ +#include + +namespace kiwano +{ + Event::Event(EventType const& type) + : type_(type) + { + } + + Event::~Event() + { + } + +} diff --git a/src/kiwano/core/event/Event.h b/src/kiwano/core/event/Event.h new file mode 100644 index 00000000..1576a2f3 --- /dev/null +++ b/src/kiwano/core/event/Event.h @@ -0,0 +1,129 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once +#include +#include +#include + +namespace kiwano +{ + /** + * \~chinese + * \defgroup Events 事件 + */ + + /** + * \addtogroup Events + * @{ + */ + + /// \~chinese + /// @brief 事件 + class KGE_API Event + { + public: + /// \~chinese + /// @brief 构造事件 + Event(EventType const& type); + + virtual ~Event(); + + /// \~chinese + /// @brief 获取类型事件 + const EventType& GetType() const; + + /// \~chinese + /// @brief 判断事件类型 + /// @return 是否是指定事件类型 + template < + typename _Ty, + typename = typename std::enable_if::value, int>::type + > + bool IsType() const; + + /// \~chinese + /// @brief 安全转换为其他类型事件 + /// @throw std::bad_cast 类型无法转换时抛出 + template < + typename _Ty, + typename = typename std::enable_if::value, int>::type + > + const _Ty& SafeCast() const; + + /// \~chinese + /// @brief 安全转换为其他类型事件 + /// @throw std::bad_cast 类型无法转换时抛出 + template < + typename _Ty, + typename = typename std::enable_if::value, int>::type + > + _Ty& SafeCast(); + + private: + const EventType type_; + }; + + /// \~chinese + /// @brief 事件特性:判断是否是事件类型 + template + struct IsEvent : public std::bool_constant::value || std::is_same::value> + { + }; + + /// \~chinese + /// @brief 事件特性:判断是否是事件类型 + template ::value, int>::type> + struct IsEventType + { + inline bool operator()(const Event& evt) const + { + return evt.GetType() == KGE_EVENT(_Ty); + } + }; + + /** @} */ + + inline const EventType& Event::GetType() const + { + return type_; + } + + template + inline bool Event::IsType() const + { + return kiwano::IsEventType<_Ty>()(*this); + } + + template + inline const _Ty& Event::SafeCast() const + { + if (!IsType<_Ty>()) + throw std::bad_cast(); + return dynamic_cast(*this); + } + + template + inline _Ty& Event::SafeCast() + { + return const_cast<_Ty&>(const_cast(this)->SafeCast<_Ty>()); + } + +} diff --git a/src/kiwano/core/event/EventType.h b/src/kiwano/core/event/EventType.h new file mode 100644 index 00000000..d10341a4 --- /dev/null +++ b/src/kiwano/core/event/EventType.h @@ -0,0 +1,64 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once +#include +#include +#include + +namespace kiwano +{ + /** + * \addtogroup Events + * @{ + */ + + /// \~chinese + /// @brief 事件类型 + class EventType + : public std::type_index + { + class Dummy { }; + + public: + /// \~chinese + /// @brief 构建事件类型 + EventType(); + + using std::type_index::type_index; + using std::type_index::operator==; + using std::type_index::operator!=; + using std::type_index::operator<; + using std::type_index::operator>=; + using std::type_index::operator>; + using std::type_index::operator<=; + }; + + /** @} */ + +#define KGE_EVENT(EVENT_TYPE) ::kiwano::EventType(typeid(EVENT_TYPE)) + + + inline EventType::EventType() + : std::type_index(typeid(EventType::Dummy)) + { + } + +} diff --git a/src/kiwano/core/event/KeyEvent.cpp b/src/kiwano/core/event/KeyEvent.cpp new file mode 100644 index 00000000..4ae1e86e --- /dev/null +++ b/src/kiwano/core/event/KeyEvent.cpp @@ -0,0 +1,23 @@ +#include + +namespace kiwano +{ + KeyDownEvent::KeyDownEvent() + : Event(KGE_EVENT(KeyDownEvent)) + , code(0) + { + } + + KeyUpEvent::KeyUpEvent() + : Event(KGE_EVENT(KeyUpEvent)) + , code(0) + { + } + + KeyCharEvent::KeyCharEvent() + : Event(KGE_EVENT(KeyCharEvent)) + , value() + { + } + +} diff --git a/src/kiwano/core/event/KeyEvent.h b/src/kiwano/core/event/KeyEvent.h new file mode 100644 index 00000000..bcc78322 --- /dev/null +++ b/src/kiwano/core/event/KeyEvent.h @@ -0,0 +1,85 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once +#include +#include + +namespace kiwano +{ + /** + * \addtogroup Events + * @{ + */ + + /// \~chinese + /// @brief 键盘事件 + class KGE_API KeyEvent + : public Event + { + }; + + /// \~chinese + /// @brief 键盘按下事件 + class KGE_API KeyDownEvent + : public Event + { + public: + KeyCode::Value code; ///< 键值 + + KeyDownEvent(); + }; + + /// \~chinese + /// @brief 键盘抬起事件 + class KGE_API KeyUpEvent + : public Event + { + public: + KeyCode::Value code; ///< 键值 + + KeyUpEvent(); + }; + + /// \~chinese + /// @brief 键盘字符事件 + class KGE_API KeyCharEvent + : public Event + { + public: + char value; ///< 字符 + + KeyCharEvent(); + }; + + /** @} */ + + template <> + struct IsEventType + { + inline bool operator()(const Event& evt) const + { + return evt.GetType() == KGE_EVENT(KeyDownEvent) + || evt.GetType() == KGE_EVENT(KeyUpEvent) + || evt.GetType() == KGE_EVENT(KeyCharEvent); + } + }; + +} diff --git a/src/kiwano/core/event/MouseEvent.cpp b/src/kiwano/core/event/MouseEvent.cpp new file mode 100644 index 00000000..dc428684 --- /dev/null +++ b/src/kiwano/core/event/MouseEvent.cpp @@ -0,0 +1,53 @@ +#include + +namespace kiwano +{ + MouseEvent::MouseEvent(EventType const& type) + : Event(type) + , pos() + , left_btn_down(false) + , right_btn_down(false) + , target(nullptr) + { + } + + MouseMoveEvent::MouseMoveEvent() + : MouseEvent(KGE_EVENT(MouseMoveEvent)) + { + } + + MouseDownEvent::MouseDownEvent() + : MouseEvent(KGE_EVENT(MouseDownEvent)) + , button(0) + { + } + + MouseUpEvent::MouseUpEvent() + : MouseEvent(KGE_EVENT(MouseUpEvent)) + , button(0) + { + } + + MouseClickEvent::MouseClickEvent() + : MouseEvent(KGE_EVENT(MouseClickEvent)) + , button(0) + { + } + + MouseHoverEvent::MouseHoverEvent() + : MouseEvent(KGE_EVENT(MouseHoverEvent)) + { + } + + MouseOutEvent::MouseOutEvent() + : MouseEvent(KGE_EVENT(MouseOutEvent)) + { + } + + MouseWheelEvent::MouseWheelEvent() + : MouseEvent(KGE_EVENT(MouseWheelEvent)) + , wheel(0.f) + { + } + +} diff --git a/src/kiwano/core/event/MouseEvent.h b/src/kiwano/core/event/MouseEvent.h new file mode 100644 index 00000000..7f3c9162 --- /dev/null +++ b/src/kiwano/core/event/MouseEvent.h @@ -0,0 +1,137 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once +#include +#include +#include + +namespace kiwano +{ + class Actor; + + /** + * \addtogroup Events + * @{ + */ + + /// \~chinese + /// @brief 鼠标事件 + class KGE_API MouseEvent + : public Event + { + public: + 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: + MouseMoveEvent(); + }; + + /// \~chinese + /// @brief 鼠标按键按下事件 + class KGE_API MouseDownEvent + : public MouseEvent + { + public: + MouseButton::Value button; ///< 鼠标键值 + + MouseDownEvent(); + }; + + /// \~chinese + /// @brief 鼠标按键抬起事件 + class KGE_API MouseUpEvent + : public MouseEvent + { + public: + MouseButton::Value button; ///< 鼠标键值 + + MouseUpEvent(); + }; + + /// \~chinese + /// @brief 鼠标点击事件 + class KGE_API MouseClickEvent + : public MouseEvent + { + public: + MouseButton::Value button; ///< 鼠标键值 + + MouseClickEvent(); + }; + + /// \~chinese + /// @brief 鼠标移入事件 + class KGE_API MouseHoverEvent + : public MouseEvent + { + public: + MouseHoverEvent(); + }; + + /// \~chinese + /// @brief 鼠标移出事件 + class KGE_API MouseOutEvent + : public MouseEvent + { + public: + MouseOutEvent(); + }; + + /// \~chinese + /// @brief 鼠标滚轮事件 + class KGE_API MouseWheelEvent + : public MouseEvent + { + public: + float wheel; ///< 滚轮值 + + MouseWheelEvent(); + }; + + /** @} */ + + template <> + struct IsEventType + { + inline bool operator()(const Event& evt) const + { + return evt.GetType() == KGE_EVENT(MouseMoveEvent) + || evt.GetType() == KGE_EVENT(MouseDownEvent) + || evt.GetType() == KGE_EVENT(MouseUpEvent) + || evt.GetType() == KGE_EVENT(MouseClickEvent) + || evt.GetType() == KGE_EVENT(MouseHoverEvent) + || evt.GetType() == KGE_EVENT(MouseOutEvent) + || evt.GetType() == KGE_EVENT(MouseWheelEvent); + } + }; + +} diff --git a/src/kiwano/core/event/WindowEvent.cpp b/src/kiwano/core/event/WindowEvent.cpp new file mode 100644 index 00000000..608b72e4 --- /dev/null +++ b/src/kiwano/core/event/WindowEvent.cpp @@ -0,0 +1,36 @@ +#include + +namespace kiwano +{ + WindowMovedEvent::WindowMovedEvent() + : Event(KGE_EVENT(WindowMovedEvent)) + , x(0) + , y(0) + { + } + + WindowResizedEvent::WindowResizedEvent() + : Event(KGE_EVENT(WindowResizedEvent)) + , width(0) + , height(0) + { + } + + WindowFocusChangedEvent::WindowFocusChangedEvent() + : Event(KGE_EVENT(WindowFocusChangedEvent)) + , focus(false) + { + } + + WindowTitleChangedEvent::WindowTitleChangedEvent() + : Event(KGE_EVENT(WindowTitleChangedEvent)) + , title() + { + } + + WindowClosedEvent::WindowClosedEvent() + : Event(KGE_EVENT(WindowClosedEvent)) + { + } + +} diff --git a/src/kiwano/core/event/WindowEvent.h b/src/kiwano/core/event/WindowEvent.h new file mode 100644 index 00000000..5514853a --- /dev/null +++ b/src/kiwano/core/event/WindowEvent.h @@ -0,0 +1,108 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once +#include + +namespace kiwano +{ + /** + * \addtogroup Events + * @{ + */ + + /// \~chinese + /// @brief 窗口事件 + class KGE_API WindowEvent + : public Event + { + }; + + /// \~chinese + /// @brief 窗口移动事件 + class KGE_API WindowMovedEvent + : public Event + { + public: + int x; ///< 窗口左上角 x 坐标 + int y; ///< 窗口左上角 y 坐标 + + WindowMovedEvent(); + }; + + /// \~chinese + /// @brief 窗口大小变化事件 + class KGE_API WindowResizedEvent + : public Event + { + public: + int width; ///< 窗口宽度 + int height; ///< 窗口高度 + + WindowResizedEvent(); + }; + + /// \~chinese + /// @brief 窗口焦点变化事件 + class KGE_API WindowFocusChangedEvent + : public Event + { + public: + bool focus; ///< 是否获取到焦点 + + WindowFocusChangedEvent(); + }; + + /// \~chinese + /// @brief 窗口标题更改事件 + class KGE_API WindowTitleChangedEvent + : public Event + { + public: + String title; ///< 标题 + + WindowTitleChangedEvent(); + }; + + /// \~chinese + /// @brief 窗口关闭事件 + class KGE_API WindowClosedEvent + : public Event + { + public: + WindowClosedEvent(); + }; + + /** @} */ + + template <> + struct IsEventType + { + inline bool operator()(const Event& evt) const + { + return evt.GetType() == KGE_EVENT(WindowMovedEvent) + || evt.GetType() == KGE_EVENT(WindowResizedEvent) + || evt.GetType() == KGE_EVENT(WindowFocusChangedEvent) + || evt.GetType() == KGE_EVENT(WindowTitleChangedEvent) + || evt.GetType() == KGE_EVENT(WindowClosedEvent); + } + }; + +} diff --git a/src/kiwano/kiwano.h b/src/kiwano/kiwano.h index 8e9df3c1..10b43e39 100644 --- a/src/kiwano/kiwano.h +++ b/src/kiwano/kiwano.h @@ -49,7 +49,10 @@ #include #include #include -#include +#include +#include +#include +#include #include #include #include diff --git a/src/kiwano/platform/Application.h b/src/kiwano/platform/Application.h index 24dcbca6..e48e384c 100644 --- a/src/kiwano/platform/Application.h +++ b/src/kiwano/platform/Application.h @@ -22,7 +22,10 @@ #include #include #include -#include +#include +#include +#include +#include #include #include diff --git a/src/kiwano/ui/Button.cpp b/src/kiwano/ui/Button.cpp index 3684e61f..6342d1f8 100644 --- a/src/kiwano/ui/Button.cpp +++ b/src/kiwano/ui/Button.cpp @@ -105,7 +105,9 @@ namespace kiwano void Button::UpdateStatus(Event& evt) { - if (enabled_ && (evt.Cast().target == this)) + KGE_ASSERT(evt.IsType()); + + if (enabled_ && (evt.SafeCast().target == this)) { if (evt.IsType()) {