Exemple #1
0
/**
 * @brief Opens the keybindings menu.
 */
void opt_menuKeybinds (void)
{
   unsigned int wid;
   int w, h;
   int bw, bh;
   int lw;

   /* Dimensions. */
   w = 500;
   h = 300;

   /* Create the window. */
   wid = window_create( "Keybindings", -1, -1, w, h );

   menuKeybinds_getDim( wid, &w, &h, &lw, NULL, &bw, &bh );

   /* Close button. */
   window_addButton( wid, -20, 20, bw, bh,
         "btnClose", "Close", window_close );
   /* Set button. */
   window_addButton( wid, -20 - bw - 20, 20, bw, bh,
         "btnSet", "Set Key", opt_setKey );

   /* Text stuff. */
   window_addText( wid, 20+lw+20, -40, w-(20+lw+20), 30, 1, "txtName",
         NULL, &cDConsole, NULL );
   window_addText( wid, 20+lw+20, -90, w-(20+lw+20), h-70-60-bh,
         0, "txtDesc", &gl_smallFont, NULL, NULL );

   /* Generate the list. */
   menuKeybinds_genList( wid );
}
Exemple #2
0
/**
 * @brief Opens the keybindings menu.
 */
static void opt_keybinds( unsigned int wid )
{
   int w, h, lw, bw, bh;

   /* Get dimensions. */
   menuKeybinds_getDim( wid, &w, &h, &lw, NULL, &bw, &bh );

   /* Close button. */
   window_addButton( wid, -20, 20, bw, bh,
         "btnClose", "Close", opt_close );
   /* Set button. */
   window_addButton( wid, -20 - bw - 20, 20, bw, bh,
         "btnSet", "Set Key", opt_setKey );
   /* Restore deafaults button. */
   window_addButton( wid, -20, 20+bh+20, bw, bh,
         "btnDefaults", "Defaults", opt_keyDefaults );

   /* Text stuff. */
   window_addText( wid, 20+lw+20, -40, w-(20+lw+20), 30, 1, "txtName",
         NULL, &cDConsole, NULL );
   window_addText( wid, 20+lw+20, -90, w-(20+lw+20), h-70-60-bh,
         0, "txtDesc", &gl_smallFont, NULL, NULL );

   /* Generate the list. */
   menuKeybinds_genList( wid );
}
Exemple #3
0
static void menuKeybinds_genList( unsigned int wid )
{
   int i, j;
   char **str;
   SDLKey key;
   KeybindType type;
   SDLMod mod;
   int w, h;
   int lw, lh;

   /* Get dimensions. */
   menuKeybinds_getDim( wid, &w, &h, &lw, &lh, NULL, NULL );

   /* Create the list. */
   for (i=0; strcmp(keybindNames[i],"end"); i++);
   str = malloc(sizeof(char*) * i);
   for (j=0; j < i; j++) {
      str[j] = malloc(sizeof(char) * 64);
      key = input_getKeybind( keybindNames[j], &type, &mod );
      switch (type) {
         case KEYBIND_KEYBOARD:
            /* SDL_GetKeyName returns lowercase which is ugly. */
            if (nstd_isalpha(key))
               snprintf(str[j], 64, "%s <%c>", keybindNames[j], nstd_toupper(key) );
            else
               snprintf(str[j], 64, "%s <%s>", keybindNames[j], SDL_GetKeyName(key) );
            break;
         case KEYBIND_JAXISPOS:
            snprintf(str[j], 64, "%s <ja+%d>", keybindNames[j], key);
            break;
         case KEYBIND_JAXISNEG:
            snprintf(str[j], 64, "%s <ja-%d>", keybindNames[j], key);
            break;
         case KEYBIND_JBUTTON:
            snprintf(str[j], 64, "%s <jb%d>", keybindNames[j], key);
            break;
         default:
            snprintf(str[j], 64, "%s", keybindNames[j]);
            break;
      }
   }
   window_addList( wid, 20, -40, lw, lh, "lstKeybinds",
         str, i, 0, menuKeybinds_update );

   /* Update the list. */
   menuKeybinds_update( wid, NULL );
}
Exemple #4
0
/**
 * @brief Generates the keybindings list.
 */
static void menuKeybinds_genList( unsigned int wid )
{
   int i, j, l, p;
   char **str, mod_text[64];
   SDLKey key;
   KeybindType type;
   SDLMod mod;
   int w, h;
   int lw, lh;

   /* Get dimensions. */
   menuKeybinds_getDim( wid, &w, &h, &lw, &lh, NULL, NULL );

   /* Create the list. */
   for (i=0; strcmp(keybind_info[i][0],"end"); i++);
   str = malloc(sizeof(char*) * i);
   for (j=0; j < i; j++) {
      l = 64;
      str[j] = malloc(sizeof(char) * l);
      key = input_getKeybind( keybind_info[j][0], &type, &mod );
      switch (type) {
         case KEYBIND_KEYBOARD:
            /* Generate mod text. */
            if (mod == NMOD_ALL)
               snprintf( mod_text, sizeof(mod_text), "any+" );
            else {
               p = 0;
               mod_text[0] = '\0';
               if (mod & NMOD_SHIFT)
                  p += snprintf( &mod_text[p], sizeof(mod_text)-p, "shift+" );
               if (mod & NMOD_CTRL)
                  p += snprintf( &mod_text[p], sizeof(mod_text)-p, "ctrl+" );
               if (mod & NMOD_ALT)
                  p += snprintf( &mod_text[p], sizeof(mod_text)-p, "alt+" );
               if (mod & NMOD_META)
                  p += snprintf( &mod_text[p], sizeof(mod_text)-p, "meta+" );
            }

            /* SDL_GetKeyName returns lowercase which is ugly. */
            if (nstd_isalpha(key))
               snprintf(str[j], l, "%s <%s%c>", keybind_info[j][1], mod_text, nstd_toupper(key) );
            else
               snprintf(str[j], l, "%s <%s%s>", keybind_info[j][1], mod_text, SDL_GetKeyName(key) );
            break;
         case KEYBIND_JAXISPOS:
            snprintf(str[j], l, "%s <ja+%d>", keybind_info[j][1], key);
            break;
         case KEYBIND_JAXISNEG:
            snprintf(str[j], l, "%s <ja-%d>", keybind_info[j][1], key);
            break;
         case KEYBIND_JBUTTON:
            snprintf(str[j], l, "%s <jb%d>", keybind_info[j][1], key);
            break;
         default:
            snprintf(str[j], l, "%s", keybind_info[j][1]);
            break;
      }
   }
   window_addList( wid, 20, -40, lw, lh, "lstKeybinds",
         str, i, 0, menuKeybinds_update );
}