added files of io/event
This commit is contained in:
104
inc/hgl/io/event/InputEvent.h
Normal file
104
inc/hgl/io/event/InputEvent.h
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#ifndef HGL_IO_INPUT_EVENT_INCLUDE
|
||||||
|
#define HGL_IO_INPUT_EVENT_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/type/Sets.h>
|
||||||
|
#include<hgl/io/event/InputEventSource.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace io
|
||||||
|
{
|
||||||
|
struct EventHeader
|
||||||
|
{
|
||||||
|
uint8 type; ///<<3C><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
||||||
|
uint8 index; ///<<3C><><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>ͬһ<CDAC>豸<EFBFBD>ж<EFBFBD><D0B6><EFBFBD>)
|
||||||
|
uint16 id; ///<<3C>¼<EFBFBD>id
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t EventHeaderBytes=sizeof(EventHeader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
enum class EventProcResult
|
||||||
|
{
|
||||||
|
Continue,
|
||||||
|
Break,
|
||||||
|
};
|
||||||
|
|
||||||
|
class InputEvent
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
InputEventSource source_type;
|
||||||
|
|
||||||
|
Sets<InputEvent *> sub_event_proc[size_t(InputEventSource::RANGE_SIZE)];
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const InputEventSource GetInputEventSource()const{return source_type;}
|
||||||
|
|
||||||
|
virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data)
|
||||||
|
{
|
||||||
|
if(!RangeCheck((InputEventSource)header.type))
|
||||||
|
return(EventProcResult::Break);
|
||||||
|
|
||||||
|
if(sub_event_proc[header.type].GetCount()>0)
|
||||||
|
{
|
||||||
|
for(InputEvent *ie:sub_event_proc[header.type])
|
||||||
|
if(ie->OnEvent(header,data)==EventProcResult::Break)
|
||||||
|
return EventProcResult::Break;
|
||||||
|
|
||||||
|
if(sub_event_proc[size_t(InputEventSource::Root)].GetCount()>0
|
||||||
|
&&InputEventSource(header.type)!=InputEventSource::Root)
|
||||||
|
{
|
||||||
|
for(InputEvent *ie:sub_event_proc[size_t(InputEventSource::Root)])
|
||||||
|
if(ie->OnEvent(header,data)==EventProcResult::Break)
|
||||||
|
return EventProcResult::Break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(EventProcResult::Continue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
InputEvent()
|
||||||
|
{
|
||||||
|
source_type=InputEventSource::Root;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputEvent(InputEventSource ies)
|
||||||
|
{
|
||||||
|
source_type=ies;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~InputEvent()=default;
|
||||||
|
|
||||||
|
virtual bool Join(InputEvent *ie)
|
||||||
|
{
|
||||||
|
if(!ie)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
const InputEventSource ies=ie->GetInputEventSource();
|
||||||
|
|
||||||
|
if(!RangeCheck(ies))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return(sub_event_proc[size_t(ies)].Add(ie)!=-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unjoin(InputEvent *ie)
|
||||||
|
{
|
||||||
|
if(!ie)return(false);
|
||||||
|
|
||||||
|
const InputEventSource ies=ie->GetInputEventSource();
|
||||||
|
|
||||||
|
if(!RangeCheck(ies))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return sub_event_proc[size_t(ies)].Delete(ie);
|
||||||
|
}
|
||||||
|
};//class InputEvent
|
||||||
|
}//namespace io
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_IO_INPUT_EVENT_INCLUDE
|
24
inc/hgl/io/event/InputEventSource.h
Normal file
24
inc/hgl/io/event/InputEventSource.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef HGL_IO_INPUT_DEVICE_SOURCE_INCLUDE
|
||||||
|
#define HGL_IO_INPUT_DEVICE_SOURCE_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/TypeFunc.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace io
|
||||||
|
{
|
||||||
|
enum class InputEventSource
|
||||||
|
{
|
||||||
|
Root=0,
|
||||||
|
|
||||||
|
OS,
|
||||||
|
Window,
|
||||||
|
|
||||||
|
Keyboard,
|
||||||
|
Mouse,
|
||||||
|
Joystick,
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(Root,Joystick)
|
||||||
|
};
|
||||||
|
}//namespace io
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_IO_INPUT_DEVICE_SOURCE_INCLUDE
|
61
inc/hgl/io/event/JoystickEvent.h
Normal file
61
inc/hgl/io/event/JoystickEvent.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#ifndef HGL_IO_DEVICE_MOUSE_EVENT_INCLUDE
|
||||||
|
#define HGL_IO_DEVICE_MOUSE_EVENT_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/TypeFunc.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace io
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* <20>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>
|
||||||
|
*/
|
||||||
|
enum class JoystickButton
|
||||||
|
{
|
||||||
|
NONE=0,
|
||||||
|
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
|
||||||
|
_0, _1, _2, _3, _4, _5, _6, _7,
|
||||||
|
_8, _9, _10, _11, _12, _13, _14, _15,
|
||||||
|
_16, _17, _18, _19, _20, _21, _22, _23,
|
||||||
|
_24, _25, _26, _27, _28, _29, _30, _31,
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(NONE,_31)
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class PlayStationButton
|
||||||
|
{
|
||||||
|
Up =JoystickButton::Up,
|
||||||
|
Down =JoystickButton::Down,
|
||||||
|
Left =JoystickButton::Left,
|
||||||
|
Right =JoystickButton::Right,
|
||||||
|
|
||||||
|
Fork =JoystickButton::_0, // <20><>
|
||||||
|
Circle =JoystickButton::_1, // Բ
|
||||||
|
Square =JoystickButton::_2, // <20><>
|
||||||
|
Triangle =JoystickButton::_3, // <20><><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
L1 =JoystickButton::_6, L2 =JoystickButton::_4,
|
||||||
|
R1 =JoystickButton::_7, R2 =JoystickButton::_5,
|
||||||
|
Select =JoystickButton::_8, Start =JoystickButton::_9,
|
||||||
|
};
|
||||||
|
|
||||||
|
//enum class XBoxButton
|
||||||
|
//{
|
||||||
|
// //DreamCast/XBOX
|
||||||
|
// X=JoystickButton::_2,
|
||||||
|
// Y=JoystickButton::_3,
|
||||||
|
// A=JoystickButton::_0,
|
||||||
|
// B=JoystickButton::_1,
|
||||||
|
// L=JoystickButton::_4,
|
||||||
|
// R=JoystickButton::_5,
|
||||||
|
|
||||||
|
// //XBOX/XBOX360
|
||||||
|
// //XBOX, //<2F><><EFBFBD>ϼ<EFBFBD>
|
||||||
|
//};
|
||||||
|
}//namespace io
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_IO_DEVICE_MOUSE_EVENT_INCLUDE
|
277
inc/hgl/io/event/KeyboardEvent.h
Normal file
277
inc/hgl/io/event/KeyboardEvent.h
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
#ifndef HGL_IO_KEYBOARD_EVENT_INCLUDE
|
||||||
|
#define HGL_IO_KEYBOARD_EVENT_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/io/event/InputEvent.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace io
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* <20><><EFBFBD><EFBFBD>ö<EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
|
||||||
|
*/
|
||||||
|
enum class KeyboardButton
|
||||||
|
{
|
||||||
|
NONE=0,
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Esc, ///<ESC
|
||||||
|
|
||||||
|
//F<><46><EFBFBD>ܼ<EFBFBD>
|
||||||
|
F1, ///<F1
|
||||||
|
F2, ///<F2
|
||||||
|
F3, ///<F3
|
||||||
|
F4, ///<F4
|
||||||
|
F5, ///<F5
|
||||||
|
F6, ///<F6
|
||||||
|
F7, ///<F7
|
||||||
|
F8, ///<F8
|
||||||
|
F9, ///<F9
|
||||||
|
F10, ///<F10
|
||||||
|
F11, ///<F11
|
||||||
|
F12, ///<F12
|
||||||
|
|
||||||
|
Grave, //<`<60><>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ּ<EFBFBD>1<EFBFBD><31><EFBFBD>ߵİ<DFB5>ť)
|
||||||
|
|
||||||
|
//10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
_0, ///<<3C><><EFBFBD>ּ<EFBFBD>0
|
||||||
|
_1, ///<<3C><><EFBFBD>ּ<EFBFBD>1
|
||||||
|
_2, ///<<3C><><EFBFBD>ּ<EFBFBD>2
|
||||||
|
_3, ///<<3C><><EFBFBD>ּ<EFBFBD>3
|
||||||
|
_4, ///<<3C><><EFBFBD>ּ<EFBFBD>4
|
||||||
|
_5, ///<<3C><><EFBFBD>ּ<EFBFBD>5
|
||||||
|
_6, ///<<3C><><EFBFBD>ּ<EFBFBD>6
|
||||||
|
_7, ///<<3C><><EFBFBD>ּ<EFBFBD>7
|
||||||
|
_8, ///<<3C><><EFBFBD>ּ<EFBFBD>8
|
||||||
|
_9, ///<<3C><><EFBFBD>ּ<EFBFBD>9
|
||||||
|
|
||||||
|
Minus, ///< - (<28><><EFBFBD><EFBFBD>)
|
||||||
|
Equals, ///< = (<28>Ⱥ<EFBFBD>)
|
||||||
|
BackSlash, ///< \ (<28><>б<EFBFBD><D0B1>)
|
||||||
|
BackSpace, ///< <20>˸<EFBFBD><CBB8><EFBFBD>
|
||||||
|
|
||||||
|
Tab, ///<Tab<61><62>
|
||||||
|
|
||||||
|
A, ///<A
|
||||||
|
B, ///<B
|
||||||
|
C, ///<C
|
||||||
|
D, ///<D
|
||||||
|
E, ///<E
|
||||||
|
F, ///<F
|
||||||
|
G, ///<G
|
||||||
|
H, ///<H
|
||||||
|
I, ///<I
|
||||||
|
J, ///<J
|
||||||
|
K, ///<K
|
||||||
|
L, ///<L
|
||||||
|
M, ///<M
|
||||||
|
N, ///<N
|
||||||
|
O, ///<O
|
||||||
|
P, ///<P
|
||||||
|
Q, ///<Q
|
||||||
|
R, ///<R
|
||||||
|
S, ///<S
|
||||||
|
T, ///<T
|
||||||
|
U, ///<U
|
||||||
|
V, ///<V
|
||||||
|
W, ///<W
|
||||||
|
X, ///<X
|
||||||
|
Y, ///<Y
|
||||||
|
Z, ///<Z
|
||||||
|
|
||||||
|
LeftBracket, ///<[
|
||||||
|
RightBracket, ///<]
|
||||||
|
|
||||||
|
CapsLock, ///<<3C><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
Semicolon, ///<; (<28>ֺ<EFBFBD>)
|
||||||
|
Apostrophe, ///<' (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||||
|
Enter, ///<<3C>س<EFBFBD><D8B3><EFBFBD>
|
||||||
|
|
||||||
|
LeftShift, ///<<3C><><EFBFBD>ߵ<EFBFBD>Shift<66><74>
|
||||||
|
|
||||||
|
Comma, ///<, (<28><><EFBFBD><EFBFBD>)
|
||||||
|
Period, ///<. (<28><><EFBFBD><EFBFBD>)
|
||||||
|
Slash, ///</ (<28><><EFBFBD><EFBFBD>)
|
||||||
|
RightShift, ///<<3C>ұߵ<D2B1>Shift<66><74>
|
||||||
|
|
||||||
|
LeftCtrl, ///<<3C><><EFBFBD>ߵ<EFBFBD>Ctrl<72><6C>
|
||||||
|
LeftOS, ///<<3C><><EFBFBD>ߵ<EFBFBD>OS<4F><53>(Win/Apple<6C><65>)
|
||||||
|
LeftAlt, ///<<3C><><EFBFBD>ߵ<EFBFBD>Alt<6C><74>
|
||||||
|
Space, ///<<3C>ո<EFBFBD><D5B8><EFBFBD>
|
||||||
|
RightAlt, ///<<3C>ұߵ<D2B1>Alt<6C><74>
|
||||||
|
RightOS, ///<<3C>ұߵ<D2B1>OS<4F><53>(Win/Apple<6C><65>)
|
||||||
|
RightMenu, ///<<3C>ұߵ<D2B1>Menu<6E><75>
|
||||||
|
RightCtrl, ///<<3C>ұߵ<D2B1>Ctrl<72><6C>
|
||||||
|
|
||||||
|
//<2F>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
PrintScreen, ///<<3C><>ӡ<EFBFBD><D3A1>Ļ<EFBFBD><C4BB>
|
||||||
|
ScrollLock, ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Pause, ///<<3C><>ͣ<EFBFBD><CDA3>
|
||||||
|
|
||||||
|
Insert, ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Delete, ///<ɾ<><C9BE><EFBFBD><EFBFBD>
|
||||||
|
Home, ///<<3C><><EFBFBD><EFBFBD>
|
||||||
|
End, ///<<3C><>β<EFBFBD><CEB2>
|
||||||
|
PageUp, ///<<3C><>ǰ<EFBFBD><C7B0>ҳ<EFBFBD><D2B3>
|
||||||
|
PageDown, ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||||
|
|
||||||
|
Up, ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Down, ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Left, ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Right, ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
//С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
NumLock, ///<С<><D0A1><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
NumAdd, ///<С<><D0A1><EFBFBD><EFBFBD> +
|
||||||
|
NumSubtract, ///<С<><D0A1><EFBFBD><EFBFBD> -
|
||||||
|
NumMultiply, ///<С<><D0A1><EFBFBD><EFBFBD> *
|
||||||
|
NumDivide, ///<С<><D0A1><EFBFBD><EFBFBD> /
|
||||||
|
|
||||||
|
Num0, ///<С<><D0A1><EFBFBD><EFBFBD> 0
|
||||||
|
Num1, ///<С<><D0A1><EFBFBD><EFBFBD> 1
|
||||||
|
Num2, ///<С<><D0A1><EFBFBD><EFBFBD> 2
|
||||||
|
Num3, ///<С<><D0A1><EFBFBD><EFBFBD> 3
|
||||||
|
Num4, ///<С<><D0A1><EFBFBD><EFBFBD> 4
|
||||||
|
Num5, ///<С<><D0A1><EFBFBD><EFBFBD> 5
|
||||||
|
Num6, ///<С<><D0A1><EFBFBD><EFBFBD> 6
|
||||||
|
Num7, ///<С<><D0A1><EFBFBD><EFBFBD> 7
|
||||||
|
Num8, ///<С<><D0A1><EFBFBD><EFBFBD> 8
|
||||||
|
Num9, ///<С<><D0A1><EFBFBD><EFBFBD> 9
|
||||||
|
|
||||||
|
NumDecimal, ///<С<><D0A1><EFBFBD><EFBFBD> . (С<><D0A1><EFBFBD><EFBFBD>/ɾ<><C9BE><EFBFBD><EFBFBD>)
|
||||||
|
NumEnter, ///<С<><D0A1><EFBFBD><EFBFBD> <20>س<EFBFBD><D8B3><EFBFBD>
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(NONE,NumEnter)
|
||||||
|
};//enum KeyboardButton
|
||||||
|
|
||||||
|
enum class KeyboardEventID
|
||||||
|
{
|
||||||
|
Pressed=0,
|
||||||
|
Released,
|
||||||
|
Char
|
||||||
|
};
|
||||||
|
|
||||||
|
union KeyboardEventData
|
||||||
|
{
|
||||||
|
uint64 data;
|
||||||
|
uint32 key;
|
||||||
|
os_char ch;
|
||||||
|
};
|
||||||
|
|
||||||
|
class KeyboardEvent:public InputEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
KeyboardEvent():InputEvent(InputEventSource::Keyboard){}
|
||||||
|
virtual ~KeyboardEvent()=default;
|
||||||
|
|
||||||
|
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
|
||||||
|
{
|
||||||
|
if(InputEvent::OnEvent(header,data)==EventProcResult::Break)
|
||||||
|
return EventProcResult::Break;
|
||||||
|
|
||||||
|
switch(KeyboardEventID(header.id))
|
||||||
|
{
|
||||||
|
case KeyboardEventID::Pressed: if(OnPressed (KeyboardButton(((KeyboardEventData *)&data)->key)))return EventProcResult::Break;break;
|
||||||
|
case KeyboardEventID::Released: if(OnReleased (KeyboardButton(((KeyboardEventData *)&data)->key)))return EventProcResult::Break;break;
|
||||||
|
case KeyboardEventID::Char: if(OnChar ( ((KeyboardEventData *)&data)->ch ) )return EventProcResult::Break;break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EventProcResult::Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnPressed(const KeyboardButton &kb){}
|
||||||
|
virtual bool OnReleased(const KeyboardButton &kb){}
|
||||||
|
virtual bool OnChar(const wchar_t &){}
|
||||||
|
};//class KeyboardEvent
|
||||||
|
|
||||||
|
class KeyboardStateEvent:public KeyboardEvent
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
double cur_time;
|
||||||
|
bool press_states[size_t(KeyboardButton::RANGE_SIZE)];
|
||||||
|
double pressed_time[size_t(KeyboardButton::RANGE_SIZE)];
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
KeyboardStateEvent():KeyboardEvent()
|
||||||
|
{
|
||||||
|
cur_time=0;
|
||||||
|
hgl_zero(press_states);
|
||||||
|
hgl_zero(pressed_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~KeyboardStateEvent()=default;
|
||||||
|
|
||||||
|
virtual bool OnPressed(const KeyboardButton &kb) override
|
||||||
|
{
|
||||||
|
if(!RangeCheck(kb))return(false);
|
||||||
|
|
||||||
|
press_states[(size_t)kb]=true;
|
||||||
|
pressed_time[(size_t)kb]=cur_time;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnReleased(const KeyboardButton &kb) override
|
||||||
|
{
|
||||||
|
if(!RangeCheck(kb))return(false);
|
||||||
|
|
||||||
|
press_states[(size_t)kb]=false;
|
||||||
|
pressed_time[(size_t)kb]=0;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ij<><C4B3><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||||
|
*/
|
||||||
|
const bool HasPressed(const KeyboardButton &kb)const
|
||||||
|
{
|
||||||
|
if(!RangeCheck(kb))return(false);
|
||||||
|
|
||||||
|
return press_states[size_t(kb)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20>趨<EFBFBD><E8B6A8>ǰʱ<C7B0><CAB1>
|
||||||
|
*/
|
||||||
|
void SetCurTime(const double &ct)
|
||||||
|
{
|
||||||
|
cur_time=ct;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ʱ<EFBFBD><CAB1>
|
||||||
|
*/
|
||||||
|
const double GetPressedTime(const KeyboardButton &kb)const
|
||||||
|
{
|
||||||
|
if(!RangeCheck(kb))return(0);
|
||||||
|
|
||||||
|
return pressed_time[size_t(kb)];
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool ShiftPressed()const
|
||||||
|
{
|
||||||
|
return press_states[size_t(KeyboardButton::LeftShift)]
|
||||||
|
||press_states[size_t(KeyboardButton::RightShift)];
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool CtrlPressed()const
|
||||||
|
{
|
||||||
|
return press_states[size_t(KeyboardButton::LeftCtrl)]
|
||||||
|
||press_states[size_t(KeyboardButton::RightCtrl)];
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool AltPressed()const
|
||||||
|
{
|
||||||
|
return press_states[size_t(KeyboardButton::LeftAlt)]
|
||||||
|
||press_states[size_t(KeyboardButton::RightAlt)];
|
||||||
|
}
|
||||||
|
};//class KeyboardStateEvent
|
||||||
|
}//namespace io
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_IO_KEYBOARD_EVENT_INCLUDE
|
99
inc/hgl/io/event/MouseEvent.h
Normal file
99
inc/hgl/io/event/MouseEvent.h
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#ifndef HGL_IO_MOUSE_EVENT_INCLUDE
|
||||||
|
#define HGL_IO_MOUSE_EVENT_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/io/event/InputEvent.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace io
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* <20><><EFBFBD>갴ťö<C5A5><C3B6>
|
||||||
|
*/
|
||||||
|
enum class MouseButton
|
||||||
|
{
|
||||||
|
None=0,
|
||||||
|
|
||||||
|
Left,
|
||||||
|
Mid,
|
||||||
|
Right,
|
||||||
|
|
||||||
|
X1,X2,
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(Left,X2)
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class MouseEventID
|
||||||
|
{
|
||||||
|
Move =0,
|
||||||
|
Pressed,
|
||||||
|
Released,
|
||||||
|
DblClicked,
|
||||||
|
Wheel
|
||||||
|
};
|
||||||
|
|
||||||
|
union MouseEventData
|
||||||
|
{
|
||||||
|
uint64 data;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int16 x,y;
|
||||||
|
uint8 button;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t MouseEventDataBytes=sizeof(MouseEventData);
|
||||||
|
|
||||||
|
class MouseEvent:public InputEvent
|
||||||
|
{
|
||||||
|
MouseEventData *med;
|
||||||
|
|
||||||
|
int x,y;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MouseEvent():InputEvent(InputEventSource::Mouse){}
|
||||||
|
virtual ~MouseEvent()=default;
|
||||||
|
|
||||||
|
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
|
||||||
|
{
|
||||||
|
if(InputEvent::OnEvent(header,data)==EventProcResult::Break)
|
||||||
|
return EventProcResult::Break;
|
||||||
|
|
||||||
|
med=(MouseEventData *)&data;
|
||||||
|
|
||||||
|
if(MouseEventID(header.id)==MouseEventID::Wheel)
|
||||||
|
{
|
||||||
|
if(OnWheel (med->x,med->y) )return EventProcResult::Break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x=med->x;y=med->y;
|
||||||
|
|
||||||
|
switch(MouseEventID(header.id))
|
||||||
|
{
|
||||||
|
case MouseEventID::Move: if(OnMove (med->x,med->y) )return EventProcResult::Break;break;
|
||||||
|
case MouseEventID::Pressed: if(OnPressed (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
||||||
|
case MouseEventID::Released: if(OnReleased (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
||||||
|
case MouseEventID::DblClicked: if(OnDblClicked (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EventProcResult::Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnMove (int,int){return false;}
|
||||||
|
virtual bool OnWheel (int,int){return false;}
|
||||||
|
|
||||||
|
virtual bool OnPressed (int,int,MouseButton){return false;}
|
||||||
|
virtual bool OnReleased (int,int,MouseButton){return false;}
|
||||||
|
virtual bool OnDblClicked(int,int,MouseButton){return false;}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const int GetX()const{return x;}
|
||||||
|
const int GetY()const{return y;}
|
||||||
|
};//class MouseEvent
|
||||||
|
}//namespace io
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_IO_MOUSE_EVENT_INCLUDE
|
64
inc/hgl/io/event/WindowEvent.h
Normal file
64
inc/hgl/io/event/WindowEvent.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#ifndef HGL_IO_WINDOW_EVENT_INCLUDE
|
||||||
|
#define HGL_IO_WINDOW_EVENT_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/io/event/InputEvent.h>
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace io
|
||||||
|
{
|
||||||
|
enum class WindowEventID
|
||||||
|
{
|
||||||
|
Active,
|
||||||
|
Resize,
|
||||||
|
Close
|
||||||
|
};//enum class WindowEventID
|
||||||
|
|
||||||
|
union WindowEventData
|
||||||
|
{
|
||||||
|
uint64 data;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int16 width,height;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool active;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t WindowEventDataBytes=sizeof(WindowEventData);
|
||||||
|
|
||||||
|
class WindowEvent:public InputEvent
|
||||||
|
{
|
||||||
|
WindowEventData *wed;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
WindowEvent():InputEvent(InputEventSource::Window){}
|
||||||
|
virtual ~WindowEvent()=default;
|
||||||
|
|
||||||
|
EventProcResult OnEvent(const EventHeader &header,const uint64 data) override
|
||||||
|
{
|
||||||
|
wed=(WindowEventData *)&data;
|
||||||
|
|
||||||
|
switch(WindowEventID(header.id))
|
||||||
|
{
|
||||||
|
case WindowEventID::Active:OnActive (wed->active) ;break;
|
||||||
|
case WindowEventID::Resize:OnResize (wed->width,wed->height);break;
|
||||||
|
case WindowEventID::Close: OnClose () ;break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(InputEvent::OnEvent(header,data)==EventProcResult::Break)
|
||||||
|
return EventProcResult::Break;
|
||||||
|
|
||||||
|
return EventProcResult::Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void OnResize(uint,uint){}
|
||||||
|
virtual void OnActive(bool){}
|
||||||
|
virtual void OnClose (){}
|
||||||
|
};//class WindowEvent:public InputEvent
|
||||||
|
}//namespace io
|
||||||
|
}//namespace hgl
|
||||||
|
#endif//HGL_IO_WINDOW_EVENT_INCLUDE
|
@@ -119,6 +119,13 @@ SET(IO_JAVA_FILES ${IO_INCLUDE_PATH}/JavaInputStream.h
|
|||||||
|
|
||||||
SET(IO_TEXT_FILES IO/TextOutputStream.cpp)
|
SET(IO_TEXT_FILES IO/TextOutputStream.cpp)
|
||||||
|
|
||||||
|
SET(INPUT_EVENT_FILES ${IO_INCLUDE_PATH}/event/KeyboardEvent.h
|
||||||
|
${IO_INCLUDE_PATH}/event/MouseEvent.h
|
||||||
|
${IO_INCLUDE_PATH}/event/JoystickEvent.h
|
||||||
|
${IO_INCLUDE_PATH}/event/InputEvent.h)
|
||||||
|
|
||||||
|
SOURCE_GROUP("IO\\Event" FILES ${INPUT_EVENT_FILES})
|
||||||
|
|
||||||
SOURCE_GROUP("IO\\Base" FILES ${IO_BASE_FILES})
|
SOURCE_GROUP("IO\\Base" FILES ${IO_BASE_FILES})
|
||||||
SOURCE_GROUP("IO\\Data" FILES ${IO_DATA_FILES})
|
SOURCE_GROUP("IO\\Data" FILES ${IO_DATA_FILES})
|
||||||
SOURCE_GROUP("IO\\Memory" FILES ${IO_MEMORY_FILES})
|
SOURCE_GROUP("IO\\Memory" FILES ${IO_MEMORY_FILES})
|
||||||
@@ -131,7 +138,8 @@ SET(IO_SOURCE_FILES ${IO_BASE_FILES}
|
|||||||
${IO_MEMORY_FILES}
|
${IO_MEMORY_FILES}
|
||||||
${IO_FILE_FILES}
|
${IO_FILE_FILES}
|
||||||
${IO_JAVA_FILES}
|
${IO_JAVA_FILES}
|
||||||
${IO_TEXT_FILES})
|
${IO_TEXT_FILES}
|
||||||
|
${INPUT_EVENT_FILES})
|
||||||
|
|
||||||
SET(FILESYSTEM_INCLUDE_PATH ${CMCORE_ROOT_INCLUDE_PATH}/hgl/filesystem)
|
SET(FILESYSTEM_INCLUDE_PATH ${CMCORE_ROOT_INCLUDE_PATH}/hgl/filesystem)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user