273 lines
5.0 KiB
C
273 lines
5.0 KiB
C
|
|
// 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 <kiwano/core/core.h>
|
|||
|
|
#include <kiwano/math/math.h>
|
|||
|
|
#include <kiwano/base/keys.hpp>
|
|||
|
|
|
|||
|
|
namespace kiwano
|
|||
|
|
{
|
|||
|
|
class Actor;
|
|||
|
|
|
|||
|
|
// <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
struct EventType
|
|||
|
|
{
|
|||
|
|
inline EventType() : hash(0), type()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
inline EventType(String const& type) : hash(0), type(type)
|
|||
|
|
{
|
|||
|
|
hash = type.hash();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
inline bool operator==(const EventType& rhs) const
|
|||
|
|
{
|
|||
|
|
return hash == rhs.hash && type == rhs.type;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
size_t hash;
|
|||
|
|
String type;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
// <20>¼<EFBFBD>
|
|||
|
|
class KGE_API Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
const EventType type;
|
|||
|
|
|
|||
|
|
Event(EventType const& type);
|
|||
|
|
virtual ~Event();
|
|||
|
|
|
|||
|
|
template <
|
|||
|
|
typename _Ty,
|
|||
|
|
typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type
|
|||
|
|
>
|
|||
|
|
inline const _Ty* SafeCast() const
|
|||
|
|
{
|
|||
|
|
const _Ty* ptr = dynamic_cast<const _Ty*>(this);
|
|||
|
|
if (ptr)
|
|||
|
|
{
|
|||
|
|
return ptr;
|
|||
|
|
}
|
|||
|
|
return nullptr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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>());
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
Point pos;
|
|||
|
|
bool left_btn_down; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
bool right_btn_down; // <20>Ҽ<EFBFBD><D2BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
Actor* target;
|
|||
|
|
|
|||
|
|
MouseEvent(EventType const& type);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseMoveEvent
|
|||
|
|
: public MouseEvent
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
MouseButton::Value button;
|
|||
|
|
|
|||
|
|
MouseMoveEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>갴<EFBFBD><EAB0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseDownEvent
|
|||
|
|
: public MouseEvent
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
MouseButton::Value button;
|
|||
|
|
|
|||
|
|
MouseDownEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>갴<EFBFBD><EAB0B4>̧<EFBFBD><CCA7><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseUpEvent
|
|||
|
|
: public MouseEvent
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
MouseButton::Value button;
|
|||
|
|
|
|||
|
|
MouseUpEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseClickEvent
|
|||
|
|
: public MouseEvent
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
MouseButton::Value button;
|
|||
|
|
|
|||
|
|
MouseClickEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseHoverEvent
|
|||
|
|
: public MouseEvent
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
MouseHoverEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseOutEvent
|
|||
|
|
: public MouseEvent
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
MouseOutEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API MouseWheelEvent
|
|||
|
|
: public MouseEvent
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
float wheel;
|
|||
|
|
|
|||
|
|
MouseWheelEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>̰<EFBFBD><CCB0><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API KeyDownEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
KeyCode::Value code;
|
|||
|
|
int count;
|
|||
|
|
|
|||
|
|
KeyDownEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API KeyUpEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
KeyCode::Value code;
|
|||
|
|
int count;
|
|||
|
|
|
|||
|
|
KeyUpEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>¼<EFBFBD>
|
|||
|
|
class KGE_API KeyCharEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
char value;
|
|||
|
|
int count;
|
|||
|
|
|
|||
|
|
KeyCharEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6>¼<EFBFBD>
|
|||
|
|
class KGE_API WindowMovedEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
int x;
|
|||
|
|
int y;
|
|||
|
|
|
|||
|
|
WindowMovedEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ڴ<EFBFBD>С<EFBFBD>仯<EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API WindowResizedEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
int width;
|
|||
|
|
int height;
|
|||
|
|
|
|||
|
|
WindowResizedEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>仯<EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API WindowFocusChangedEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
bool focus;
|
|||
|
|
|
|||
|
|
WindowFocusChangedEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
class KGE_API WindowTitleChangedEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
String title;
|
|||
|
|
|
|||
|
|
WindowTitleChangedEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ڹر<DAB9><D8B1>¼<EFBFBD>
|
|||
|
|
class KGE_API WindowClosedEvent
|
|||
|
|
: public Event
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
WindowClosedEvent();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace event
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
extern EventType MouseMove; // <20>ƶ<EFBFBD>
|
|||
|
|
extern EventType MouseDown; // <20><><EFBFBD>갴<EFBFBD><EAB0B4>
|
|||
|
|
extern EventType MouseUp; // <20><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7>
|
|||
|
|
extern EventType MouseWheel; // <20><><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>
|
|||
|
|
extern EventType MouseHover; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern EventType MouseOut; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
|
|||
|
|
extern EventType MouseClick; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
extern EventType KeyDown; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern EventType KeyUp; // <20><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7>
|
|||
|
|
extern EventType KeyChar; // <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
extern EventType WindowMoved; // <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
|||
|
|
extern EventType WindowResized; // <20><><EFBFBD>ڴ<EFBFBD>С<EFBFBD>仯
|
|||
|
|
extern EventType WindowFocusChanged; // <20><><EFBFBD>û<EFBFBD>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>
|
|||
|
|
extern EventType WindowTitleChanged; // <20><><EFBFBD><EFBFBD><EFBFBD>仯
|
|||
|
|
extern EventType WindowClosed; // <20><><EFBFBD>ڱ<EFBFBD><DAB1>ر<EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|