-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellInfoWindow.cpp
130 lines (107 loc) · 2.83 KB
/
CellInfoWindow.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
#include "CellInfoWindow.h"
#include "include.h"
#include "world.h"
#include "Cell.h"
#include "RenderClass.h"
#include "Camera.h"
#include "ChemicalContainer.h"
#include "Chunk.h"
#include "NeuralNetwork.h"
CellInfoWindow::CellInfoWindow(HINSTANCE hIns, World* w, RenderClass* render)
{
hInstance = hIns;
world = w;
this->render = render;
cam = render->GetCamera();
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = Proc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "eveCellInfo";
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL, "Call to RegisterClassEx on info failed!", "Eve", NULL);
}
hWnd = CreateWindow("eveCellInfo", "Eve Cell Info", WS_VISIBLE | WS_OVERLAPPEDWINDOW, 0, 0, 350, 1000, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
MessageBox(NULL, "Call to CreateWindow on info failed!", "Eve", NULL);
}
RECT desktop;
GetWindowRect(GetDesktopWindow(), &desktop);
SetWindowPos(hWnd, HWND_TOP, desktop.right - 25 - 350, 25, 0, 0, SWP_NOSIZE || SWP_SHOWWINDOW);
RECT rect;
GetWindowRect(hWnd, &rect);
textLabel = CreateWindow("STATIC", "not initilized", WS_VISIBLE | WS_CHILD | SS_LEFT, 0, 0, rect.right, rect.bottom, hWnd, NULL, hInstance, NULL);
WriteInfoData();
ShowWindow(hWnd, 1);
UpdateWindow(hWnd);
}
void CellInfoWindow::SetClosestCellAsCurrentCell()
{
//yes the real distance is the root of d but since we are just comparing this is equivalent to comparing the real distance
float d = -1;
float cd = 0;
XMFLOAT4* camPos = cam->GetPosition();
Cell* newCCell = nullptr;
for (Cell* c : *world->GetCellVec())
{
cd = pow(c->GetPositionX() - camPos->x, 2) + pow(c->GetPositionY() - camPos->y, 2) + pow(c->GetPositionZ() - camPos->z, 2);
if (d == -1 || cd < d)
{
d = cd;
newCCell = c;
}
}
SetCellAsCurrentCell(newCCell);
}
void CellInfoWindow::SetCellAsCurrentCell(Cell* newCCell)
{
if (currentCell)
{
currentCell->SetSelected(false);
}
currentCell = newCCell;
if (newCCell)
{
newCCell->SetSelected(true);
}
}
void CellInfoWindow::WriteInfoData()
{
string buffer = "";
if (currentCell != nullptr)
{
buffer += currentCell->GetOutputString();
}
SetWindowText(textLabel, TEXT(buffer.c_str()));
}
LRESULT CellInfoWindow::Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
{
//world->WriteInfoData();
break;
}
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
}
return 0;
}
CellInfoWindow::~CellInfoWindow()
{
}