From 231b0f22f9bca15509141f3ff08e728fe814dbaa Mon Sep 17 00:00:00 2001 From: Danilo Date: Thu, 1 Aug 2024 11:18:07 -0300 Subject: [PATCH] Remove Keyboard::IsConnected --- framework/platform-dx/keyboard.cpp | 10 +--------- inc/xna/input/keyboard.hpp | 16 +++++++++++++--- inc/xna/xna-dx.hpp | 8 ++++++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/framework/platform-dx/keyboard.cpp b/framework/platform-dx/keyboard.cpp index 867ca54..9cf2892 100644 --- a/framework/platform-dx/keyboard.cpp +++ b/framework/platform-dx/keyboard.cpp @@ -1,4 +1,3 @@ -#include "xna/input/keyboard.hpp" #include "xna/xna-dx.hpp" namespace xna { @@ -15,12 +14,5 @@ namespace xna { void Keyboard::Initialize() { impl = unew(); - } - - bool Keyboard::IsConnected() { - if (!impl || !impl->_dxKeyboard) - return false; - - return impl->_dxKeyboard->IsConnected(); - } + } } \ No newline at end of file diff --git a/inc/xna/input/keyboard.hpp b/inc/xna/input/keyboard.hpp index 67fd58b..510c601 100644 --- a/inc/xna/input/keyboard.hpp +++ b/inc/xna/input/keyboard.hpp @@ -10,6 +10,8 @@ namespace xna { //same implementation of the DirectX::Keyboard::State structure // public: + + //Returns whether a specified key is currently being pressed. constexpr bool IsKeyDown(Keys key) const { const auto k = static_cast(key); @@ -22,10 +24,19 @@ namespace xna { return false; } + //Returns whether a specified key is currently not pressed. constexpr bool IsKeyUp(Keys key) const { return !IsKeyDown(key); } + //Returns the state of a particular key. + KeyState operator[](Keys key) { + const auto isDown = IsKeyDown(key); + const auto state = static_cast(static_cast(isDown)); + + return state; + } + private: bool Reserved0 : 8; bool Back : 1; // VK_BACK, 0x8 @@ -217,9 +228,8 @@ namespace xna { //Allows retrieval of keystrokes from a keyboard input device. class Keyboard { public: - //Returns the current keyboard or Chatpad state. - static KeyboardState GetState(); - static bool IsConnected(); + //Returns the current keyboard. + static KeyboardState GetState(); private: friend class Game; diff --git a/inc/xna/xna-dx.hpp b/inc/xna/xna-dx.hpp index a943583..e5c19c7 100644 --- a/inc/xna/xna-dx.hpp +++ b/inc/xna/xna-dx.hpp @@ -635,9 +635,13 @@ namespace xna { }; struct Keyboard::PlatformImplementation { - uptr _dxKeyboard = unew(); + PlatformImplementation() { + _dxKeyboard = unew(); + } - void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const { + uptr _dxKeyboard = nullptr; + + inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const { if (_dxKeyboard) _dxKeyboard->ProcessMessage(message, wParam, lParam); }