diff --git a/framework/platform-dx/game.cpp b/framework/platform-dx/game.cpp index b128ff8..ec10b7d 100644 --- a/framework/platform-dx/game.cpp +++ b/framework/platform-dx/game.cpp @@ -81,8 +81,8 @@ namespace xna { } void Game::Initialize() { - Keyboard::Initialize(); - Mouse::Initialize(); + Keyboard::Initialize(); + Mouse::Initialize(_gameWindow->Handle()); GamePad::Initialize(); AudioEngine::Initialize(); diff --git a/framework/platform-dx/mouse.cpp b/framework/platform-dx/mouse.cpp index 039a37d..77b3842 100644 --- a/framework/platform-dx/mouse.cpp +++ b/framework/platform-dx/mouse.cpp @@ -2,9 +2,6 @@ namespace xna { MouseState Mouse::GetState() { - if (!impl || !impl->_dxMouse) - return MouseState(); - const auto state = impl->_dxMouse->GetState(); MouseState mstate; mstate.LeftButton = static_cast(state.leftButton); @@ -19,35 +16,32 @@ namespace xna { return mstate; } - bool Mouse::IsConnected() { - if (!impl || !impl->_dxMouse) - return false; - + bool Mouse::IsConnected() { return impl->_dxMouse->IsConnected(); } bool Mouse::IsVisible() { - if (!impl || !impl->_dxMouse) - return false; - return impl->_dxMouse->IsVisible(); } void Mouse::IsVisible(bool value) { - if (!impl || !impl->_dxMouse) - return; - impl->_dxMouse->SetVisible(value); } void Mouse::ResetScrollWheel() { - if (!impl || !impl->_dxMouse) - return; - impl->_dxMouse->ResetScrollWheelValue(); } - void Mouse::Initialize() { + void Mouse::Initialize(intptr_t handle) { impl = unew(); + windowHandle = handle; + } + + void Mouse::WindowHandle(intptr_t value) { + auto hwnd = reinterpret_cast(value); + + if (!hwnd) return; + + impl->_dxMouse->SetWindow(hwnd); } } \ No newline at end of file diff --git a/inc/xna/input/mouse.hpp b/inc/xna/input/mouse.hpp index 8686291..23c9a3c 100644 --- a/inc/xna/input/mouse.hpp +++ b/inc/xna/input/mouse.hpp @@ -4,15 +4,24 @@ #include "../default.hpp" namespace xna { + //Represents the state of a mouse input device, including mouse cursor position and buttons pressed. struct MouseState { + //Returns the state of the left mouse button. ButtonState LeftButton{ ButtonState::Released }; - ButtonState RightButton{ ButtonState::Released }; + //Returns the state of the middle mouse button. ButtonState MiddleButton{ ButtonState::Released }; - ButtonState XButton1{ ButtonState::Released }; - ButtonState XButton2{ ButtonState::Released }; - int X{ 0 }; - int Y{ 0 }; + //Returns the state of the right mouse button. + ButtonState RightButton{ ButtonState::Released }; + //Gets the cumulative mouse scroll wheel value since the game was started. int ScroolWheelValue{ 0 }; + //Specifies the horizontal position of the mouse cursor. + int X{ 0 }; + //Returns the state of XBUTTON1. + ButtonState XButton1{ ButtonState::Released }; + //Returns the state of XBUTTON2. + ButtonState XButton2{ ButtonState::Released }; + //Specifies the vertical position of the mouse cursor. + int Y{ 0 }; }; //Allows retrieval of position and button clicks from a mouse input device. @@ -21,6 +30,16 @@ namespace xna { //Gets the current state of the mouse, including mouse position and buttons pressed. static MouseState GetState(); + //Gets or sets the window used for mouse processing. + //Mouse coordinates returned by GetState are relative to the upper-left corner of this window. + constexpr static intptr_t WindowHandle() { + return windowHandle; + } + + //Gets or sets the window used for mouse processing. + //Mouse coordinates returned by GetState are relative to the upper-left corner of this window. + static void WindowHandle(intptr_t value); + static bool IsConnected(); static bool IsVisible(); static void IsVisible(bool value); @@ -28,12 +47,14 @@ namespace xna { private: friend class Game; - static void Initialize(); + static void Initialize(intptr_t windowHandle); Mouse() = default; Mouse(Mouse&) = default; Mouse(Mouse&&) = default; + inline static intptr_t windowHandle = 0; + public: struct PlatformImplementation; inline static uptr impl = nullptr;