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

#include <C4KeyboardInput.h>

Inheritance diagram for C4CustomKey:
[legend]

Public 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
 

Public Member Functions

 C4CustomKey (const C4CustomKey &rCpy, bool fCopyCallbacks)
 
virtual ~C4CustomKey ()
 
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)
 

Public Attributes

CBVec vecCallbacks
 

Protected Member Functions

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

Protected Attributes

int iRef
 

Friends

class C4Game
 

Detailed Description

Definition at line 423 of file C4KeyboardInput.h.

Member Typedef Documentation

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

Definition at line 426 of file C4KeyboardInput.h.

Member Enumeration Documentation

Enumerator
PRIO_None 
PRIO_Base 
PRIO_Dlg 
PRIO_Ctrl 
PRIO_CtrlOverride 
PRIO_FocusCtrl 
PRIO_Context 
PRIO_PlrControl 
PRIO_MoreThanMax 

Definition at line 438 of file C4KeyboardInput.h.

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

Constructor & Destructor Documentation

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

Definition at line 571 of file C4KeyboardInput.cpp.

References StdStrBuf::Copy(), C4KeyCodeEx::Key, KEY_Default, C4KeyboardCallbackInterface::pOriginalKey, C4KeyboardCallbackInterface::Ref(), and vecCallbacks.

572  : Scope(Scope), Name(), uiPriority(uiPriority), iRef(0), is_down(false)
573 {
574  // generate code
575  if (DefCode.Key != KEY_Default) DefaultCodes.push_back(DefCode);
576  // ctor for default key
577  Name.Copy(szName);
578  if (pCallback)
579  {
580  pCallback->Ref();
581  vecCallbacks.push_back(pCallback);
582  pCallback->pOriginalKey = this;
583  }
584 }
const C4KeyCode KEY_Default
C4KeyCode Key
void Copy()
Definition: StdBuf.h:475
class C4CustomKey * pOriginalKey

Here is the call graph for this function:

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

Definition at line 586 of file C4KeyboardInput.cpp.

References StdStrBuf::Copy(), C4KeyboardCallbackInterface::pOriginalKey, C4KeyboardCallbackInterface::Ref(), and vecCallbacks.

587  : DefaultCodes(rDefCodes), Scope(Scope), Name(), uiPriority(uiPriority), iRef(0), is_down(false)
588 {
589  // ctor for default key
590  Name.Copy(szName);
591  if (pCallback)
592  {
593  pCallback->Ref();
594  vecCallbacks.push_back(pCallback);
595  pCallback->pOriginalKey = this;
596  }
597 }
void Copy()
Definition: StdBuf.h:475
class C4CustomKey * pOriginalKey

Here is the call graph for this function:

C4CustomKey::C4CustomKey ( const C4CustomKey rCpy,
bool  fCopyCallbacks 
)

Definition at line 599 of file C4KeyboardInput.cpp.

References StdStrBuf::Copy(), GetName(), and vecCallbacks.

600  : Codes(rCpy.Codes), DefaultCodes(rCpy.DefaultCodes), Scope(rCpy.Scope), Name(), uiPriority(rCpy.uiPriority), iRef(0), is_down(false)
601 {
602  Name.Copy(rCpy.GetName());
603  if (fCopyCallbacks)
604  {
605  for (CBVec::const_iterator i = rCpy.vecCallbacks.begin(); i != rCpy.vecCallbacks.end(); ++i)
606  {
607  (*i)->Ref();
608  vecCallbacks.push_back(*i);
609  }
610  }
611 }
const StdStrBuf & GetName() const
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

C4CustomKey::~C4CustomKey ( )
virtual

Definition at line 613 of file C4KeyboardInput.cpp.

References vecCallbacks.

614 {
615  // free callback handles
616  for (CBVec::const_iterator i = vecCallbacks.begin(); i != vecCallbacks.end(); ++i)
617  (*i)->Deref();
618 }

Member Function Documentation

void C4CustomKey::CompileFunc ( StdCompiler pComp)

Definition at line 662 of file C4KeyboardInput.cpp.

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

663 {
664  pComp->Value(mkNamingAdapt(mkSTLContainerAdapt(Codes), Name.getData(), DefaultCodes));
665 }
const char * getData() const
Definition: StdBuf.h:450
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:171
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:679

Here is the call graph for this function:

void C4CustomKey::Deref ( )
inline

Definition at line 462 of file C4KeyboardInput.h.

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

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

Here is the caller graph for this function:

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

Definition at line 667 of file C4KeyboardInput.cpp.

References KEYEV_Down, and vecCallbacks.

Referenced by C4KeyboardInput::DoInput().

668 {
669  // remember down-state
670  is_down = (eEv == KEYEV_Down);
671  // execute all callbacks
672  for (CBVec::iterator i = vecCallbacks.begin(); i != vecCallbacks.end(); ++i)
673  if ((*i)->OnKeyEvent(key, eEv))
674  return true;
675  // no event processed it
676  return false;
677 }

Here is the caller graph for this function:

const CodeList& C4CustomKey::GetCodes ( ) const
inline

Definition at line 464 of file C4KeyboardInput.h.

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

464 { 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
inline

Definition at line 465 of file C4KeyboardInput.h.

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

465 { return Name; }

Here is the caller graph for this function:

unsigned int C4CustomKey::GetPriority ( ) const
inline

Definition at line 467 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::DoInput().

467 { return uiPriority; }

Here is the caller graph for this function:

C4KeyScope C4CustomKey::GetScope ( ) const
inline

Definition at line 466 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::DoInput().

466 { return Scope; }

Here is the caller graph for this function:

bool C4CustomKey::IsCodeMatched ( const C4KeyCodeEx key) const

Definition at line 620 of file C4KeyboardInput.cpp.

References GetCodes().

Referenced by C4KeyboardInput::DoInput().

621 {
622  const CodeList &codes = GetCodes();
623  for (const auto &code : codes)
624  if (code == key)
625  return true;
626  return false;
627 }
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
inline

Definition at line 473 of file C4KeyboardInput.h.

Referenced by C4KeyboardInput::DoInput().

473 { return is_down; }

Here is the caller graph for this function:

void C4CustomKey::KillCallbacks ( const C4CustomKey pOfKey)

Definition at line 650 of file C4KeyboardInput.cpp.

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

Referenced by C4KeyboardInput::UnregisterKeyBinding().

651 {
652  // remove all instances from list
653  CBVec::iterator i;
654  while ((i = std::find_if(vecCallbacks.begin(), vecCallbacks.end(), std::bind2nd(std::ptr_fun(&C4KeyboardCallbackInterfaceHasOriginalKey), pOfKey))) != vecCallbacks.end())
655  {
656  C4KeyboardCallbackInterface *pItfc = *i;
657  vecCallbacks.erase(i);
658  pItfc->Deref();
659  }
660 }
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 ( )
inline

Definition at line 461 of file C4KeyboardInput.h.

References iRef.

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

461 { ++iRef; }

Here is the caller graph for this function:

void C4CustomKey::Update ( const C4CustomKey pByKey)

Definition at line 629 of file C4KeyboardInput.cpp.

References KEYSCOPE_None, PRIO_None, and vecCallbacks.

Referenced by C4KeyboardInput::RegisterKey().

630 {
631  assert(pByKey);
632  assert(Name == pByKey->Name);
633  // transfer any assigned data, except name which should be equal anyway
634  if (pByKey->DefaultCodes.size()) DefaultCodes = pByKey->DefaultCodes;
635  if (pByKey->Codes.size()) Codes = pByKey->Codes;
636  if (pByKey->Scope != KEYSCOPE_None) Scope = pByKey->Scope;
637  if (pByKey->uiPriority != PRIO_None) uiPriority = pByKey->uiPriority;
638  for (CBVec::const_iterator i = pByKey->vecCallbacks.begin(); i != pByKey->vecCallbacks.end(); ++i)
639  {
640  (*i)->Ref();
641  vecCallbacks.push_back(*i);
642  }
643 }

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4Game
friend

Definition at line 455 of file C4KeyboardInput.h.

Member Data Documentation

int C4CustomKey::iRef
protected

Definition at line 452 of file C4KeyboardInput.h.

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

CBVec C4CustomKey::vecCallbacks

Definition at line 436 of file C4KeyboardInput.h.

Referenced by C4CustomKey(), Execute(), KillCallbacks(), Update(), and ~C4CustomKey().


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