// ==============================================================
// ORBITER MODULE: DialogTemplate
// Part of the ORBITER SDK
// Copyright (C) 2003-2010 Martin Schweiger
// All rights reserved
//
// MFDTemplate.cpp
//
// This module demonstrates how to build an Orbiter plugin which
// inserts a new MFD (multi-functional display) mode. The code
// is not very useful in itself, but it can be used as a starting
// point for your own MFD developments.
// ==============================================================
#define STRICT
#define ORBITER_MODULE
#include "windows.h"
#include "orbitersdk.h"
#include "MFDTemplate.h"
// ==============================================================
// Global variables
int g_MFDmode; // identifier for new MFD mode
// ==============================================================
// API interface
DLLCLBK void InitModule (HINSTANCE hDLL)
{
static char *name = "MFD Template"; // MFD mode name
MFDMODESPECEX spec;
spec.name = name;
spec.key = OAPI_KEY_T; // MFD mode selection key
spec.context = NULL;
spec.msgproc = MFDTemplate::MsgProc; // MFD mode callback function
// Register the new MFD mode with Orbiter
g_MFDmode = oapiRegisterMFDMode (spec);
}
DLLCLBK void ExitModule (HINSTANCE hDLL)
{
// Unregister the custom MFD mode when the module is unloaded
oapiUnregisterMFDMode (g_MFDmode);
}
// ==============================================================
// MFD class implementation
// Constructor
MFDTemplate::MFDTemplate (DWORD w, DWORD h, VESSEL *vessel)
: MFD2 (w, h, vessel)
{
font = oapiCreateFont (w/20, true, "Arial", FONT_NORMAL, 0);
pRed = oapiCreatePen(1, 1, MFD_RED);
pGreen = oapiCreatePen(1, 1, MFD_GREEN);
pBlue = oapiCreatePen(1,1, MFD_BLUE);
pWhite = oapiCreatePen(1,1, MFD_WHITE);
pGaslox = oapiCreatePen(2,1, MFD_GASLOX);
pControl = oapiCreatePen(2,1, MFD_Control);
bBlack = oapiCreateBrush(MFD_BLACK);
bWhite = oapiCreateBrush(MFD_WHITE);
bRed = oapiCreateBrush(MFD_RED);
bGreen = oapiCreateBrush(MFD_GREEN);
bBlue = oapiCreateBrush(MFD_BLUE);
bGaslox = oapiCreateBrush(MFD_GASLOX);
bGasnit = oapiCreateBrush(MFD_GASNIT);
bLox = oapiCreateBrush(MFD_LOX);
// Add MFD initialisation here
}
// Destructor
MFDTemplate::~MFDTemplate ()
{
oapiReleaseFont (font);
oapiReleasePen (pRed);
oapiReleasePen (pGreen);
oapiReleasePen (pBlue);
oapiReleasePen (pGaslox);
oapiReleasePen (pControl);
oapiReleaseBrush(bBlack);
oapiReleaseBrush(bWhite);
oapiReleaseBrush(bRed);
oapiReleaseBrush(bGreen);
oapiReleaseBrush(bBlue);
oapiReleaseBrush(bGaslox);
oapiReleaseBrush(bGasnit);
oapiReleaseBrush(bLox);
// Add MFD cleanup code here
}
// Return button labels
char *MFDTemplate::ButtonLabel (int bt)
{
// The labels for the four buttons used by our MFD mode
static char *label[4] = {"PRE", "HYD", "ELE", "PNE"};
return (bt < 4 ? label[bt] : 0);
}
// Return button menus
int MFDTemplate::ButtonMenu (const MFDBUTTONMENU **menu) const
{
// The menu descriptions for the four buttons
static const MFDBUTTONMENU mnu[4] = {
{"Pressurisation", 0, '['},
{"Hydraulic", 0, '['},
{"Electrical", 0, '['},
{"Pneumatic", 0, ']'}
};
if (menu) *menu = mnu;
return 4; // return the number of buttons used
}
// Repaint the MFD
bool MFDTemplate::Update (oapi::Sketchpad *skp)
{
Title (skp, "PACK A");
// Draws the MFD title
skp->SetFont (font);
skp->SetTextAlign (oapi::Sketchpad::CENTER, oapi::Sketchpad::BASELINE);
skp->SetTextColor (MFD_WHITE);
skp->Rectangle (W/4, 0, (3*W)/4, H/15);
skp->Text (W/2, H/20,"LOX PRESSURISATION", 18);
skp->Rectangle (W/80, H/12, (21*W)/64, H/7);
skp->Text (W/6, H/8,"Main Sequencer", 14);
skp->Rectangle ((3*W)/8, H/12, (5*W)/8, H/7);
skp->Text (W/2, H/8,"- 00:00:10", 10);
skp->Rectangle ((45*W)/64, H/12, (63*W)/64, (34*H)/128);
skp->Text((27*W)/32,(9*H)/64, "Pressurisation",14);
skp->Text((27*W)/32,(12*H)/64, "Control",7);
skp->Text((27*W)/32,(30*H)/128, "Unit",4);
skp->Rectangle((11*W)/32, H/6, (21*W)/32, (27*H)/128);
skp->Text(W/2,H/5,"Ground Nitrogen",15);
skp->Rectangle((11*W)/32, (55*H)/256, (21*W)/32, (34*H)/128);
skp->Text(W/2,H/4,"Heat Exchanger", 14);
skp->SetPen(pRed);
skp->Line((21*W)/64,H/9,(3*W/8),H/9);
skp->Line((5*W)/8,H/9,(45*W/64),H/9);
skp->Line((21*W)/32,12*H/64, (45*W/64),12*H/64);
skp->Line((21*W)/32,15*H/64, (45*W/64),15*H/64);
// ----------- end of control graphics -------------------------
// ------------- Tanks and valves ------------------------------
// --------------- Start Tank Assembly -------------------------
skp->SetPen(pWhite);
skp->Rectangle((1*W)/32, (12*H)/32, (8*W)/32, (24*H)/32); // Start Tank
skp->Text((9*W)/64, (51*H)/64, "Start Tank",10);
skp->Rectangle((2*W)/32, (9*H)/32, (3*W)/32, (12*H)/32); // Start Tank filler
skp->Rectangle((1*W)/32, (17*H)/64, (4*W)/32, (9*H)/32);
//Start Tank Pressurisation Pipe
skp->SetBrush(bGasnit);
skp->Rectangle((48*W)/64,(17*H)/64,(49*W)/64,(21*H)/64); // Pipe 1
skp->Rectangle((8*W)/64,(20*H)/64,(49*W)/64,(21*H)/64); // Pipe 2 horiz
skp->Rectangle((8*W)/64,(20*H)/64,(9*W)/64,(24*H)/64); // Pipe 3
//skp->Rectangle((8*W)/32, (27*H)/64, (10*W)/32, (14*H)/32); // Vent pipe
skp->SetBrush(NULL); // back to unfilled rectangles
skp->Rectangle((8*W)/32, (12*H)/32, (17*W)/32, (27*H)/64); // Valve border
skp->Text((23*W)/64,(53*H)/128, "Vent Valve",10);
skp->SetBrush(bGreen);
skp->Rectangle((15*W)/32, (12*H)/32, (17*W)/32, (27*H)/64); // Start Tank Vent
skp->SetBrush(NULL); // back to unfilled rectangles
skp->SetPen(pWhite);
// -------------------- Run Tank Asembly -------------------------
skp->Rectangle((16*W)/32, (16*H)/32, (24*W)/32, (24*H)/32); // Run Tank
skp->Text((10*W/16), (51*H)/64, "Run Tank",8);
//Run Tank Pressurisation Pipes
skp->SetBrush(bGaslox);
skp->Rectangle((59*W)/64,(17*H)/64,(60*W)/64,(34*H)/64); // Pipe 1 vert
skp->Rectangle((24*W)/32,(33*H)/64,(60*W)/64,(34*H)/64); // Pipe 2 horiz
skp->SetBrush(NULL); // back to unfilled rectangles
skp->Rectangle((35*W)/64,(29*H)/64,(52*W)/64,(32*H)/64); // Valve border
skp->Text((21*W)/32,(63*H)/128, "Vent Valve",10);
skp->SetBrush(bGreen);
skp->Rectangle((48*W)/64,(29*H)/64,(52*W)/64,(32*H)/64); // Run Tank Vent
skp->SetBrush(NULL); // back to unfilled rectangles
// ------------------ Valve Control -----------------------------
skp->SetPen(pControl);
skp->Line((51*W)/64,(17*H)/64,(51*W)/64,(25*H)/64);
skp->LineTo((33*W)/64,(25*H)/64);
skp->Line((57*W)/64,(17*H)/64,(57*W)/64,(30*H)/64);
skp->LineTo((52*W)/64,(30*H)/64);
skp->Line((54*W)/64,(17*H)/64,(54*W)/64,(28*H)/64);
skp->LineTo((24*W)/64,(28*H)/64);
skp->LineTo((24*W)/64,(40*H)/64);
// ------------------- end of valve control ----------------------
// ------------------- Main Pipework -----------------------------
skp->SetPen(pWhite);
skp->Rectangle((8*W)/32, (20*H)/32, (16*W)/32, (22*H)/32);
skp->Rectangle((24*W)/32, (20*H)/32, (28*W)/32, (22*H)/32);
skp->Rectangle((28*W)/32, (19*H)/32, (57*W)/64, (23*H)/32);
skp->Rectangle((57*W)/64, (19*H)/32, (58*W)/64, (23*H)/32);
skp->Line((58*W)/64, (20*H)/32, (62*W)/64, (20*H)/32);
skp->Line((58*W)/64, (22*H)/32, (62*W)/64, (22*H)/32);
skp->Ellipse((11*W)/32, (20*H)/32, (13*W)/32, (22*H)/32);
skp->Text((12*W)/32, (47*H)/64, "Fill/Check",10);
skp->Text((55*W)/64, (49*H)/64, "To Engines",10);
// ----------------------------------------------------------------
// -------------------- Data Area ---------------------------------
skp->Line(0,(52*H)/64,W, (52*H)/64);
skp->Text(W/2, (55*H)/64, "Ullage Pressure",15);
skp->Text(W/2, (58*H)/64, "Tank Volume",11);
skp->Text(W/2, (61*H)/64, "Tank Flow",9);
//--------------------- Fill/Check Valve draw ----------------------
skp->SetBrush(bGreen);
skp->Ellipse((11*W)/32, (20*H)/32, (13*W)/32, (22*H)/32);
skp->SetBrush(bBlack);
skp->Ellipse((11*W)/32, (20*H)/32, (13*W)/32, (22*H)/32);
skp->SetBrush(bRed);
skp->Rectangle((23*W)/64, (20*H)/32, (25*W)/64, (22*H)/32);
skp->SetBrush(bBlack);
skp->Rectangle((23*W)/64, (20*H)/32, (25*W)/64, (22*H)/32);
// Add MFD display routines here.
// Use the device context (hDC) for Windows GDI paint functions.
return true;
}
// MFD message parser
int MFDTemplate::MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam)
{
switch (msg) {
case OAPI_MSG_MFD_OPENED:
// Our new MFD mode has been selected, so we create the MFD and
// return a pointer to it.
return (int)(new MFDTemplate (LOWORD(wparam), HIWORD(wparam), (VESSEL*)lparam));
}
return 0;
}