Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7661 in orxonox.OLD for trunk/src/lib/event


Ignore:
Timestamp:
May 18, 2006, 12:55:34 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the QT_GUI back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/qt_gui . -r7607:HEAD

absolutely no conflicts :)

Location:
trunk/src/lib/event
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/key_mapper.cc

    r7256 r7661  
    2727#include "util/preferences.h"
    2828#include "key_names.h"
     29#include "event_def.h"
    2930#include "debug.h"
    3031
     
    7172 * and you do not have to care about The namings, as they might change
    7273 */
    73 orxKeyMapping map[] = {
    74   {&KeyMapper::PEV_FORWARD,              CONFIG_NAME_PLAYER_FORWARD},
    75   {&KeyMapper::PEV_BACKWARD,             CONFIG_NAME_PLAYER_BACKWARD},
    76   {&KeyMapper::PEV_UP,                   CONFIG_NAME_PLAYER_UP},
    77   {&KeyMapper::PEV_DOWN,                 CONFIG_NAME_PLAYER_DOWN},
    78   {&KeyMapper::PEV_LEFT,                 CONFIG_NAME_PLAYER_LEFT},
    79   {&KeyMapper::PEV_RIGHT,                CONFIG_NAME_PLAYER_RIGHT},
    80   {&KeyMapper::PEV_ROLL_LEFT,            CONFIG_NAME_PLAYER_ROLL_RIGHT},
    81   {&KeyMapper::PEV_ROLL_RIGHT,           CONFIG_NAME_PLAYER_ROLL_LEFT},
    82   {&KeyMapper::PEV_STRAFE_LEFT,          "StrafeLeft"},
    83   {&KeyMapper::PEV_STRAFE_RIGHT,         "StrafeRight"},
    84 
    85   {&KeyMapper::PEV_FIRE1,                CONFIG_NAME_PLAYER_FIRE},
    86   {&KeyMapper::PEV_FIRE1,                "Fire1"},
    87   {&KeyMapper::PEV_FIRE2,                "Fire2"},
    88   {&KeyMapper::PEV_NEXT_WEAPON,          CONFIG_NAME_PLAYER_NEXT_WEAPON},
    89   {&KeyMapper::PEV_PREVIOUS_WEAPON,      CONFIG_NAME_PLAYER_PREV_WEAPON},
    90 
    91   {&KeyMapper::PEV_CHANGE_SHIP,          CONFIG_NAME_PLAYER_CHANGE_SHIP},
    92 
    93 
    94   {&KeyMapper::PEV_VIEW0,                CONFIG_NAME_VIEW0},
    95   {&KeyMapper::PEV_VIEW1,                CONFIG_NAME_VIEW1},
    96   {&KeyMapper::PEV_VIEW2,                CONFIG_NAME_VIEW2},
    97   {&KeyMapper::PEV_VIEW3,                CONFIG_NAME_VIEW3},
    98   {&KeyMapper::PEV_VIEW4,                CONFIG_NAME_VIEW4},
    99   {&KeyMapper::PEV_VIEW5,                CONFIG_NAME_VIEW5},
    100 
    101   {&KeyMapper::PEV_NEXT_WORLD,           CONFIG_NAME_NEXT_WORLD},
    102   {&KeyMapper::PEV_PREVIOUS_WORLD,       CONFIG_NAME_PREV_WORLD},
    103 
    104   {&KeyMapper::PEV_PAUSE,                CONFIG_NAME_PAUSE},
    105   {&KeyMapper::PEV_QUIT,                 CONFIG_NAME_QUIT},
    106   {NULL, NULL}
     74KeyMapper::KeyMapping KeyMapper::map[] = {
     75  {&KeyMapper::PEV_FORWARD,              CONFIG_NAME_PLAYER_FORWARD,         SDLK_w},
     76  {&KeyMapper::PEV_BACKWARD,             CONFIG_NAME_PLAYER_BACKWARD,        SDLK_s},
     77  {&KeyMapper::PEV_UP,                   CONFIG_NAME_PLAYER_UP,              SDLK_r},
     78  {&KeyMapper::PEV_DOWN,                 CONFIG_NAME_PLAYER_DOWN,            SDLK_f},
     79  {&KeyMapper::PEV_LEFT,                 CONFIG_NAME_PLAYER_LEFT,            SDLK_a},
     80  {&KeyMapper::PEV_RIGHT,                CONFIG_NAME_PLAYER_RIGHT,           SDLK_d},
     81  {&KeyMapper::PEV_ROLL_RIGHT,           CONFIG_NAME_PLAYER_ROLL_LEFT,       SDLK_z},
     82  {&KeyMapper::PEV_ROLL_LEFT,            CONFIG_NAME_PLAYER_ROLL_RIGHT,      SDLK_c},
     83  {&KeyMapper::PEV_STRAFE_LEFT,          "StrafeLeft",                       SDLK_q},
     84  {&KeyMapper::PEV_STRAFE_RIGHT,         "StrafeRight",                      SDLK_e},
     85
     86  {&KeyMapper::PEV_FIRE1,                CONFIG_NAME_PLAYER_FIRE,            EV_MOUSE_BUTTON_LEFT},
     87  {&KeyMapper::PEV_FIRE2,                "Fire2",                            EV_MOUSE_BUTTON_RIGHT},
     88  {&KeyMapper::PEV_NEXT_WEAPON,          CONFIG_NAME_PLAYER_NEXT_WEAPON,     EV_MOUSE_BUTTON_WHEELUP},
     89  {&KeyMapper::PEV_PREVIOUS_WEAPON,      CONFIG_NAME_PLAYER_PREV_WEAPON,     EV_MOUSE_BUTTON_WHEELDOWN},
     90
     91  {&KeyMapper::PEV_CHANGE_SHIP,          CONFIG_NAME_PLAYER_CHANGE_SHIP,     SDLK_g},
     92
     93
     94  {&KeyMapper::PEV_VIEW0,                CONFIG_NAME_VIEW0,                  SDLK_1},
     95  {&KeyMapper::PEV_VIEW1,                CONFIG_NAME_VIEW1,                  SDLK_2},
     96  {&KeyMapper::PEV_VIEW2,                CONFIG_NAME_VIEW2,                  SDLK_3},
     97  {&KeyMapper::PEV_VIEW3,                CONFIG_NAME_VIEW3,                  SDLK_4},
     98  {&KeyMapper::PEV_VIEW4,                CONFIG_NAME_VIEW4,                  SDLK_5},
     99  {&KeyMapper::PEV_VIEW5,                CONFIG_NAME_VIEW5,                  SDLK_6},
     100
     101  {&KeyMapper::PEV_NEXT_WORLD,           CONFIG_NAME_NEXT_WORLD,             SDLK_x},
     102  {&KeyMapper::PEV_PREVIOUS_WORLD,       CONFIG_NAME_PREV_WORLD,             SDLK_z},
     103
     104  {&KeyMapper::PEV_PAUSE,                CONFIG_NAME_PAUSE,                  SDLK_p},
     105  {&KeyMapper::PEV_QUIT,                 CONFIG_NAME_QUIT,                   SDLK_ESCAPE},
     106  {NULL, "", 0}
    107107};
    108108
     
    138138void KeyMapper::loadKeyBindings(IniParser* iniParser)
    139139{
    140   if( !iniParser->getSection (CONFIG_SECTION_PLAYER "1"))
    141   {
    142     PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1\n");
     140  if( !iniParser->getSection (CONFIG_SECTION_CONTROL))
     141  {
     142    PRINTF(1)("Could not find key bindings " CONFIG_SECTION_CONTROL "\n");
    143143    return;
    144144  }
     
    158158
    159159  // PARSE MISC SECTION
    160   if( !iniParser->getSection (CONFIG_SECTION_MISC_KEYS))
    161   {
    162     PRINTF(1)("Could not find key bindings" CONFIG_SECTION_MISC_KEYS "\n");
     160//   if( !iniParser->getSection (CONFIG_SECTION_MISC_KEYS))
     161//   {
     162//     PRINTF(1)("Could not find key bindings" CONFIG_SECTION_MISC_KEYS "\n");
     163//     return;
     164//   }
     165//
     166//   iniParser->firstVar();
     167//   while( iniParser->getCurrentName() != "" )
     168//   {
     169//     PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
     170//     index = nameToIndex (iniParser->getCurrentValue());
     171//     this->mapKeys(iniParser->getCurrentName(), index);
     172//     iniParser->nextVar();
     173//   }
     174}
     175
     176void KeyMapper::loadKeyBindings()
     177{
     178  if( !Preferences::getInstance()->sectionExists(CONFIG_SECTION_CONTROL))
     179  {
     180    PRINTF(1)("Could not find key bindings " CONFIG_SECTION_CONTROL "\n");
    163181    return;
    164182  }
    165 
    166   iniParser->firstVar();
    167   while( iniParser->getCurrentName() != "" )
    168   {
    169     PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
    170     index = nameToIndex (iniParser->getCurrentValue());
    171     this->mapKeys(iniParser->getCurrentName(), index);
    172     iniParser->nextVar();
    173   }
    174 }
    175 
    176 void KeyMapper::loadKeyBindings()
    177 {
    178   if( !Preferences::getInstance()->sectionExists(CONFIG_SECTION_PLAYER "1"))
    179   {
    180     PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1\n");
    181     return;
    182   }
    183183  int* index;
    184184
    185   std::list<std::string> keys = Preferences::getInstance()->listKeys(CONFIG_SECTION_PLAYER "1");
     185  std::list<std::string> keys = Preferences::getInstance()->listKeys(CONFIG_SECTION_CONTROL);
    186186  for ( std::list<std::string>::const_iterator it = keys.begin(); it!=keys.end(); it++ )
    187187  {
    188     PRINTF(3)("Keys: Parsing %s, %s now.\n", it->c_str(), Preferences::getInstance()->getString(CONFIG_SECTION_PLAYER "1", *it, "").c_str());
     188    PRINTF(3)("Keys: Parsing %s, %s now.\n", it->c_str(), Preferences::getInstance()->getString(CONFIG_SECTION_CONTROL, *it, "").c_str());
    189189    // map the name to an sdl index
    190     index = nameToIndex (Preferences::getInstance()->getString(CONFIG_SECTION_PLAYER "1", *it, ""));
     190    index = nameToIndex (Preferences::getInstance()->getString(CONFIG_SECTION_CONTROL, *it, ""));
    191191    // map the index to a internal name
    192     this->mapKeys(*it, index);
    193   }
    194 
    195 
    196   // PARSE MISC SECTION
    197   if( !Preferences::getInstance()->sectionExists (CONFIG_SECTION_MISC_KEYS))
    198   {
    199     PRINTF(1)("Could not find key bindings " CONFIG_SECTION_MISC_KEYS "\n");
    200     return;
    201   }
    202 
    203   keys = Preferences::getInstance()->listKeys(CONFIG_SECTION_MISC_KEYS);
    204   for ( std::list<std::string>::const_iterator it = keys.begin(); it!=keys.end(); it++ )
    205   {
    206     PRINTF(3)("MISC: Parsing %s, %s now.\n", it->c_str(), Preferences::getInstance()->getString(CONFIG_SECTION_MISC_KEYS, *it, "").c_str());
    207     index = nameToIndex (Preferences::getInstance()->getString(CONFIG_SECTION_MISC_KEYS, *it, ""));
    208192    this->mapKeys(*it, index);
    209193  }
     
    266250  for(int i = 0; map[i].pValue != NULL; ++i)
    267251    {
    268       PRINT(0)("%s = %i\n",map[i].pName, *map[i].pValue);
     252      PRINT(0)("%s = %i\n",map[i].pName.c_str(), *map[i].pValue);
    269253    }
    270254  PRINT(0)("=======================================================\n");
  • trunk/src/lib/event/key_mapper.h

    r7256 r7661  
    1010
    1111#include "base_object.h"
    12 //#include "event_def.h"
    13 
     12#include <string>
    1413class IniParser;
    1514
    16 //! A mapping from key-name to key-id
    17 typedef struct orxKeyMapping
     15//! The map class functionalities
     16class KeyMapper : public BaseObject
    1817{
    19   int* pValue;
    20   char* pName;
    21 };
     18public:
     19  //! A mapping from key-name to key-id
     20  typedef struct KeyMapping
     21  {
     22    int*              pValue;
     23    const std::string pName;
     24    int               defaultValue;
     25  };
    2226
    23 
    24 //! The map class functionalities
    25 class KeyMapper : public BaseObject {
    26 
    27  public:
     27public:
    2828  KeyMapper();
    2929  virtual ~KeyMapper();
     
    3333  void loadKeyBindings(IniParser* iniParser);
    3434
     35  static const KeyMapping* getKeyMapping() { return KeyMapper::map; };
     36
    3537  void debug();
    3638
    37  private:
     39private:
    3840  int* nameToIndex (const std::string& name);
    3941  void mapKeys(const std::string& name, int* index);
    4042
    41  public:
     43public:
    4244  static int PEV_FORWARD;           //!< forward button
    4345  static int PEV_BACKWARD;          //!< backward buttton
     
    7375  static int PEV_QUIT;              //!< quit button
    7476
    75  private:
    76   int         coord[2];              //!< temp place to save variables in nameToIndex() function
     77private:
     78  int                coord[2];      //!< temp place to save variables in nameToIndex() function
     79  static KeyMapping  map[];         //!< The KeyMapping that maps strings to ID's and Vice Versa
    7780};
    7881
  • trunk/src/lib/event/key_names.cc

    r7221 r7661  
    1717#include "event_def.h"
    1818
    19 #include "stdincl.h"
    20 
    21 #include <string.h>
    22 
    23 using namespace std;
     19std::string EVToKeyName(int key)
     20{
     21  std::string name = SDLBToButtonname( key );
     22  if (name != "UNKNOWN")
     23    return name;
     24  else
     25    return SDLKToKeyname( key );
     26}
     27
     28int KeyNameToEV(const std::string& keyName)
     29{
     30  int key = buttonnameToSDLB( keyName );
     31  if (key != -1)
     32    return key;
     33  else
     34    return keynameToSDLK( keyName );
     35}
     36
    2437
    2538int buttonnameToSDLB(const std::string& name)
     
    3346}
    3447
    35 const char* SDLBToButtonname( int button)
     48std::string SDLBToButtonname( int button)
    3649{
    3750        if( button == EV_MOUSE_BUTTON_LEFT) return "BUTTON_LEFT";
     
    181194}
    182195
    183 const char* SDLKToKeyname(int key)
     196std::string SDLKToKeyname(int key)
    184197{
    185198        if( key == SDLK_BACKSPACE) return "BACKSPACE";
  • trunk/src/lib/event/key_names.h

    r7221 r7661  
    1111
    1212/**
    13  *  converts a button name string to a integer representing the corresponding SDL mouse button identifier
     13 * @brief converts an EVKey into a String, naming the Event.
     14 * @param key the Key (either key or button) to convert.
     15 * @returns the String containing the Event.
     16 */
     17std::string EVToKeyName(int key);
     18/**
     19 * @brief converts a KeyName into an Event.
     20 * @param keyName the Key to transform.
     21 * @returns the Event-Number
     22 */
     23int KeyNameToEV(const std::string& keyName);
     24
     25
     26/**
     27 * @brief converts a button name string to a integer representing the corresponding SDL mouse button identifier
    1428 * @param name: the name of the mouse button
    1529 * @return an int containing the SDL identifier of the mouse button or -1 if the button name is not valid
     
    1832
    1933/**
    20  * converst a SDL mouse button identifier to a name string
     34 * @brief converst a SDL mouse button identifier to a name string
    2135 * @param button: an SDL mouse button identifier
    2236 * @return a pointer to a string containing the name of the mouse button
    2337 */
    24 const char* SDLBToButtonname( int button);
     38std::string SDLBToButtonname( int button);
    2539
    2640/**
    27  * converts a key name string to a integer representing the corresponding SDLK sym
     41 * @brief converts a key name string to a integer representing the corresponding SDLK sym
    2842 * @param name: the name of the key
    2943 * @return the SDLK sym of the named key or -1 if the key name is not valid
     
    3246
    3347/**
    34  * converts an SDLK sym to a name string
     48 * @brief converts an SDLK sym to a name string
    3549 * @param key: the SDLK sym
    3650 * @return a pointer to a string containig the name of the key
    3751 */
    38 const char* SDLKToKeyname( int key);
    39 
     52std::string SDLKToKeyname( int key);
    4053
    4154#endif /* _KEY_NAMES_H */
Note: See TracChangeset for help on using the changeset viewer.