Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2005, 4:18:58 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: key binding implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/event/event_handler.cc

    r4366 r4369  
    7474}
    7575
    76 
    77 /**
    78    \brief loads new key bindings from a file
    79    \param filename: The path and name of the file to load the bindings from
    80 */
    81 void EventHandler::loadKeyBindings (const char* fileName)
    82 {
    83   FILE* stream;
    84  
    85   PRINTF(4)("Loading key bindings from %s\n", fileName);
    86  
    87   // remove old bindings if present
    88   if( this->keyAliases != NULL)
    89     {
    90       free (this->keyAliases);
    91       this->keyAliases = NULL;
    92     }
    93  
    94   // create parser
    95   IniParser parser(fileName);
    96   if( parser.getSection (CONFIG_SECTION_PLAYER "1") == -1)
    97     {
    98       PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1 in %s\n", fileName);
    99       return;
    100     }
    101   // allocate empty lookup table
    102   this->keyAliases = (KeyBindings*) calloc (1, sizeof (KeyBindings));
    103  
    104   char namebuf[256];
    105   char valuebuf[256];
    106   memset (namebuf, 0, 256);
    107   memset (valuebuf, 0, 256);
    108   int* index;
    109  
    110   while( parser.nextVar (namebuf, valuebuf) != -1)
    111     {
    112       //index = nameToIndex (valuebuf);
    113       int c;
    114       if( (c = keynameToSDLK (valuebuf)) != -1)
    115         {
    116           index[1] = c; index[0] = 0;
    117         }
    118       if( (c = buttonnameToSDLB (valuebuf)) != -1)
    119         {
    120           index[1] = c; index[0] = 1;
    121         }
    122 
    123       switch( index[0])
    124         {
    125         case 0:
    126           PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf);
    127           strcpy (this->keyAliases->keys[index[1]], namebuf);
    128           break;
    129         case 1:
    130           PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf);
    131           strcpy (this->keyAliases->buttons[index[1]], namebuf);
    132           break;
    133         default:
    134           break;
    135         }
    136       memset (namebuf, 0, 256);
    137       memset (valuebuf, 0, 256);
    138     }
    139 
    140 
    141   // PARSE MISC SECTION
    142   if( parser.getSection (CONFIG_SECTION_MISC_KEYS) == -1)
    143     {
    144       PRINTF(1)("Could not find key bindings in %s\n", fileName);
    145       return;
    146     }
    147 
    148   while( parser.nextVar (namebuf, valuebuf) != -1)
    149     {
    150       //index = nameToIndex (valuebuf);     
    151       int c;
    152       if( (c = keynameToSDLK (valuebuf)) != -1)
    153         {
    154           index[1] = c; index[0] = 0;
    155         }
    156       if( (c = buttonnameToSDLB (valuebuf)) != -1)
    157         {
    158           index[1] = c; index[0] = 1;
    159         }
    160 
    161 
    162       switch( index[0])
    163         {
    164         case 0:
    165           PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf);
    166           strcpy (keyAliases->keys[index[1]], namebuf);
    167           break;
    168         case 1:
    169           PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf);
    170           strcpy (keyAliases->buttons[index[1]], namebuf);
    171           break;
    172         default:
    173           break;
    174         }
    175       memset (namebuf, 0, 256);
    176       memset (valuebuf, 0, 256);
    177     }
    178 }
    17976
    18077
Note: See TracChangeset for help on using the changeset viewer.