Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Key< T > Class Template Reference

#include <Key.h>

Public Member Functions

 Key ()
 
 Key (const T &character, const short &additional)
 
 ~Key ()
 
bool Match (const Key< T > &other, bool strict=false) const
 
std::string GenerateStringMessage (const int &style=0)
 
bool Match (const T &chara, const short &additional, bool strict=false) const
 
bool Match (const T &chara) const
 
GetCharacter () const
 
short GetAdditional () const
 
void Set (const T &character, const short &additional)
 
void SetAdditional (const short &additional)
 
std::string GenerateStringFromKey ()
 

Static Public Member Functions

static void DeConstructSpecial (short keyspes, bool &Shift, bool &Alt, bool &Ctrl)
 
static Key< T > GenerateKeyFromString (const std::string &representation)
 https://wiki.libsdl.org/SDL_Keycode for key names More...
 

Detailed Description

template<class T>
class Leviathan::Key< T >

Definition at line 51 of file Key.h.

Constructor & Destructor Documentation

◆ Key() [1/2]

template<class T>
Leviathan::Key< T >::Key ( )
inline

Definition at line 53 of file Key.h.

54  {
55  Extras = 0;
56  Character = (T)0;
57  }

◆ Key() [2/2]

template<class T>
Leviathan::Key< T >::Key ( const T &  character,
const short &  additional 
)
inline

Definition at line 58 of file Key.h.

59  {
60  Extras = additional;
61  Character = character;
62  }

◆ ~Key()

template<class T>
Leviathan::Key< T >::~Key ( )
inline

Definition at line 63 of file Key.h.

63 {}

Member Function Documentation

◆ DeConstructSpecial()

template<class T>
static void Leviathan::Key< T >::DeConstructSpecial ( short  keyspes,
bool &  Shift,
bool &  Alt,
bool &  Ctrl 
)
inlinestatic

Definition at line 138 of file Key.h.

139  {
140 
141  if(keyspes & KEYSPECIAL_SHIFT)
142  Shift = true;
143  if(keyspes & KEYSPECIAL_ALT)
144  Alt = true;
145  if(keyspes & KEYSPECIAL_CTRL)
146  Ctrl = true;
147  }

◆ GenerateKeyFromString()

template<class T>
static Key<T> Leviathan::Key< T >::GenerateKeyFromString ( const std::string &  representation)
inlinestatic

https://wiki.libsdl.org/SDL_Keycode for key names

Definition at line 150 of file Key.h.

151  {
152  if(representation.size() == 0) {
153  // empty, nothing to do //
154  return Key<T>((T)0, 0);
155  }
156 
157  StringIterator itr(representation);
158 
159  auto str = itr.GetUntilNextCharacterOrAll<std::string>('+');
160 
161  T character;
162 
163  // Only upcase single letters as long key codes have also lowercase letters
164  if(str->length() <= 1) {
165 
166  auto converted = StringOperations::ToUpperCase<std::string>(*str);
167 
168  character = Leviathan::KeyMapping::ConvertStringToKeyCode(converted);
169 
170  } else {
171 
173  }
174 
175  short special = 0;
176 
177  while((str = itr.GetUntilNextCharacterOrAll<std::string>('+')) && (str->size() > 0)) {
178 
179  if(StringOperations::CompareInsensitive(*str, std::string("ALT"))) {
180  special |= KEYSPECIAL_ALT;
181  }
182  if(StringOperations::CompareInsensitive(*str, std::string("SHIFT"))) {
183  special |= KEYSPECIAL_SHIFT;
184  }
185  if(StringOperations::CompareInsensitive(*str, std::string("CTRL"))) {
186  special |= KEYSPECIAL_CTRL;
187  }
188  if(StringOperations::CompareInsensitive(*str, std::string("WIN")) ||
189  StringOperations::CompareInsensitive(*str, std::string("META")) ||
190  StringOperations::CompareInsensitive(*str, std::string("SUPER")) ||
191  StringOperations::CompareInsensitive(*str, std::string("GUI"))) {
192  special |= KEYSPECIAL_SUPER;
193  }
194  }
195 
196  return Key<T>(character, special);
197  }
DLLEXPORT int32_t ConvertStringToKeyCode(const std::string &str)
Definition: KeyMapping.cpp:38
static bool CompareInsensitive(const StringTypeN &data, const StringTypeN &second)

◆ GenerateStringFromKey()

template<class T>
std::string Leviathan::Key< T >::GenerateStringFromKey ( )
inline

Definition at line 199 of file Key.h.

200  {
201  // First the actual key value //
202  auto resultstr = Leviathan::KeyMapping::ConvertKeyCodeToString(Character);
203 
204  // Add special modifiers //
205  if(Extras & KEYSPECIAL_ALT)
206  resultstr += "+ALT";
207  if(Extras & KEYSPECIAL_CTRL)
208  resultstr += "+CTRL";
209  if(Extras & KEYSPECIAL_SHIFT)
210  resultstr += "+SHIFT";
211  if(Extras & KEYSPECIAL_SUPER)
212  resultstr += "+META";
213  // Result is done //
214  return resultstr;
215  }
DLLEXPORT std::string ConvertKeyCodeToString(const int32_t &code)
Definition: KeyMapping.cpp:52

◆ GenerateStringMessage()

template<class T>
std::string Leviathan::Key< T >::GenerateStringMessage ( const int &  style = 0)
inline

Definition at line 87 of file Key.h.

88  {
89  // create a string that represents this key //
90  if(style == 0) {
91  // debug string //
92  std::string resultstr = "Key[" + Convert::ToString((char)Character) + "]=";
93 
94  resultstr += Convert::ToString<T>(Character);
95  resultstr += "(0x" + Convert::ToHexadecimalString<T>(Character) + ")+";
96 
97  return resultstr;
98  }
99  // various styles from which a key can be easily parsed //
100  DEBUG_BREAK;
101  return "error";
102  }
static std::string ToString(const T &val)
Definition: Convert.h:72

◆ GetAdditional()

template<class T>
short Leviathan::Key< T >::GetAdditional ( ) const
inline

Definition at line 121 of file Key.h.

122  {
123  return Extras;
124  }

◆ GetCharacter()

template<class T>
T Leviathan::Key< T >::GetCharacter ( ) const
inline

Definition at line 117 of file Key.h.

118  {
119  return Character;
120  }

◆ Match() [1/3]

template<class T>
bool Leviathan::Key< T >::Match ( const Key< T > &  other,
bool  strict = false 
) const
inline

Definition at line 65 of file Key.h.

66  {
67  if(other.Character != this->Character)
68  return false;
69  if(strict) {
70  if(other.Extras != this->Extras)
71  return false;
72  } else {
73 
74  if((Extras & KEYSPECIAL_SHIFT) && !(other.Extras & KEYSPECIAL_SHIFT)) {
75  return false;
76  }
77  if((Extras & KEYSPECIAL_ALT) && !(other.Extras & KEYSPECIAL_ALT)) {
78  return false;
79  }
80  if((Extras & KEYSPECIAL_CTRL) && !(other.Extras & KEYSPECIAL_CTRL)) {
81  return false;
82  }
83  }
84  return true;
85  }

◆ Match() [2/3]

template<class T>
bool Leviathan::Key< T >::Match ( const T &  chara,
const short &  additional,
bool  strict = false 
) const
inline

Definition at line 104 of file Key.h.

105  {
106  return Match(Key<T>(chara, additional), strict);
107  }
bool Match(const Key< T > &other, bool strict=false) const
Definition: Key.h:65

◆ Match() [3/3]

template<class T>
bool Leviathan::Key< T >::Match ( const T &  chara) const
inline

Definition at line 109 of file Key.h.

110  {
111  if(chara != this->Character)
112  return false;
113  return true;
114  }

◆ Set()

template<class T>
void Leviathan::Key< T >::Set ( const T &  character,
const short &  additional 
)
inline

Definition at line 126 of file Key.h.

127  {
128  Character = character;
129  Extras = additional;
130  }

◆ SetAdditional()

template<class T>
void Leviathan::Key< T >::SetAdditional ( const short &  additional)
inline

Definition at line 132 of file Key.h.

133  {
134 
135  Extras = additional;
136  }

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