-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.cpp
More file actions
184 lines (175 loc) · 6.73 KB
/
render.cpp
File metadata and controls
184 lines (175 loc) · 6.73 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "render.h"
void Render_Map()
{
SDL_Rect mapRect{
(g.fWindowWidth/2.f) - g.fMapX * g.fMapZoom,
(g.fWindowHeight/2.f) - g.fMapY * g.fMapZoom,
g.fWindowHeight* g.fMapZoom,
g.fWindowHeight* g.fMapZoom };
SDL_RenderCopy(g.mainRenderer, g.mapTexture, 0, &mapRect);
}
void Render_CustomMapMarkers()
{
for (auto& myMarker : g.vecMyMarkers)
{
auto rect = Utils::GetRect(myMarker.first, myMarker.second, g.appInfo.mapsize(), g.appMap.width(), false, 40, 40);
SDL_RenderCopy(g.mainRenderer, Icons::myMarker, 0, &rect);
}
}
void Render_Events()
{
static float angle = 0.f;
angle += 10.f;
for (int i = 0; i < g.appMapMarkers.markers_size(); i++)
{
auto& marker = g.appMapMarkers.markers().Get(i);
if (marker.type() == Crate)
{
auto rect = Utils::GetRect(marker.x(), marker.y(), g.appInfo.mapsize(), g.appMap.width(), false, 32, 32);
SDL_RenderCopy(g.mainRenderer, Icons::crate, 0, &rect);
}
else if (marker.type() == Explosion)
{
auto rect = Utils::GetRect(marker.x(), marker.y(), g.appInfo.mapsize(), g.appMap.width(), false, 32, 32);
SDL_RenderCopy(g.mainRenderer, Icons::explosion, 0, &rect);
}
else if (marker.type() == CargoShip)
{
auto rect = Utils::GetRect(marker.x(), marker.y(), g.appInfo.mapsize(), g.appMap.width(), true, 32, 32);
SDL_RenderCopyEx(g.mainRenderer, Icons::cargo, 0, &rect, -marker.rotation() - 90.0, 0, SDL_FLIP_NONE);
}
else if (marker.type() == CH47 || marker.type() == PatrolHelicopter)
{
float x = marker.x() + 1000.f;
float y = g.appInfo.mapsize() - marker.y() + 1000.f;
float scale = g.appMap.width() / (g.fWindowWidth / 2.f);
x /= scale;
y /= scale;
SDL_Rect rect{
(g.fWindowWidth / 2.f) - (10.f * g.fMapZoom) + (x - g.fMapX) * g.fMapZoom,
(g.fWindowHeight / 2.f) - (10.f * g.fMapZoom) + (y - g.fMapY) * g.fMapZoom,
20.f * g.fMapZoom,
20.f * g.fMapZoom };
SDL_RenderCopyEx(g.mainRenderer, Icons::chinook, 0, &rect, -marker.rotation() - 90.0, 0, SDL_FLIP_NONE);
SDL_Rect rectBlades1{
(g.fWindowWidth / 2.f) - (6.f * g.fMapZoom) + (x + 6.f * sinf(DEG2RAD(marker.rotation())) - g.fMapX) * g.fMapZoom,
(g.fWindowHeight / 2.f) - (6.f * g.fMapZoom) + (y + 6.f * cosf(DEG2RAD(marker.rotation())) - g.fMapY) * g.fMapZoom,
12.f * g.fMapZoom,
12.f * g.fMapZoom };
SDL_Rect rectBlades2{
(g.fWindowWidth / 2.f) - (6.f * g.fMapZoom) + (x + 6.f * -sinf(DEG2RAD(marker.rotation())) - g.fMapX) * g.fMapZoom,
(g.fWindowHeight / 2.f) - (6.f * g.fMapZoom) + (y + 6.f * -cosf(DEG2RAD(marker.rotation())) - g.fMapY) * g.fMapZoom,
12.f * g.fMapZoom,
12.f * g.fMapZoom };
SDL_RenderCopyEx(g.mainRenderer, Icons::blade, 0, &rectBlades1, angle, 0, SDL_FLIP_NONE);
SDL_RenderCopyEx(g.mainRenderer, Icons::blade, 0, &rectBlades2, -angle, 0, SDL_FLIP_NONE);
}
else if (marker.type() == VendingMachine)
{
//marker.sellorders().Get(0).
}
}
}
void Render_Markers()
{
//Draw Team markers
for (int i = 0; i < g.appTeamInfo.leadermapnotes_size(); i++)
{
auto& teamMarker = g.appTeamInfo.leadermapnotes().Get(i);
float x = teamMarker.x() + 1000.f;
float y = g.appInfo.mapsize() - teamMarker.y() + 1000.f;
float scale = g.appMap.height() / (g.fWindowHeight / 2.f);
x /= scale;
y /= scale;
SDL_Rect rectMarker{
(g.fWindowWidth / 2.f) - 16.f + (x - g.fMapX) * g.fMapZoom,
(g.fWindowHeight / 2.f) - 32.f + (y - g.fMapY) * g.fMapZoom,
32.f,
32.f };
SDL_RenderCopy(g.mainRenderer, Icons::marker, 0, &rectMarker);
}
//Draw markers
for (int i = 0; i < g.appTeamInfo.mapnotes_size(); i++)
{
auto& teamMarker = g.appTeamInfo.mapnotes().Get(i);
float x = teamMarker.x() + 1000.f;
float y = g.appInfo.mapsize() - teamMarker.y() + 1000.f;
float scale = g.appMap.height() / (g.fWindowHeight / 2.f);
x /= scale;
y /= scale;
SDL_Rect rectMarker{
(g.fWindowWidth / 2.f) - 16.f + (x - g.fMapX) * g.fMapZoom,
(g.fWindowHeight / 2.f) - (teamMarker.type() ? 32.f : 16.f) + (y - g.fMapY) * g.fMapZoom,
32.f,
32.f };
SDL_RenderCopy(g.mainRenderer, teamMarker.type() ? Icons::marker : Icons::death, 0, &rectMarker);
}
}
void Render_TeamMembers()
{
for (int i = 0; i < g.appTeamInfo.members_size(); i++)
{
auto& member = g.appTeamInfo.members().Get(i);
if (g.bFocus && member.steamid() == g.jID)
{
float x = member.x() + 1000.f;
float y = g.appInfo.mapsize() - member.y() + 1000.f;
float scale = g.appMap.height() / (g.fWindowHeight / 2.f);
x /= scale;
y /= scale;
g.fMapX = x;
g.fMapY = y;
}
auto rect = Utils::GetRect(member.x(), member.y(), g.appInfo.mapsize(), g.appMap.width(), false, 16, 16);
SDL_RenderCopy(g.mainRenderer, member.isalive() ? member.isonline() ? Icons::player : Icons::playerOff : Icons::playerDead, 0, &rect);
auto nametag = g.nametags.find(member.name());
if (nametag == g.nametags.end() && !member.name().empty()) // tex doesnt exist
{
Utils::CreateNametagTexture(member.name(),g.mainRenderer,g.nametags, { 170, 255, 0 });
nametag = g.nametags.find(member.name());
}
if (nametag == g.nametags.end())
return;
rect.x -= nametag->second.w / 2 - 8;
rect.y -= nametag->second.h;
rect.w = nametag->second.w;
rect.h = nametag->second.h;
SDL_RenderCopy(g.mainRenderer, nametag->second.m_Texture, 0, &rect);
}
}
void Render_GUI()
{
for (GUIElement* element : GUI::Elements()) {
if (element->m_bEnabled) {
if (Block* block = dynamic_cast<Block*>(element)) {
SDL_RenderCopy(g.mainRenderer, block->m_Texture, 0, &block->rect);
}
if (Button* button = dynamic_cast<Button*>(element)) {
SDL_RenderCopy(g.mainRenderer, button->m_Texture, 0, &button->rect);
}
if (Checkbox* checkbox = dynamic_cast<Checkbox*>(element)) {
SDL_RenderCopy(g.mainRenderer, checkbox->m_bChecked ? checkbox->m_texChecked : checkbox->m_texUnChecked, 0, &checkbox->rect);
}
if (Label* label = dynamic_cast<Label*>(element)) {
SDL_RenderCopy(g.mainRenderer, label->m_Texture, 0, &label->rect);
}
if (TextInput* textInput = dynamic_cast<TextInput*>(element)) {
SDL_RenderCopy(g.mainRenderer, textInput->m_Texture, 0, &textInput->rect);
}
}
}
}
extern SDL_Renderer* cameraRenderer;
void Render_CameraWindow()
{
static SDL_Window* window = SDL_CreateWindow("Camera Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 160*PIXEL_SIZE, 90*PIXEL_SIZE, 0);
SDL_SetWindowTitle(window, g.activeCamera.c_str());
if(!cameraRenderer)
cameraRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_ShowWindow(window);
// Clear the renderer to black
SDL_SetRenderDrawColor(cameraRenderer, 0, 0, 0, 255);
SDL_RenderClear(cameraRenderer);
// Update the window
SDL_RenderPresent(cameraRenderer);
}