C/C++ GAUGES
C/C++ gauges can be developed for Microsoft Flight Simulator with the Microsoft Flight Simulator Platform Toolset which installs at the same time as the SDK itself (see the Additional Tools and WebAssembly pages for more information).
Adding A Gauge To Your Project
In order to add a new gauge to your project, you simply need to create a new source file and include the "MSFS.h
" header found in the "WASM
" subfolder of the Microsoft Flight Simulator SDK:
You can then create a callback for your gauge as follows:
extern "C" {
MSFS_CALLBACK bool <GAUGENAME>_gauge_callback(FsContext ctx, int service_id, void* pData)
{
switch (service_id)
{
...
}
return false;
}
}
The panel.cfg
file must then be modified to reference your new gauge:
[VCockpit01]
size_mm=1024,768
pixel_size=1024,768
texture=TEXTURE
background_color=0,0,255
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=<MODULENAME>.wasm&wasm_gauge=<GAUGENAME>,0,0,1024,768,<OPTIONAL PARAMETER STRING>
Events Received By The Gauge Callback
One the gauge has been loaded by Microsoft Flight Simulator, the following events are sent to the callback function:
PANEL_SERVICE_PRE_INSTALL
: sent before the gauge is installed. ThepData
parameter points to asGaugeInstallData
structure:- The
iSizeX
member gives the width of the gauge bitmap. - The
iSizeY
member gives the height of the gauge bitmap. - The
strParameters
member gives the optional parameter string.
- The
PANEL_SERVICE_POST_INSTALL
: sent after the gauge has been installed. ThepData
parameter points to asGaugePostInstallData
structure:- The
ctx
member is a pointer to theFsContex
t used by the gauge (it is the same as thectx
parameter provided to the callback function).
- The
PANEL_SERVICE_PRE_INITIALIZE
: sent before the gauge is initialized. ThepData
parameter is null.PANEL_SERVICE_POST_INITIALIZE
: sent after the gauge has been initialized. ThepData
parameter is null.PANEL_SERVICE_PRE_UPDATE
: sent before the gauge is updated. ThepData
parameter is null.PANEL_SERVICE_POST_UPDATE
: sent after the gauge has been updated. ThepData
parameter is null.PANEL_SERVICE_PRE_DRAW
: sent before the gauge is drawn. ThepData
parameter points to asGaugeDrawData
structure:- The
mx
member gives the X-coordinate of the mouse in texture space. - The
my
member gives the Y-coordinate of the mouse in texture space. - The
t
member gives the absolute simulation time. - The
dt
member gives the time elapsed since last frame. - The
winWidth
member gives the width of the gauge bitmap. - The
winHeight
member gives the height of the gauge bitmap. - The
fbWidth
member gives the width of the gauge bitmap. - The
fbHeight
member gives the height of the gauge bitmap.
- The
PANEL_SERVICE_POST_DRAW
: sent after the gauge has been drawn. ThepData
parameter points to asGaugeDrawData
structure (see above).PANEL_SERVICE_PRE_KILL
: sent before the gauge is deleted. ThepData
parameter is null.PANEL_SERVICE_POST_KILL
: sent after the gauge has been deleted. ThepData
parameter is null.
Handling Mouse Events
Mouse events are forwarded to your gauge through a mouse callback that is defined as follows:
extern "C" {
MSFS_CALLBACK void <GAUGENAME>_mouse_callback(float fX, float fY, unsigned int iFlags)
{
...
}
}
- The
fX
parameter gives the X-coordinate of the mouse in texture space. - The
fY
parameter gives the Y-coordinate of the mouse in texture space. - The
iFlags
parameter is a combination of the variousMOUSE_*
flags defined ingauges.h
. Supported flags are:MOUSE_MOVE
: the mouse cursor has moved.MOUSE_LEFTDRAG
: left button down.MOUSE_RIGHTDRAG
: right button down.MOUSE_MIDDLEDRAG
: middle button down.MOUSE_LEFTRELEASE
: left button up.MOUSE_RIGHTRELEASE
: right button up.MOUSE_MIDDLERELEASE
: middle button up.MOUSE_LEFTSINGLE
: left button click (sent after a down/up sequence).MOUSE_RIGHTSINGLE
: right button click (sent after a down/up sequence).MOUSE_MIDDLESINGLE
: middle button click (sent after a down/up sequence).MOUSE_LEFTDOUBLE
: left button click (sent after two consecutive clicks).MOUSE_MIDDLEDOUBLE
: middle button click (sent after two consecutive clicks).MOUSE_WHEEL_UP
: wheel moved up.MOUSE_WHEEL_DOWN
: wheel moved down.
Gauge API
A set of functions named the Gauge API can be used to access (read and/or write) several variables related to the gauges you develop. You can find more information on the page below: