Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
in_kb.h File Reference
#include "gldrv/winsys.h"
#include "in.h"

Go to the source code of this file.

Enumerations

enum  KB_MODIFIER_ENUM { KB_MOD_ALT =1, KB_MOD_CTRL =2, KB_MOD_SHIFT =4, KB_MOD_MASK =7 }
 

Functions

unsigned int getActiveModifiers ()
 
unsigned int pullActiveModifiers ()
 
void setActiveModifiers (unsigned int mask)
 
unsigned int getModifier (const char *mod_name)
 
void ProcessKB (unsigned int player)
 
void BindKey (int key, unsigned int modifiers, unsigned int player, KBHandler handler, const KBData &data)
 
void UnbindKey (int key, unsigned int modifiers)
 
void InitKB ()
 
void RestoreKB ()
 

Variables

const int KEYMAP_SIZE = WSK_LAST
 
const int LAST_MODIFIER = KB_MOD_MASK+1
 

Enumeration Type Documentation

Enumerator
KB_MOD_ALT 
KB_MOD_CTRL 
KB_MOD_SHIFT 
KB_MOD_MASK 

Definition at line 30 of file in_kb.h.

31 {
32  KB_MOD_ALT =1,
33  KB_MOD_CTRL =2,
34  KB_MOD_SHIFT=4,
35  KB_MOD_MASK =7
36 };

Function Documentation

void BindKey ( int  key,
unsigned int  modifiers,
unsigned int  player,
KBHandler  handler,
const KBData data 
)

Definition at line 213 of file in_kb.cpp.

References HandlerCall::data, HandlerCall::function, playerBindings, and RESET.

Referenced by createObjects(), and InitializeInput().

214 {
215  keyBindings[mod][key].function = handler;
216  keyBindings[mod][key].data = data;
217  playerBindings[mod][key] = player;
218  handler( std::string(), RESET ); //key is not used in handler
219 }
unsigned int getActiveModifiers ( )

Definition at line 109 of file in_kb.cpp.

References _activeModifiers.

Referenced by pullActiveModifiers().

110 {
111  return _activeModifiers;
112 }
unsigned int getModifier ( const char *  mod_name)

Definition at line 120 of file in_kb.cpp.

References KB_MOD_ALT, KB_MOD_CTRL, and KB_MOD_SHIFT.

Referenced by glut_keyboard_cb().

121 {
122  if (mod_name[0] == '\0')
123  return 0;
124  unsigned int rv = 0;
125  if ( strstr( mod_name, "shift" ) || strstr( mod_name, "uppercase" ) || strstr( mod_name, "caps" ) )
126  rv |= KB_MOD_SHIFT;
127  if ( strstr( mod_name, "ctrl" ) || strstr( mod_name, "cntrl" ) || strstr( mod_name, "control" ) )
128  rv |= KB_MOD_CTRL;
129  if ( strstr( mod_name, "alt" ) || strstr( mod_name, "alternate" ) )
130  rv |= KB_MOD_ALT;
131  return rv;
132 }
void InitKB ( )

Definition at line 195 of file in_kb.cpp.

References a, i, KEYMAP_SIZE, keyState, LAST_MODIFIER, RestoreKB(), UnbindKey(), and UP.

Referenced by InitInput().

196 {
197  for (int i = 0; i < LAST_MODIFIER; ++i)
198  for (int a = 0; a < KEYMAP_SIZE; a++) {
199  keyState[i][a] = UP;
200  UnbindKey( a, i );
201  }
202  RestoreKB();
203 }
void ProcessKB ( unsigned int  player)

Definition at line 205 of file in_kb.cpp.

References a, HandlerCall::function, KEYMAP_SIZE, keyState, LAST_MODIFIER, and playerBindings.

Referenced by ProcessInput().

206 {
207  for (int mod = 0; mod < LAST_MODIFIER; mod++)
208  for (int a = 0; a < KEYMAP_SIZE; a++)
209  if (playerBindings[mod][a] == player)
210  keyBindings[mod][a].function( keyBindings[mod][a].data, keyState[mod][a] );
211 }
unsigned int pullActiveModifiers ( )

Definition at line 113 of file in_kb.cpp.

References getActiveModifiers().

Referenced by BaseUtil::SetKeyStatusEventData().

114 {
115 #ifdef SDL_WINDOWING
116  setActiveModifiersSDL( SDL_GetModState() );
117 #endif
118  return getActiveModifiers();
119 }
void RestoreKB ( )

Definition at line 184 of file in_kb.cpp.

References a, DOWN, HandlerCall::function, glut_keyboard_cb(), i, KEYMAP_SIZE, keyState, LAST_MODIFIER, RELEASE, UP, and winsys_set_keyboard_func().

Referenced by GameCockpit::Draw(), InitKB(), restore_main_loop(), CockpitKeys::TextMessageCallback(), and NavComputer::toggleVisibility().

185 {
186  for (int i = 0; i < LAST_MODIFIER; ++i)
187  for (int a = 0; a < KEYMAP_SIZE; a++)
188  if (keyState[i][a] == DOWN) {
189  keyBindings[i][a].function( keyBindings[i][a].data, RELEASE );
190  keyState[i][a] = UP;
191  }
193 }
void setActiveModifiers ( unsigned int  mask)

Definition at line 96 of file in_kb.cpp.

References _activeModifiers.

Referenced by base_keyboard_cb(), gamemenu_keyboard_handler(), and glut_keyboard_cb().

97 {
98  _activeModifiers = mask;
99 }
void UnbindKey ( int  key,
unsigned int  modifiers 
)

Definition at line 221 of file in_kb.cpp.

Referenced by InitKB().

222 {
223  keyBindings[mod][key] = HandlerCall();
224 }

Variable Documentation

const int KEYMAP_SIZE = WSK_LAST

Definition at line 40 of file in_kb.h.

Referenced by InitKB(), ProcessKB(), and RestoreKB().

const int LAST_MODIFIER = KB_MOD_MASK+1

Definition at line 41 of file in_kb.h.

Referenced by glut_keyboard_cb(), InitKB(), ProcessKB(), and RestoreKB().