1
2#include "../ExternalCameraOverlay.h"
3#include "../Dialogs/ExternalCameraDialogVisibility.h"
4#include "NativeUiTest11.h"
5#include <wrl/client.h>
6#include <algorithm>
7#include <cstdlib>
8#include <iostream>
9#include <limits>
10#include <vector>
11
12using Microsoft::WRL::ComPtr;
13static void Check(bool pass, const char* what)
14{
15 if (!pass) { std::cerr << "FAIL: " << what << '\n'; std::exit(1); }
16}
17static void HR(
HRESULT hr,
const char* what) { Check(SUCCEEDED(hr), what); }
18
19static void CheckDialogVisibility()
20{
22 bool active = false, minimized = false;
23 const auto update = [&](bool external, bool hidden = false, bool allMinimized = false)
24 {
25 return visibility.
Update(external, hidden, allMinimized, active, minimized);
26 };
27 Check(!update(false) && !active, "cockpit starts hidden");
28 Check(update(true) && active, "external entry opens dialog");
29 active = false;
30 Check(!update(true) && !active, "staying external respects close");
31 update(true, true); update(true);
32 Check(!active, "keymap does not reopen a closed dialog");
33 active = true;
34 update(true, true); update(true, true);
35 Check(!active, "keymap/time lapse temporarily hides dialog");
36 update(true);
37 Check(active, "leaving temporary overlay restores open dialog");
38 active = false; minimized = true;
39 update(true);
40 Check(!active && minimized, "staying external respects minimize all");
41 update(false);
42 Check(!active && !minimized, "leaving external clears pending restore");
43 Check(update(true, false, true) && !active && minimized, "entry respects minimize all");
44 active = true; minimized = false;
45 update(true);
46 Check(active, "restored external dialog stays open");
47 update(true, true); update(false, true); update(true, true);
48 Check(!active, "entering external while keymap is open stays hidden");
49 update(true);
50 Check(active, "entry under keymap opens when keymap closes");
51}
52
53static void CheckFlightReadouts()
54{
61 const auto checkAltitude = [&](const wchar_t* value, const wchar_t* units)
62 {
64 Check(result.value == value && std::wstring(result.units) == units,
65 "altitude value, reference, and units agree at flight boundaries");
66 };
67 const auto checkSpeed = [&](const wchar_t* value, const wchar_t* label, const wchar_t* units)
68 {
70 Check(result.value == value && std::wstring(result.label) == label && std::wstring(result.units) == units,
71 "speed source, label, and units agree at flight boundaries");
72 };
73 checkAltitude(L"999", L"M / AGL");
74 checkSpeed(L"70", L"AIRSPEED", L"M/S");
76 checkAltitude(L"1.00", L"KM / AGL");
78 checkAltitude(L"2.35", L"KM / AGL");
80 checkAltitude(L"0", L"M / AGL");
83 checkAltitude(L"10.00", L"KM / MSL");
84 checkSpeed(L"0.10", L"GROUND SPEED", L"KM/S");
87 checkAltitude(L"150", L"KM / MSL");
88 checkSpeed(L"8.13", L"GROUND SPEED", L"KM/S");
91 checkSpeed(L"-36", L"GROUND SPEED", L"KM/H");
93 checkSpeed(L"-36", L"GROUND SPEED", L"KM/H");
96 checkAltitude(L"--", L"AGL");
97 checkSpeed(L"--", L"AIRSPEED", L"M/S");
98 flight.
altitudeMslKm = std::numeric_limits<float>::quiet_NaN();
99 checkAltitude(L"--", L"");
100 checkSpeed(L"--", L"SPEED", L"");
102 checkAltitude(L"--", L"");
103 checkSpeed(L"--", L"SPEED", L"");
104}
105
106int main(
int argc,
char** argv)
107{
108 CheckDialogVisibility();
109 CheckFlightReadouts();
114 Check(std::fabs(wide -
RiseMath::Pi / 2) < 0.001f && zoomed < wide,
115 "view cone uses flipped projection and narrows as zoom increases");
116
117 const bool warp = argc > 2 && std::string(argv[2]) == "--warp";
118 NativeUiTest11 fixture(960,540,warp);
119 auto* device=&fixture.device;
122 ComPtr<Rendering::RenderTexture> background;
123 HR(
Rendering::LoadTexture(device, L
"Textures/GUI/smokescreen.png", &background),
"load shared dialog background");
130
131 const auto render = [&](int width, int height, float scale, const char* filename,
132 bool guiBehind = false, float left = 24, float top = 24, bool guiInFront = false)
133 {
134 fixture.Resize(width,height);
136 HR(device->SetViewport(&viewport), "set viewport");
138 HR(device->BeginScene(), "begin scene");
139 if (guiBehind)
140 {
141
142 ComPtr<Rendering::RenderTexture>
gui;
145 HR(
gui->LockRect(0, &pixel,
nullptr, 0),
"lock mock GUI");
146 *
static_cast<DWORD*
>(pixel.
pBits) = 0xFFFF00FF;
151 guiTransform._41 = 300; guiTransform._42 = 60;
152 sprite->SetTransform(&guiTransform);
153 HR(sprite->Draw(
gui.Get(),
nullptr,
nullptr,
nullptr, 0xFFFFFFFF),
"draw opaque GUI window");
154 HR(sprite->End(), "end GUI pass");
155 }
159 sprite->SetTransform(&original);
160 const RECT scissor = {0, 0, width, height};
161 device->SetScissorRect(&scissor);
163
166 contentTransform._41 = left * scale; contentTransform._42 = top * scale;
167 sprite->SetTransform(&contentTransform);
169 HR(sprite->Draw(background.Get(), &content, nullptr, nullptr, 0xFFFFFFFF), "draw shared dialog background");
170 sprite->SetTransform(&original);
171 overlay.
Draw(sprite.Get(), data, left * scale, top * scale, scale);
173 Check(restored == original, "caller sprite transform preserved");
174 DWORD scissorEnabled = FALSE;
176 Check(scissorEnabled == TRUE, "caller scissor state preserved");
177 if (guiInFront)
178 {
179
180 ComPtr<Rendering::RenderTexture> foreground;
184 HR(foreground->LockRect(0, &pixel, nullptr, 0), "lock foreground dialog");
185 *
static_cast<DWORD*
>(pixel.
pBits) = 0xFFFF00FF;
186 foreground->UnlockRect(0);
189 transform._41 = 450; transform._42 = 90;
190 sprite->SetTransform(&transform);
191 HR(sprite->Draw(foreground.Get(), nullptr, nullptr, nullptr, 0xFFFFFFFF), "draw foreground dialog");
192 HR(sprite->Flush(), "flush foreground dialog");
193 }
194 HR(sprite->End(), "end sprite");
195 HR(device->EndScene(), "end scene");
196 if (filename)
197 {
198 fixture.Save(filename);
199 if(width==960 && height==540){
const RECT panel={0,0,
static_cast<LONG
>(
ExternalCamera::Width)+48,160};fixture.Save(std::string(filename)+
".panel.png",&panel);}
200 }
201 const auto pixels=fixture.Pixels();fixture.DebugClean();
202 size_t changed = 0;
203 for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x)
204 {
205 if ((pixels[y * width + x] & 0xFFFFFF) == 0x7893A2) continue;
206 ++changed;
209 "content follows dialog position and scale without changing size");
210 }
211 Check(changed > 1000, "overlay rendered visible pixels");
212 return pixels;
213 };
214 const std::string
output = argc > 1 ? argv[1] :
"x64/Release/ExternalCameraOverlayTests";
215 const auto active = render(960, 540, 1, (output + "/active.png").c_str());
216 Check(render(960, 540, 1, nullptr) == active, "unchanged dialog contents retain identical brightness");
219 const auto moved = render(960, 540, 1, (output + "/pan-tilt-zoom.png").c_str());
220 Check(moved != active, "camera controls update graphic indicators");
221
223 Check(active[y * 960 + x] == moved[y * 960 + x], "camera motion does not change vehicle telemetry");
224
225 const auto lightPixels = [](const std::vector<DWORD>& pixels)
226 {
227 int count = 0;
228 for (int y = -27; y <= 27; ++y) for (int x = -27; x <= 27; ++x)
229 if (x * x + y * y < 27 * 27 && ((pixels[(79 + y) * 960 + 280 + x] >> 16) & 255) > 170)
230 ++count;
231 return count;
232 };
233 const auto sample = [](const std::vector<DWORD>& pixels, int x, int y)
234 {
235 return (pixels[(79 + y) * 960 + 280 + x] >> 16) & 255;
236 };
237 const auto bankIndexPixels = [&](const std::vector<DWORD>& pixels, int side)
238 {
239
240
241 int count = 0;
242 for (int y = -3; y <= 3; ++y) for (int x = 34; x <= 38; ++x)
243 if (sample(pixels, side * x, y) > 210) ++count;
244 return count;
245 };
247 const auto noseUp = render(960, 540, 1, (output + "/attitude-nose-up.png").c_str());
249 const auto noseDown = render(960, 540, 1, (output + "/attitude-nose-down.png").c_str());
250 Check(lightPixels(noseUp) > lightPixels(active) + 350 && lightPixels(noseDown) < lightPixels(active) - 350,
251 "positive craft pitch lowers the horizon and negative pitch raises it");
253 const auto rolled = render(960, 540, 1, (output + "/attitude-roll-90.png").c_str());
254 Check(sample(rolled, -15, -8) > 170 && sample(rolled, 15, -8) < 100,
255 "positive bus roll moves sky left, matching the cockpit sprite's inverse rotation");
256 Check(bankIndexPixels(rolled, -1) >= 3 && bankIndexPixels(rolled, 1) == 0,
257 "positive bus roll moves the bank index left with the ball");
259 const auto rolledNegative = render(960, 540, 1, (output + "/attitude-roll-minus-90.png").c_str());
260 Check(sample(rolledNegative, 15, -8) > 170 && sample(rolledNegative, -15, -8) < 100,
261 "negative bus roll moves sky right, matching the cockpit sprite's inverse rotation");
262 Check(bankIndexPixels(rolledNegative, 1) >= 3 && bankIndexPixels(rolledNegative, -1) == 0,
263 "negative bus roll moves the bank index right with the ball");
265 const auto inverted = render(960, 540, 1, (output + "/attitude-inverted.png").c_str());
266 Check(sample(inverted, 9, -14) < 100 && sample(inverted, 9, 14) > 170,
267 "inverted flight reverses sky and ground");
269 const auto verticalUp = render(960, 540, 1, (output + "/attitude-vertical-up.png").c_str());
271 const auto verticalDown = render(960, 540, 1, (output + "/attitude-vertical-down.png").c_str());
272 Check(lightPixels(verticalUp) > 1500 && lightPixels(verticalDown) < 150,
273 "vertical flight remains a bounded, unambiguous hemisphere");
275 const auto invalidAttitude = render(960, 540, 1, (output + "/attitude-invalid.png").c_str());
277 const auto invalidRoll = render(960, 540, 1, nullptr);
279 const auto noVehicle = render(960, 540, 1, nullptr);
280 for (int y = 38; y < 120; ++y) for (int x = 239; x < 322; ++x)
281 Check(invalidAttitude[y * 960 + x] == noVehicle[y * 960 + x] &&
282 invalidRoll[y * 960 + x] == noVehicle[y * 960 + x],
283 "missing or invalid craft attitude displays unavailable rather than false level flight");
285 const auto overGui = render(960, 540, 1, (output + "/over-gui.png").c_str(), true);
286 const DWORD blended = overGui[115 * 960 + 450];
287 Check(((blended >> 16) & 255) < 160 && (blended & 255) < 160,
288 "shared dialog background composites on top of an opaque GUI window");
289 const auto foreground = render(960, 540, 1, (output + "/dialog-in-front.png").c_str(), false, 24, 24, true);
290 Check((foreground[110 * 960 + 470] & 0xFFFFFF) == 0xFF00FF, "dialog focus order is respected");
291 const auto relocated = render(960, 540, 1, (output + "/relocated.png").c_str(), false, 170, 260);
292 int bezelEdgeDifferences = 0;
294 if (moved[y * 960 + x] != relocated[(y + 236) * 960 + x + 146])
295 {
296
297
298 const int radiusSquared = (x - 280) * (x - 280) + (y - 79) * (y - 79);
299 Check(radiusSquared >= 31 * 31 && radiusSquared <= 35 * 35,
300 "moving dialog translates all instruments and text together");
301 ++bezelEdgeDifferences;
302 }
303 Check(bezelEdgeDifferences <= 8, "translated bezel differs only at a few rasterized edge pixels");
304 render(1920, 1080, 1.5f, (output + "/relocated-scaled.png").c_str(), false, 250, 320);
306 render(960, 540, 1, (output + "/agl-kilometers.png").c_str());
308 render(960, 540, 1, (output + "/high-altitude.png").c_str());
309 render(3440, 1440, 1.5f, (output + "/ultrawide.png").c_str());
311 render(640, 480, 1, (output + "/small-window.png").c_str());
314 render(480, 800, 1, (output + "/unavailable.png").c_str());
316 fixture.Resize(960,540);
318 render(960, 540, 1, nullptr);
320 sprite.Reset(); fixture.DebugClean();
321 std::cout << "PASS: altitude/speed boundaries and labels, GUI compositing, heading/FOV, steady dialog brightness, live PTZ rendering, stable telemetry, "
322 "craft attitude pitch/roll/inversion/vertical flight/unavailable data, dialog visibility/translation/scale/focus order, "
323 "small/portrait/ultrawide bounds, invalid data, render-state preservation, and native target resize\n";
324}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
bool Update(bool external, bool hideTemporarily, bool allMinimized, bool &active, bool &minimized)
HRESULT OnCreateDevice(Rendering::RenderDevice *device)
void Draw(Rendering::RenderSprite *sprite, const ExternalCamera::Readout &data, float left, float top, float scale)
float HorizontalFov(float projectionX, float zoom)
int HeadingDegrees(float degrees)
MetricText FormatAltitude(const Readout &data)
MetricText FormatSpeed(const Readout &data)
constexpr uint32_t TARGET
constexpr uint32_t SCISSORTESTENABLE
constexpr DWORD AlphaBlend
HRESULT CreateSprite(RenderDevice *owner, RenderSprite **result)
HRESULT LoadTexture(RenderDevice *owner, const wchar_t *path, RenderTexture **result, UINT levels=0, UINT width=0, UINT height=0)
HRESULT CreateTexture(RenderDevice *owner, UINT width, UINT height, UINT levels, DWORD usage, ImageFormat format, ResourcePool pool, RenderTexture **result)
Matrix * MatrixScaling(Matrix *out, float x, float y, float z)
Matrix * MatrixTranslation(Matrix *out, float x, float y, float z)
float pitchAttitudeRadians
float rollAttitudeRadians
float indicatedAirspeedKms