-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.h
More file actions
61 lines (46 loc) · 1.23 KB
/
Copy pathWindow.h
File metadata and controls
61 lines (46 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#define NOMINMAX
#include <windows.h>
#include <string>
#define WINDOW_GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#define WINDOW_GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
class Window {
public:
HWND hwnd; //is a number that corresponds to a window
HINSTANCE hinstance;
std::string name;
int width;
int height;
POINT center;
RECT clientRect;
bool keys[256];
int mousex;
int mousey;
int deltaX;
int deltaY;
bool mouseButtons[3];
int mouseWheel;
bool ignoreMouseMovement = false; //this is for setting the cursor to the center of the screen (so that you dont use that mvmt)
void init(int window_width, int window_height, std::string window_name);
void processMessages();
void updateMouse(int x, int y)
{
if (!ignoreMouseMovement)
{
deltaX = x - center.x;
deltaY = y - center.y;
ignoreMouseMovement = true;
ClientToScreen(hwnd, ¢er);//references window position every call - fixes for if window moves
SetCursorPos(center.x, center.y);
}
else {
ignoreMouseMovement = false;
}
}
void updateMouseOnScreen() {
GetClientRect(hwnd, &clientRect);
center.x = (clientRect.right - clientRect.left) / 2;
center.y = (clientRect.bottom - clientRect.top) / 2;
ClipCursor(&clientRect);
}
};