All Classes Functions Typedefs
Classes | Public Member Functions | Protected Types | Protected Member Functions | List of all members
EnjoLib::MFDGoodies::MFDButtonPage< MFDClass > Class Template Reference

Manages MFD button pages. More...

#include <MFDButtonPage.hpp>

Classes

struct  Page
 Represents button page.

Public Member Functions

 MFDButtonPage ()
 Ctor.
virtual ~MFDButtonPage ()
 Dtor.
void SwitchPage (MFDClass *mfdInstance) const
 Switches between button pages.
void SelectPage (MFDClass *mfdInstance, int pageIndex) const
 Selects a specific buttons page.
bool ConsumeButton (MFDClass *mfdInstance, int button, int event) const
 Reacts on mouse clicks on buttons.
bool ConsumeKeyBuffered (MFDClass *mfdInstance, DWORD key) const
 Reacts on keyboard presses.
bool ConsumeKeyImmediate (MFDClass *mfdInstance, char *kstate) const
 Reacts on continuous keyboard presses.
int ButtonMenu (const MFDBUTTONMENU **menu) const
 Returns button menu of the current page.
char * ButtonLabel (int button) const
 Returns button labels of the current page.

Protected Types

typedef void(MFDClass::* MFDFunctionPtr )(void)
 Function pointers of the MFDClass.

Protected Member Functions

virtual bool SearchForKeysInOtherPages () const =0
 Should other pages be searched for when pressing a key?
void RegisterFunction (const std::string &label, DWORD key, MFDFunctionPtr funLClick, MFDFunctionPtr funRClick=NULL)
 Registeres handler in MFD scope for buttons.
void RegisterFunctionCont (const std::string &label, DWORD key, MFDFunctionPtr funLClick, MFDFunctionPtr funRClick=NULL)
 Registeres handler in MFD scope for buttons that should have a continous reaction.
void RegisterPage (const MFDBUTTONMENU *menu, int size)
 Registeres button page, and buttons menu.

Detailed Description

template<class MFDClass>
class EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >

Manages MFD button pages.

Allows to register many switchable MFD button pages of the MFDClass and associates handlers for the buttons. The handlers must reside in the MFDClass, and they must not have any arguments.

Template Parameters
<MFDClass>Your MFD class that should contain handlers

Member Function Documentation

template<class MFDClass >
char * EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::ButtonLabel ( int  button) const

Returns button labels of the current page.

Call from MFD::ButtonLabel(). Example:

char * LaunchMFD::ButtonLabel (int bt)
{
return m_buttonPages.ButtonLabel(bt);
}
Parameters
button- button number
template<class MFDClass >
int EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::ButtonMenu ( const MFDBUTTONMENU **  menu) const

Returns button menu of the current page.

Call from MFD::ButtonMenu(). Example:

int LaunchMFD::ButtonMenu (const MFDBUTTONMENU **menu) const
{
return m_buttonPages.ButtonMenu( menu );
}
Parameters
menu- this will be initialised by internal structure
template<class MFDClass>
bool EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::ConsumeButton ( MFDClass *  mfdInstance,
int  button,
int  event 
) const

Reacts on mouse clicks on buttons.

Call from MFD::ConsumeButton(). Example:

bool LaunchMFD::ConsumeButton (int bt, int event)
{
return m_buttonPages.ConsumeButton(this, bt, event);
}
Parameters
mfdInstance- Instance of your MFD class (this)
button- button number
event- Windows event
template<class MFDClass>
bool EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::ConsumeKeyBuffered ( MFDClass *  mfdInstance,
DWORD  key 
) const

Reacts on keyboard presses.

Searches for the provided key in a map for the selected page and fires associated function. If SearchForKeysInOtherPages() returns true, then other pages are searched for as well. Call from MFD::ConsumeKeyBuffered(). Example:

{
return m_buttonPages.ConsumeKeyBuffered(this, key);
}
Parameters
mfdInstance- Instance of your MFD class (this)
key- key designation, like OAPI_KEY_T
template<class MFDClass>
bool EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::ConsumeKeyImmediate ( MFDClass *  mfdInstance,
char *  kstate 
) const

Reacts on continuous keyboard presses.

Searches for the provided key in a map for the selected page and fires associated function. If SearchForKeysInOtherPages() returns true, then other pages are searched for as well. The function's execution is continuous. Call from MFD::ConsumeKeyImmediate(). Example:

bool LaunchMFD::ConsumeKeyImmediate(char * kstate)
{
return m_buttonPages.ConsumeKeyImmediate(this, kstate);
}
Parameters
mfdInstance- Instance of your MFD class (this)
kstate- key state from Orbiter
template<class MFDClass >
void EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::RegisterFunction ( const std::string &  label,
DWORD  key,
MFDFunctionPtr  funLClick,
MFDFunctionPtr  funRClick = NULL 
)
protected

Registeres handler in MFD scope for buttons.

Before this method has any effect, a button page needs to be registered first with RegisterPage(). The keys may be repeated in different pages.

MFDButtonPageLaunchMFD::MFDButtonPageLaunchMFD()
{
// ... add menu first, then functions
RegisterFunction("TGT", OAPI_KEY_T, &LaunchMFD::OpenDialogTarget);
RegisterFunction("ALT", OAPI_KEY_A, &LaunchMFD::OpenDialogAltitude);
RegisterFunction("PG", OAPI_KEY_P, &LaunchMFD::SwitchButtonsPage);
RegisterFuncCont("I +", OAPI_KEY_EQUALS, &LaunchMFD::IncreaseInclination, &LaunchMFD::DecreaseInclination);
RegisterFuncCont("I -", OAPI_KEY_MINUS, &LaunchMFD::DecreaseInclination, &LaunchMFD::IncreaseInclination);
}
Parameters
label- max 3 char long label of button. Example: "TGT"
key- associated key on keyboard, one of OAPI_KEY_*. Example: OAPI_KEY_T
funLClick- on left click MFD function pointer (handler). Example: & MyMFD::OpenDialogTarget. The handler can"t take any arguments.
funRClick- on right click MFD function pointer (handler). Optional
template<class MFDClass >
void EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::RegisterFunctionCont ( const std::string &  label,
DWORD  key,
MFDFunctionPtr  funLClick,
MFDFunctionPtr  funRClick = NULL 
)
protected

Registeres handler in MFD scope for buttons that should have a continous reaction.

Same as RegisterFunction(), but allows for continuous reaction on the keys, like for example, when you want to continuously modify a variable.

Parameters
label- max 3 char long label of button. Example: "TGT"
key- associated key on keyboard, one of OAPI_KEY_*. Example: OAPI_KEY_T
funLClick- on left click MFD function pointer (handler). Example: & MyMFD::OpenDialogTarget. The handler can"t take any arguments.
funRClick- on right click MFD function pointer (handler). Optional
template<class MFDClass >
void EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::RegisterPage ( const MFDBUTTONMENU *  menu,
int  size 
)
protected

Registeres button page, and buttons menu.

Must be called before RegisterFunction() is called. The menu must be STATICALLY declared. For example:

static const MFDBUTTONMENU mnu1[] =
{
{"Select target", 0, 'T'},
{"Enter altitude", "km", 'A'},
{"Switch button page", 0, 'P'},
};
RegisterPage(mnu1, sizeof(mnu1) / sizeof(MFDBUTTONMENU));
Parameters
menu- STATICALLY declared button menu
size- menu size. Use sizeof(menu) / sizeof(MFDBUTTONMENU)
template<class MFDClass>
virtual bool EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::SearchForKeysInOtherPages ( ) const
protectedpure virtual

Should other pages be searched for when pressing a key?

Normally the system reacts only keys on the current page. If this method returns true, then other pages are searched for as well.

Implemented in MyMFDButtonsPage.

template<class MFDClass>
void EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::SelectPage ( MFDClass *  mfdInstance,
int  pageIndex 
) const

Selects a specific buttons page.

Could be used instead of SwitchPage(). Example:

void LaunchMFD::SomeFunction( int pageIndex )
{
m_buttonPages.SelectPage(this, pageIndex);
}
Parameters
mfdInstance- Instance of your MFD class
pageIndex- Index of page to switch to.
template<class MFDClass>
void EnjoLib::MFDGoodies::MFDButtonPage< MFDClass >::SwitchPage ( MFDClass *  mfdInstance) const

Switches between button pages.

A button for this method needs to be registered through RegisterFunction(), which should call MFDClass' method, which then calls this method. Example:

MFDButtonPageLaunchMFD::MFDButtonPageLaunchMFD()
{
// ... add menu first, then functions
RegisterFunction("PG", OAPI_KEY_P, &LaunchMFD::SwitchButtonsPage);
// ...
}
void LaunchMFD::SwitchButtonsPage()
{
m_buttonPages.SwitchPage(this);
}
Parameters
mfdInstance- Instance of your MFD class

The documentation for this class was generated from the following file: