diff --git a/framework/platform/game-dx.cpp b/framework/platform/game-dx.cpp index b0a49d0..f360be2 100644 --- a/framework/platform/game-dx.cpp +++ b/framework/platform/game-dx.cpp @@ -5,7 +5,6 @@ #include "platform-dx/game-dx.hpp" #include "input/gamepad.hpp" #include "platform-dx/gdevicemanager-dx.hpp" -#include "platform-dx/keyboard-dx.hpp" #include "platform-dx/mouse-dx.hpp" #include "platform-dx/implementations.hpp" #include "platform-dx/window-dx.hpp" diff --git a/framework/platform/keyboard-dx.cpp b/framework/platform/keyboard-dx.cpp index a594347..224a0eb 100644 --- a/framework/platform/keyboard-dx.cpp +++ b/framework/platform/keyboard-dx.cpp @@ -1,5 +1,20 @@ -#include "platform-dx/keyboard-dx.hpp" +#include "input/keyboard.hpp" +#include "platform-dx/implementations.hpp" namespace xna { + KeyboardState Keyboard::GetState() { + if (!impl->_dxKeyboard) + return KeyboardState(); + const auto state = Keyboard::impl->_dxKeyboard->GetState(); + auto ptr = reinterpret_cast(&state); + const auto xnaState = reinterpret_cast(ptr); + + return *xnaState; + } + + void Keyboard::Initialize() { + impl = uNew(); + impl->_dxKeyboard = uNew(); + } } \ No newline at end of file diff --git a/framework/platform/window-dx.cpp b/framework/platform/window-dx.cpp index 4c2aea3..2a6d283 100644 --- a/framework/platform/window-dx.cpp +++ b/framework/platform/window-dx.cpp @@ -1,5 +1,4 @@ #include "platform-dx/window-dx.hpp" -#include "platform-dx/keyboard-dx.hpp" #include "platform-dx/mouse-dx.hpp" #include "input/gamepad.hpp" #include "platform-dx/implementations.hpp" @@ -142,18 +141,18 @@ namespace xna { return 0; case WM_ACTIVATE: case WM_ACTIVATEAPP: - Keyboard::_dxKeyboard->ProcessMessage(msg, wParam, lParam); + Keyboard::impl->ProcessMessage(msg, wParam, lParam); Mouse::_dxMouse->ProcessMessage(msg, wParam, lParam); break; case WM_SYSKEYDOWN: - if (!(wParam == VK_RETURN && (lParam & 0x60000000) == 0x20000000)) { - Keyboard::_dxKeyboard->ProcessMessage(msg, wParam, lParam); + if (!(wParam == VK_RETURN && (lParam & 0x60000000) == 0x20000000)) { + Keyboard::impl->ProcessMessage(msg, wParam, lParam); } break; case WM_KEYDOWN: case WM_KEYUP: case WM_SYSKEYUP: - Keyboard::_dxKeyboard->ProcessMessage(msg, wParam, lParam); + Keyboard::impl->ProcessMessage(msg, wParam, lParam); break; case WM_INPUT: @@ -171,12 +170,10 @@ namespace xna { Mouse::_dxMouse->ProcessMessage(msg, wParam, lParam); break; case WM_KILLFOCUS: - if(GamePad::impl->_dxGamePad) - GamePad::impl->_dxGamePad->Suspend(); + GamePad::impl->Suspend(); break; case WM_SETFOCUS: - if (GamePad::impl->_dxGamePad) - GamePad::impl->_dxGamePad->Resume(); + GamePad::impl->Resume(); break; } return DefWindowProc(hWnd, msg, wParam, lParam); diff --git a/inc/enums.hpp b/inc/enums.hpp index d86d559..d7e92f0 100644 --- a/inc/enums.hpp +++ b/inc/enums.hpp @@ -237,167 +237,185 @@ namespace xna { HiDef }; - enum class Keys { + enum class Keys : unsigned char{ None = 0, - Back = 8, - Tab = 9, - Enter = 13, // 0x0000000D - Pause = 19, // 0x00000013 - CapsLock = 20, // 0x00000014 - Kana = 21, // 0x00000015 - Kanji = 25, // 0x00000019 - Escape = 27, // 0x0000001B - ImeConvert = 28, // 0x0000001C - ImeNoConvert = 29, // 0x0000001D - Space = 32, // 0x00000020 - PageUp = 33, // 0x00000021 - PageDown = 34, // 0x00000022 - End = 35, // 0x00000023 - Home = 36, // 0x00000024 - Left = 37, // 0x00000025 - Up = 38, // 0x00000026 - Right = 39, // 0x00000027 - Down = 40, // 0x00000028 - Select = 41, // 0x00000029 - Print = 42, // 0x0000002A - Execute = 43, // 0x0000002B - PrintScreen = 44, // 0x0000002C - Insert = 45, // 0x0000002D - Delete = 46, // 0x0000002E - Help = 47, // 0x0000002F - D0 = 48, // 0x00000030 - D1 = 49, // 0x00000031 - D2 = 50, // 0x00000032 - D3 = 51, // 0x00000033 - D4 = 52, // 0x00000034 - D5 = 53, // 0x00000035 - D6 = 54, // 0x00000036 - D7 = 55, // 0x00000037 - D8 = 56, // 0x00000038 - D9 = 57, // 0x00000039 - A = 65, // 0x00000041 - B = 66, // 0x00000042 - C = 67, // 0x00000043 - D = 68, // 0x00000044 - E = 69, // 0x00000045 - F = 70, // 0x00000046 - G = 71, // 0x00000047 - H = 72, // 0x00000048 - I = 73, // 0x00000049 - J = 74, // 0x0000004A - K = 75, // 0x0000004B - L = 76, // 0x0000004C - M = 77, // 0x0000004D - N = 78, // 0x0000004E - O = 79, // 0x0000004F - P = 80, // 0x00000050 - Q = 81, // 0x00000051 - R = 82, // 0x00000052 - S = 83, // 0x00000053 - T = 84, // 0x00000054 - U = 85, // 0x00000055 - V = 86, // 0x00000056 - W = 87, // 0x00000057 - X = 88, // 0x00000058 - Y = 89, // 0x00000059 - Z = 90, // 0x0000005A - LeftWindows = 91, // 0x0000005B - RightWindows = 92, // 0x0000005C - Apps = 93, // 0x0000005D - Sleep = 95, // 0x0000005F - NumPad0 = 96, // 0x00000060 - NumPad1 = 97, // 0x00000061 - NumPad2 = 98, // 0x00000062 - NumPad3 = 99, // 0x00000063 - NumPad4 = 100, // 0x00000064 - NumPad5 = 101, // 0x00000065 - NumPad6 = 102, // 0x00000066 - NumPad7 = 103, // 0x00000067 - NumPad8 = 104, // 0x00000068 - NumPad9 = 105, // 0x00000069 - Multiply = 106, // 0x0000006A - Add = 107, // 0x0000006B - Separator = 108, // 0x0000006C - Subtract = 109, // 0x0000006D - Decimal = 110, // 0x0000006E - Divide = 111, // 0x0000006F - F1 = 112, // 0x00000070 - F2 = 113, // 0x00000071 - F3 = 114, // 0x00000072 - F4 = 115, // 0x00000073 - F5 = 116, // 0x00000074 - F6 = 117, // 0x00000075 - F7 = 118, // 0x00000076 - F8 = 119, // 0x00000077 - F9 = 120, // 0x00000078 - F10 = 121, // 0x00000079 - F11 = 122, // 0x0000007A - F12 = 123, // 0x0000007B - F13 = 124, // 0x0000007C - F14 = 125, // 0x0000007D - F15 = 126, // 0x0000007E - F16 = 127, // 0x0000007F - F17 = 128, // 0x00000080 - F18 = 129, // 0x00000081 - F19 = 130, // 0x00000082 - F20 = 131, // 0x00000083 - F21 = 132, // 0x00000084 - F22 = 133, // 0x00000085 - F23 = 134, // 0x00000086 - F24 = 135, // 0x00000087 - NumLock = 144, // 0x00000090 - Scroll = 145, // 0x00000091 - LeftShift = 160, // 0x000000A0 - RightShift = 161, // 0x000000A1 - LeftControl = 162, // 0x000000A2 - RightControl = 163, // 0x000000A3 - LeftAlt = 164, // 0x000000A4 - RightAlt = 165, // 0x000000A5 - BrowserBack = 166, // 0x000000A6 - BrowserForward = 167, // 0x000000A7 - BrowserRefresh = 168, // 0x000000A8 - BrowserStop = 169, // 0x000000A9 - BrowserSearch = 170, // 0x000000AA - BrowserFavorites = 171, // 0x000000AB - BrowserHome = 172, // 0x000000AC - VolumeMute = 173, // 0x000000AD - VolumeDown = 174, // 0x000000AE - VolumeUp = 175, // 0x000000AF - MediaNextTrack = 176, // 0x000000B0 - MediaPreviousTrack = 177, // 0x000000B1 - MediaStop = 178, // 0x000000B2 - MediaPlayPause = 179, // 0x000000B3 - LaunchMail = 180, // 0x000000B4 - SelectMedia = 181, // 0x000000B5 - LaunchApplication1 = 182, // 0x000000B6 - LaunchApplication2 = 183, // 0x000000B7 - OemSemicolon = 186, // 0x000000BA - OemPlus = 187, // 0x000000BB - OemComma = 188, // 0x000000BC - OemMinus = 189, // 0x000000BD - OemPeriod = 190, // 0x000000BE - OemQuestion = 191, // 0x000000BF - OemTilde = 192, // 0x000000C0 - ChatPadGreen = 202, // 0x000000CA - ChatPadOrange = 203, // 0x000000CB - OemOpenBrackets = 219, // 0x000000DB - OemPipe = 220, // 0x000000DC - OemCloseBrackets = 221, // 0x000000DD - OemQuotes = 222, // 0x000000DE - Oem8 = 223, // 0x000000DF - OemBackslash = 226, // 0x000000E2 - ProcessKey = 229, // 0x000000E5 - OemCopy = 242, // 0x000000F2 - OemAuto = 243, // 0x000000F3 - OemEnlW = 244, // 0x000000F4 - Attn = 246, // 0x000000F6 - Crsel = 247, // 0x000000F7 - Exsel = 248, // 0x000000F8 - EraseEof = 249, // 0x000000F9 - Play = 250, // 0x000000FA - Zoom = 251, // 0x000000FB - Pa1 = 253, // 0x000000FD - OemClear = 254, // 0x000000FE + + Back = 0x8, + Tab = 0x9, + + Enter = 0xd, + + Pause = 0x13, + CapsLock = 0x14, + Kana = 0x15, + ImeOn = 0x16, + + Kanji = 0x19, + + ImeOff = 0x1a, + Escape = 0x1b, + ImeConvert = 0x1c, + ImeNoConvert = 0x1d, + + Space = 0x20, + PageUp = 0x21, + PageDown = 0x22, + End = 0x23, + Home = 0x24, + Left = 0x25, + Up = 0x26, + Right = 0x27, + Down = 0x28, + Select = 0x29, + Print = 0x2a, + Execute = 0x2b, + PrintScreen = 0x2c, + Insert = 0x2d, + Delete = 0x2e, + Help = 0x2f, + D0 = 0x30, + D1 = 0x31, + D2 = 0x32, + D3 = 0x33, + D4 = 0x34, + D5 = 0x35, + D6 = 0x36, + D7 = 0x37, + D8 = 0x38, + D9 = 0x39, + + A = 0x41, + B = 0x42, + C = 0x43, + D = 0x44, + E = 0x45, + F = 0x46, + G = 0x47, + H = 0x48, + I = 0x49, + J = 0x4a, + K = 0x4b, + L = 0x4c, + M = 0x4d, + N = 0x4e, + O = 0x4f, + P = 0x50, + Q = 0x51, + R = 0x52, + S = 0x53, + T = 0x54, + U = 0x55, + V = 0x56, + W = 0x57, + X = 0x58, + Y = 0x59, + Z = 0x5a, + LeftWindows = 0x5b, + RightWindows = 0x5c, + Apps = 0x5d, + + Sleep = 0x5f, + NumPad0 = 0x60, + NumPad1 = 0x61, + NumPad2 = 0x62, + NumPad3 = 0x63, + NumPad4 = 0x64, + NumPad5 = 0x65, + NumPad6 = 0x66, + NumPad7 = 0x67, + NumPad8 = 0x68, + NumPad9 = 0x69, + Multiply = 0x6a, + Add = 0x6b, + Separator = 0x6c, + Subtract = 0x6d, + + Decimal = 0x6e, + Divide = 0x6f, + F1 = 0x70, + F2 = 0x71, + F3 = 0x72, + F4 = 0x73, + F5 = 0x74, + F6 = 0x75, + F7 = 0x76, + F8 = 0x77, + F9 = 0x78, + F10 = 0x79, + F11 = 0x7a, + F12 = 0x7b, + F13 = 0x7c, + F14 = 0x7d, + F15 = 0x7e, + F16 = 0x7f, + F17 = 0x80, + F18 = 0x81, + F19 = 0x82, + F20 = 0x83, + F21 = 0x84, + F22 = 0x85, + F23 = 0x86, + F24 = 0x87, + + NumLock = 0x90, + Scroll = 0x91, + + LeftShift = 0xa0, + RightShift = 0xa1, + LeftControl = 0xa2, + RightControl = 0xa3, + LeftAlt = 0xa4, + RightAlt = 0xa5, + BrowserBack = 0xa6, + BrowserForward = 0xa7, + BrowserRefresh = 0xa8, + BrowserStop = 0xa9, + BrowserSearch = 0xaa, + BrowserFavorites = 0xab, + BrowserHome = 0xac, + VolumeMute = 0xad, + VolumeDown = 0xae, + VolumeUp = 0xaf, + MediaNextTrack = 0xb0, + MediaPreviousTrack = 0xb1, + MediaStop = 0xb2, + MediaPlayPause = 0xb3, + LaunchMail = 0xb4, + SelectMedia = 0xb5, + LaunchApplication1 = 0xb6, + LaunchApplication2 = 0xb7, + + OemSemicolon = 0xba, + OemPlus = 0xbb, + OemComma = 0xbc, + OemMinus = 0xbd, + OemPeriod = 0xbe, + OemQuestion = 0xbf, + OemTilde = 0xc0, + + OemOpenBrackets = 0xdb, + OemPipe = 0xdc, + OemCloseBrackets = 0xdd, + OemQuotes = 0xde, + Oem8 = 0xdf, + + OemBackslash = 0xe2, + + ProcessKey = 0xe5, + + OemCopy = 0xf2, + OemAuto = 0xf3, + OemEnlW = 0xf4, + + Attn = 0xf6, + Crsel = 0xf7, + Exsel = 0xf8, + EraseEof = 0xf9, + Play = 0xfa, + Zoom = 0xfb, + + Pa1 = 0xfd, + OemClear = 0xfe, }; enum class KeyState { diff --git a/inc/input/keyboard.hpp b/inc/input/keyboard.hpp index 30dc205..84efaa3 100644 --- a/inc/input/keyboard.hpp +++ b/inc/input/keyboard.hpp @@ -4,17 +4,221 @@ #include "../default.hpp" namespace xna { - struct IKeyboardState { + struct KeyboardState { public: - virtual bool IsKeyDown(Keys key) const = 0; - virtual bool IsKeyUp(Keys key) const = 0; + bool IsKeyDown(Keys key) const { + const auto k = static_cast(key); + + if (k <= 0xfe) + { + auto ptr = reinterpret_cast(this); + const unsigned int bf = 1u << (k & 0x1f); + return (ptr[(k >> 5)] & bf) != 0; + } + return false; + } + + bool IsKeyUp(Keys key) const { + return !IsKeyDown(key); + } + + private: + bool Reserved0 : 8; + bool Back : 1; // VK_BACK, 0x8 + bool Tab : 1; // VK_TAB, 0x9 + bool Reserved1 : 3; + bool Enter : 1; // VK_RETURN, 0xD + bool Reserved2 : 2; + bool Reserved3 : 3; + bool Pause : 1; // VK_PAUSE, 0x13 + bool CapsLock : 1; // VK_CAPITAL, 0x14 + bool Kana : 1; // VK_KANA, 0x15 + bool ImeOn : 1; // VK_IME_ON, 0x16 + bool Reserved4 : 1; + bool Reserved5 : 1; + bool Kanji : 1; // VK_KANJI, 0x19 + bool ImeOff : 1; // VK_IME_OFF, 0X1A + bool Escape : 1; // VK_ESCAPE, 0x1B + bool ImeConvert : 1; // VK_CONVERT, 0x1C + bool ImeNoConvert : 1; // VK_NONCONVERT, 0x1D + bool Reserved7 : 2; + bool Space : 1; // VK_SPACE, 0x20 + bool PageUp : 1; // VK_PRIOR, 0x21 + bool PageDown : 1; // VK_NEXT, 0x22 + bool End : 1; // VK_END, 0x23 + bool Home : 1; // VK_HOME, 0x24 + bool Left : 1; // VK_LEFT, 0x25 + bool Up : 1; // VK_UP, 0x26 + bool Right : 1; // VK_RIGHT, 0x27 + bool Down : 1; // VK_DOWN, 0x28 + bool Select : 1; // VK_SELECT, 0x29 + bool Print : 1; // VK_PRINT, 0x2A + bool Execute : 1; // VK_EXECUTE, 0x2B + bool PrintScreen : 1; // VK_SNAPSHOT, 0x2C + bool Insert : 1; // VK_INSERT, 0x2D + bool Delete : 1; // VK_DELETE, 0x2E + bool Help : 1; // VK_HELP, 0x2F + bool D0 : 1; // 0x30 + bool D1 : 1; // 0x31 + bool D2 : 1; // 0x32 + bool D3 : 1; // 0x33 + bool D4 : 1; // 0x34 + bool D5 : 1; // 0x35 + bool D6 : 1; // 0x36 + bool D7 : 1; // 0x37 + bool D8 : 1; // 0x38 + bool D9 : 1; // 0x39 + bool Reserved8 : 6; + bool Reserved9 : 1; + bool A : 1; // 0x41 + bool B : 1; // 0x42 + bool C : 1; // 0x43 + bool D : 1; // 0x44 + bool E : 1; // 0x45 + bool F : 1; // 0x46 + bool G : 1; // 0x47 + bool H : 1; // 0x48 + bool I : 1; // 0x49 + bool J : 1; // 0x4A + bool K : 1; // 0x4B + bool L : 1; // 0x4C + bool M : 1; // 0x4D + bool N : 1; // 0x4E + bool O : 1; // 0x4F + bool P : 1; // 0x50 + bool Q : 1; // 0x51 + bool R : 1; // 0x52 + bool S : 1; // 0x53 + bool T : 1; // 0x54 + bool U : 1; // 0x55 + bool V : 1; // 0x56 + bool W : 1; // 0x57 + bool X : 1; // 0x58 + bool Y : 1; // 0x59 + bool Z : 1; // 0x5A + bool LeftWindows : 1; // VK_LWIN, 0x5B + bool RightWindows : 1; // VK_RWIN, 0x5C + bool Apps : 1; // VK_APPS, 0x5D + bool Reserved10 : 1; + bool Sleep : 1; // VK_SLEEP, 0x5F + bool NumPad0 : 1; // VK_NUMPAD0, 0x60 + bool NumPad1 : 1; // VK_NUMPAD1, 0x61 + bool NumPad2 : 1; // VK_NUMPAD2, 0x62 + bool NumPad3 : 1; // VK_NUMPAD3, 0x63 + bool NumPad4 : 1; // VK_NUMPAD4, 0x64 + bool NumPad5 : 1; // VK_NUMPAD5, 0x65 + bool NumPad6 : 1; // VK_NUMPAD6, 0x66 + bool NumPad7 : 1; // VK_NUMPAD7, 0x67 + bool NumPad8 : 1; // VK_NUMPAD8, 0x68 + bool NumPad9 : 1; // VK_NUMPAD9, 0x69 + bool Multiply : 1; // VK_MULTIPLY, 0x6A + bool Add : 1; // VK_ADD, 0x6B + bool Separator : 1; // VK_SEPARATOR, 0x6C + bool Subtract : 1; // VK_SUBTRACT, 0x6D + bool Decimal : 1; // VK_DECIMANL, 0x6E + bool Divide : 1; // VK_DIVIDE, 0x6F + bool F1 : 1; // VK_F1, 0x70 + bool F2 : 1; // VK_F2, 0x71 + bool F3 : 1; // VK_F3, 0x72 + bool F4 : 1; // VK_F4, 0x73 + bool F5 : 1; // VK_F5, 0x74 + bool F6 : 1; // VK_F6, 0x75 + bool F7 : 1; // VK_F7, 0x76 + bool F8 : 1; // VK_F8, 0x77 + bool F9 : 1; // VK_F9, 0x78 + bool F10 : 1; // VK_F10, 0x79 + bool F11 : 1; // VK_F11, 0x7A + bool F12 : 1; // VK_F12, 0x7B + bool F13 : 1; // VK_F13, 0x7C + bool F14 : 1; // VK_F14, 0x7D + bool F15 : 1; // VK_F15, 0x7E + bool F16 : 1; // VK_F16, 0x7F + bool F17 : 1; // VK_F17, 0x80 + bool F18 : 1; // VK_F18, 0x81 + bool F19 : 1; // VK_F19, 0x82 + bool F20 : 1; // VK_F20, 0x83 + bool F21 : 1; // VK_F21, 0x84 + bool F22 : 1; // VK_F22, 0x85 + bool F23 : 1; // VK_F23, 0x86 + bool F24 : 1; // VK_F24, 0x87 + bool Reserved11 : 8; + bool NumLock : 1; // VK_NUMLOCK, 0x90 + bool Scroll : 1; // VK_SCROLL, 0x91 + bool Reserved12 : 6; + bool Reserved13 : 8; + bool LeftShift : 1; // VK_LSHIFT, 0xA0 + bool RightShift : 1; // VK_RSHIFT, 0xA1 + bool LeftControl : 1; // VK_LCONTROL, 0xA2 + bool RightControl : 1; // VK_RCONTROL, 0xA3 + bool LeftAlt : 1; // VK_LMENU, 0xA4 + bool RightAlt : 1; // VK_RMENU, 0xA5 + bool BrowserBack : 1; // VK_BROWSER_BACK, 0xA6 + bool BrowserForward : 1; // VK_BROWSER_FORWARD, 0xA7 + bool BrowserRefresh : 1; // VK_BROWSER_REFRESH, 0xA8 + bool BrowserStop : 1; // VK_BROWSER_STOP, 0xA9 + bool BrowserSearch : 1; // VK_BROWSER_SEARCH, 0xAA + bool BrowserFavorites : 1; // VK_BROWSER_FAVORITES, 0xAB + bool BrowserHome : 1; // VK_BROWSER_HOME, 0xAC + bool VolumeMute : 1; // VK_VOLUME_MUTE, 0xAD + bool VolumeDown : 1; // VK_VOLUME_DOWN, 0xAE + bool VolumeUp : 1; // VK_VOLUME_UP, 0xAF + bool MediaNextTrack : 1; // VK_MEDIA_NEXT_TRACK, 0xB0 + bool MediaPreviousTrack : 1;// VK_MEDIA_PREV_TRACK, 0xB1 + bool MediaStop : 1; // VK_MEDIA_STOP, 0xB2 + bool MediaPlayPause : 1; // VK_MEDIA_PLAY_PAUSE, 0xB3 + bool LaunchMail : 1; // VK_LAUNCH_MAIL, 0xB4 + bool SelectMedia : 1; // VK_LAUNCH_MEDIA_SELECT, 0xB5 + bool LaunchApplication1 : 1;// VK_LAUNCH_APP1, 0xB6 + bool LaunchApplication2 : 1;// VK_LAUNCH_APP2, 0xB7 + bool Reserved14 : 2; + bool OemSemicolon : 1; // VK_OEM_1, 0xBA + bool OemPlus : 1; // VK_OEM_PLUS, 0xBB + bool OemComma : 1; // VK_OEM_COMMA, 0xBC + bool OemMinus : 1; // VK_OEM_MINUS, 0xBD + bool OemPeriod : 1; // VK_OEM_PERIOD, 0xBE + bool OemQuestion : 1; // VK_OEM_2, 0xBF + bool OemTilde : 1; // VK_OEM_3, 0xC0 + bool Reserved15 : 7; + bool Reserved16 : 8; + bool Reserved17 : 8; + bool Reserved18 : 3; + bool OemOpenBrackets : 1; // VK_OEM_4, 0xDB + bool OemPipe : 1; // VK_OEM_5, 0xDC + bool OemCloseBrackets : 1; // VK_OEM_6, 0xDD + bool OemQuotes : 1; // VK_OEM_7, 0xDE + bool Oem8 : 1; // VK_OEM_8, 0xDF + bool Reserved19 : 2; + bool OemBackslash : 1; // VK_OEM_102, 0xE2 + bool Reserved20 : 2; + bool ProcessKey : 1; // VK_PROCESSKEY, 0xE5 + bool Reserved21 : 2; + bool Reserved22 : 8; + bool Reserved23 : 2; + bool OemCopy : 1; // 0XF2 + bool OemAuto : 1; // 0xF3 + bool OemEnlW : 1; // 0xF4 + bool Reserved24 : 1; + bool Attn : 1; // VK_ATTN, 0xF6 + bool Crsel : 1; // VK_CRSEL, 0xF7 + bool Exsel : 1; // VK_EXSEL, 0xF8 + bool EraseEof : 1; // VK_EREOF, 0xF9 + bool Play : 1; // VK_PLAY, 0xFA + bool Zoom : 1; // VK_ZOOM, 0xFB + bool Reserved25 : 1; + bool Pa1 : 1; // VK_PA1, 0xFD + bool OemClear : 1; // VK_OEM_CLEAR, 0xFE + bool Reserved26 : 1; }; - class IKeyboard { - public: - virtual ~IKeyboard(){} + class Keyboard { + public: static KeyboardState GetState(); - static bool IsConnected(); + //static bool IsConnected(); + static void Initialize(); + + public: + struct PlatformImplementation; + inline static uptr impl = nullptr; }; } diff --git a/inc/platform-dx/implementations.hpp b/inc/platform-dx/implementations.hpp index 9d479e5..838d88c 100644 --- a/inc/platform-dx/implementations.hpp +++ b/inc/platform-dx/implementations.hpp @@ -7,6 +7,7 @@ #include "graphics/displaymode.hpp" #include "graphics/sprite.hpp" #include "input/gamepad.hpp" +#include "input/keyboard.hpp" #include "platform-dx/presentparameters-dx.hpp" #include "platform-dx/rendertarget-dx.hpp" #include "platform-dx/swapchain-dx.hpp" @@ -142,6 +143,16 @@ namespace xna { struct GamePad::PlatformImplementation { inline static uptr _dxGamePad = nullptr; + + void Suspend() { + if (_dxGamePad) + _dxGamePad->Suspend(); + } + + void Resume() { + if (_dxGamePad) + _dxGamePad->Resume(); + } }; struct IndexBuffer::PlatformImplementation { @@ -171,4 +182,13 @@ namespace xna { return true; } + + struct Keyboard::PlatformImplementation { + inline static uptr _dxKeyboard = nullptr; + + void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) { + if (_dxKeyboard) + Keyboard::impl->_dxKeyboard->ProcessMessage(message, wParam, lParam); + } + }; } \ No newline at end of file diff --git a/inc/platform-dx/keyboard-dx.hpp b/inc/platform-dx/keyboard-dx.hpp deleted file mode 100644 index 3f48e42..0000000 --- a/inc/platform-dx/keyboard-dx.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef XNA_PLATFORM_KEYBOARD_DX_HPP -#define XNA_PLATFORM_KEYBOARD_DX_HPP - -#include "../input/keyboard.hpp" -#include - -namespace xna { - struct KeyboardState : public IKeyboardState { - public: - KeyboardState() = default; - KeyboardState(DirectX::Keyboard::State const& state) :_state(state) {} - - virtual bool IsKeyDown(Keys key) const override { - const auto k = static_cast(key); - return _state.IsKeyDown(k); - } - - virtual bool IsKeyUp(Keys key) const override { - const auto k = static_cast(key); - return _state.IsKeyUp(k); - } - - public: - DirectX::Keyboard::State _state{}; - }; - - struct Keyboard : public IKeyboard { - inline static void Initialize() { - _dxKeyboard = uNew(); - } - - private: - constexpr Keyboard() = default; - constexpr Keyboard(Keyboard&&) = default; - constexpr Keyboard(const Keyboard&) = default; - - public: - inline static uptr _dxKeyboard = nullptr; - }; - - inline KeyboardState IKeyboard::GetState() { - if (!Keyboard::_dxKeyboard) - return KeyboardState(); - - const auto state = Keyboard::_dxKeyboard->GetState(); - return KeyboardState(state); - } - - inline bool IKeyboard::IsConnected() { - if (!Keyboard::_dxKeyboard) - return false; - - return Keyboard::_dxKeyboard->IsConnected(); - } -} - -#endif \ No newline at end of file diff --git a/inc/platform-dx/xna-dx.hpp b/inc/platform-dx/xna-dx.hpp index 76846e5..d23a59c 100644 --- a/inc/platform-dx/xna-dx.hpp +++ b/inc/platform-dx/xna-dx.hpp @@ -7,7 +7,6 @@ #include "gdeviceinfo-dx.hpp" #include "gdevicemanager-dx.hpp" #include "init-dx.hpp" -#include "keyboard-dx.hpp" #include "mouse-dx.hpp" #include "presentparameters-dx.hpp" #include "rasterizerstate-dx.hpp"