Update Events
This commit is contained in:
parent
fad362f1aa
commit
939fadcb97
11
Doxyfile
11
Doxyfile
|
|
@ -42,7 +42,7 @@ FILE_PATTERNS = *.c \
|
|||
*.hh \
|
||||
*.hxx \
|
||||
*.hpp \
|
||||
*.h++ \
|
||||
*.h++
|
||||
|
||||
RECURSIVE = YES
|
||||
EXCLUDE = src/3rd-party
|
||||
|
|
@ -60,8 +60,13 @@ PREDEFINED = KGE_API=
|
|||
# preprocessor.
|
||||
# This tag requires that the tag SEARCH_INCLUDES is set to YES.
|
||||
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH = src/
|
||||
INCLUDE_FILE_PATTERNS = *.h \
|
||||
*.hh \
|
||||
*.hxx \
|
||||
*.hpp \
|
||||
*.h++
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the HTML output
|
||||
|
|
|
|||
|
|
@ -24,4 +24,4 @@
|
|||
#include <kiwano-imgui/ImGuiModule.h>
|
||||
|
||||
// ImGui
|
||||
#include <3rd-party/imgui/imgui.h>
|
||||
#include <imgui/imgui.h>
|
||||
|
|
|
|||
|
|
@ -22,17 +22,10 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
namespace physics
|
||||
{
|
||||
namespace events
|
||||
{
|
||||
KGE_IMPLEMENT_EVENT_TYPE(ContactBegin, physics::ContactBeginEvent);
|
||||
KGE_IMPLEMENT_EVENT_TYPE(ContactEnd, physics::ContactEndEvent);
|
||||
}
|
||||
|
||||
ContactBeginEvent::ContactBeginEvent()
|
||||
: Event(events::ContactBegin)
|
||||
: Event(KGE_EVENT(ContactBeginEvent))
|
||||
, body_a(nullptr)
|
||||
, body_b(nullptr)
|
||||
{
|
||||
|
|
@ -47,7 +40,7 @@ namespace kiwano
|
|||
}
|
||||
|
||||
ContactEndEvent::ContactEndEvent()
|
||||
: Event(events::ContactEnd)
|
||||
: Event(KGE_EVENT(ContactEndEvent))
|
||||
, body_a(nullptr)
|
||||
, body_b(nullptr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,19 +26,6 @@ namespace kiwano
|
|||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace events
|
||||
{
|
||||
/**
|
||||
* \addtogroup EventTypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
KGE_DECLARE_EVENT_TYPE(ContactBegin); ///< ½Ó´¥¿ªÊ¼
|
||||
KGE_DECLARE_EVENT_TYPE(ContactEnd); ///< ½Ó´¥½áÊø
|
||||
|
||||
/** @} */
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 接触开始事件
|
||||
class KGE_API ContactBeginEvent
|
||||
|
|
@ -67,5 +54,16 @@ namespace kiwano
|
|||
ContactEndEvent(Contact const& contact);
|
||||
};
|
||||
|
||||
/**
|
||||
* \addtogroup EventTypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
KGE_EVENT_BEGIN(PhysicEvents);
|
||||
KGE_DEFINE_EVENT(ContactBegin, ContactBeginEvent); ///< ½Ó´¥¿ªÊ¼ @see kiwano::physics::ContactBeginEvent
|
||||
KGE_DEFINE_EVENT(ContactEnd, ContactEndEvent); ///< ½Ó´¥½áÊø @see kiwano::physics::ContactEndEvent
|
||||
KGE_EVENT_END;
|
||||
|
||||
/** @} */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace kiwano
|
|||
style.line_spacing = 20.f;
|
||||
debug_text_->SetStyle(style);
|
||||
|
||||
AddListener(events::MouseHover, [=](Event&) { SetOpacity(0.4f); });
|
||||
AddListener(events::MouseOut, [=](Event&) { SetOpacity(1.f); });
|
||||
AddListener(MouseEvents::Hover(), [=](Event&) { SetOpacity(0.4f); });
|
||||
AddListener(MouseEvents::Out(), [=](Event&) { SetOpacity(1.f); });
|
||||
}
|
||||
|
||||
DebugActor::~DebugActor()
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ namespace kiwano
|
|||
{
|
||||
auto handler = Closure(this, &Layer::HandleMessages);
|
||||
|
||||
AddListener(events::MouseDown, handler);
|
||||
AddListener(events::MouseUp, handler);
|
||||
AddListener(events::MouseMove, handler);
|
||||
AddListener(events::MouseWheel, handler);
|
||||
AddListener(MouseEvents::Down(), handler);
|
||||
AddListener(MouseEvents::Up(), handler);
|
||||
AddListener(MouseEvents::Move(), handler);
|
||||
AddListener(MouseEvents::Wheel(), handler);
|
||||
|
||||
AddListener(events::KeyDown, handler);
|
||||
AddListener(events::KeyUp, handler);
|
||||
AddListener(events::KeyChar, handler);
|
||||
AddListener(KeyEvents::Down(), handler);
|
||||
AddListener(KeyEvents::Up(), handler);
|
||||
AddListener(KeyEvents::Char(), handler);
|
||||
}
|
||||
|
||||
Layer::~Layer()
|
||||
|
|
|
|||
|
|
@ -2,27 +2,6 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -42,91 +21,90 @@ namespace kiwano
|
|||
}
|
||||
|
||||
MouseMoveEvent::MouseMoveEvent()
|
||||
: MouseEvent(events::MouseMove)
|
||||
, button(0)
|
||||
: MouseEvent(KGE_EVENT(MouseMoveEvent))
|
||||
{
|
||||
}
|
||||
|
||||
MouseDownEvent::MouseDownEvent()
|
||||
: MouseEvent(events::MouseDown)
|
||||
: MouseEvent(KGE_EVENT(MouseDownEvent))
|
||||
, button(0)
|
||||
{
|
||||
}
|
||||
|
||||
MouseUpEvent::MouseUpEvent()
|
||||
: MouseEvent(events::MouseUp)
|
||||
: MouseEvent(KGE_EVENT(MouseUpEvent))
|
||||
, button(0)
|
||||
{
|
||||
}
|
||||
|
||||
MouseClickEvent::MouseClickEvent()
|
||||
: MouseEvent(events::MouseClick)
|
||||
: MouseEvent(KGE_EVENT(MouseClickEvent))
|
||||
, button(0)
|
||||
{
|
||||
}
|
||||
|
||||
MouseHoverEvent::MouseHoverEvent()
|
||||
: MouseEvent(events::MouseHover)
|
||||
: MouseEvent(KGE_EVENT(MouseHoverEvent))
|
||||
{
|
||||
}
|
||||
|
||||
MouseOutEvent::MouseOutEvent()
|
||||
: MouseEvent(events::MouseOut)
|
||||
: MouseEvent(KGE_EVENT(MouseOutEvent))
|
||||
{
|
||||
}
|
||||
|
||||
MouseWheelEvent::MouseWheelEvent()
|
||||
: MouseEvent(events::MouseWheel)
|
||||
: MouseEvent(KGE_EVENT(MouseWheelEvent))
|
||||
, wheel(0.f)
|
||||
{
|
||||
}
|
||||
|
||||
KeyDownEvent::KeyDownEvent()
|
||||
: Event(events::KeyDown)
|
||||
: Event(KGE_EVENT(KeyDownEvent))
|
||||
, code(0)
|
||||
{
|
||||
}
|
||||
|
||||
KeyUpEvent::KeyUpEvent()
|
||||
: Event(events::KeyUp)
|
||||
: Event(KGE_EVENT(KeyUpEvent))
|
||||
, code(0)
|
||||
{
|
||||
}
|
||||
|
||||
KeyCharEvent::KeyCharEvent()
|
||||
: Event(events::KeyChar)
|
||||
: Event(KGE_EVENT(KeyCharEvent))
|
||||
, value()
|
||||
{
|
||||
}
|
||||
|
||||
WindowMovedEvent::WindowMovedEvent()
|
||||
: Event(events::WindowMoved)
|
||||
: Event(KGE_EVENT(WindowMovedEvent))
|
||||
, x(0)
|
||||
, y(0)
|
||||
{
|
||||
}
|
||||
|
||||
WindowResizedEvent::WindowResizedEvent()
|
||||
: Event(events::WindowResized)
|
||||
: Event(KGE_EVENT(WindowResizedEvent))
|
||||
, width(0)
|
||||
, height(0)
|
||||
{
|
||||
}
|
||||
|
||||
WindowFocusChangedEvent::WindowFocusChangedEvent()
|
||||
: Event(events::WindowFocusChanged)
|
||||
: Event(KGE_EVENT(WindowFocusChangedEvent))
|
||||
, focus(false)
|
||||
{
|
||||
}
|
||||
|
||||
WindowTitleChangedEvent::WindowTitleChangedEvent()
|
||||
: Event(events::WindowTitleChanged)
|
||||
: Event(KGE_EVENT(WindowTitleChangedEvent))
|
||||
, title()
|
||||
{
|
||||
}
|
||||
|
||||
WindowClosedEvent::WindowClosedEvent()
|
||||
: Event(events::WindowClosed)
|
||||
: Event(KGE_EVENT(WindowClosedEvent))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,12 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
#include <kiwano/common/common.h>
|
||||
#include <kiwano/math/math.h>
|
||||
#include <kiwano/core/keys.h>
|
||||
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
class Actor;
|
||||
|
|
@ -53,49 +52,8 @@ namespace kiwano
|
|||
EventType(const std::type_index& index) : std::type_index(index) {}
|
||||
};
|
||||
|
||||
#define KGE_EVENT(EVENT_TYPE) ::kiwano::EventType(typeid(EVENT_TYPE))
|
||||
|
||||
#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
|
||||
* @{
|
||||
*/
|
||||
|
||||
// 鼠标事件
|
||||
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); ///< 鼠标点击
|
||||
|
||||
// 按键事件
|
||||
KGE_DECLARE_EVENT_TYPE(KeyDown); ///< 按键按下
|
||||
KGE_DECLARE_EVENT_TYPE(KeyUp); ///< 按键抬起
|
||||
KGE_DECLARE_EVENT_TYPE(KeyChar); ///< 输出字符
|
||||
|
||||
// 窗口消息
|
||||
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
|
||||
|
|
@ -166,6 +124,12 @@ namespace kiwano
|
|||
const EventType type_;
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 事件特性:判断是否是事件类型
|
||||
template <typename _Ty>
|
||||
class IsEvent : public std::bool_constant<std::is_base_of<Event, _Ty>::value || std::is_same<Event, _Ty>::value> {};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief Êó±êʼþ
|
||||
class KGE_API MouseEvent
|
||||
|
|
@ -186,8 +150,6 @@ namespace kiwano
|
|||
: public MouseEvent
|
||||
{
|
||||
public:
|
||||
MouseButton::Value button; ///< 鼠标键值
|
||||
|
||||
MouseMoveEvent();
|
||||
};
|
||||
|
||||
|
|
@ -343,4 +305,57 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup EventTypes 事件类型
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup EventTypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
#define KGE_EVENT_BEGIN(NAME) struct NAME {
|
||||
#define KGE_EVENT_END };
|
||||
#define KGE_DEFINE_EVENT(EVENT_NAME, EVENT_TYPE) \
|
||||
static inline const EventType& EVENT_NAME() \
|
||||
{ \
|
||||
static EventType event_type = KGE_EVENT(EVENT_TYPE); \
|
||||
return event_type; \
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标事件
|
||||
KGE_EVENT_BEGIN(MouseEvents);
|
||||
KGE_DEFINE_EVENT(Move, MouseMoveEvent); ///< 鼠标移动
|
||||
KGE_DEFINE_EVENT(Down, MouseDownEvent); ///< 鼠标按下
|
||||
KGE_DEFINE_EVENT(Up, MouseUpEvent); ///< 鼠标抬起
|
||||
KGE_DEFINE_EVENT(Wheel, MouseWheelEvent); ///< 滚轮滚动
|
||||
KGE_DEFINE_EVENT(Hover, MouseHoverEvent); ///< 鼠标移入
|
||||
KGE_DEFINE_EVENT(Out, MouseOutEvent); ///< 鼠标移出
|
||||
KGE_DEFINE_EVENT(Click, MouseClickEvent); ///< 鼠标点击
|
||||
KGE_EVENT_END;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 键盘按键事件
|
||||
KGE_EVENT_BEGIN(KeyEvents);
|
||||
KGE_DEFINE_EVENT(Down, KeyDownEvent); ///< 按键按下
|
||||
KGE_DEFINE_EVENT(Up, KeyUpEvent); ///< 按键抬起
|
||||
KGE_DEFINE_EVENT(Char, KeyCharEvent); ///< 输出字符
|
||||
KGE_EVENT_END;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 窗口事件
|
||||
KGE_EVENT_BEGIN(WindowEvents);
|
||||
KGE_DEFINE_EVENT(Moved, WindowMovedEvent); ///< 窗口移动
|
||||
KGE_DEFINE_EVENT(Resized, WindowResizedEvent); ///< 窗口大小变化
|
||||
KGE_DEFINE_EVENT(FocusChanged, WindowFocusChangedEvent); ///< 获得或失去焦点
|
||||
KGE_DEFINE_EVENT(TitleChanged, WindowTitleChangedEvent); ///< 标题变化
|
||||
KGE_DEFINE_EVENT(Closed, WindowClosedEvent); ///< 窗口被关闭
|
||||
KGE_EVENT_END;
|
||||
|
||||
/** @} */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,17 +40,35 @@ namespace kiwano
|
|||
|
||||
// 添加监听器
|
||||
EventListener* AddListener(
|
||||
String const& name,
|
||||
EventType type,
|
||||
EventListener::Callback callback
|
||||
);
|
||||
|
||||
// 添加监听器
|
||||
EventListener* AddListener(
|
||||
String const& name,
|
||||
EventType type,
|
||||
EventListener::Callback callback
|
||||
);
|
||||
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type
|
||||
>
|
||||
EventListener* AddListener(EventListener::Callback callback)
|
||||
{
|
||||
return AddListener(KGE_EVENT(_EventTy), callback);
|
||||
}
|
||||
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>
|
||||
>
|
||||
EventListener* AddListener(String const& name, EventListener::Callback callback)
|
||||
{
|
||||
return AddListener(name, KGE_EVENT(_EventTy), callback);
|
||||
}
|
||||
|
||||
// 启动监听器
|
||||
void StartListeners(
|
||||
String const& listener_name
|
||||
|
|
|
|||
|
|
@ -106,8 +106,8 @@ namespace kiwano
|
|||
String ToString() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 时间段格式化
|
||||
/// @param format 格式
|
||||
/// @brief 解析时间段字符串
|
||||
/// @param str 时间段字符串
|
||||
/// @details
|
||||
/// 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀
|
||||
/// 例如: "300ms", "-1.5h", "2h45m"
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ namespace kiwano
|
|||
/**
|
||||
* \~chinese
|
||||
* @brief 删除文件
|
||||
* @param path 文件路径
|
||||
* @param file_path 文件路径
|
||||
* @return 删除是否成功
|
||||
*/
|
||||
bool RemoveFile(String const& file_path) const;
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ namespace kiwano
|
|||
{
|
||||
SetResponsible(true);
|
||||
|
||||
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));
|
||||
AddListener(MouseEvents::Hover(), Closure(this, &Button::UpdateStatus));
|
||||
AddListener(MouseEvents::Out(), Closure(this, &Button::UpdateStatus));
|
||||
AddListener(MouseEvents::Down(), Closure(this, &Button::UpdateStatus));
|
||||
AddListener(MouseEvents::Up(), Closure(this, &Button::UpdateStatus));
|
||||
}
|
||||
|
||||
Button::Button(const Callback& click)
|
||||
|
|
|
|||
Loading…
Reference in New Issue