1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Remove Keyboard::IsConnected

This commit is contained in:
Danilo 2024-08-01 11:18:07 -03:00
parent a5b9ca4485
commit 231b0f22f9
3 changed files with 20 additions and 14 deletions

View File

@ -1,4 +1,3 @@
#include "xna/input/keyboard.hpp"
#include "xna/xna-dx.hpp" #include "xna/xna-dx.hpp"
namespace xna { namespace xna {
@ -15,12 +14,5 @@ namespace xna {
void Keyboard::Initialize() { void Keyboard::Initialize() {
impl = unew<PlatformImplementation>(); impl = unew<PlatformImplementation>();
} }
bool Keyboard::IsConnected() {
if (!impl || !impl->_dxKeyboard)
return false;
return impl->_dxKeyboard->IsConnected();
}
} }

View File

@ -10,6 +10,8 @@ namespace xna {
//same implementation of the DirectX::Keyboard::State structure //same implementation of the DirectX::Keyboard::State structure
// //
public: public:
//Returns whether a specified key is currently being pressed.
constexpr bool IsKeyDown(Keys key) const { constexpr bool IsKeyDown(Keys key) const {
const auto k = static_cast<unsigned char>(key); const auto k = static_cast<unsigned char>(key);
@ -22,10 +24,19 @@ namespace xna {
return false; return false;
} }
//Returns whether a specified key is currently not pressed.
constexpr bool IsKeyUp(Keys key) const { constexpr bool IsKeyUp(Keys key) const {
return !IsKeyDown(key); return !IsKeyDown(key);
} }
//Returns the state of a particular key.
KeyState operator[](Keys key) {
const auto isDown = IsKeyDown(key);
const auto state = static_cast<KeyState>(static_cast<int>(isDown));
return state;
}
private: private:
bool Reserved0 : 8; bool Reserved0 : 8;
bool Back : 1; // VK_BACK, 0x8 bool Back : 1; // VK_BACK, 0x8
@ -217,9 +228,8 @@ namespace xna {
//Allows retrieval of keystrokes from a keyboard input device. //Allows retrieval of keystrokes from a keyboard input device.
class Keyboard { class Keyboard {
public: public:
//Returns the current keyboard or Chatpad state. //Returns the current keyboard.
static KeyboardState GetState(); static KeyboardState GetState();
static bool IsConnected();
private: private:
friend class Game; friend class Game;

View File

@ -635,9 +635,13 @@ namespace xna {
}; };
struct Keyboard::PlatformImplementation { struct Keyboard::PlatformImplementation {
uptr<DirectX::Keyboard> _dxKeyboard = unew<DirectX::Keyboard>(); PlatformImplementation() {
_dxKeyboard = unew<DirectX::Keyboard>();
}
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const { uptr<DirectX::Keyboard> _dxKeyboard = nullptr;
inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
if (_dxKeyboard) if (_dxKeyboard)
_dxKeyboard->ProcessMessage(message, wParam, lParam); _dxKeyboard->ProcessMessage(message, wParam, lParam);
} }