mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa Mouse
This commit is contained in:
parent
3274acf478
commit
796bceb034
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# Add source to this project's executable.
|
# Add source to this project's executable.
|
||||||
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizerstate-dx.cpp" "platform/vertexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp" "common/matrix.cpp" "platform/constbuffer-dx.cpp" "platform/databuffer-dx.cpp" "platform/samplerstate-dx.cpp" "platform/spritebatch-dx.cpp" "platform/spritefont-dx.cpp" "platform/depthstencilstate-dx.cpp" "platform/keyboard-dx.cpp")
|
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizerstate-dx.cpp" "platform/vertexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp" "common/matrix.cpp" "platform/constbuffer-dx.cpp" "platform/databuffer-dx.cpp" "platform/samplerstate-dx.cpp" "platform/spritebatch-dx.cpp" "platform/spritefont-dx.cpp" "platform/depthstencilstate-dx.cpp" "platform/keyboard-dx.cpp" "platform/mouse-dx.cpp")
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||||
set_property(TARGET xna PROPERTY CXX_STANDARD 20)
|
set_property(TARGET xna PROPERTY CXX_STANDARD 20)
|
||||||
|
@ -32,6 +32,12 @@ namespace xna {
|
|||||||
|
|
||||||
using BlendOperation = BlendFunction;
|
using BlendOperation = BlendFunction;
|
||||||
|
|
||||||
|
enum class ButtonState
|
||||||
|
{
|
||||||
|
Released,
|
||||||
|
Pressed,
|
||||||
|
};
|
||||||
|
|
||||||
enum class ColorWriteChannels {
|
enum class ColorWriteChannels {
|
||||||
Red,
|
Red,
|
||||||
Green,
|
Green,
|
||||||
|
@ -135,6 +135,8 @@ namespace xna {
|
|||||||
//Input
|
//Input
|
||||||
struct KeyboardState;
|
struct KeyboardState;
|
||||||
using PKeyboardState = std::shared_ptr<KeyboardState>;
|
using PKeyboardState = std::shared_ptr<KeyboardState>;
|
||||||
|
struct MouseState;
|
||||||
|
using PMouseState = std::shared_ptr<MouseState>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
29
framework/input/mouse.hpp
Normal file
29
framework/input/mouse.hpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef XNA_INPUT_MOUSE_HPP
|
||||||
|
#define XNA_INPUT_MOUSE_HPP
|
||||||
|
|
||||||
|
#include "../default.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
struct IMouseState {
|
||||||
|
ButtonState LeftButton{ 0 };
|
||||||
|
ButtonState RightButton{ 0 };
|
||||||
|
ButtonState MiddleButton{ 0 };
|
||||||
|
ButtonState XButton1{ 0 };
|
||||||
|
ButtonState XButton2{ 0 };
|
||||||
|
int X{ 0 };
|
||||||
|
int Y{ 0 };
|
||||||
|
int ScroolWheelValue{ 0 };
|
||||||
|
};
|
||||||
|
|
||||||
|
class IMouse {
|
||||||
|
public:
|
||||||
|
virtual ~IMouse() {}
|
||||||
|
static MouseState GetState();
|
||||||
|
static bool IsConnected();
|
||||||
|
static bool IsVisible();
|
||||||
|
static void IsVisible(bool value);
|
||||||
|
static void ResetScrollWheel();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -20,23 +20,16 @@ namespace xna {
|
|||||||
return _state.IsKeyUp(k);
|
return _state.IsKeyUp(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
public:
|
||||||
DirectX::Keyboard::State _state{};
|
DirectX::Keyboard::State _state{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Keyboard : public IKeyboard {
|
class Keyboard : public IKeyboard {
|
||||||
public:
|
public:
|
||||||
friend class IKeyboard;
|
|
||||||
friend class GameWindow;
|
|
||||||
|
|
||||||
Keyboard() = default;
|
Keyboard() = default;
|
||||||
|
|
||||||
private:
|
public:
|
||||||
inline static sptr<DirectX::Keyboard> initializeKeyboard() {
|
inline static sptr<DirectX::Keyboard> _dxKeyboard = New<DirectX::Keyboard>();
|
||||||
return New<DirectX::Keyboard>();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static sptr<DirectX::Keyboard> _dxKeyboard = initializeKeyboard();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline KeyboardState IKeyboard::GetState() {
|
inline KeyboardState IKeyboard::GetState() {
|
||||||
|
5
framework/platform/mouse-dx.cpp
Normal file
5
framework/platform/mouse-dx.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "mouse-dx.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
|
||||||
|
}
|
65
framework/platform/mouse-dx.hpp
Normal file
65
framework/platform/mouse-dx.hpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#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.leftButton);
|
||||||
|
MiddleButton = static_cast<ButtonState>(dxMouseState.leftButton);
|
||||||
|
XButton1 = static_cast<ButtonState>(dxMouseState.leftButton);
|
||||||
|
XButton2 = static_cast<ButtonState>(dxMouseState.leftButton);
|
||||||
|
X = dxMouseState.x;
|
||||||
|
Y = dxMouseState.y;
|
||||||
|
ScroolWheelValue = dxMouseState.scrollWheelValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Mouse : public IMouse {
|
||||||
|
public:
|
||||||
|
inline static sptr<DirectX::Mouse> _dxMouse = New<DirectX::Mouse>();
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
@ -1,5 +1,6 @@
|
|||||||
#include "window-dx.hpp"
|
#include "window-dx.hpp"
|
||||||
#include "keyboard-dx.hpp"
|
#include "keyboard-dx.hpp"
|
||||||
|
#include "mouse-dx.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
GameWindow::GameWindow() {
|
GameWindow::GameWindow() {
|
||||||
@ -140,6 +141,7 @@ namespace xna {
|
|||||||
case WM_ACTIVATE:
|
case WM_ACTIVATE:
|
||||||
case WM_ACTIVATEAPP:
|
case WM_ACTIVATEAPP:
|
||||||
Keyboard::_dxKeyboard->ProcessMessage(msg, wParam, lParam);
|
Keyboard::_dxKeyboard->ProcessMessage(msg, wParam, lParam);
|
||||||
|
Mouse::_dxMouse->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)) {
|
||||||
@ -151,6 +153,21 @@ namespace xna {
|
|||||||
case WM_SYSKEYUP:
|
case WM_SYSKEYUP:
|
||||||
Keyboard::_dxKeyboard->ProcessMessage(msg, wParam, lParam);
|
Keyboard::_dxKeyboard->ProcessMessage(msg, wParam, lParam);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM_INPUT:
|
||||||
|
case WM_MOUSEMOVE:
|
||||||
|
case WM_LBUTTONDOWN:
|
||||||
|
case WM_LBUTTONUP:
|
||||||
|
case WM_RBUTTONDOWN:
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
case WM_MBUTTONDOWN:
|
||||||
|
case WM_MBUTTONUP:
|
||||||
|
case WM_MOUSEWHEEL:
|
||||||
|
case WM_XBUTTONDOWN:
|
||||||
|
case WM_XBUTTONUP:
|
||||||
|
case WM_MOUSEHOVER:
|
||||||
|
Mouse::_dxMouse->ProcessMessage(msg, wParam, lParam);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||||
|
@ -49,18 +49,15 @@ public:
|
|||||||
}
|
}
|
||||||
if (state.IsKeyDown(Keys::Down)) {
|
if (state.IsKeyDown(Keys::Down)) {
|
||||||
position.Y += 1 * gameTime.ElapsedGameTime.TotalMilliseconds();
|
position.Y += 1 * gameTime.ElapsedGameTime.TotalMilliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
oldState = currentState;
|
||||||
|
const auto currentState = Mouse::GetState();
|
||||||
|
|
||||||
|
if (currentState.LeftButton == ButtonState::Pressed && oldState.LeftButton == ButtonState::Released) {
|
||||||
|
points.push_back(Vector2(currentState.X, currentState.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (position.X > 1280 || position.X < 0)
|
|
||||||
vel *= -1;
|
|
||||||
|
|
||||||
if (gameTime.ElapsedGameTime.TotalMilliseconds() > 1) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
position.X += 0.05 * (gameTime.ElapsedGameTime.TotalMilliseconds() * vel);*/
|
|
||||||
//position.X += 2 * vel;
|
|
||||||
|
|
||||||
Game::Update(gameTime);
|
Game::Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +65,11 @@ public:
|
|||||||
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||||
|
|
||||||
spriteBatch->Begin();
|
spriteBatch->Begin();
|
||||||
spriteBatch->Draw(*texture, position, nullptr, Colors::White, 0, { 0,0 }, 0.5F, SpriteEffects::None, 0);
|
// spriteBatch->Draw(*texture, position, nullptr, Colors::White, 0, { 0,0 }, 0.5F, SpriteEffects::None, 0);
|
||||||
|
for (size_t i = 0; i < points.size(); ++i) {
|
||||||
|
spriteBatch->Draw(*texture, points[i], nullptr, Colors::White, 0, {0,0}, 0.5F, SpriteEffects::None, 0);
|
||||||
|
}
|
||||||
|
|
||||||
spriteBatch->End();
|
spriteBatch->End();
|
||||||
|
|
||||||
Game::Draw(gameTime);
|
Game::Draw(gameTime);
|
||||||
@ -79,16 +80,14 @@ private:
|
|||||||
PSpriteBatch spriteBatch = nullptr;
|
PSpriteBatch spriteBatch = nullptr;
|
||||||
PTexture2D texture = nullptr;
|
PTexture2D texture = nullptr;
|
||||||
Vector2 position{};
|
Vector2 position{};
|
||||||
|
std::vector<Vector2> points;
|
||||||
|
MouseState currentState;
|
||||||
|
MouseState oldState;
|
||||||
float vel = 1;
|
float vel = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
|
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
|
||||||
/*FileStream stream("D:/VS_EXPBSLN_x64_enu.CAB");
|
auto game = Game1();
|
||||||
auto pos = stream.Position();
|
const auto result = game.Run();
|
||||||
auto len = stream.Length();
|
return result;
|
||||||
pos = stream.Position();*/
|
|
||||||
|
|
||||||
Game1 game;
|
|
||||||
game.Run();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,6 @@
|
|||||||
#include "platform/spritebatch-dx.hpp"
|
#include "platform/spritebatch-dx.hpp"
|
||||||
#include "common/color.hpp"
|
#include "common/color.hpp"
|
||||||
#include "platform/keyboard-dx.hpp"
|
#include "platform/keyboard-dx.hpp"
|
||||||
|
#include "platform/mouse-dx.hpp"
|
||||||
|
|
||||||
// TODO: Reference additional headers your program requires here.
|
// TODO: Reference additional headers your program requires here.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user