used newly InputEvent
This commit is contained in:
@@ -1,214 +0,0 @@
|
|||||||
#ifndef HGL_INPUT_DEVICE_INCLUDE
|
|
||||||
#define HGL_INPUT_DEVICE_INCLUDE
|
|
||||||
|
|
||||||
#include<hgl/TypeFunc.h>
|
|
||||||
namespace hgl
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 鼠标状态枚举定义
|
|
||||||
*/
|
|
||||||
enum MouseButton
|
|
||||||
{
|
|
||||||
mbMove =0x00000001, ///<鼠标移动了
|
|
||||||
|
|
||||||
mbLeft =0x00000002, ///<鼠标左键处于按下状态
|
|
||||||
mbMid =0x00000004, ///<鼠标中键处于按下状态
|
|
||||||
mbRight =0x00000008, ///<鼠标右键处于按下状态
|
|
||||||
|
|
||||||
mbX1 =0x00000010,
|
|
||||||
mbX2 =0x00000020,
|
|
||||||
|
|
||||||
mbShift =0x10000000, ///<Shift键处于按下状态
|
|
||||||
mbCtrl =0x20000000, ///<Ctrl键处于按下状态
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 按键枚举定义
|
|
||||||
*/
|
|
||||||
enum class KeyboardButton
|
|
||||||
{
|
|
||||||
NONE=0,
|
|
||||||
//主键盘区
|
|
||||||
Esc, ///<ESC
|
|
||||||
|
|
||||||
//F功能键
|
|
||||||
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, //<`号(主键盘数字键1左边的按钮)
|
|
||||||
|
|
||||||
//10个数字
|
|
||||||
_0, ///<数字键0
|
|
||||||
_1, ///<数字键1
|
|
||||||
_2, ///<数字键2
|
|
||||||
_3, ///<数字键3
|
|
||||||
_4, ///<数字键4
|
|
||||||
_5, ///<数字键5
|
|
||||||
_6, ///<数字键6
|
|
||||||
_7, ///<数字键7
|
|
||||||
_8, ///<数字键8
|
|
||||||
_9, ///<数字键9
|
|
||||||
|
|
||||||
Minus, ///< - (减号)
|
|
||||||
Equals, ///< = (等号)
|
|
||||||
BackSlash, ///< \ (反斜杠)
|
|
||||||
BackSpace, ///< 退格键
|
|
||||||
|
|
||||||
Tab, ///<Tab键
|
|
||||||
|
|
||||||
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, ///<大写锁定键
|
|
||||||
|
|
||||||
Semicolon, ///<; (分号)
|
|
||||||
Apostrophe, ///<' (单引号)
|
|
||||||
Enter, ///<回车键
|
|
||||||
|
|
||||||
LeftShift, ///<左边的Shift键
|
|
||||||
|
|
||||||
Comma, ///<, (逗号)
|
|
||||||
Period, ///<. (句号)
|
|
||||||
Slash, ///</ (除号)
|
|
||||||
RightShift, ///<右边的Shift键
|
|
||||||
|
|
||||||
LeftCtrl, ///<左边的Ctrl键
|
|
||||||
LeftOS, ///<左边的OS键(Win/Apple键)
|
|
||||||
LeftAlt, ///<左边的Alt键
|
|
||||||
Space, ///<空格键
|
|
||||||
RightAlt, ///<右边的Alt键
|
|
||||||
RightOS, ///<右边的OS键(Win/Apple键)
|
|
||||||
RightMenu, ///<右边的Menu键
|
|
||||||
RightCtrl, ///<右边的Ctrl键
|
|
||||||
|
|
||||||
//中键盘区
|
|
||||||
PrintScreen, ///<打印屏幕键
|
|
||||||
ScrollLock, ///<滚动锁定键
|
|
||||||
Pause, ///<暂停键
|
|
||||||
|
|
||||||
Insert, ///<插入键
|
|
||||||
Delete, ///<删除键
|
|
||||||
Home, ///<行首键
|
|
||||||
End, ///<行尾键
|
|
||||||
PageUp, ///<向前翻页键
|
|
||||||
PageDown, ///<向后翻页键
|
|
||||||
|
|
||||||
Up, ///<↑光标键
|
|
||||||
Down, ///<↓光标键
|
|
||||||
Left, ///<←光标键
|
|
||||||
Right, ///<→光标键
|
|
||||||
|
|
||||||
//小键盘区
|
|
||||||
NumLock, ///<小键盘 数字锁定键
|
|
||||||
|
|
||||||
NumAdd, ///<小键盘 +
|
|
||||||
NumSubtract, ///<小键盘 -
|
|
||||||
NumMultiply, ///<小键盘 *
|
|
||||||
NumDivide, ///<小键盘 /
|
|
||||||
|
|
||||||
Num0, ///<小键盘 0
|
|
||||||
Num1, ///<小键盘 1
|
|
||||||
Num2, ///<小键盘 2
|
|
||||||
Num3, ///<小键盘 3
|
|
||||||
Num4, ///<小键盘 4
|
|
||||||
Num5, ///<小键盘 5
|
|
||||||
Num6, ///<小键盘 6
|
|
||||||
Num7, ///<小键盘 7
|
|
||||||
Num8, ///<小键盘 8
|
|
||||||
Num9, ///<小键盘 9
|
|
||||||
|
|
||||||
NumDecimal, ///<小键盘 . (小数点/删除键)
|
|
||||||
NumEnter, ///<小键盘 回车键
|
|
||||||
|
|
||||||
ENUM_CLASS_RANGE(NONE,NumEnter)
|
|
||||||
};//enum KeyboardButton
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手柄按键枚举
|
|
||||||
*/
|
|
||||||
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, // 叉
|
|
||||||
Circle =JoystickButton::_1, // 圆
|
|
||||||
Square =JoystickButton::_2, // 方
|
|
||||||
Triangle =JoystickButton::_3, // 三角
|
|
||||||
|
|
||||||
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, //西瓜键
|
|
||||||
//};
|
|
||||||
}//namespace hgl
|
|
||||||
#endif//HGL_INPUT_DEVICE_INCLUDE
|
|
@@ -2,11 +2,11 @@
|
|||||||
#define HGL_GRAPH_WINDOW_INCLUDE
|
#define HGL_GRAPH_WINDOW_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/String.h>
|
#include<hgl/type/String.h>
|
||||||
#include<hgl/platform/InputDevice.h>
|
#include<hgl/io/event/WindowEvent.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
class Window
|
class Window:io::WindowEvent
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -19,78 +19,31 @@ namespace hgl
|
|||||||
bool is_close;
|
bool is_close;
|
||||||
bool is_min;
|
bool is_min;
|
||||||
|
|
||||||
bool key_push[size_t(KeyboardButton::RANGE_SIZE)];
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
io::InputEvent input_event;
|
||||||
|
io::InputEvent sub_input_event;
|
||||||
|
|
||||||
|
void OnResize(uint,uint) override;
|
||||||
|
void OnActive(bool) override;
|
||||||
|
void OnClose () override;
|
||||||
|
|
||||||
virtual bool MessageProc()=0;
|
virtual bool MessageProc()=0;
|
||||||
virtual bool WaitMessage()=0;
|
virtual bool WaitMessage()=0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void ProcMouseMove (int x,int y) {SafeCallEvent(OnMouseMove, (x,y));}
|
const uint GetWidth()const{return width;}
|
||||||
virtual void ProcMouseWheel (int v,int h,uint mb) {SafeCallEvent(OnMouseWheel, (v,h,mb));}
|
const uint GetHeight()const{return height;}
|
||||||
virtual void ProcMousePressed (int x,int y,uint mb) {SafeCallEvent(OnMousePressed, (x,y,mb));}
|
|
||||||
virtual void ProcMouseReleased (int x,int y,uint mb) {SafeCallEvent(OnMouseReleased, (x,y,mb));}
|
|
||||||
virtual void ProcMouseDblClicked(int x,int y,uint mb) {SafeCallEvent(OnMouseDblClicked, (x,y,mb));}
|
|
||||||
|
|
||||||
//virtual void ProcJoystickPressed (uint);
|
|
||||||
//virtual void ProcJoystickRepeat (uint);
|
|
||||||
//virtual void ProcJoystickReleased(uint);
|
|
||||||
|
|
||||||
virtual void ProcKeyPressed (KeyboardButton);
|
|
||||||
virtual void ProcKeyRepeat (KeyboardButton kb){SafeCallEvent(OnKeyRepeat,(kb));}
|
|
||||||
virtual void ProcKeyReleased(KeyboardButton);
|
|
||||||
|
|
||||||
virtual void ProcChar (os_char ch){SafeCallEvent(OnChar,(ch));}
|
|
||||||
|
|
||||||
virtual void ProcResize (uint,uint);
|
|
||||||
|
|
||||||
virtual void ProcActive (bool);
|
|
||||||
virtual void ProcClose ();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
uint GetWidth()const{return width;}
|
Window(const OSString &);
|
||||||
uint GetHeight()const{return height;}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DefEvent(void,OnMouseMove, (int,int));
|
|
||||||
DefEvent(void,OnMouseWheel, (int,int,uint));
|
|
||||||
DefEvent(void,OnMousePressed, (int,int,uint));
|
|
||||||
DefEvent(void,OnMouseReleased, (int,int,uint));
|
|
||||||
DefEvent(void,OnMouseDblClicked,(int,int,uint));
|
|
||||||
|
|
||||||
//DefEvent(void,OnJoystickDown ,(uint));
|
|
||||||
//DefEvent(void,OnJoystickPress ,(uint));
|
|
||||||
//DefEvent(void,OnJoystickUp ,(uint));
|
|
||||||
|
|
||||||
DefEvent(void,OnKeyPressed, (KeyboardButton));
|
|
||||||
DefEvent(void,OnKeyRepeat, (KeyboardButton));
|
|
||||||
DefEvent(void,OnKeyReleased,(KeyboardButton));
|
|
||||||
|
|
||||||
DefEvent(void,OnChar ,(os_char));
|
|
||||||
|
|
||||||
DefEvent(void,OnResize ,(uint,uint));
|
|
||||||
|
|
||||||
DefEvent(void,OnActive ,(bool));
|
|
||||||
DefEvent(void,OnClose ,());
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Window(const OSString &wn)
|
|
||||||
{
|
|
||||||
width=height=0;
|
|
||||||
full_screen=false;
|
|
||||||
win_name=wn;
|
|
||||||
active=false;
|
|
||||||
is_close=true;
|
|
||||||
is_min=false;
|
|
||||||
hgl_zero(key_push);
|
|
||||||
}
|
|
||||||
virtual ~Window()=default;
|
virtual ~Window()=default;
|
||||||
|
|
||||||
|
bool Join(InputEvent *ie){return sub_input_event.Join(ie);}
|
||||||
|
bool Unjoin(InputEvent *ie){return sub_input_event.Unjoin(ie);}
|
||||||
|
|
||||||
virtual bool Create(uint,uint)=0;
|
virtual bool Create(uint,uint)=0;
|
||||||
virtual bool Create(uint,uint,uint)=0;
|
virtual bool Create(uint,uint,uint)=0;
|
||||||
virtual void Close()=0;
|
virtual void Close()=0;
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
#include"WinWindow.h"
|
#include"WinWindow.h"
|
||||||
#include<hgl/platform/InputDevice.h>
|
#include<hgl/io/event/KeyboardEvent.h>
|
||||||
|
#include<hgl/io/event/MouseEvent.h>
|
||||||
|
#include<hgl/io/event/WindowEvent.h>
|
||||||
#include<Windows.h>
|
#include<Windows.h>
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@@ -8,29 +10,14 @@
|
|||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
|
using namespace io;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#define PROP_DPIISOLATION L"PROP_ISOLATION"
|
#define PROP_DPIISOLATION L"PROP_ISOLATION"
|
||||||
|
|
||||||
static KeyboardButton KeyConvert[256];
|
static KeyboardButton KeyConvert[256];
|
||||||
static void (*WMProc[2048])(WinWindow *,uint32,uint32); //消息处理队列
|
static void (*WMProc[2048])(InputEvent *,uint32,uint32); //消息处理队列
|
||||||
|
|
||||||
uint32 GetMouseKeyFlags(uint32 wflags)
|
|
||||||
{
|
|
||||||
uint32 flag=0;
|
|
||||||
|
|
||||||
if(wflags&MK_LBUTTON)flag|=mbLeft;
|
|
||||||
if(wflags&MK_RBUTTON)flag|=mbRight;
|
|
||||||
if(wflags&MK_MBUTTON)flag|=mbMid;
|
|
||||||
|
|
||||||
if(wflags&MK_XBUTTON1)flag|=mbX1;
|
|
||||||
if(wflags&MK_XBUTTON2)flag|=mbX2;
|
|
||||||
|
|
||||||
if(wflags&MK_SHIFT )flag|=mbShift;
|
|
||||||
if(wflags&MK_CONTROL)flag|=mbCtrl;
|
|
||||||
|
|
||||||
return(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitKeyConvert()
|
void InitKeyConvert()
|
||||||
{
|
{
|
||||||
@@ -191,79 +178,33 @@ namespace hgl
|
|||||||
|
|
||||||
return KeyConvert[key];
|
return KeyConvert[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EventHeader event_header;
|
||||||
|
static WindowEventData window_event_data;
|
||||||
|
|
||||||
void WMProcNCCreate(WinWindow *win,uint32 wParam,uint32 lParam)
|
void WMProcDestroy(InputEvent *ie,uint32,uint32)
|
||||||
{
|
{
|
||||||
auto createStruct = reinterpret_cast<const CREATESTRUCTW *>(lParam);
|
event_header.type =(uint8)InputEventSource::Window;
|
||||||
auto createParams = static_cast<const WindowCreateExteraParams *>(createStruct->lpCreateParams);
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)WindowEventID::Close;
|
||||||
|
|
||||||
if (createParams->bEnableNonClientDpiScaling)
|
ie->OnEvent(event_header,window_event_data.data);
|
||||||
{
|
|
||||||
EnableNonClientDpiScaling(win->GetWnd());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store a flag on the window to note that it'll run its child in a different awareness
|
|
||||||
if (createParams->bChildWindowDpiIsolation)
|
|
||||||
{
|
|
||||||
SetPropW(win->GetWnd(), PROP_DPIISOLATION, (HANDLE)TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WMProcCreate(WinWindow *win,uint32 wParam,uint32 lParam)
|
|
||||||
{
|
|
||||||
HWND hWnd=win->GetWnd();
|
|
||||||
RECT rcWindow = {};
|
|
||||||
UINT uDpi = 96;
|
|
||||||
DPI_AWARENESS dpiAwareness = GetAwarenessFromDpiAwarenessContext(GetThreadDpiAwarenessContext());
|
|
||||||
|
|
||||||
switch (dpiAwareness)
|
|
||||||
{
|
|
||||||
// Scale the window to the system DPI
|
|
||||||
case DPI_AWARENESS_SYSTEM_AWARE:
|
|
||||||
uDpi = GetDpiForSystem();
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Scale the window to the monitor DPI
|
|
||||||
case DPI_AWARENESS_PER_MONITOR_AWARE:
|
|
||||||
uDpi = GetDpiForWindow(hWnd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetWindowRect(hWnd, &rcWindow);
|
|
||||||
rcWindow.right = rcWindow.left + MulDiv(win->GetWidth(), uDpi, 96);
|
|
||||||
rcWindow.bottom = rcWindow.top + MulDiv(win->GetHeight(), uDpi, 96);
|
|
||||||
SetWindowPos(hWnd, nullptr, rcWindow.right, rcWindow.top, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
||||||
|
|
||||||
BOOL bDpiIsolation = PtrToInt(GetPropW(hWnd, PROP_DPIISOLATION));
|
|
||||||
|
|
||||||
DPI_AWARENESS_CONTEXT previousDpiContext = {};
|
|
||||||
DPI_HOSTING_BEHAVIOR previousDpiHostingBehavior = {};
|
|
||||||
|
|
||||||
if (bDpiIsolation)
|
|
||||||
{
|
|
||||||
previousDpiHostingBehavior = SetThreadDpiHostingBehavior(DPI_HOSTING_BEHAVIOR_MIXED);
|
|
||||||
|
|
||||||
// For this example, we'll have the external content run with System-DPI awareness
|
|
||||||
previousDpiContext = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);
|
|
||||||
|
|
||||||
SetThreadDpiAwarenessContext(previousDpiContext);
|
|
||||||
SetThreadDpiHostingBehavior(previousDpiHostingBehavior);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WMProcDestroy(WinWindow *win,uint32,uint32)
|
|
||||||
{
|
|
||||||
win->ProcClose();
|
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WMEF_MOUSE(button,action) void WMProcMouse##button##action(WinWindow *win,uint32 wParam,uint32 lParam) \
|
static MouseEventData mouse_event_data;
|
||||||
|
|
||||||
|
#define WMEF_MOUSE(mouse_button,action) void WMProcMouse##mouse_button##action(InputEvent *ie,uint32 wParam,uint32 lParam) \
|
||||||
{ \
|
{ \
|
||||||
const int x=LOWORD(lParam); \
|
mouse_event_data.x=LOWORD(lParam); \
|
||||||
const int y=HIWORD(lParam); \
|
mouse_event_data.y=HIWORD(lParam); \
|
||||||
|
mouse_event_data.button=(uint8)MouseButton::mouse_button; \
|
||||||
\
|
\
|
||||||
win->ProcMouseMove(x,y); \
|
event_header.type =(uint8)InputEventSource::Mouse; \
|
||||||
win->ProcMouse##action(x,y,mb##button|GetMouseKeyFlags(wParam)); \
|
event_header.index =0; \
|
||||||
|
event_header.id =(uint16)MouseEventID::action; \
|
||||||
|
\
|
||||||
|
ie->OnEvent(event_header,mouse_event_data.data); \
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEF_MOUSE(Left,Pressed);
|
WMEF_MOUSE(Left,Pressed);
|
||||||
@@ -278,49 +219,100 @@ namespace hgl
|
|||||||
WMEF_MOUSE(Right,Released);
|
WMEF_MOUSE(Right,Released);
|
||||||
WMEF_MOUSE(Right,DblClicked);
|
WMEF_MOUSE(Right,DblClicked);
|
||||||
|
|
||||||
void WMProcMouseMove(WinWindow *win,uint32 wParam,uint32 lParam)
|
void WMProcMouseMove(InputEvent *ie,uint32 wParam,uint32 lParam)
|
||||||
{
|
{
|
||||||
win->ProcMouseMove(LOWORD(lParam),HIWORD(lParam));
|
mouse_event_data.x=LOWORD(lParam);
|
||||||
|
mouse_event_data.y=HIWORD(lParam);
|
||||||
|
mouse_event_data.button=0;
|
||||||
|
|
||||||
|
event_header.type =(uint8)InputEventSource::Mouse;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)MouseEventID::Move;
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,mouse_event_data.data);
|
||||||
}
|
}
|
||||||
#undef WMEF_MOUSE
|
#undef WMEF_MOUSE
|
||||||
|
|
||||||
#define WMEF2(name) void name(WinWindow *win,uint32 wParam,uint32 lParam)
|
#define WMEF2(name) void name(InputEvent *ie,uint32 wParam,uint32 lParam)
|
||||||
WMEF2(WMProcMouseWheel)
|
WMEF2(WMProcMouseWheel)
|
||||||
{
|
{
|
||||||
const int zDelta=GET_WHEEL_DELTA_WPARAM(wParam);
|
const int zDelta=GET_WHEEL_DELTA_WPARAM(wParam);
|
||||||
const uint key=(uint)ConvertOSKey(GET_KEYSTATE_WPARAM(wParam));
|
//const uint key=(uint)ConvertOSKey(GET_KEYSTATE_WPARAM(wParam));
|
||||||
|
|
||||||
win->ProcMouseWheel(zDelta,0,key);
|
mouse_event_data.x=0;
|
||||||
|
mouse_event_data.y=zDelta;
|
||||||
|
mouse_event_data.button=0;
|
||||||
|
|
||||||
|
event_header.type =(uint8)InputEventSource::Mouse;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)MouseEventID::Wheel;
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,mouse_event_data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEF2(WMProcMouseHWheel)
|
WMEF2(WMProcMouseHWheel)
|
||||||
{
|
{
|
||||||
const int zDelta=GET_WHEEL_DELTA_WPARAM(wParam);
|
const int zDelta=GET_WHEEL_DELTA_WPARAM(wParam);
|
||||||
const uint key=(uint)ConvertOSKey(GET_KEYSTATE_WPARAM(wParam));
|
//const uint key=(uint)ConvertOSKey(GET_KEYSTATE_WPARAM(wParam));
|
||||||
|
|
||||||
win->ProcMouseWheel(0,zDelta,key);
|
mouse_event_data.x=zDelta;
|
||||||
|
mouse_event_data.y=0;
|
||||||
|
mouse_event_data.button=0;
|
||||||
|
|
||||||
|
event_header.type =(uint8)InputEventSource::Mouse;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)MouseEventID::Wheel;
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,mouse_event_data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEF2(WMProcSize)
|
WMEF2(WMProcSize)
|
||||||
{
|
{
|
||||||
win->ProcResize(LOWORD(lParam),HIWORD(lParam));
|
event_header.type =(uint8)InputEventSource::Window;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)WindowEventID::Resize;
|
||||||
|
|
||||||
|
window_event_data.width =LOWORD(lParam);
|
||||||
|
window_event_data.height=HIWORD(lParam);
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,window_event_data.data);
|
||||||
}
|
}
|
||||||
#undef WMEF2
|
#undef WMEF2
|
||||||
|
|
||||||
#define WMEF1(name) void name(WinWindow *win,uint32 wParam,uint32)
|
static KeyboardEventData keyboard_event_data;
|
||||||
|
|
||||||
|
#define WMEF1(name) void name(InputEvent *ie,uint32 wParam,uint32)
|
||||||
WMEF1(WMProcKeyDown)
|
WMEF1(WMProcKeyDown)
|
||||||
{
|
{
|
||||||
win->ProcKeyPressed(ConvertOSKey(wParam));
|
event_header.type =(uint8)InputEventSource::Keyboard;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)KeyboardEventID::Pressed;
|
||||||
|
|
||||||
|
keyboard_event_data.key=(uint32)ConvertOSKey(wParam);
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,keyboard_event_data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEF1(WMProcKeyUp)
|
WMEF1(WMProcKeyUp)
|
||||||
{
|
{
|
||||||
win->ProcKeyReleased(ConvertOSKey(wParam));
|
event_header.type =(uint8)InputEventSource::Keyboard;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)KeyboardEventID::Released;
|
||||||
|
|
||||||
|
keyboard_event_data.key=(uint32)ConvertOSKey(wParam);
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,keyboard_event_data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEF1(WMProcChar)
|
WMEF1(WMProcChar)
|
||||||
{
|
{
|
||||||
win->ProcChar((wchar_t)wParam);
|
event_header.type =(uint8)InputEventSource::Keyboard;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)KeyboardEventID::Char;
|
||||||
|
|
||||||
|
keyboard_event_data.ch=(wchar_t)wParam;
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,keyboard_event_data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEF1(WMProcActive)
|
WMEF1(WMProcActive)
|
||||||
@@ -328,7 +320,13 @@ namespace hgl
|
|||||||
//if(JoyPlugIn)
|
//if(JoyPlugIn)
|
||||||
// JoyInterface.SetInputActive(wParam);
|
// JoyInterface.SetInputActive(wParam);
|
||||||
|
|
||||||
win->ProcActive(wParam);
|
event_header.type =(uint8)InputEventSource::Window;
|
||||||
|
event_header.index =0;
|
||||||
|
event_header.id =(uint16)WindowEventID::Active;
|
||||||
|
|
||||||
|
window_event_data.active=wParam;
|
||||||
|
|
||||||
|
ie->OnEvent(event_header,window_event_data.data);
|
||||||
}
|
}
|
||||||
#undef WMEF1
|
#undef WMEF1
|
||||||
}//namespace
|
}//namespace
|
||||||
@@ -343,8 +341,6 @@ namespace hgl
|
|||||||
|
|
||||||
#define WM_MAP(wm,func) WMProc[wm]=func;
|
#define WM_MAP(wm,func) WMProc[wm]=func;
|
||||||
|
|
||||||
WM_MAP(WM_NCCREATE ,WMProcNCCreate);
|
|
||||||
WM_MAP(WM_CREATE ,WMProcCreate);
|
|
||||||
WM_MAP(WM_CLOSE ,WMProcDestroy);
|
WM_MAP(WM_CLOSE ,WMProcDestroy);
|
||||||
WM_MAP(WM_LBUTTONDOWN ,WMProcMouseLeftPressed);
|
WM_MAP(WM_LBUTTONDOWN ,WMProcMouseLeftPressed);
|
||||||
WM_MAP(WM_LBUTTONUP ,WMProcMouseLeftReleased);
|
WM_MAP(WM_LBUTTONUP ,WMProcMouseLeftReleased);
|
||||||
@@ -375,10 +371,10 @@ namespace hgl
|
|||||||
if(uMsg<2048)
|
if(uMsg<2048)
|
||||||
if(WMProc[uMsg])
|
if(WMProc[uMsg])
|
||||||
{
|
{
|
||||||
WinWindow *win=(WinWindow *)GetWindowLongPtrW(hWnd,GWLP_USERDATA);
|
InputEvent *ie=(InputEvent *)GetWindowLongPtrW(hWnd,GWLP_USERDATA);
|
||||||
|
|
||||||
if(win)
|
if(ie)
|
||||||
WMProc[uMsg](win,wParam,lParam);
|
WMProc[uMsg](ie,wParam,lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (DefWindowProcW(hWnd, uMsg, wParam, lParam));
|
return (DefWindowProcW(hWnd, uMsg, wParam, lParam));
|
||||||
|
@@ -98,7 +98,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
win_dc = GetDC(win_hwnd);
|
win_dc = GetDC(win_hwnd);
|
||||||
SetWindowLongPtrW(win_hwnd, GWLP_USERDATA, (LONG_PTR)this);
|
SetWindowLongPtrW(win_hwnd, GWLP_USERDATA, (LONG_PTR)&input_event);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,8 +205,8 @@ namespace hgl
|
|||||||
TranslateMessage(&win_msg);
|
TranslateMessage(&win_msg);
|
||||||
DispatchMessage(&win_msg);
|
DispatchMessage(&win_msg);
|
||||||
|
|
||||||
if(win_msg.message==WM_QUIT)
|
// if(win_msg.message==WM_QUIT)
|
||||||
ProcClose();
|
// OnClose();
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@@ -2,24 +2,20 @@
|
|||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
void Window::ProcKeyPressed(KeyboardButton kb)
|
Window::Window(const OSString &wn)
|
||||||
{
|
{
|
||||||
if(key_push[size_t(kb)])
|
width=height=0;
|
||||||
ProcKeyRepeat(kb);
|
full_screen=false;
|
||||||
else
|
win_name=wn;
|
||||||
key_push[size_t(kb)]=true;
|
active=false;
|
||||||
|
is_close=true;
|
||||||
|
is_min=false;
|
||||||
|
|
||||||
SafeCallEvent(OnKeyPressed,(kb));
|
input_event.Join(this);
|
||||||
|
input_event.Join(&sub_input_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::ProcKeyReleased(KeyboardButton kb)
|
void Window::OnResize(uint w,uint h)
|
||||||
{
|
|
||||||
key_push[size_t(kb)]=false;
|
|
||||||
|
|
||||||
SafeCallEvent(OnKeyReleased,(kb));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::ProcResize(uint w,uint h)
|
|
||||||
{
|
{
|
||||||
if(w==width&&height==h)
|
if(w==width&&height==h)
|
||||||
return;
|
return;
|
||||||
@@ -35,20 +31,17 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
is_min=false;
|
is_min=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeCallEvent(OnResize,(w,h));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::ProcActive(bool a)
|
void Window::OnActive(bool a)
|
||||||
{
|
{
|
||||||
active=a;
|
active=a;
|
||||||
SafeCallEvent(OnActive,(a));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::ProcClose()
|
void Window::OnClose()
|
||||||
{
|
{
|
||||||
is_close=true;
|
input_event.Unjoin(this);
|
||||||
SafeCallEvent(OnClose,());
|
is_close=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::Update()
|
bool Window::Update()
|
||||||
|
Reference in New Issue
Block a user