-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint.cpp
144 lines (128 loc) · 5.62 KB
/
paint.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "paint.h"
#define BGCOLOR RGB(28, 48, 68)
HBRUSH bg = CreateSolidBrush(BGCOLOR);
RECT createRECT(int left, int top, int width, int height)
{
RECT rect = RECT();
rect.left = left;
rect.top = top;
rect.right = width+left;
rect.bottom = height+top;
return rect;
}
void drawText(HDC* hdc, std::string txt, RECT rect, unsigned int flag, COLORREF bgcol)
{
COLORREF oldBGcol = GetBkColor(*hdc);
if (bgcol == NULL)
bgcol = oldBGcol;
std::wstring stemp = std::wstring(txt.begin(), txt.end());
LPCWSTR sw = stemp.c_str();
SetBkColor(*hdc, bgcol);
DrawText(*hdc, sw, -1, &rect, flag);
SetBkColor(*hdc, oldBGcol);
}
bool intersecting(RECT rect1, RECT rect2)
{
if (rect1.left >= rect2.right || rect2.left >= rect1.right)
return false;
// If one rectangle is above other
if (rect1.top >= rect2.bottom || rect2.top >= rect1.bottom)
return false;
return true;
}
void pnt(HWND hWnd, RECT* region)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HDC buffer = CreateCompatibleDC(hdc);
HBITMAP buffermap = CreateCompatibleBitmap(hdc, 784, 615);
SelectObject(buffer, buffermap);
FillRect(buffer, &ps.rcPaint, bg);
COLORREF tempCol;
RECT temprect;
switch (globals::curScreen)
{
case 0:
tempCol = globals::NewGame->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::NewGame->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::NewGame->text, temprect, globals::NewGame->txtFlag, tempCol);
tempCol = globals::Continue->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::Continue->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::Continue->text, temprect, globals::Continue->txtFlag, tempCol);
tempCol = globals::Options0->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::Options0->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::Options0->text, temprect, globals::Options0->txtFlag, tempCol);
tempCol = globals::End->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::End->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::End->text, temprect, globals::End->txtFlag, tempCol);
break;
case 1:
tempCol = globals::ExitOps->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::ExitOps->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::ExitOps->text, temprect, globals::ExitOps->txtFlag, tempCol);
break;
case 2:
tempCol = globals::Resume->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::Resume->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::Resume->text, temprect, globals::Resume->txtFlag, tempCol);
tempCol = globals::Options->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::Options->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::Options->text, temprect, globals::Options->txtFlag, tempCol);
tempCol = globals::Exit->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
temprect = globals::Exit->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::Exit->text, temprect, globals::Exit->txtFlag, tempCol);
break;
case 3:
stage* background = globals::g_level->background;
stage* foreground = globals::g_level->foreground;
std::vector<tile*>* dat = &background[(globals::g_player->Cx) + (globals::g_player->Cy * globals::g_level->lw)].data;
if (background[(globals::g_player->Cx) + (globals::g_player->Cy * globals::g_level->lw)].exists) {
for (unsigned char i = 0; i < 108; i++)
{
temprect = createRECT((i % 12) * 64, int(floor(i / 12)) * 64, 64, 64);
if (intersecting(temprect, *region)) dat->at(i)->draw(&buffer, temprect.left, temprect.top);
}
}
dat = &foreground[(globals::g_player->Cx) + (globals::g_player->Cy * globals::g_level->lw)].data;
if (foreground[(globals::g_player->Cx) + (globals::g_player->Cy * globals::g_level->lw)].exists) {
for (unsigned char i = 0; i < 108; i++)
{
temprect = createRECT((i % 12) * 64, int(floor(i / 12)) * 64, 64, 64);
if (intersecting(temprect, *region)) dat->at(i)->draw(&buffer, temprect.left, temprect.top);
}
}
if (intersecting(globals::g_player->rect, *region)) globals::g_player->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
for (unsigned short i = 0; i < globals::g_ScreenObjects.size(); i++)
{
if (intersecting(globals::g_ScreenObjects.at(i)->rect, *region))
{
if (globals::g_debug == false and globals::g_ScreenObjects.at(i)->debug == true)
globals::g_ScreenObjects.at(i)->hide();
else if (globals::g_ScreenObjects.at(i)->debug == true)
globals::g_ScreenObjects.at(i)->show();
if (globals::g_ScreenObjects.at(i)->visible)
{
COLORREF tempCol = globals::g_ScreenObjects.at(i)->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
SelectObject(buffer, buffermap);
RECT temprect = globals::g_ScreenObjects.at(i)->rect;
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
drawText(&buffer, globals::g_ScreenObjects.at(i)->text, temprect, globals::g_ScreenObjects.at(i)->txtFlag, tempCol);
}
}
}
break;
}
BitBlt(hdc, 0, 0, 784, 615, buffer, 0, 0, SRCCOPY);
DeleteDC(buffer);
DeleteDC(hdc);
DeleteObject(buffermap);
EndPaint(hWnd, &ps);
}