15 for (rapidxml::xml_node<>* screenNode = xml_node->first_node(); screenNode; screenNode = screenNode->next_sibling())
19 rapidxml::xml_attribute<>* screenName = screenNode->first_attribute(
"name");
20 if (screenName) screen.
name = screenName->value();
21 rapidxml::xml_attribute<>* xAtt = screenNode->first_attribute(
"x");
22 screen.
x = atoi(xAtt->value());
23 rapidxml::xml_attribute<>* yAtt = screenNode->first_attribute(
"y");
24 screen.
y = atoi(yAtt->value());
25 rapidxml::xml_attribute<>* widthAtt = screenNode->first_attribute(
"width");
26 screen.
width = atoi(widthAtt->value());
27 rapidxml::xml_attribute<>* heightAtt = screenNode->first_attribute(
"height");
28 screen.
height = atoi(heightAtt->value());
29 screen.
rect.top = screen.
y;
30 screen.
rect.left = screen.
x;
34 for (rapidxml::xml_node<>* pageNode = screenNode->first_node(); pageNode; pageNode = pageNode->next_sibling())
37 rapidxml::xml_attribute<>* pageName = pageNode->first_attribute(
"name");
38 page.
name = pageName->value();
40 for (rapidxml::xml_node<>* instrumentOrElementNode = pageNode->first_node(); instrumentOrElementNode;
41 instrumentOrElementNode = instrumentOrElementNode->next_sibling())
43 if (_strcmpi(instrumentOrElementNode->name(),
"Instrument") == 0)
45 rapidxml::xml_attribute<>* xAtt = instrumentOrElementNode->first_attribute(
"x");
46 int x = atoi(xAtt->value()) + screen.
x;
47 rapidxml::xml_attribute<>* yAtt = instrumentOrElementNode->first_attribute(
"y");
48 int y = atoi(yAtt->value()) + screen.
y;
49 rapidxml::xml_attribute<>* xScaleAtt = instrumentOrElementNode->first_attribute(
"xScale");
50 float xScale = xScaleAtt ?
static_cast<float>(atof(xScaleAtt->value())) : 1.0f;
51 rapidxml::xml_attribute<>* yScaleAtt = instrumentOrElementNode->first_attribute(
"yScale");
52 float yScale = yScaleAtt ?
static_cast<float>(atof(yScaleAtt->value())) : 1.0f;
60 rapidxml::xml_attribute<>* typeAtt = instrumentOrElementNode->first_attribute(
"type");
61 std::string type = typeAtt->value();
73 rapidxml::xml_attribute<> *ordinalElement = instrumentOrElementNode->first_attribute(
"ordinal");
74 const int ordinal = ordinalElement ? atoi(ordinalElement->value()) : -1;
107 else if (_strcmpi(instrumentOrElementNode->name(),
"Element") == 0)
110 rapidxml::xml_attribute<>* x = instrumentOrElementNode->first_attribute(
"x");
111 element.
x = atoi(x->value()) + screen.
x;
112 rapidxml::xml_attribute<>* y = instrumentOrElementNode->first_attribute(
"y");
113 element.
y = atoi(y->value()) + screen.
y;
115 for (rapidxml::xml_node<>* componentNode = instrumentOrElementNode->first_node(); componentNode; componentNode =
116 componentNode->next_sibling())
119 rapidxml::xml_attribute<>* busval = componentNode->first_attribute(
"busval");
122 const std::string type = busval->value();
165 rapidxml::xml_attribute<>* modulate = componentNode->first_attribute(
"modulate");
166 if (modulate) component.
modulate =
static_cast<float>(atof(modulate->value()));
167 rapidxml::xml_attribute<>* bias = componentNode->first_attribute(
"bias");
168 if (bias) component.
bias =
static_cast<float>(atof(bias->value()));
169 rapidxml::xml_attribute<>* abs = componentNode->first_attribute(
"abs");
170 if (abs) component.
abs = atoi(abs->value());
172 for (rapidxml::xml_node<>* conditionNode = componentNode->first_node(); conditionNode; conditionNode =
173 conditionNode->next_sibling())
176 rapidxml::xml_attribute<>* min = conditionNode->first_attribute(
"min");
177 if (min) condition.
min =
static_cast<float>(atof(min->value()));
178 rapidxml::xml_attribute<>* max = conditionNode->first_attribute(
"max");
179 if (max) condition.
max =
static_cast<float>(atof(max->value()));
181 for (rapidxml::xml_node<>* spriteOrTextNode = conditionNode->first_node(); spriteOrTextNode; spriteOrTextNode =
182 spriteOrTextNode->next_sibling())
184 if (_strcmpi(spriteOrTextNode->name(),
"Sprite") == 0)
186 std::string pathAndFilename = spriteOrTextNode->value();
187 rapidxml::xml_attribute<>* spriteX = spriteOrTextNode->first_attribute(
"x");
188 int x = atoi(spriteX->value()) + element.
x;
189 rapidxml::xml_attribute<>* spriteY = spriteOrTextNode->first_attribute(
"y");
190 int y = atoi(spriteY->value()) + element.
y;
191 rapidxml::xml_attribute<>* zAttr = spriteOrTextNode->first_attribute(
"z");
193 if (zAttr) z =
static_cast<float>(atof(zAttr->value()));
195 rapidxml::xml_attribute<>* spriteTop = spriteOrTextNode->first_attribute(
"top");
197 if (spriteTop) top = atoi(spriteTop->value());
198 rapidxml::xml_attribute<>* spriteLeft = spriteOrTextNode->first_attribute(
"left");
200 if (spriteLeft) left = atoi(spriteLeft->value());
201 rapidxml::xml_attribute<>* widthAttr = spriteOrTextNode->first_attribute(
"width");
202 int width = atoi(widthAttr->value());
203 rapidxml::xml_attribute<>* heightAttr = spriteOrTextNode->first_attribute(
"height");
204 int height = atoi(heightAttr->value());
206 rapidxml::xml_attribute<>* colorAttr = spriteOrTextNode->first_attribute(
"color");
207 DWORD color = 0xFFFFFFFF;
208 if (colorAttr) color = strtoul(colorAttr->value(),
nullptr, 16);
211 rapidxml::xml_attribute<>* scaleXAttr = spriteOrTextNode->first_attribute(
"xScale");
212 if (scaleXAttr) scaleX =
static_cast<float>(atof(scaleXAttr->value()));
214 rapidxml::xml_attribute<>* scaleYAttr = spriteOrTextNode->first_attribute(
"yScale");
215 if (scaleYAttr) scaleY =
static_cast<float>(atof(scaleYAttr->value()));
222 const Sprite sprite =
Sprite(
logger,
pDevice, pathAndFilename, x, y, z, top, left, width, height, color, scaleX, scaleY);
224 condition.
sprites.emplace_back(sprite);
226 else if (_strcmpi(spriteOrTextNode->name(),
"Text") == 0)
228 rapidxml::xml_attribute<>* textX = spriteOrTextNode->first_attribute(
"x");
229 int x = atoi(textX->value()) + element.
x;
230 rapidxml::xml_attribute<>* textY = spriteOrTextNode->first_attribute(
"y");
231 int y = atoi(textY->value()) + element.
y;
232 rapidxml::xml_attribute<>* font = spriteOrTextNode->first_attribute(
"font");
234 rapidxml::xml_attribute<>* widthAttr = spriteOrTextNode->first_attribute(
"width");
236 if (widthAttr) width = atoi(widthAttr->value());
237 rapidxml::xml_attribute<>* heightAttr = spriteOrTextNode->first_attribute(
"height");
239 if (heightAttr) height = atoi(heightAttr->value());
242 if (font) fontInt = atoi(font->value());
243 if (fontInt >= (
int)
fonts.size() || fontInt < 0)
245 throw std::exception(
"Font requested is not in available fonts list!");
249 std::string temptext = spriteOrTextNode->value();
254 found = temptext.find(-62);
255 if (found != std::string::npos)
256 temptext.erase(found, 1);
257 }
while (found != std::string::npos);
261 rapidxml::xml_attribute<>* align = spriteOrTextNode->first_attribute(
"align");
264 if (_strcmpi(align->value(),
"left") == 0) text.
flags |= DT_LEFT;
265 if (_strcmpi(align->value(),
"center") == 0) text.
flags |= DT_CENTER;
266 if (_strcmpi(align->value(),
"right") == 0) text.
flags |= DT_RIGHT;
269 rapidxml::xml_attribute<>* valign = spriteOrTextNode->first_attribute(
"valign");
272 if (_strcmpi(valign->value(),
"top") == 0) text.
flags |= DT_TOP;
273 if (_strcmpi(valign->value(),
"center") == 0) text.
flags |= DT_VCENTER;
274 if (_strcmpi(valign->value(),
"bottom") == 0) text.
flags |= DT_BOTTOM;
277 rapidxml::xml_attribute<>* color = spriteOrTextNode->first_attribute(
"color");
278 text.
color = strtoul(color->value(),
nullptr, 16);
280 condition.
text.emplace_back(text);
290 page.
elements.emplace_back(element);
293 screen.
pages.emplace_back(page);
303 for (rapidxml::xml_node<>* fontNode = xml_node->first_node(); fontNode; fontNode = fontNode->next_sibling())
305 rapidxml::xml_attribute<>* width = fontNode->first_attribute(
"width");
306 int iwidth = atoi(width->value());
307 rapidxml::xml_attribute<>* height = fontNode->first_attribute(
"height");
308 int iheight = atoi(height->value());
309 rapidxml::xml_attribute<>* name = fontNode->first_attribute(
"name");
310 std::string iname = name->value();
311 std::string ipathAndFilename = fontNode->value();
314 fonts.emplace_back(
new Font(
logger, DXUTGetD3D9Device(), iwidth, iheight, iname, ipathAndFilename));
329 setlocale(LC_ALL,
"English");
331 WCHAR configFilePath[MAX_PATH];
335 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\C-98.xml");
338 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\E-10.xml");
341 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\P-13.xml");
344 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\A-4.xml");
347 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\C-2.xml");
351 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\T-120.xml");
354 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\E-11.xml");
357 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\C-2A.xml");
360 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\W-6.xml");
363 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\T-19.xml");
366 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\T-27.xml");
369 wcscpy_s(configFilePath, MAX_PATH, L
"Displays\\Apartment.xml");
376 _wsopen_s(&configFile, configFilePath, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, SH_DENYWR, S_IREAD);
377 if (configFile == -1)
380 sprintf_s(msg, 99,
"Config::Initialize could not open file: %S", configFilePath);
386 const int fileLength = _filelength(configFile);
387 char* buffer =
new char[fileLength + 1];
388 _read(configFile, buffer, fileLength);
390 buffer[fileLength] = 0;
392 rapidxml::xml_document<> doc;
395 doc.parse<0>(buffer);
399 SAFE_DELETE_ARRAY(buffer);
401 sprintf_s(msg, 99,
"Config::Initialize exception parsing file: %S", configFilePath);
406 rapidxml::xml_node<>* rootNode = doc.first_node(
"Displays");
408 rapidxml::xml_node<>* fontsNode = rootNode->first_node(
"Fonts");
411 rapidxml::xml_node<>* screensNode = rootNode->first_node(
"Screens");
414 SAFE_DELETE_ARRAY(buffer);
425 V(
pDevice->
pSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT));
427 for (UINT i = 0; i <
screens.size(); i++)
446 if (command.
name ==
"ChangeMfdPage")
451 else if (command.
name ==
"RestorePage")
458 for (UINT i = 0; i <
screens.size(); i++)
459 screens.at(i).FrameMove(fElapsed);
465 for (UINT i = 0; i <
screens.size(); i++)
467 if (
screens.at(i).HandleKeyPress(key, shift))
478 for (UINT i = 0; i <
fonts.size(); i++)
479 fonts.at(i)->pFont->OnLostDevice();
487 for (UINT i = 0; i <
fonts.size(); i++)
488 fonts.at(i)->pFont->OnResetDevice();
496 for (UINT i = 0; i <
screens.size(); i++)
498 if (
screens.at(i).name == screenName)
500 if (
screens.at(i).ChangePage(pageName))
503 sprintf_s(msg, 99,
"Displays::ChangePage found screen %s but couldn't find page: %s", screenName.c_str(),
509 sprintf_s(msg, 99,
"Displays::ChangePage could not find screen named: %s", screenName.c_str());
519 for (UINT i = 0; i <
screens.size(); i++)
521 if (
screens.at(i).name == screenName)
523 screens.at(i).ChangePage(pageNumber);
528 sprintf_s(msg, 99,
"Displays::ChangePage could not find screen named: %s", screenName.c_str());
535 for (UINT i = 0; i <
screens.size(); i++)
537 if (
screens.at(i).name == screenName)
539 if (
screens.at(i).pages.size() == 0)
550 sprintf_s(msg, 99,
"Displays::ChangePage could not find screen named: %s", screenName.c_str());
558 for (UINT i = 0; i <
screens.size(); i++)
560 if (
screens.at(i).name == screenName)
562 if (
screens.at(i).pages.size() == 0)
564 if (
screens.at(i).currentPage == 0)
574 sprintf_s(msg, 99,
"Displays::ChangePage could not find screen named: %s", screenName.c_str());
595 for (UINT i = 0; i <
fonts.size(); i++)
596 fonts.at(i)->OnDestroyDevice();
607 for (UINT i = 0; i <
screens.size(); i++)
609 if (
screens.at(i).name == screenName)
616 sprintf_s(msg, 99,
"Displays::RestorePage could not find screen named: %s", screenName.c_str());
std::vector< Element > elements
std::vector< Command > commandStream
float TvmCurrentClosingSpeed
void FrameMove(float fElapsed)
s_network_objects playerships[MAX_SCAN]
float WindDirectionDegrees
void ConfigureScreens(rapidxml::xml_node<> *xml_node)
void ChangePage(std::string screenName, std::string pageName)
float AngleOfAttackRadians
float GlideslopeDeviationRadians
D3DXVECTOR3 NormalAcceleration
float DesiredClosingSpeed
std::vector< Sprite > sprites
void OnLostDevice() const
HRESULT SetRenderState(_D3DRENDERSTATETYPE renderStateType, int value) const
Displays(Logger *prmLogger, Bus *prmBus, HMI *prmGui)
std::string formattedText
float HeadingTrackDegrees
std::string TogglePage(std::string screenName)
float IndicatedAirspeedKms
bool HandleKeyPress(short key, bool shift)
float MapScaleInnerRingKm
std::vector< Page > pages
float AirframeTemperatureCelsius
std::vector< Component > components
std::string TogglePageReverse(std::string screenName)
void OnResetDevice() const
HRESULT SetScissorRect(RECT *rect) const
std::vector< Condition > conditions
std::vector< Font * > fonts
void Log(const char *msg, Level level=Info, int errorCode=0)
void RestorePage(std::string screenName)
float OutsideAirTemperatureKelvin
float TotalAirTemperatureCelsius
void ConfigureFonts(rapidxml::xml_node<> *xml_node)
void AddToCallStack(const char *msg)
std::vector< Screen > screens
float StaticAirTemperatureCelsius
float FlightPathAngleRadians
std::vector< Instrument * > instruments