Changes
This commit is contained in:
+28
-3
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "def.h"
|
||||
#include "hbp.h"
|
||||
|
||||
struct KeyStatus {
|
||||
String name;
|
||||
@@ -26,13 +27,22 @@ struct KeyStatus {
|
||||
struct KeyBinding;
|
||||
|
||||
class InteractManager {
|
||||
inline static TRACKMOUSEEVENT trackMouseEvent{
|
||||
.cbSize = sizeof(TRACKMOUSEEVENT),
|
||||
.dwFlags = TME_HOVER | TME_LEAVE | TME_NONCLIENT,
|
||||
.hwndTrack = nullptr,
|
||||
.dwHoverTime = 0
|
||||
};
|
||||
KeyStatus keyStatus[256];
|
||||
int mouseX = 0, mouseY = 0;
|
||||
int mouseWheel = 0;
|
||||
int rebindResult = 0;
|
||||
bool rebinding = false;
|
||||
bool inWindow = false; // 鼠标是否在窗口内部
|
||||
bool inWindow = false;// 鼠标是否在窗口内部
|
||||
bool hovering = false;
|
||||
|
||||
public:
|
||||
static void initialize() noexcept { trackMouseEvent.hwndTrack = MainWindowHandle; }
|
||||
explicit InteractManager();
|
||||
|
||||
void update(const int keyCode, const bool isPressed) noexcept {
|
||||
@@ -51,14 +61,29 @@ public:
|
||||
void updateMouse(const int x, const int y) noexcept {
|
||||
mouseX = x;
|
||||
mouseY = y;
|
||||
std::wcout << x << " " << y << std::endl;
|
||||
inWindow = true;
|
||||
hovering = false;
|
||||
if (!TrackMouseEvent(&trackMouseEvent)) std::wcout << L"TrackMouseEvent failed. LastError: " << GetLastError() << std::endl;
|
||||
}
|
||||
|
||||
void mouseHover() noexcept {
|
||||
hovering = true;
|
||||
inWindow = true;
|
||||
std::wcout << L"hover" << std::endl;
|
||||
}
|
||||
|
||||
void mouseLeave() noexcept {
|
||||
inWindow = false;
|
||||
hovering = false;
|
||||
std::wcout << L"leave" << std::endl;
|
||||
}
|
||||
|
||||
void updateWheel(const int wheel) noexcept { mouseWheel += wheel; }
|
||||
|
||||
[[nodiscard]] int getMouseX() const noexcept { return mouseX; }
|
||||
[[nodiscard]] int getMouseY() const noexcept { return mouseY; }
|
||||
[[nodiscard]] int getMouseWheel() const noexcept { return mouseWheel; }
|
||||
[[nodiscard]] bool isHovering() const noexcept { return hovering; }
|
||||
[[nodiscard]] bool isInWindow() const noexcept { return inWindow; }
|
||||
KeyStatus& getKey(const int keyCode) noexcept { return keyStatus[keyCode]; }
|
||||
KeyStatus& getKey(const KeyBinding& binding) noexcept;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user