-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGFXWindow.cpp
More file actions
151 lines (126 loc) · 4.65 KB
/
Copy pathGFXWindow.cpp
File metadata and controls
151 lines (126 loc) · 4.65 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
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
143
144
145
146
147
148
#include "GFXWindow.h"
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <fcntl.h>
int GFX::Window::RUN(){
if (debugFlag && AllocConsole()) {
int ifd = _open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT);
int ofd = _open_osfhandle((intptr_t)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
*stdin = *_fdopen(ifd, "r");
*stdout = *_fdopen(ofd, "w");
}
MSG msg = {0};
POINT p = {0, 0};
bool reset = false;
//Vec2d p(Width/2+100, Height/2-40);
std::vector<GFX::Math::Vec2d> trgPoints(3);
//{(243, 46), (362, 185), (148, 372)} {0, 0}, {150, 100}, {30, 80}
//(23, 177), (360, 216), (244, 356) , (22, 195), (361, 200), (259, 351)
GFX::Math::Triangle2d trg({243, 46}, {362, 185}, {148, 372});
double phi = 0;
GFX::Math::Vec2d cntrCircle = {Width/2.0f-10, Height/2.0f+10};
GFX::Math::Vec2d point = trg.GetTriangleCentre();
int counter = 0;
while (true){
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)){
DispatchMessage(&msg);
if (msg.message == WM_QUIT) {
break;
}
}
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), {0, 0});
//printf("Points %d: ", counter); PrintVector(trgPoints);
if (GetAsyncKeyState('R')) reset = true;
if (GetAsyncKeyState(RI_MOUSE_BUTTON_1_UP) && reset){
GetCursorPos(&p);
ScreenToClient(WindowHandle, &p);
if (counter == 0){
trgPoints[0] = GFX::Math::Vec2d(p.x, p.y);
counter++;
} else{
if (trgPoints[counter-1] != GFX::Math::Vec2d(p.x, p.y)){
trgPoints[counter] = GFX::Math::Vec2d(p.x, p.y);
counter++;
//printf("%d %d %d\n", p.x, p.y, counter);
}
if (counter > 2) {
counter = 0;
trg = GFX::Math::Triangle2d(trgPoints);
reset = false;
printf("Done\n");
}
}
}
phi += 0.01 ;
if (abs(phi) > 2*M_PI) phi = 0;
//trg.RotateTriangle(0, 0, M_PI/6);
//SCR->SetPixel(p.x, p.y, {255, 0, 0});
SCR->FillColor({0, 0, 0});
printf("Triangle: "); PrintTriangle2d(GFX::Math::RotateTriangle2d(trg, point, phi));
printf("%f\n", phi);
if (!reset){
point = trg.GetTriangleCentre();
SCR->PlotTriangle2d(GFX::Math::RotateTriangle2d(trg, point, phi), {255, 255, 0});
}
//Vec2d cntrCircle = RotatePoint(Vec2d(Width/2, Height/2), cntrCircle, phi);
//SCR->PlotCircle(cntrCircle.x, cntrCircle.y, 50, true, {255, 255, 0});
TransferBufferToWindow();
Sleep(10);
}
fclose(stdout);
fclose(stdin);
return 0;
}
GFX::Window::Window(int x, int y, int W, int H, std::wstring Title,
std::wstring ClassName, HINSTANCE hInstance, DWORD Style) : Width(W), Height(H)
{
SCR = new GFX::Screen(W, H);
WindowClass = {0};
WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WindowClass.hIcon = LoadIcon(NULL, IDI_QUESTION);
WindowClass.hInstance = hInstance;
WindowClass.lpszClassName = ClassName.c_str();
WindowClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
WindowClass.lpfnWndProc = WinProcedure;
if (RegisterClass(&WindowClass)){
WindowHandle = CreateWindowW(ClassName.c_str(), Title.c_str(), Style, x, y, W, H, NULL, NULL, NULL, NULL);
}
GFX::currentWindow = this;
}
GFX::Window* GFX::Window::ReceiveWindow(){
return currentWindow;
}
GFX::Window::~Window(){
delete SCR;
}
void GFX::Window::Resize(int W, int H){
Width = W, Height = H;
SCR->Resize(W, H);
}
void GFX::Window::TransferBufferToWindow(){
HBITMAP hBitMap = CreateBitmap(Width, Height, 1, 8 * 4, SCR->GetFrameBuffer());
HDC hdc = GetDC(WindowHandle);
HDC hdcSrc = CreateCompatibleDC(hdc);
SelectObject(hdcSrc, hBitMap);
BitBlt(hdc, 0, 0, Width, Height, hdcSrc, 0, 0, SRCCOPY);
DeleteObject(hBitMap);
DeleteDC(hdcSrc);
DeleteDC(hdc);
}
LRESULT CALLBACK GFX::Window::WinProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
switch (msg) {
case WM_CREATE:
break;
/*case WM_SIZE:{
int newW = LOWORD(lp), newH = HIWORD(lp);
if (currentWindow != nullptr &&
(currentWindow->Width < newW || currentWindow->Height < newH))
currentWindow->Resize(newW, newH);
} break;*/
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msg, wp, lp);
}