Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.
By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.
Which sim platform are you targeting?I have a working XML Gauge for Prepar3d, and need to find a way to port it into a C++ solution (dll). All the gauge is doing is reading the Angle of Incidence and changing the image of the gauge depending on its value.
Thanks in advance.
DigitalAviator said:I need help to convert this FSX XML gauge code to MSFS C++ DLL gauge
<?xml version="1.0" encoding="UTF-8"?>
<SimBase.Document
Type="AceXML"
version="1,0"
id="Fuel Pressure Gauge">
<Descr>AceXML Document</Descr>
<SimGauge.Gauge id="Gauge" ArtDirectory="C:\Flight Simulator X\SDK\SimObject Creation Kit\Panels and Gauges SDK\XML Gauge samples">
<FloatPosition>0.000,0.000</FloatPosition>
<Size>100,80</Size>
<Image id="FuelPressureBackground.bmp" Name="FuelPressureBackground.bmp">
<Transparent>True</Transparent>
</Image>
<Element id="Element">
<FloatPosition>5.000,10.000</FloatPosition>
<GaugeText id="GaugeText">
<Bold>True</Bold>
<Fixed>True</Fixed>
<FontFace>ARIAL</FontFace>
<FontColor>gold</FontColor>
<FontHeight>13</FontHeight>
<GaugeString>Fuel Pressure</GaugeString>
<HilightColor>blue</HilightColor>
<Length>32</Length>
<Size>90,15</Size>
<Transparent>True</Transparent>
<VerticalAlign>CENTER</VerticalAlign>
</GaugeText>
</Element>
<Element id="Element">
<FloatPosition>5.000,40.000</FloatPosition>
<Rectangle id="Rectangle">
<LineWidth>1</LineWidth>
<Width>90</Width>
<Height>24</Height>
<LineColor>darkslateblue</LineColor>
<FillColor>black</FillColor>
</Rectangle>
</Element>
<Element id="Element">
<FloatPosition>10.000,44.000</FloatPosition>
<GaugeText id="GaugeText">
<FontFace>COURIER</FontFace>
<FontColor>red</FontColor>
<FontHeight>16</FontHeight>
<GaugeString>%( (A:GENERAL ENG FUEL PRESSURE:1, psi) )%!09d!</GaugeString>
<Length>9</Length>
<Size>90,16</Size>
<Transparent>True</Transparent>
<VerticalAlign>CENTER</VerticalAlign>
</GaugeText>
</Element>
</SimGauge.Gauge>
</SimBase.Document>
ClaudeAI said:To convert this FSX XML gauge code to an MSFS C++ DLL gauge, we'll need to create a C++ class that inherits from the appropriate MSFS gauge base class and implement the necessary functionality. Here's a basic structure for the converted gauge:
Code:#include <MSFS/MSFS.h> #include <MSFS/MSFS_Render.h> #include <MSFS/MSFS_WindowsTypes.h> #include <MSFS/MSFS_SDL.h> #include <SimConnect.h> class FuelPressureGauge : public BaseGauge { private: // Texture handles MSFS::Texture* m_backgroundTexture; // Font handles MSFS::Font* m_titleFont; MSFS::Font* m_valueFont; // SimConnect variables HANDLE m_hSimConnect; float m_fuelPressure; public: FuelPressureGauge() : BaseGauge(), m_backgroundTexture(nullptr), m_titleFont(nullptr), m_valueFont(nullptr), m_hSimConnect(nullptr), m_fuelPressure(0.0f) {} virtual bool Initialize() override { // Load textures m_backgroundTexture = MSFS::Texture::CreateFromFile("FuelPressureBackground.png"); // Create fonts m_titleFont = MSFS::Font::CreateInstance("Arial", 13, MSFS::FONT_WEIGHT_BOLD); m_valueFont = MSFS::Font::CreateInstance("Courier New", 16, MSFS::FONT_WEIGHT_NORMAL); // Initialize SimConnect if (SUCCEEDED(SimConnect_Open(&m_hSimConnect, "Fuel Pressure Gauge", nullptr, 0, 0, 0))) { // Add data definition for fuel pressure SimConnect_AddToDataDefinition(m_hSimConnect, 0, "GENERAL ENG FUEL PRESSURE:1", "psi"); // Request data SimConnect_RequestDataOnSimObject(m_hSimConnect, 0, 0, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SIM_FRAME); } return true; } virtual void Update() override { // Process SimConnect messages SimConnect_CallDispatch(m_hSimConnect, DispatchProc, this); } virtual void Draw() override { // Draw background if (m_backgroundTexture) { MSFS::DrawContext::SetTexture(m_backgroundTexture); MSFS::DrawContext::DrawRectangle(0, 0, 100, 80); } // Draw title if (m_titleFont) { MSFS::DrawContext::SetFont(m_titleFont); MSFS::DrawContext::SetColor(1.0f, 0.84f, 0.0f, 1.0f); // Gold color MSFS::DrawContext::DrawText(5, 10, "Fuel Pressure", 90, 15, MSFS::TEXT_ALIGNMENT_CENTER, MSFS::TEXT_ALIGNMENT_CENTER); } // Draw value background MSFS::DrawContext::SetColor(0.0f, 0.0f, 0.0f, 1.0f); // Black MSFS::DrawContext::DrawRectangle(5, 40, 90, 24); // Draw value border MSFS::DrawContext::SetColor(0.28f, 0.24f, 0.55f, 1.0f); // Dark slate blue MSFS::DrawContext::DrawRectangleOutline(5, 40, 90, 24, 1); // Draw value if (m_valueFont) { MSFS::DrawContext::SetFont(m_valueFont); MSFS::DrawContext::SetColor(1.0f, 0.0f, 0.0f, 1.0f); // Red color char valueText[10]; snprintf(valueText, sizeof(valueText), "%09.2f", m_fuelPressure); MSFS::DrawContext::DrawText(10, 44, valueText, 80, 16, MSFS::TEXT_ALIGNMENT_LEFT, MSFS::TEXT_ALIGNMENT_CENTER); } } virtual void Destroy() override { // Clean up resources if (m_backgroundTexture) { delete m_backgroundTexture; } if (m_titleFont) { delete m_titleFont; } if (m_valueFont) { delete m_valueFont; } if (m_hSimConnect) { SimConnect_Close(m_hSimConnect); } } private: static void CALLBACK DispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext) { FuelPressureGauge* pThis = static_cast<FuelPressureGauge*>(pContext); pThis->ProcessSimConnectMessage(pData, cbData); } void ProcessSimConnectMessage(SIMCONNECT_RECV* pData, DWORD cbData) { switch (pData->dwID) { case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: { SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = static_cast<SIMCONNECT_RECV_SIMOBJECT_DATA*>(pData); if (pObjData->dwRequestID == 0) { m_fuelPressure = *((float*)&pObjData->dwData); } break; } } } }; // Export the gauge creation function extern "C" MSFS_CALLBACK FuelPressureGauge* CreateGauge() { return new FuelPressureGauge(); }
This C++ code creates a FuelPressureGauge class that inherits from BaseGauge. Here's a breakdown of the conversion:
- The gauge size is set to 100x80 pixels, matching the XML.
- The background image is loaded as a texture.
- Fonts are created for the title and value text.
- SimConnect is used to retrieve the fuel pressure data.
- The Draw method handles rendering the gauge, including the background, title, and fuel pressure value.
- The fuel pressure value is updated through SimConnect in the Update method.
To compile this into a DLL for MSFS, you'll need to:
- Set up the MSFS SDK and ensure you have the necessary include directories and library files.
- Create a project in your preferred C++ IDE or use CMake to generate the project files.
- Compile the code as a DLL.
- Create an XML layout file that references this DLL and place it in your aircraft's panel folder.
Note that you may need to adjust some details, such as file paths and exact color values, to match your specific requirements and MSFS conventions.
I’ve been totally blown away by Claude this last week. It generates windows power tools scripts perfectly. I’ve been working with it all day (subscription version) and pulled 4000 lines of information from every aircraft I have installed.Thank you for your response. I am primarily targeting Prepar3d V5, and will give Claude a shot.