OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4KeyBinding Class Reference

#include <C4KeyboardInput.h>

Inheritance diagram for C4KeyBinding:
[legend]
Collaboration diagram for C4KeyBinding:
[legend]

Public Member Functions

 C4KeyBinding (const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority=PRIO_Base)
 
 C4KeyBinding (const CodeList &rDefCodes, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority=PRIO_Base)
 
 ~C4KeyBinding () override
 

Protected Types

enum  Priority {
  PRIO_None = 0u, PRIO_Base = 1u, PRIO_Dlg = 2u, PRIO_Ctrl = 3u,
  PRIO_CtrlOverride = 4u, PRIO_FocusCtrl = 5u, PRIO_Context = 6u, PRIO_PlrControl = 7u,
  PRIO_MoreThanMax = 100u
}
 
typedef std::vector< C4KeyCodeExCodeList
 

Protected Member Functions

void Ref ()
 
void Deref ()
 
const CodeListGetCodes () const
 
const StdStrBufGetName () const
 
C4KeyScope GetScope () const
 
unsigned int GetPriority () const
 
bool IsCodeMatched (const C4KeyCodeEx &key) const
 
void Update (const C4CustomKey *pByKey)
 
bool Execute (C4KeyEventType eEv, C4KeyCodeEx key)
 
bool IsDown () const
 
void KillCallbacks (const C4CustomKey *pOfKey)
 
void CompileFunc (StdCompiler *pComp)
 

Protected Attributes

CBVec vecCallbacks
 
int iRef
 

Detailed Description

Definition at line 474 of file C4KeyboardInput.h.

Member Typedef Documentation

typedef std::vector<C4KeyCodeEx> C4CustomKey::CodeList
inherited

Definition at line 419 of file C4KeyboardInput.h.

Member Enumeration Documentation

enum C4CustomKey::Priority
inherited
Enumerator
PRIO_None 
PRIO_Base 
PRIO_Dlg 
PRIO_Ctrl 
PRIO_CtrlOverride 
PRIO_FocusCtrl 
PRIO_Context 
PRIO_PlrControl 
PRIO_MoreThanMax 

Definition at line 431 of file C4KeyboardInput.h.

432  {
433  PRIO_None = 0u,
434  PRIO_Base = 1u,
435  PRIO_Dlg = 2u,
436  PRIO_Ctrl = 3u, // controls have higher priority than dialogs in GUI
437  PRIO_CtrlOverride = 4u, // dialog handlings of keys that overwrite regular control handlings
438  PRIO_FocusCtrl = 5u, // controls override special dialog handling keys (e.g., RenameEdit)
439  PRIO_Context = 6u, // context menus above controls
440  PRIO_PlrControl = 7u, // player controls overwrite any other controls
441  PRIO_MoreThanMax = 100u // must be larger than otherwise largest used priority
442  };

Constructor & Destructor Documentation

C4KeyBinding::C4KeyBinding ( const C4KeyCodeEx DefCode,
const char *  szName,
C4KeyScope  Scope,
C4KeyboardCallbackInterface pCallback,
unsigned int  uiPriority = PRIO_Base 
)

Definition at line 678 of file C4KeyboardInput.cpp.

References C4KeyboardInput_Init(), C4CustomKey::Ref(), and C4KeyboardInput::RegisterKey().

Referenced by C4GUI::RenameEdit::RenameEdit().

679  : C4CustomKey(DefCode, szName, Scope, pCallback, uiPriority)
680 {
681  // self holds a ref
682  Ref();
683  // register into keyboard input class
685 }
C4CustomKey(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority=PRIO_Base)
C4KeyboardInput & C4KeyboardInput_Init()
void RegisterKey(C4CustomKey *pRegKey)

Here is the call graph for this function:

Here is the caller graph for this function:

C4KeyBinding::C4KeyBinding ( const CodeList rDefCodes,
const char *  szName,
C4KeyScope  Scope,
C4KeyboardCallbackInterface pCallback,
unsigned int  uiPriority = PRIO_Base 
)

Definition at line 687 of file C4KeyboardInput.cpp.

References C4KeyboardInput_Init(), C4CustomKey::Ref(), and C4KeyboardInput::RegisterKey().

688  : C4CustomKey(rDefCodes, szName, Scope, pCallback, uiPriority)
689 {
690  // self holds a ref
691  Ref();
692  // register into keyboard input class
694 }
C4CustomKey(const C4KeyCodeEx &DefCode, const char *szName, C4KeyScope Scope, C4KeyboardCallbackInterface *pCallback, unsigned int uiPriority=PRIO_Base)
C4KeyboardInput & C4KeyboardInput_Init()
void RegisterKey(C4CustomKey *pRegKey)

Here is the call graph for this function:

C4KeyBinding::~C4KeyBinding ( )
override

Definition at line 696 of file C4KeyboardInput.cpp.

References Game, C4CustomKey::iRef, C4KeyboardInput::IsValid, C4Game::KeyboardInput, and C4KeyboardInput::UnregisterKeyBinding().

697 {
698  // deregister from keyboard input class, if that class still exists
701  // shouldn't be refed now
702  assert(iRef==1);
703  iRef = 0;
704 }
C4Game Game
Definition: C4Globals.cpp:52
C4KeyboardInput & KeyboardInput
Definition: C4Game.h:96
static bool IsValid
void UnregisterKeyBinding(C4CustomKey *pKey)

Here is the call graph for this function:

Member Function Documentation

void C4CustomKey::CompileFunc ( StdCompiler pComp)
inherited

Definition at line 657 of file C4KeyboardInput.cpp.

References StdStrBuf::getData(), mkNamingAdapt(), mkSTLContainerAdapt(), and StdCompiler::Value().

658 {
659  pComp->Value(mkNamingAdapt(mkSTLContainerAdapt(Codes), Name.getData(), DefaultCodes));
660 }
const char * getData() const
Definition: StdBuf.h:442
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Value(const T &rStruct)
Definition: StdCompiler.h:161
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:681

Here is the call graph for this function:

void C4CustomKey::Deref ( )
inlineinherited

Definition at line 455 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::RegisterKey(), and C4KeyboardInput::UnregisterKey().

455 { if (!--iRef) delete this; }

Here is the caller graph for this function:

bool C4CustomKey::Execute ( C4KeyEventType  eEv,
C4KeyCodeEx  key 
)
inherited

Definition at line 662 of file C4KeyboardInput.cpp.

References KEYEV_Down, and C4CustomKey::vecCallbacks.

Referenced by C4KeyboardInput::DoInput().

663 {
664  // remember down-state
665  is_down = (eEv == KEYEV_Down);
666  // execute all callbacks
667  for (auto & callback : vecCallbacks)
668  if (callback->OnKeyEvent(key, eEv))
669  return true;
670  // no event processed it
671  return false;
672 }

Here is the caller graph for this function:

const CodeList& C4CustomKey::GetCodes ( ) const
inlineinherited

Definition at line 457 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::GetKeyCodeNameByKeyName(), C4CustomKey::IsCodeMatched(), C4KeyboardInput::RegisterKey(), and C4KeyboardInput::UnregisterKey().

457 { return Codes.size() ? Codes : DefaultCodes; } // return assigned codes; default if no custom has been assigned

Here is the caller graph for this function:

const StdStrBuf& C4CustomKey::GetName ( ) const
inlineinherited

Definition at line 458 of file C4KeyboardInput.h.

Referenced by C4CustomKey::C4CustomKey(), C4KeyboardInput::RegisterKey(), and C4KeyboardInput::UnregisterKeyBinding().

458 { return Name; }

Here is the caller graph for this function:

unsigned int C4CustomKey::GetPriority ( ) const
inlineinherited

Definition at line 460 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::DoInput().

460 { return uiPriority; }

Here is the caller graph for this function:

C4KeyScope C4CustomKey::GetScope ( ) const
inlineinherited

Definition at line 459 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::DoInput().

459 { return Scope; }

Here is the caller graph for this function:

bool C4CustomKey::IsCodeMatched ( const C4KeyCodeEx key) const
inherited

Definition at line 615 of file C4KeyboardInput.cpp.

References C4CustomKey::GetCodes().

Referenced by C4KeyboardInput::DoInput().

616 {
617  const CodeList &codes = GetCodes();
618  for (const auto &code : codes)
619  if (code == key)
620  return true;
621  return false;
622 }
std::vector< C4KeyCodeEx > CodeList
const CodeList & GetCodes() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4CustomKey::IsDown ( ) const
inlineinherited

Definition at line 466 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::DoInput().

466 { return is_down; }

Here is the caller graph for this function:

void C4CustomKey::KillCallbacks ( const C4CustomKey pOfKey)
inherited

Definition at line 645 of file C4KeyboardInput.cpp.

References C4KeyboardCallbackInterfaceHasOriginalKey(), C4KeyboardCallbackInterface::Deref(), and C4CustomKey::vecCallbacks.

Referenced by C4KeyboardInput::UnregisterKeyBinding().

646 {
647  // remove all instances from list
648  CBVec::iterator i;
649  while ((i = std::find_if(vecCallbacks.begin(), vecCallbacks.end(), std::bind2nd(std::ptr_fun(&C4KeyboardCallbackInterfaceHasOriginalKey), pOfKey))) != vecCallbacks.end())
650  {
651  C4KeyboardCallbackInterface *pItfc = *i;
652  vecCallbacks.erase(i);
653  pItfc->Deref();
654  }
655 }
bool C4KeyboardCallbackInterfaceHasOriginalKey(C4KeyboardCallbackInterface *pIntfc, const C4CustomKey *pCheckKey)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4CustomKey::Ref ( )
inlineinherited

Definition at line 454 of file C4KeyboardInput.h.

References C4CustomKey::iRef.

Referenced by C4KeyBinding(), and C4KeyboardInput::RegisterKey().

454 { ++iRef; }

Here is the caller graph for this function:

void C4CustomKey::Update ( const C4CustomKey pByKey)
inherited

Definition at line 624 of file C4KeyboardInput.cpp.

References KEYSCOPE_None, C4CustomKey::PRIO_None, and C4CustomKey::vecCallbacks.

Referenced by C4KeyboardInput::RegisterKey().

625 {
626  assert(pByKey);
627  assert(Name == pByKey->Name);
628  // transfer any assigned data, except name which should be equal anyway
629  if (pByKey->DefaultCodes.size()) DefaultCodes = pByKey->DefaultCodes;
630  if (pByKey->Codes.size()) Codes = pByKey->Codes;
631  if (pByKey->Scope != KEYSCOPE_None) Scope = pByKey->Scope;
632  if (pByKey->uiPriority != PRIO_None) uiPriority = pByKey->uiPriority;
633  for (auto callback : pByKey->vecCallbacks)
634  {
635  callback->Ref();
636  vecCallbacks.push_back(callback);
637  }
638 }

Here is the caller graph for this function:

Member Data Documentation

int C4CustomKey::iRef
protectedinherited

Definition at line 445 of file C4KeyboardInput.h.

Referenced by C4CustomKey::Ref(), and ~C4KeyBinding().

CBVec C4CustomKey::vecCallbacks
inherited

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