mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige Mouse
This commit is contained in:
parent
3122fe2bf3
commit
c35067ff72
@ -3,9 +3,7 @@
|
|||||||
#include "platform-dx/audioengine-dx.hpp"
|
#include "platform-dx/audioengine-dx.hpp"
|
||||||
#include "platform-dx/device-dx.hpp"
|
#include "platform-dx/device-dx.hpp"
|
||||||
#include "platform-dx/game-dx.hpp"
|
#include "platform-dx/game-dx.hpp"
|
||||||
#include "input/gamepad.hpp"
|
|
||||||
#include "platform-dx/gdevicemanager-dx.hpp"
|
#include "platform-dx/gdevicemanager-dx.hpp"
|
||||||
#include "platform-dx/mouse-dx.hpp"
|
|
||||||
#include "platform-dx/implementations.hpp"
|
#include "platform-dx/implementations.hpp"
|
||||||
#include "platform-dx/window-dx.hpp"
|
#include "platform-dx/window-dx.hpp"
|
||||||
|
|
||||||
@ -40,7 +38,7 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::Initialize() {
|
void Game::Initialize() {
|
||||||
//#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
//#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
|
||||||
Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
|
Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
|
||||||
if (FAILED(initialize))
|
if (FAILED(initialize))
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
KeyboardState Keyboard::GetState() {
|
KeyboardState Keyboard::GetState() {
|
||||||
if (!impl->_dxKeyboard)
|
if (!impl || !impl->_dxKeyboard)
|
||||||
return KeyboardState();
|
return KeyboardState();
|
||||||
|
|
||||||
const auto state = Keyboard::impl->_dxKeyboard->GetState();
|
const auto state = Keyboard::impl->_dxKeyboard->GetState();
|
||||||
@ -17,4 +17,11 @@ namespace xna {
|
|||||||
impl = uNew<PlatformImplementation>();
|
impl = uNew<PlatformImplementation>();
|
||||||
impl->_dxKeyboard = uNew<DirectX::Keyboard>();
|
impl->_dxKeyboard = uNew<DirectX::Keyboard>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Keyboard::IsConnected() {
|
||||||
|
if (!impl || !impl->_dxKeyboard)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return impl->_dxKeyboard->IsConnected();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,55 @@
|
|||||||
#include "platform-dx/mouse-dx.hpp"
|
#include "input/mouse.hpp"
|
||||||
|
#include "platform-dx/implementations.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
MouseState Mouse::GetState() {
|
||||||
|
if (!impl || !impl->_dxMouse)
|
||||||
|
return MouseState();
|
||||||
|
|
||||||
|
const auto state = impl->_dxMouse->GetState();
|
||||||
|
MouseState mstate;
|
||||||
|
mstate.LeftButton = static_cast<ButtonState>(state.leftButton);
|
||||||
|
mstate.RightButton = static_cast<ButtonState>(state.rightButton);
|
||||||
|
mstate.MiddleButton = static_cast<ButtonState>(state.middleButton);
|
||||||
|
mstate.XButton1 = static_cast<ButtonState>(state.xButton1);
|
||||||
|
mstate.XButton2 = static_cast<ButtonState>(state.xButton2);
|
||||||
|
mstate.X = state.x;
|
||||||
|
mstate.Y = state.y;
|
||||||
|
mstate.ScroolWheelValue = state.scrollWheelValue;
|
||||||
|
|
||||||
|
return mstate;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mouse::IsConnected() {
|
||||||
|
if (!impl || !impl->_dxMouse)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
impl = uNew<PlatformImplementation>();
|
||||||
|
impl->_dxMouse = uNew<DirectX::Mouse>();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
#include "platform-dx/window-dx.hpp"
|
#include "platform-dx/window-dx.hpp"
|
||||||
#include "platform-dx/mouse-dx.hpp"
|
|
||||||
#include "input/gamepad.hpp"
|
#include "input/gamepad.hpp"
|
||||||
#include "platform-dx/implementations.hpp"
|
#include "platform-dx/implementations.hpp"
|
||||||
|
|
||||||
@ -142,7 +141,7 @@ namespace xna {
|
|||||||
case WM_ACTIVATE:
|
case WM_ACTIVATE:
|
||||||
case WM_ACTIVATEAPP:
|
case WM_ACTIVATEAPP:
|
||||||
Keyboard::impl->ProcessMessage(msg, wParam, lParam);
|
Keyboard::impl->ProcessMessage(msg, wParam, lParam);
|
||||||
Mouse::_dxMouse->ProcessMessage(msg, wParam, lParam);
|
Mouse::impl->ProcessMessage(msg, wParam, lParam);
|
||||||
break;
|
break;
|
||||||
case WM_SYSKEYDOWN:
|
case WM_SYSKEYDOWN:
|
||||||
if (!(wParam == VK_RETURN && (lParam & 0x60000000) == 0x20000000)) {
|
if (!(wParam == VK_RETURN && (lParam & 0x60000000) == 0x20000000)) {
|
||||||
@ -167,7 +166,7 @@ namespace xna {
|
|||||||
case WM_XBUTTONDOWN:
|
case WM_XBUTTONDOWN:
|
||||||
case WM_XBUTTONUP:
|
case WM_XBUTTONUP:
|
||||||
case WM_MOUSEHOVER:
|
case WM_MOUSEHOVER:
|
||||||
Mouse::_dxMouse->ProcessMessage(msg, wParam, lParam);
|
Mouse::impl->ProcessMessage(msg, wParam, lParam);
|
||||||
break;
|
break;
|
||||||
case WM_KILLFOCUS:
|
case WM_KILLFOCUS:
|
||||||
GamePad::impl->Suspend();
|
GamePad::impl->Suspend();
|
||||||
|
@ -215,6 +215,7 @@ namespace xna {
|
|||||||
static KeyboardState GetState();
|
static KeyboardState GetState();
|
||||||
//static bool IsConnected();
|
//static bool IsConnected();
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
|
static bool IsConnected();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
struct IMouseState {
|
struct MouseState {
|
||||||
ButtonState LeftButton{ ButtonState::Released };
|
ButtonState LeftButton{ ButtonState::Released };
|
||||||
ButtonState RightButton{ ButtonState::Released };
|
ButtonState RightButton{ ButtonState::Released };
|
||||||
ButtonState MiddleButton{ ButtonState::Released };
|
ButtonState MiddleButton{ ButtonState::Released };
|
||||||
@ -15,14 +15,19 @@ namespace xna {
|
|||||||
int ScroolWheelValue{ 0 };
|
int ScroolWheelValue{ 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class IMouse {
|
class Mouse {
|
||||||
public:
|
public:
|
||||||
virtual ~IMouse() {}
|
|
||||||
static MouseState GetState();
|
static MouseState GetState();
|
||||||
static bool IsConnected();
|
static bool IsConnected();
|
||||||
static bool IsVisible();
|
static bool IsVisible();
|
||||||
static void IsVisible(bool value);
|
static void IsVisible(bool value);
|
||||||
static void ResetScrollWheel();
|
static void ResetScrollWheel();
|
||||||
|
|
||||||
|
static void Initialize();
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct PlatformImplementation;
|
||||||
|
inline static uptr<PlatformImplementation> impl = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "graphics/sprite.hpp"
|
#include "graphics/sprite.hpp"
|
||||||
#include "input/gamepad.hpp"
|
#include "input/gamepad.hpp"
|
||||||
#include "input/keyboard.hpp"
|
#include "input/keyboard.hpp"
|
||||||
|
#include "input/mouse.hpp"
|
||||||
#include "platform-dx/presentparameters-dx.hpp"
|
#include "platform-dx/presentparameters-dx.hpp"
|
||||||
#include "platform-dx/rendertarget-dx.hpp"
|
#include "platform-dx/rendertarget-dx.hpp"
|
||||||
#include "platform-dx/swapchain-dx.hpp"
|
#include "platform-dx/swapchain-dx.hpp"
|
||||||
@ -188,7 +189,16 @@ namespace xna {
|
|||||||
|
|
||||||
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) {
|
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||||
if (_dxKeyboard)
|
if (_dxKeyboard)
|
||||||
Keyboard::impl->_dxKeyboard->ProcessMessage(message, wParam, lParam);
|
_dxKeyboard->ProcessMessage(message, wParam, lParam);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Mouse::PlatformImplementation {
|
||||||
|
inline static uptr<DirectX::Mouse> _dxMouse = nullptr;
|
||||||
|
|
||||||
|
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||||
|
if (_dxMouse)
|
||||||
|
_dxMouse->ProcessMessage(message, wParam, lParam);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -1,74 +0,0 @@
|
|||||||
#ifndef XNA_PLATFORM_MOUSE_DX_HPP
|
|
||||||
#define XNA_PLATFORM_MOUSE_DX_HPP
|
|
||||||
|
|
||||||
#include "../input/mouse.hpp"
|
|
||||||
#include <Mouse.h>
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
struct MouseState : public IMouseState {
|
|
||||||
constexpr MouseState() = default;
|
|
||||||
|
|
||||||
constexpr MouseState(DirectX::Mouse::State const& dxMouseState) {
|
|
||||||
LeftButton = static_cast<ButtonState>(dxMouseState.leftButton);
|
|
||||||
RightButton = static_cast<ButtonState>(dxMouseState.rightButton);
|
|
||||||
MiddleButton = static_cast<ButtonState>(dxMouseState.middleButton);
|
|
||||||
XButton1 = static_cast<ButtonState>(dxMouseState.xButton1);
|
|
||||||
XButton2 = static_cast<ButtonState>(dxMouseState.xButton2);
|
|
||||||
X = dxMouseState.x;
|
|
||||||
Y = dxMouseState.y;
|
|
||||||
ScroolWheelValue = dxMouseState.scrollWheelValue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mouse : public IMouse {
|
|
||||||
inline static void Initialize() {
|
|
||||||
_dxMouse = uNew<DirectX::Mouse>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline static uptr<DirectX::Mouse> _dxMouse = nullptr;
|
|
||||||
|
|
||||||
private:
|
|
||||||
constexpr Mouse() = default;
|
|
||||||
constexpr Mouse(Mouse&&) = default;
|
|
||||||
constexpr Mouse(const Mouse&) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline MouseState IMouse::GetState() {
|
|
||||||
if (!Mouse::_dxMouse)
|
|
||||||
return MouseState();
|
|
||||||
|
|
||||||
const auto state = Mouse::_dxMouse->GetState();
|
|
||||||
return MouseState(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IMouse::IsConnected() {
|
|
||||||
if (!Mouse::_dxMouse)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return Mouse::_dxMouse->IsConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IMouse::IsVisible() {
|
|
||||||
if (!Mouse::_dxMouse)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return Mouse::_dxMouse->IsVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void IMouse::IsVisible(bool value) {
|
|
||||||
if (!Mouse::_dxMouse)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Mouse::_dxMouse->SetVisible(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void IMouse::ResetScrollWheel() {
|
|
||||||
if (!Mouse::_dxMouse)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Mouse::_dxMouse->ResetScrollWheelValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -7,7 +7,6 @@
|
|||||||
#include "gdeviceinfo-dx.hpp"
|
#include "gdeviceinfo-dx.hpp"
|
||||||
#include "gdevicemanager-dx.hpp"
|
#include "gdevicemanager-dx.hpp"
|
||||||
#include "init-dx.hpp"
|
#include "init-dx.hpp"
|
||||||
#include "mouse-dx.hpp"
|
|
||||||
#include "presentparameters-dx.hpp"
|
#include "presentparameters-dx.hpp"
|
||||||
#include "rasterizerstate-dx.hpp"
|
#include "rasterizerstate-dx.hpp"
|
||||||
#include "rendertarget-dx.hpp"
|
#include "rendertarget-dx.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user