-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSiTRadar.cpp
209 lines (168 loc) · 4.9 KB
/
CSiTRadar.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "pch.h"
#include "CSiTRadar.h"
#include "TopMenu.h"
#include "SituPlugin.h"
#include "vatsimAPI.h"
map<string, ACData> CSiTRadar::mAcData;
map<int, string> CSiTRadar::slotTime;
bool CSiTRadar::canAmend;
int CSiTRadar::refreshStatus;
int CSiTRadar::amendStatus;
string CSiTRadar::eventCode;
POINT CSiTRadar::menu{ 10, 140 };
int CSiTRadar::tagLocation{ 2 };
CSiTRadar::CSiTRadar()
{
CDataHandler::GetVatsimAPIurlData();
time = clock();
oldTime = clock();
amendStatus = 1;
}
void CSiTRadar::OnRefresh(HDC hdc, int phase)
{
if (phase != REFRESH_PHASE_AFTER_TAGS && phase != REFRESH_PHASE_BEFORE_TAGS) {
return;
}
// set up the drawing renderer
CDC dc;
dc.Attach(hdc);
if (phase == REFRESH_PHASE_AFTER_TAGS) {
for (CRadarTarget radarTarget = GetPlugIn()->RadarTargetSelectFirst(); radarTarget.IsValid();
radarTarget = GetPlugIn()->RadarTargetSelectNext(radarTarget))
{
POINT p = ConvertCoordFromPositionToPixel(radarTarget.GetPosition().GetPosition());
string callSign = radarTarget.GetCallsign();
if (radarTarget.GetPosition().GetRadarFlags() != 0) {
if (mAcData[callSign].hasCTP) {
CFont font;
LOGFONT lgfont;
memset(&lgfont, 0, sizeof(LOGFONT));
lgfont.lfWeight = 500;
strcpy_s(lgfont.lfFaceName, _T("EuroScope"));
lgfont.lfHeight = 12;
font.CreateFontIndirect(&lgfont);
dc.SetTextColor(RGB(255,132,0));
RECT rectPAM;
// Toggle between location of tag, right, bottom or left
switch (tagLocation) {
case 0:
continue;
case 1:
rectPAM.left = p.x + 10;
rectPAM.right = p.x + 90; rectPAM.top = p.y - 6; rectPAM.bottom = p.y + 30;
break;
case 2:
rectPAM.left = p.x - 9;
rectPAM.right = p.x + 75; rectPAM.top = p.y + 8; rectPAM.bottom = p.y + 30;
break;
case 3:
rectPAM.left = p.x - 30;
rectPAM.right = p.x + 60; rectPAM.top = p.y - 6; rectPAM.bottom = p.y + 30;
break;
case 4:
rectPAM.left = p.x - 9;
rectPAM.right = p.x + 60; rectPAM.top = p.y - 18; rectPAM.bottom = p.y + 30;
break;
}
dc.DrawText(CDataHandler::tagLabel.c_str(), &rectPAM, DT_LEFT);
DeleteObject(font);
}
}
}
RECT but;
but = TopMenu::DrawButton(&dc, menu, 60, 23, "Refresh", autoRefresh);
ButtonToScreen(this, but, "Refresh Slot Data", BUTTON_MENU_REFRESH);
POINT m2 = menu;
m2.x = menu.x + 65;
but = TopMenu::DrawButton(&dc, m2, 60, 23, CSiTRadar::eventCode.c_str(), 0);
ButtonToScreen(this, but, "Settings", BUTTON_MENU_SETTINGS);
// if correct event code, draw a green square:
COLORREF targetPenColor = RGB(0, 150, 50);
if (amendStatus == 1) {
targetPenColor = RGB(255, 188, 5);
}
if (amendStatus == 2) {
targetPenColor = RGB(153, 36, 0);
}
InflateRect(&but, 1, 1);
HPEN targetPen = CreatePen(PS_SOLID, 2, targetPenColor);
dc.SelectObject(targetPen);
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(&but);
// Indicator to show tag is hidden
if (tagLocation == 0) {
dc.MoveTo(but.right - 5, but.top + 3);
dc.LineTo(but.right - 5, but.top + 5);
}
DeleteObject(targetPen);
}
if (autoRefresh) {
time = clock();
if ((time - oldTime) / CLOCKS_PER_SEC > CDataHandler::refreshInterval) {
CAsync* data = new CAsync();
data->Plugin = GetPlugIn();
_beginthread(CDataHandler::GetVatsimAPIData, 0, (void*) data);
oldTime = clock();
}
}
dc.Detach();
}
void CSiTRadar::OnClickScreenObject(int ObjectType,
const char* sObjectId,
POINT Pt,
RECT Area,
int Button)
{
if (ObjectType == BUTTON_MENU_REFRESH) {
if (Button == BUTTON_LEFT) {
CSiTRadar::canAmend = FALSE;
CSiTRadar::amendStatus = 1;
CAsync* data = new CAsync();
data->Plugin = GetPlugIn();
_beginthread(CDataHandler::GetVatsimAPIData, 0, (void*) data);
oldTime = clock(); }
if (Button == BUTTON_RIGHT) { autoRefresh = !autoRefresh; }
}
if (ObjectType == BUTTON_MENU_SETTINGS) {
if (Button == BUTTON_LEFT) {
GetPlugIn()->OpenPopupEdit(Area, FUNCTION_SET_URL, CSiTRadar::eventCode.c_str());
}
if (Button == BUTTON_RIGHT) {
// toggle between tag locations
if (tagLocation < 4) { tagLocation++; }
else { tagLocation = 0; }
}
}
}
void CSiTRadar::OnMoveScreenObject(int ObjectType,
const char* sObjectId,
POINT Pt,
RECT Area,
bool Released) {
if (ObjectType == BUTTON_MENU_REFRESH) {
menu.x = Pt.x - 30;
menu.y = Pt.y - 12;
}
}
void CSiTRadar::ButtonToScreen(CSiTRadar* radscr, RECT rect, string btext, int itemtype) {
AddScreenObject(itemtype, btext.c_str(), rect, 1, "");
}
void CSiTRadar::OnFlightPlanDisconnect(CFlightPlan FlightPlan) {
string callSign = FlightPlan.GetCallsign();
mAcData.erase(callSign);
}
void CSiTRadar::OnFunctionCall(int FunctionId,
const char* sItemString,
POINT Pt,
RECT Area) {
if (FunctionId == FUNCTION_SET_URL) {
try {
CSiTRadar::eventCode = sItemString;
}
catch (...) {}
CDataHandler::firstSlotPull = TRUE;
}
}
CSiTRadar::~CSiTRadar()
{
}