OpenClonk
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 (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 418 of file C4KeyboardInput.h.

Member Typedef Documentation

◆ CodeList

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

Definition at line 421 of file C4KeyboardInput.h.

Member Enumeration Documentation

◆ Priority

Enumerator
PRIO_None 
PRIO_Base 
PRIO_Dlg 
PRIO_Ctrl 
PRIO_CtrlOverride 
PRIO_FocusCtrl 
PRIO_Context 
PRIO_PlrControl 
PRIO_MoreThanMax 

Definition at line 433 of file C4KeyboardInput.h.

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

Constructor & Destructor Documentation

◆ C4CustomKey() [1/3]

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

Definition at line 619 of file C4KeyboardInput.cpp.

620  : Scope(Scope), Name(), uiPriority(uiPriority), iRef(0), is_down(false)
621 {
622  // generate code
623  if (DefCode.Key != KEY_Default) DefaultCodes.push_back(DefCode);
624  // ctor for default key
625  Name.Copy(szName);
626  if (pCallback)
627  {
628  pCallback->Ref();
629  vecCallbacks.push_back(pCallback);
630  pCallback->pOriginalKey = this;
631  }
632 }
const C4KeyCode KEY_Default
class C4CustomKey * pOriginalKey
void Copy()
Definition: StdBuf.h:467
C4KeyCode Key

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

Here is the call graph for this function:

◆ C4CustomKey() [2/3]

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

Definition at line 634 of file C4KeyboardInput.cpp.

635  : DefaultCodes(std::move(rDefCodes)), Scope(Scope), Name(), uiPriority(uiPriority), iRef(0), is_down(false)
636 {
637  // ctor for default key
638  Name.Copy(szName);
639  if (pCallback)
640  {
641  pCallback->Ref();
642  vecCallbacks.push_back(pCallback);
643  pCallback->pOriginalKey = this;
644  }
645 }

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

Here is the call graph for this function:

◆ C4CustomKey() [3/3]

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

Definition at line 647 of file C4KeyboardInput.cpp.

648  : Codes(rCpy.Codes), DefaultCodes(rCpy.DefaultCodes), Scope(rCpy.Scope), Name(), uiPriority(rCpy.uiPriority), iRef(0), is_down(false)
649 {
650  Name.Copy(rCpy.GetName());
651  if (fCopyCallbacks)
652  {
653  for (auto callback : rCpy.vecCallbacks)
654  {
655  callback->Ref();
656  vecCallbacks.push_back(callback);
657  }
658  }
659 }
const StdStrBuf & GetName() const

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

Here is the call graph for this function:

◆ ~C4CustomKey()

C4CustomKey::~C4CustomKey ( )
virtual

Definition at line 661 of file C4KeyboardInput.cpp.

662 {
663  // free callback handles
664  for (CBVec::const_iterator i = vecCallbacks.begin(); i != vecCallbacks.end(); ++i)
665  (*i)->Deref();
666 }

References vecCallbacks.

Member Function Documentation

◆ CompileFunc()

void C4CustomKey::CompileFunc ( StdCompiler pComp)

Definition at line 705 of file C4KeyboardInput.cpp.

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

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

Here is the call graph for this function:

◆ Deref()

void C4CustomKey::Deref ( )
inline

Definition at line 457 of file C4KeyboardInput.h.

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

References iRef.

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

Here is the caller graph for this function:

◆ Execute()

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

Definition at line 710 of file C4KeyboardInput.cpp.

711 {
712  // remember down-state
713  is_down = (eEv == KEYEV_Down);
714  // execute all callbacks
715  for (auto & callback : vecCallbacks)
716  if (callback->OnKeyEvent(key, eEv))
717  return true;
718  // no event processed it
719  return false;
720 }
@ KEYEV_Down

References KEYEV_Down, and vecCallbacks.

Referenced by C4KeyboardInput::DoInput().

Here is the caller graph for this function:

◆ GetCodes()

const CodeList& C4CustomKey::GetCodes ( ) const
inline

Definition at line 459 of file C4KeyboardInput.h.

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

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

Here is the caller graph for this function:

◆ GetName()

const StdStrBuf& C4CustomKey::GetName ( ) const
inline

Definition at line 460 of file C4KeyboardInput.h.

460 { return Name; }

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

Here is the caller graph for this function:

◆ GetPriority()

unsigned int C4CustomKey::GetPriority ( ) const
inline

Definition at line 462 of file C4KeyboardInput.h.

462 { return uiPriority; }

Referenced by C4KeyboardInput::DoInput().

Here is the caller graph for this function:

◆ GetScope()

C4KeyScope C4CustomKey::GetScope ( ) const
inline

Definition at line 461 of file C4KeyboardInput.h.

461 { return Scope; }

Referenced by C4KeyboardInput::DoInput().

Here is the caller graph for this function:

◆ IsCodeMatched()

bool C4CustomKey::IsCodeMatched ( const C4KeyCodeEx key) const

Definition at line 668 of file C4KeyboardInput.cpp.

669 {
670  const CodeList &codes = GetCodes();
671  for (const auto &code : codes)
672  if (code == key)
673  return true;
674  return false;
675 }
const CodeList & GetCodes() const
std::vector< C4KeyCodeEx > CodeList

References GetCodes().

Referenced by C4KeyboardInput::DoInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDown()

bool C4CustomKey::IsDown ( ) const
inline

Definition at line 468 of file C4KeyboardInput.h.

468 { return is_down; }

Referenced by C4KeyboardInput::DoInput().

Here is the caller graph for this function:

◆ KillCallbacks()

void C4CustomKey::KillCallbacks ( const C4CustomKey pOfKey)

Definition at line 693 of file C4KeyboardInput.cpp.

694 {
695  // remove all instances from list
696  CBVec::iterator i;
697  while ((i = std::find_if(vecCallbacks.begin(), vecCallbacks.end(), [pOfKey](CBVec::value_type pIntfc) { return pIntfc->IsOriginalKey(pOfKey); })) != vecCallbacks.end())
698  {
699  C4KeyboardCallbackInterface *pItfc = *i;
700  vecCallbacks.erase(i);
701  pItfc->Deref();
702  }
703 }

References C4KeyboardCallbackInterface::Deref(), and vecCallbacks.

Referenced by C4KeyboardInput::UnregisterKeyBinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ref()

void C4CustomKey::Ref ( )
inline

Definition at line 456 of file C4KeyboardInput.h.

456 { ++iRef; }

References iRef.

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

Here is the caller graph for this function:

◆ Update()

void C4CustomKey::Update ( const C4CustomKey pByKey)

Definition at line 677 of file C4KeyboardInput.cpp.

678 {
679  assert(pByKey);
680  assert(Name == pByKey->Name);
681  // transfer any assigned data, except name which should be equal anyway
682  if (pByKey->DefaultCodes.size()) DefaultCodes = pByKey->DefaultCodes;
683  if (pByKey->Codes.size()) Codes = pByKey->Codes;
684  if (pByKey->Scope != KEYSCOPE_None) Scope = pByKey->Scope;
685  if (pByKey->uiPriority != PRIO_None) uiPriority = pByKey->uiPriority;
686  for (auto callback : pByKey->vecCallbacks)
687  {
688  callback->Ref();
689  vecCallbacks.push_back(callback);
690  }
691 }
@ KEYSCOPE_None

References KEYSCOPE_None, PRIO_None, and vecCallbacks.

Referenced by C4KeyboardInput::RegisterKey().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4Game

friend class C4Game
friend

Definition at line 450 of file C4KeyboardInput.h.

Member Data Documentation

◆ iRef

int C4CustomKey::iRef
protected

Definition at line 447 of file C4KeyboardInput.h.

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

◆ vecCallbacks

CBVec C4CustomKey::vecCallbacks

Definition at line 431 of file C4KeyboardInput.h.

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


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