Remove event declare macros
This commit is contained in:
parent
939fadcb97
commit
13cbca8f49
|
|
@ -53,17 +53,5 @@ namespace kiwano
|
|||
ContactEndEvent();
|
||||
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(MouseEvents::Hover(), [=](Event&) { SetOpacity(0.4f); });
|
||||
AddListener(MouseEvents::Out(), [=](Event&) { SetOpacity(1.f); });
|
||||
AddListener<MouseHoverEvent>([=](Event&) { SetOpacity(0.4f); });
|
||||
AddListener<MouseOutEvent>([=](Event&) { SetOpacity(1.f); });
|
||||
}
|
||||
|
||||
DebugActor::~DebugActor()
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ namespace kiwano
|
|||
{
|
||||
auto handler = Closure(this, &Layer::HandleMessages);
|
||||
|
||||
AddListener(MouseEvents::Down(), handler);
|
||||
AddListener(MouseEvents::Up(), handler);
|
||||
AddListener(MouseEvents::Move(), handler);
|
||||
AddListener(MouseEvents::Wheel(), handler);
|
||||
AddListener<MouseDownEvent>(handler);
|
||||
AddListener<MouseUpEvent>(handler);
|
||||
AddListener<MouseMoveEvent>(handler);
|
||||
AddListener<MouseWheelEvent>(handler);
|
||||
|
||||
AddListener(KeyEvents::Down(), handler);
|
||||
AddListener(KeyEvents::Up(), handler);
|
||||
AddListener(KeyEvents::Char(), handler);
|
||||
AddListener<KeyDownEvent>(handler);
|
||||
AddListener<KeyUpEvent>(handler);
|
||||
AddListener<KeyCharEvent>(handler);
|
||||
}
|
||||
|
||||
Layer::~Layer()
|
||||
|
|
|
|||
|
|
@ -95,22 +95,47 @@ namespace kiwano
|
|||
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& Cast() const
|
||||
{
|
||||
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& Cast()
|
||||
{
|
||||
return *dynamic_cast<_Ty*>(this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 安全转换为其他类型事件
|
||||
/// @throw std::bad_cast 无法转换的类型
|
||||
/// @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);
|
||||
if (!IsType<_Ty>())
|
||||
throw std::bad_cast();
|
||||
return Cast<_Ty>();
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 安全转换为其他类型事件
|
||||
/// @throw std::bad_cast 无法转换的类型
|
||||
/// @throw std::bad_cast 类型无法转换时抛出
|
||||
template <
|
||||
typename _Ty,
|
||||
typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type
|
||||
|
|
@ -305,57 +330,4 @@ 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;
|
||||
|
||||
/** @} */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,24 @@ namespace kiwano
|
|||
Callback const& callback
|
||||
);
|
||||
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type
|
||||
>
|
||||
EventListener(Callback const& callback)
|
||||
: EventListener(KGE_EVENT(_EventTy), callback)
|
||||
{
|
||||
}
|
||||
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type
|
||||
>
|
||||
EventListener(String const& name, Callback const& callback)
|
||||
: EventListener(name, KGE_EVENT(_EventTy), callback)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~EventListener();
|
||||
|
||||
void Start();
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ namespace kiwano
|
|||
{
|
||||
SetResponsible(true);
|
||||
|
||||
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));
|
||||
AddListener<MouseHoverEvent>(Closure(this, &Button::UpdateStatus));
|
||||
AddListener<MouseOutEvent>(Closure(this, &Button::UpdateStatus));
|
||||
AddListener<MouseDownEvent>(Closure(this, &Button::UpdateStatus));
|
||||
AddListener<MouseUpEvent>(Closure(this, &Button::UpdateStatus));
|
||||
}
|
||||
|
||||
Button::Button(const Callback& click)
|
||||
|
|
@ -105,10 +105,7 @@ namespace kiwano
|
|||
|
||||
void Button::UpdateStatus(Event& evt)
|
||||
{
|
||||
auto mouse_evt = dynamic_cast<MouseEvent*>(&evt);
|
||||
KGE_ASSERT(mouse_evt != nullptr);
|
||||
|
||||
if (enabled_ && (mouse_evt->target == this))
|
||||
if (enabled_ && (evt.Cast<MouseEvent>().target == this))
|
||||
{
|
||||
if (evt.IsType<MouseHoverEvent>())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue