-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.h
53 lines (43 loc) · 933 Bytes
/
Window.h
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
#pragma once
#include <Windows.h>
#include <string>
class Window {
public:
HWND hwnd;
HINSTANCE hinstance;
std::string name;
int width;
int height;
bool keys[256];
int mousex;
int mousey;
bool mouseButtons[3];
void create(int window_width, int window_height, const std::string window_name);
void processMessages();
bool keyPressed(int key) {
return keys[key];
}
void updateMouse(int x, int y) {
mousex = x;
mousey = y;
}
// Restricts the mouse cursor to the window's client area
void clipMouseToWindow()
{
RECT rect;
GetClientRect(hwnd, &rect);
POINT ul;
ul.x = rect.left;
ul.y = rect.top;
POINT lr;
lr.x = rect.right;
lr.y = rect.bottom;
MapWindowPoints(hwnd, nullptr, &ul, 1);
MapWindowPoints(hwnd, nullptr, &lr, 1);
rect.left = ul.x;
rect.top = ul.y;
rect.right = lr.x;
rect.bottom = lr.y;
ClipCursor(&rect);
}
};