Do not reject 1.5 format SOLs
[neverball] / share / st_resol.c
1 /*
2  * Copyright (C) 2003 Robert Kooima - 2006 Jean Privat
3  * Part of the Neverball Project http://icculus.org/neverball/
4  *
5  * NEVERBALL is  free software; you can redistribute  it and/or modify
6  * it under the  terms of the GNU General  Public License as published
7  * by the Free  Software Foundation; either version 2  of the License,
8  * or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
12  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
13  * General Public License for more details.
14  */
15
16
17 #include <string.h>
18
19 #include "gui.h"
20 #include "back.h"
21 #include "geom.h"
22 #include "part.h"
23 #include "audio.h"
24 #include "config.h"
25 #include "video.h"
26
27 #include "st_resol.h"
28
29 extern struct state st_conf;
30 extern struct state st_null;
31
32 static SDL_Rect **modes;
33
34 /*---------------------------------------------------------------------------*/
35
36 #define RESOL_BACK -1
37
38 static int resol_action(int i)
39 {
40     int r = 1;
41
42     audio_play("snd/menu.ogg", 1.0f);
43
44     switch (i)
45     {
46     case RESOL_BACK:
47         goto_state(&st_conf);
48         break;
49
50     default:
51         goto_state(&st_null);
52         r = video_mode(config_get_d(CONFIG_FULLSCREEN),
53                        modes[i]->w, modes[i]->h);
54         goto_state(&st_resol);
55         break;
56     }
57
58     return r;
59 }
60
61 static int fill_row(int id, SDL_Rect **modes, int i, int n)
62 {
63     int complete;
64
65     if (n == 0)
66         return 1;
67
68     if (modes[i])
69     {
70         char label[20];
71
72         sprintf(label, "%d x %d", modes[i]->w, modes[i]->h);
73
74         complete = fill_row(id, modes, i + 1, n - 1);
75
76         gui_state(id, label, GUI_SML, i,
77                   config_get_d(CONFIG_WIDTH)  == modes[i]->w &&
78                   config_get_d(CONFIG_HEIGHT) == modes[i]->h);
79     }
80     else
81     {
82         for (; n; gui_space(id), n--);
83         complete = 0;
84     }
85
86     return complete;
87 }
88
89 static int resol_enter(void)
90 {
91     int id, jd;
92
93     back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
94
95     modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
96
97     if (modes == (SDL_Rect **) -1)
98         modes = NULL;
99
100     if ((id = gui_vstack(0)))
101     {
102         if ((jd = gui_harray(id)))
103         {
104             gui_label(jd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
105             gui_space(jd);
106             gui_start(jd, _("Back"),       GUI_SML, RESOL_BACK, 0);
107         }
108
109         gui_space(id);
110
111         if (modes)
112         {
113             int i;
114
115             for (i = 0; fill_row(gui_harray(id), modes, i, 4); i += 4);
116         }
117
118         gui_layout(id, 0, 0);
119     }
120
121     audio_music_fade_to(0.5f, "bgm/inter.ogg");
122
123     return id;
124 }
125
126 static void resol_leave(int id)
127 {
128     back_free();
129     gui_delete(id);
130 }
131
132 static void resol_paint(int id, float st)
133 {
134     video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
135     {
136         back_draw(0);
137     }
138     video_pop_matrix();
139     gui_paint(id);
140 }
141
142 static void resol_timer(int id, float dt)
143 {
144     gui_timer(id, dt);
145 }
146
147 static void resol_point(int id, int x, int y, int dx, int dy)
148 {
149     gui_pulse(gui_point(id, x, y), 1.2f);
150 }
151
152 static void resol_stick(int id, int a, int v)
153 {
154     if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
155         gui_pulse(gui_stick(id, v, 0), 1.2f);
156     if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
157         gui_pulse(gui_stick(id, 0, v), 1.2f);
158 }
159
160 static int resol_click(int b, int d)
161 {
162     if (b == SDL_BUTTON_LEFT && d == 1)
163         return resol_action(gui_token(gui_click()));
164     return 1;
165 }
166
167 static int resol_keybd(int c, int d)
168 {
169     return (d && c == SDLK_ESCAPE) ? goto_state(&st_conf) : 1;
170 }
171
172 static int resol_buttn(int b, int d)
173 {
174     if (d)
175     {
176         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
177             return resol_action(gui_token(gui_click()));
178         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
179             return goto_state(&st_conf);
180         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
181             return goto_state(&st_conf);
182     }
183     return 1;
184 }
185
186 /*---------------------------------------------------------------------------*/
187
188
189 struct state st_resol = {
190     resol_enter,
191     resol_leave,
192     resol_paint,
193     resol_timer,
194     resol_point,
195     resol_stick,
196     NULL,
197     resol_click,
198     resol_keybd,
199     resol_buttn,
200     1, 0
201 };
202