Implement new shot name generation using a persistent index.
[neverball] / share / st_resol.c
index c067cdc..c3ebaa3 100644 (file)
@@ -32,23 +32,23 @@ static SDL_Rect **modes;
 
 /*---------------------------------------------------------------------------*/
 
-#define LANG_BACK 100
+#define RESOL_BACK -1
 
 static int resol_action(int i)
 {
-    int f = config_get_d(CONFIG_FULLSCREEN);
     int r = 1;
 
     switch (i)
     {
-    case LANG_BACK:
+    case RESOL_BACK:
         goto_state(&st_conf);
         break;
 
     default:
         goto_state(&st_null);
-        r = config_mode(f, modes[i - 1]->w, modes[i - 1]->h);
-        goto_state(&st_conf);
+        r = config_mode(config_get_d(CONFIG_FULLSCREEN),
+                        modes[i]->w, modes[i]->h);
+        goto_state(&st_resol);
         break;
     }
 
@@ -57,68 +57,48 @@ static int resol_action(int i)
 
 static int resol_enter(void)
 {
-    int id, jd, kd;
-    int i;
-    int w, h;
-    int wp, hp;
-    int c;
+    int id, jd;
 
     back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
 
-    /* Get the current resolution. */
-    w = config_get_d(CONFIG_WIDTH);
-    h = config_get_d(CONFIG_HEIGHT);
-
-    /* Get the resolution list. */
     modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
 
-    if ((int)modes == -1)
-    {
+    if (modes == (SDL_Rect **) -1)
         modes = NULL;
-        printf("Any resolution\n");
-    }
-    else if (modes == NULL)
-    {
-        printf("No resolution\n");
-    }
 
-    if ((id = gui_harray(0)))
+    if ((id = gui_vstack(0)))
     {
-        if ((jd = gui_varray(id)))
+        if ((jd = gui_harray(id)))
         {
-            if ((kd = gui_harray(jd)))
-            {
-                gui_label(kd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
-                gui_filler(kd);
-                gui_start(kd, _("Back"), GUI_SML, LANG_BACK, 0);
-            }
+            gui_label(jd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
+            gui_space(jd);
+            gui_start(jd, _("Back"),       GUI_SML, RESOL_BACK, 0);
+        }
 
-            if (modes != NULL)
+        gui_space(id);
+
+        if (modes)
+        {
+            int i;
+
+            for (i = 0; modes[i]; i++)
             {
-                hp = wp = -1;
-                c = 0;
-                for(i = 0; modes[i]; i++)
-                {
-                    if (wp != modes[i]->w || hp != modes[i]->h)
-                    {
-                        static char st[100];
-                        wp = modes[i]->w;
-                        hp = modes[i]->h;
-                        sprintf(st, "%d x %d", wp, hp);
-
-                        if (c % 4 == 0)
-                                kd = gui_harray(jd);
-
-                        gui_state(kd, st, GUI_SML, i + 1,
-                                  (w == wp) && (h == hp));
-                        c++;
-                    }
-                }
-
-                for(; c % 4 != 0; c++)
-                        gui_filler(kd);
+                char s[20];
+
+                sprintf(s, "%d x %d", modes[i]->w, modes[i]->h);
+
+                if (i % 4 == 0)
+                    jd = gui_harray(id);
+
+                gui_state(jd, s, GUI_SML, i,
+                          config_get_d(CONFIG_WIDTH)  == modes[i]->w &&
+                          config_get_d(CONFIG_HEIGHT) == modes[i]->h);
             }
+
+            for(; i % 4 != 0; i++)
+                gui_space(jd);
         }
+
         gui_layout(id, 0, 0);
     }
 
@@ -146,7 +126,6 @@ static void resol_paint(int id, float st)
 static void resol_timer(int id, float dt)
 {
     gui_timer(id, dt);
-    audio_timer(dt);
 }
 
 static void resol_point(int id, int x, int y, int dx, int dy)
@@ -198,6 +177,7 @@ struct state st_resol = {
     resol_timer,
     resol_point,
     resol_stick,
+    NULL,
     resol_click,
     resol_keybd,
     resol_buttn,