- Joined
- Nov 25, 2007
- Messages
- 1,667
- Reaction score
- 19
- Points
- 38
- Location
- Germany
- Website
- www.enderspace.de
- Preferred Pronouns
- Can't you smell my T levels?
I'd like to share a new small framework for creating and switching among multiple MFD page buttons, with little interaction with the internals. It assumes registering handlers in the MFD and calling them on typical Orbiter MFD events. Please comment before I release it more officially.
First an example usage in Launch MFD client class:
Header:
Implementation
The library documentation:
Interface
Implementation
First an example usage in Launch MFD client class:
Header:
PHP:
#ifndef MFDBUTTONPAGELAUNCHMFD_H
#define MFDBUTTONPAGELAUNCHMFD_H
#include "MDFButtonPage.hpp"
#include "LaunchMFD.h"
class MFDButtonPageLaunchMFD : public MDFButtonPage<LaunchMFD>
{
public:
MFDButtonPageLaunchMFD();
protected:
bool SearchForKeysInOtherPages() const;
private:
};
#endif // MFDBUTTONPAGELAUNCHMFD_H
PHP:
#include "MFDButtonPageLaunchMFD.hpp"
#include "localisation.h"
MFDButtonPageLaunchMFD::MFDButtonPageLaunchMFD()
{
// The menu descriptions of all buttons
static const MFDBUTTONMENU mnu1[] =
{
{SELECT_TARGET, 0, 'T'},
{ENTER_ALT, "km", 'A'},
{INCREASE_INCLINATION, 0, '+'},
{DECREASE_INCLINATION, 0, '-'},
{INCREASE_INCLINATION_FACTOR, 0, ']'},
{DECREASE_INCLINATION_FACTOR, 0, '['},
{SWITCH_BUTTONS_PAGE, 0, 'B'},
{OPERATION_MODE, 0, 'M'},
{DEFAULT_ACTION, 0, 'D'},
{SWITCH_PITCH_GUIDANCE, 0, 'I'},
{OFF_PLANE_CORRECTION, 0, 'O'},
{AUTOPILOT, 0, 'P'}
};
RegisterPage(mnu1, sizeof(mnu1) / sizeof(MFDBUTTONMENU));
RegisterFunction("TGT", OAPI_KEY_T, &LaunchMFD::OpenDialogTarget);
RegisterFunction("ALT", OAPI_KEY_A, &LaunchMFD::OpenDialogAltitude);
RegisterFuncCont("I +", OAPI_KEY_EQUALS, &LaunchMFD::IncreaseInclination, &LaunchMFD::DecreaseInclination);
RegisterFuncCont("I -", OAPI_KEY_MINUS, &LaunchMFD::DecreaseInclination, &LaunchMFD::IncreaseInclination);
RegisterFunction("Ad+", OAPI_KEY_RBRACKET, &LaunchMFD::IncreaseInclinationFactor, &LaunchMFD::DecreaseInclinationFactor);
RegisterFunction("Ad-", OAPI_KEY_LBRACKET, &LaunchMFD::DecreaseInclinationFactor, &LaunchMFD::IncreaseInclinationFactor);
RegisterFunction("PG", OAPI_KEY_B, &LaunchMFD::SwitchButtonsPage);
RegisterFunction("MOD", OAPI_KEY_M, &LaunchMFD::SwitchMode);
RegisterFunction("DEF", OAPI_KEY_D, &LaunchMFD::DefaultAction);
RegisterFunction("PTC", OAPI_KEY_I, &LaunchMFD::SwitchPitchGuidance);
RegisterFunction("COR", OAPI_KEY_O, &LaunchMFD::SwitchOffplaneCorrection);
RegisterFunction("AP", OAPI_KEY_P, &LaunchMFD::SwitchAutopilot);
static const MFDBUTTONMENU mnu2[] =
{
{GREAT_CIRCLE_SWITCH, GREAT_CIRCLE, 'G'},
{GREAT_CIRCLE_TRACK, 0, 'K'},
{GREAT_CIRCLE_ZOOM_IN, 0, 'Z'},
{GREAT_CIRCLE_ZOOM_OUT, 0, 'X'},
{GREAT_CIRCLE_PREC_INCR, 0, 'C'},
{GREAT_CIRCLE_PREC_DECR, 0, 'V'},
{SWITCH_BUTTONS_PAGE, 0, 'B'},
{SWITCH_HUD, 0, 'H'},
{SWITCH_SOUNDS, 0, 'S'},
{PID_ADJUST_XY, 0, '1'},
{PID_ADJUST_BANK, 0, '2'},
};
RegisterPage(mnu2, sizeof(mnu2) / sizeof(MFDBUTTONMENU));
RegisterFunction("GC", OAPI_KEY_G, &LaunchMFD::SwitchGreatCircleUse);
RegisterFunction("TRK", OAPI_KEY_K, &LaunchMFD::SwitchGreatCircleTrack);
RegisterFuncCont("ZM+", OAPI_KEY_Z, &LaunchMFD::GreatCircleZoomIn);
RegisterFuncCont("ZM-", OAPI_KEY_X, &LaunchMFD::GreatCircleZoomOut);
RegisterFunction("PR+", OAPI_KEY_C, &LaunchMFD::GreatCircleIncreasePlotPrecision, &LaunchMFD::GreatCircleDecreasePlotPrecision);
RegisterFunction("PR-", OAPI_KEY_V, &LaunchMFD::GreatCircleDecreasePlotPrecision, &LaunchMFD::GreatCircleIncreasePlotPrecision);
RegisterFunction("PG", OAPI_KEY_B, &LaunchMFD::SwitchButtonsPage);
RegisterFunction("HUD", OAPI_KEY_H, &LaunchMFD::SwitchHUD);
RegisterFunction("SND", OAPI_KEY_S, &LaunchMFD::SwitchSound);
RegisterFunction("PXY", OAPI_KEY_1, &LaunchMFD::OpenDialogPIDXY);
RegisterFunction("PBN", OAPI_KEY_2, &LaunchMFD::OpenDialogPIDBank);
}
bool MFDButtonPageLaunchMFD::SearchForKeysInOtherPages() const
{
return true;
}
PHP:
// ...
class LaunchMFD: public MFD2
{
public:
//....
// handlers
void SwitchButtonsPage();
void SwitchMode();
void SwitchAutopilot();
void SwitchOffplaneCorrection();
void SwitchGreatCircleUse();
void SwitchGreatCircleTrack();
void SwitchHUD();
void SwitchSound();
void GreatCircleZoomIn();
void GreatCircleZoomOut();
void IncreaseInclination();
void DecreaseInclination();
void IncreaseInclinationFactor();
void DecreaseInclinationFactor();
void DefaultAction();
void OpenDialogTarget();
void OpenDialogAltitude();
void OpenDialogPIDXY();
void OpenDialogPIDBank();
void DoNothing(); // for empty buttons
// ...
PHP:
MFDButtonPageLaunchMFD m_buttonPages; // in this example global for simplicity
char * LaunchMFD::ButtonLabel (int bt)
{
return m_buttonPages.ButtonLabel(bt);
}
int LaunchMFD::ButtonMenu (const MFDBUTTONMENU **menu) const
{
return m_buttonPages.ButtonMenu( menu );
}
bool LaunchMFD::ConsumeButton (int bt, int event)
{
return m_buttonPages.ConsumeButton(this, bt, event);
}
bool LaunchMFD::ConsumeKeyBuffered(DWORD key)
{
return m_buttonPages.ConsumeKeyBuffered(this, key);
}
bool LaunchMFD::ConsumeKeyImmediate( char * kstate )
{
return m_buttonPages.ConsumeKeyImmediate(this, kstate);
}
// Event handlers
void LaunchMFD::SwitchButtonsPage() // This handler is mandatory
{
m_buttonPages.SwitchPage(this);
}
void LaunchMFD::SwitchAutopilot()
{
m_data->SwitchAutopilot( m_data->pageView == DIRECT_ASCENT ? AP_DIRECT_ASCENT : AP_STANDARD );
}
void LaunchMFD::SwitchPitchGuidance()
{
m_data->drawPitchError = ! m_data->drawPitchError;
}
//...
Interface
Implementation
Last edited: