diff --git a/framework/input/mouse.hpp b/framework/input/mouse.hpp index 875f19d..fae2d87 100644 --- a/framework/input/mouse.hpp +++ b/framework/input/mouse.hpp @@ -5,11 +5,11 @@ namespace xna { struct IMouseState { - ButtonState LeftButton{ 0 }; - ButtonState RightButton{ 0 }; - ButtonState MiddleButton{ 0 }; - ButtonState XButton1{ 0 }; - ButtonState XButton2{ 0 }; + ButtonState LeftButton{ ButtonState::Released }; + ButtonState RightButton{ ButtonState::Released }; + ButtonState MiddleButton{ ButtonState::Released }; + ButtonState XButton1{ ButtonState::Released }; + ButtonState XButton2{ ButtonState::Released }; int X{ 0 }; int Y{ 0 }; int ScroolWheelValue{ 0 }; diff --git a/framework/platform/mouse-dx.hpp b/framework/platform/mouse-dx.hpp index 7ad313f..9ad5d93 100644 --- a/framework/platform/mouse-dx.hpp +++ b/framework/platform/mouse-dx.hpp @@ -10,14 +10,14 @@ namespace xna { constexpr MouseState(DirectX::Mouse::State const& dxMouseState) { LeftButton = static_cast(dxMouseState.leftButton); - RightButton = static_cast(dxMouseState.leftButton); - MiddleButton = static_cast(dxMouseState.leftButton); - XButton1 = static_cast(dxMouseState.leftButton); - XButton2 = static_cast(dxMouseState.leftButton); + RightButton = static_cast(dxMouseState.rightButton); + MiddleButton = static_cast(dxMouseState.middleButton); + XButton1 = static_cast(dxMouseState.xButton1); + XButton2 = static_cast(dxMouseState.xButton2); X = dxMouseState.x; Y = dxMouseState.y; ScroolWheelValue = dxMouseState.scrollWheelValue; - } + } }; struct Mouse : public IMouse { diff --git a/framework/xna.cpp b/framework/xna.cpp index 3db88f7..b82c4c9 100644 --- a/framework/xna.cpp +++ b/framework/xna.cpp @@ -36,7 +36,7 @@ public: void Update(GameTime const& gameTime) override { - const auto state = Keyboard::GetState(); + const auto state = Keyboard::GetState(); if (state.IsKeyDown(Keys::Right)) { position.X += 1 * gameTime.ElapsedGameTime.TotalMilliseconds(); @@ -49,12 +49,13 @@ public: } if (state.IsKeyDown(Keys::Down)) { position.Y += 1 * gameTime.ElapsedGameTime.TotalMilliseconds(); - } + } + oldState = currentState; - const auto currentState = Mouse::GetState(); + currentState = Mouse::GetState(); - if (currentState.LeftButton == ButtonState::Pressed && oldState.LeftButton == ButtonState::Released) { + if (currentState.LeftButton == ButtonState::Pressed && oldState.LeftButton == ButtonState::Released) { points.push_back(Vector2(currentState.X, currentState.Y)); } @@ -81,8 +82,8 @@ private: PTexture2D texture = nullptr; Vector2 position{}; std::vector points; - MouseState currentState; - MouseState oldState; + MouseState currentState{}; + MouseState oldState{}; float vel = 1; };