mirror of
https://github.com/rrika/cdcEngineDXHR.git
synced 2025-02-21 22:30:28 +00:00
implement PCMouseKeyboard::setCursorGrab, press TAB to activate
This commit is contained in:
parent
2f1419aa2f
commit
7e14dbc00e
@ -3,11 +3,11 @@
|
||||
namespace cdc {
|
||||
|
||||
void InputProducer::method_0() { /*TODO*/ }
|
||||
void InputProducer::method_4() { /*TODO*/ }
|
||||
void InputProducer::setCursorGrab(bool active) { cursorGrab = active; }
|
||||
void InputProducer::method_8() { /*TODO*/ }
|
||||
void InputProducer::method_C() { /*TODO*/ }
|
||||
void InputProducer::method_10() { /*TODO*/ }
|
||||
void InputProducer::method_14() { /*TODO*/ }
|
||||
void InputProducer::update() { /*TODO*/ }
|
||||
void InputProducer::method_18() { /*TODO*/ }
|
||||
void InputProducer::method_1C() { /*TODO*/ }
|
||||
void InputProducer::method_20() { /*TODO*/ }
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
namespace cdc {
|
||||
|
||||
struct InputProducerSub4 {
|
||||
uint8_t gap0[85];
|
||||
float float58;
|
||||
float float5C;
|
||||
struct InputState {
|
||||
uint8_t keys[85];
|
||||
float deltaX; // 58
|
||||
float deltaY; // 5C
|
||||
float float60;
|
||||
};
|
||||
|
||||
@ -22,22 +22,23 @@ struct InputProducerSub6C {
|
||||
};
|
||||
|
||||
class InputProducer {
|
||||
protected:
|
||||
// InputProducerSub4 sub4;
|
||||
// protected:
|
||||
public:
|
||||
InputState state;
|
||||
// uint8_t gap68[4];
|
||||
// InputProducerSub6C sub6C;
|
||||
// float float7C[2];
|
||||
// uint8_t byte84;
|
||||
// uint8_t byte85;
|
||||
// uint8_t byte86;
|
||||
bool cursorGrab; // 86
|
||||
// uint32_t dword88;
|
||||
public:
|
||||
virtual void method_0();
|
||||
virtual void method_4();
|
||||
virtual void setCursorGrab(bool active);
|
||||
virtual void method_8();
|
||||
virtual void method_C();
|
||||
virtual void method_10();
|
||||
virtual void method_14();
|
||||
virtual void update();
|
||||
virtual void method_18();
|
||||
virtual void method_1C();
|
||||
virtual void method_20();
|
||||
|
@ -1,10 +1,17 @@
|
||||
#define NOMINMAX
|
||||
#include "PCMouseKeyboard.h"
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <hidusage.h>
|
||||
#endif
|
||||
|
||||
extern HWND hwnd2;
|
||||
|
||||
float g_mouseXSensitivity2 = 0.00135f;
|
||||
float g_mouseYSensitivity2 = 0.00135f;
|
||||
|
||||
namespace cdc {
|
||||
|
||||
PCMouseKeyboard::PCMouseKeyboard() {
|
||||
@ -32,9 +39,54 @@ void PCMouseKeyboard::processWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
}
|
||||
|
||||
// printf("WM_INPUT with type %lu\n", input.header.dwType);
|
||||
|
||||
if (input.header.dwType == RIM_TYPEMOUSE) {
|
||||
deltaX += input.data.mouse.lLastX;
|
||||
deltaY += input.data.mouse.lLastY;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void PCMouseKeyboard::setCursorPos(float x, float y) {
|
||||
#ifdef _WIN32
|
||||
if (cursorGrab) {
|
||||
RECT rect;
|
||||
GetClientRect(hwnd2, &rect);
|
||||
POINT point;
|
||||
point.x = rect.right * std::clamp(x, 0.0f, 1.0f);
|
||||
point.y = rect.bottom * std::clamp(y, 0.0f, 1.0f);
|
||||
ClientToScreen(hwnd2, &point);
|
||||
SetCursorPos(point.x, point.y);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PCMouseKeyboard::setupClip() {
|
||||
#ifdef _WIN32
|
||||
if (!cursorGrab) {
|
||||
ClipCursor(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (true /* !fullscreen */) {
|
||||
GetClientRect(hwnd2, &m_rect);
|
||||
ClientToScreen(hwnd2, reinterpret_cast<POINT*>(&m_rect.left));
|
||||
ClientToScreen(hwnd2, reinterpret_cast<POINT*>(&m_rect.right));
|
||||
ClipCursor(&m_rect);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PCMouseKeyboard::centerCursor(bool unknown) {
|
||||
// TODO
|
||||
if (cursorGrab) {
|
||||
if (unknown) {
|
||||
setCursorPos(0.5f, 0.5f);
|
||||
}
|
||||
}
|
||||
setupClip();
|
||||
}
|
||||
|
||||
// signature is bool create() in original binary
|
||||
PCMouseKeyboard *PCMouseKeyboard::create(HWND hwnd) {
|
||||
#ifdef _WIN32
|
||||
@ -100,8 +152,25 @@ void PCMouseKeyboard::assignDefaultKeybinds(Keybind *keybinds) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void PCMouseKeyboard::method_4() { /*TODO*/ }
|
||||
void PCMouseKeyboard::method_14() { /*TODO*/ }
|
||||
void PCMouseKeyboard::setCursorGrab(bool active) {
|
||||
cursorGrab = active;
|
||||
centerCursor(false); // so, don't actually center
|
||||
}
|
||||
|
||||
void PCMouseKeyboard::update() {
|
||||
state = InputState();
|
||||
|
||||
// TODO
|
||||
|
||||
state.deltaX = deltaX * g_mouseXSensitivity2;
|
||||
state.deltaY = deltaY * g_mouseYSensitivity2;
|
||||
|
||||
// TODO
|
||||
|
||||
deltaX = 0;
|
||||
deltaY = 0;
|
||||
}
|
||||
|
||||
void PCMouseKeyboard::method_18() { /*TODO*/ }
|
||||
|
||||
}
|
||||
|
@ -14,12 +14,15 @@ public:
|
||||
#ifdef _WIN32
|
||||
void processWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
#endif
|
||||
void setCursorPos(float x, float y);
|
||||
void setupClip();
|
||||
void centerCursor(bool);
|
||||
|
||||
static PCMouseKeyboard *create(HWND hwnd);
|
||||
static void assignDefaultKeybinds(Keybind *keybinds);
|
||||
|
||||
void method_4() override;
|
||||
void method_14() override;
|
||||
void setCursorGrab(bool active) override;
|
||||
void update() override;
|
||||
void method_18() override;
|
||||
|
||||
// uint8_t gap8C[4];
|
||||
@ -28,10 +31,10 @@ public:
|
||||
// uint8_t gap92[2];
|
||||
// uint32_t dword94;
|
||||
// float float98;
|
||||
// uint8_t gap9C[16];
|
||||
RECT m_rect; // 9C
|
||||
// uint32_t dwordAC;
|
||||
// uint32_t dwordB0;
|
||||
// uint32_t dwordB4;
|
||||
int32_t deltaX = 0;
|
||||
int32_t deltaY = 0;
|
||||
// uint32_t dwordB8;
|
||||
// uint32_t dwordBC;
|
||||
// char vkeysC0[257];
|
||||
|
@ -658,6 +658,8 @@ int spinnyCube(HWND window,
|
||||
uint32_t selectedCapture = 0;
|
||||
#endif
|
||||
|
||||
bool mouseLook = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
#ifdef WIN32
|
||||
@ -691,12 +693,28 @@ int spinnyCube(HWND window,
|
||||
}
|
||||
#endif
|
||||
|
||||
mouseKeyboard->update();
|
||||
|
||||
#if ENABLE_IMGUI
|
||||
ImGui_ImplDX11_NewFrame();
|
||||
ImGui_ImplWin32_NewFrame(); // this will reset our pretty cursor
|
||||
ImGui::NewFrame();
|
||||
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Tab)) {
|
||||
mouseLook = !mouseLook;
|
||||
mouseKeyboard->setCursorGrab(mouseLook);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
SetCursor((HCURSOR)yellowCursor); // ahh, much better
|
||||
if (mouseLook) {
|
||||
// ImGui::SetMouseCursor(ImGuiMouseCursor_None);
|
||||
SetCursor((HCURSOR)0);
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NoMouse;
|
||||
} else {
|
||||
// ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow);
|
||||
SetCursor((HCURSOR)yellowCursor); // ahh, much better
|
||||
io.ConfigFlags &= ~ImGuiConfigFlags_NoMouse;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -721,6 +739,11 @@ int spinnyCube(HWND window,
|
||||
modelRotation.y += 0.009f;
|
||||
modelRotation.z += 0.001f;
|
||||
|
||||
if (mouseLook) {
|
||||
modelRotation.x += mouseKeyboard->state.deltaY;
|
||||
modelRotation.y += mouseKeyboard->state.deltaX;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float4x4 world = rotateZ * rotateY * rotateX;
|
||||
@ -795,6 +818,8 @@ int spinnyCube(HWND window,
|
||||
if (ImGui::MenuItem("Show strings")) { showStringsWindow = true; }
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (mouseLook)
|
||||
ImGui::Text("Press TAB to release cursor");
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user