예제 #1
0
파일: options.c 프로젝트: zid/naev
/**
 * @brief Updates the keybindings menu.
 *
 *    @param wid Window to update.
 *    @param name Unused.
 */
static void menuKeybinds_update( unsigned int wid, char *name )
{
   (void) name;
   int i;
   char *selected, *keybind;
   const char *desc;
   SDLKey key;
   KeybindType type;
   SDLMod mod;
   char buf[1024];
   char binding[32];

   /* Get the keybind. */
   selected = toolkit_getList( wid, "lstKeybinds" );

   /* Remove the excess. */
   for (i=0; (selected[i] != '\0') && (selected[i] != ' '); i++)
      opt_selectedKeybind[i] = selected[i];
   opt_selectedKeybind[i] = '\0';
   keybind                = opt_selectedKeybind;
   window_modifyText( wid, "txtName", keybind );

   /* Get information. */
   desc = input_getKeybindDescription( keybind );
   key = input_getKeybind( keybind, &type, &mod );

   /* Create the text. */
   switch (type) {
      case KEYBIND_NULL:
         snprintf(binding, 64, "Not bound");
         break;
      case KEYBIND_KEYBOARD:
         /* SDL_GetKeyName returns lowercase which is ugly. */
         if (nstd_isalpha(key))
            snprintf(binding, 32, "keyboard:   %s%s%c",
                  (mod != KMOD_NONE) ? input_modToText(mod) : "",
                  (mod != KMOD_NONE) ? " + " : "",
                  nstd_toupper(key));
         else
            snprintf(binding, 32, "keyboard:   %s%s%s",
                  (mod != KMOD_NONE) ? input_modToText(mod) : "",
                  (mod != KMOD_NONE) ? " + " : "",
                  SDL_GetKeyName(key));
         break;
      case KEYBIND_JAXISPOS:
         snprintf(binding, 64, "joy axis pos:   <%d>", key );
         break;
      case KEYBIND_JAXISNEG:
         snprintf(binding, 64, "joy axis neg:   <%d>", key );
         break;
      case KEYBIND_JBUTTON:
         snprintf(binding, 64, "joy button:   <%d>", key);
         break;
   }

   /* Update text. */
   snprintf(buf, 1024, "%s\n\n%s\n", desc, binding);
   window_modifyText( wid, "txtDesc", buf );
}
예제 #2
0
파일: nlua_naev.c 프로젝트: ekrumme/naev
/**
 * @brief Gets the keybinding value by name.
 *
 * @usage bindname = naev.getKey( "accel" )
 *
 *    @luaparam keyname Name of the keybinding to get value of.
 * @luafunc getKey( keyname )
 */
static int naev_getKey( lua_State *L )
{
   int p;
   const char *keyname;
   SDLKey key;
   KeybindType type;
   SDLMod mod;
   char buf[128];

   /* Get parameters. */
   keyname = luaL_checkstring( L, 1 );

   /* Get the keybinding. */
   key = input_getKeybind( keyname, &type, &mod );

   /* Handle type. */
   switch (type) {
      case KEYBIND_NULL:
         lua_pushstring( L, "Not bound" );
         break;

      case KEYBIND_KEYBOARD:
         p = 0;
         /* Handle mod. */
         if ((mod != KMOD_NONE) && (mod != KMOD_ALL))
            p += snprintf( &buf[p], sizeof(buf)-p, "%s + ", input_modToText(mod) );
         /* Print key. */
         if (nstd_isalpha(key))
            p += snprintf( &buf[p], sizeof(buf)-p, "%c", nstd_toupper(key) );
         else
            p += snprintf( &buf[p], sizeof(buf)-p, "%s", SDL_GetKeyName(key) );
         lua_pushstring( L, buf );
         break;

      case KEYBIND_JBUTTON:
         snprintf( buf, sizeof(buf), "joy button %d", key );
         lua_pushstring( L, buf );
         break;

      case KEYBIND_JAXISPOS:
         snprintf( buf, sizeof(buf), "joy axis %d-", key );
         lua_pushstring( L, buf );
         break;

      case KEYBIND_JAXISNEG:
         snprintf( buf, sizeof(buf), "joy axis %d+", key );
         lua_pushstring( L, buf );
         break;
   }

   return 1;
}
예제 #3
0
파일: options.c 프로젝트: zid/naev
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 );
}
예제 #4
0
파일: options.c 프로젝트: s0be/naev
/**
 * @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 );
}