share/gui: don't use less of widget width for truncation than available
[neverball] / share / st_resol.c
index bae9fb6..522af1e 100644 (file)
@@ -22,6 +22,7 @@
 #include "part.h"
 #include "audio.h"
 #include "config.h"
+#include "video.h"
 
 #include "st_resol.h"
 
@@ -38,6 +39,8 @@ static int resol_action(int i)
 {
     int r = 1;
 
+    audio_play("snd/menu.ogg", 1.0f);
+
     switch (i)
     {
     case RESOL_BACK:
@@ -46,8 +49,8 @@ static int resol_action(int i)
 
     default:
         goto_state(&st_null);
-        r = config_mode(config_get_d(CONFIG_FULLSCREEN),
-                        modes[i]->w, modes[i]->h);
+        r = video_mode(config_get_d(CONFIG_FULLSCREEN),
+                       modes[i]->w, modes[i]->h);
         goto_state(&st_resol);
         break;
     }
@@ -55,16 +58,43 @@ static int resol_action(int i)
     return r;
 }
 
+static int fill_row(int id, SDL_Rect **modes, int i, int n)
+{
+    int complete;
+
+    if (n == 0)
+        return 1;
+
+    if (modes[i])
+    {
+        char label[20];
+
+        sprintf(label, "%d x %d", modes[i]->w, modes[i]->h);
+
+        complete = fill_row(id, modes, i + 1, n - 1);
+
+        gui_state(id, label, GUI_SML, i,
+                  config_get_d(CONFIG_WIDTH)  == modes[i]->w &&
+                  config_get_d(CONFIG_HEIGHT) == modes[i]->h);
+    }
+    else
+    {
+        for (; n; gui_space(id), n--);
+        complete = 0;
+    }
+
+    return complete;
+}
+
 static int resol_enter(void)
 {
     int id, jd;
-    int i;
 
     back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
 
     modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
 
-    if ((int) modes == -1)
+    if (modes == (SDL_Rect **) -1)
         modes = NULL;
 
     if ((id = gui_vstack(0)))
@@ -72,28 +102,17 @@ static int resol_enter(void)
         if ((jd = gui_harray(id)))
         {
             gui_label(jd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
-            gui_filler(jd);
-            gui_start(jd, _("Back"), GUI_SML, RESOL_BACK, 0);
+            gui_space(jd);
+            gui_start(jd, _("Back"),       GUI_SML, RESOL_BACK, 0);
         }
 
+        gui_space(id);
+
         if (modes)
         {
-            for(i = 0; modes[i]; i++)
-            {
-                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);
-            }
+            int i;
 
-            for(; i % 4 != 0; i++)
-                gui_space(jd);
+            for (i = 0; fill_row(gui_harray(id), modes, i, 4); i += 4);
         }
 
         gui_layout(id, 0, 0);
@@ -112,18 +131,17 @@ static void resol_leave(int id)
 
 static void resol_paint(int id, float st)
 {
-    config_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
+    video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
     {
         back_draw(0);
     }
-    config_pop_matrix();
+    video_pop_matrix();
     gui_paint(id);
 }
 
 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)
@@ -141,7 +159,7 @@ static void resol_stick(int id, int a, int v)
 
 static int resol_click(int b, int d)
 {
-    if (b < 0 && d == 1)
+    if (b == SDL_BUTTON_LEFT && d == 1)
         return resol_action(gui_token(gui_click()));
     return 1;
 }
@@ -175,6 +193,7 @@ struct state st_resol = {
     resol_timer,
     resol_point,
     resol_stick,
+    NULL,
     resol_click,
     resol_keybd,
     resol_buttn,