remove remaining executable state of source files
[neverball] / share / st_resol.c
1 /*   
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include <string.h>
16
17 #include "gui.h"
18 #include "back.h"
19 #include "geom.h"
20 #include "part.h"
21 #include "audio.h"
22 #include "config.h"
23
24 #include "st_resol.h"
25
26 extern struct state st_conf;
27 extern struct state st_null;
28
29 SDL_Rect ** resolutions;
30
31 /*---------------------------------------------------------------------------*/
32
33 #define LANG_BACK 100
34
35 static int resol_action(int i)
36 {
37     int f = config_get_d(CONFIG_FULLSCREEN);
38     int r = 1;
39     
40     switch (i)
41     {
42     case LANG_BACK:
43         goto_state(&st_conf);
44         break;
45
46     default:
47         goto_state(&st_null);
48         r = config_mode(f, resolutions[i-1]->w, resolutions[i-1]->h);
49         goto_state(&st_conf);
50         break;
51     }
52
53     return r;
54 }
55
56 static int resol_enter(void)
57 {
58     int id, jd, kd;
59     int i;
60     int w, h;
61     int wp, hp;
62     int c;
63
64     back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
65
66     /* Get the current resolution. */
67     w = config_get_d(CONFIG_WIDTH);
68     h = config_get_d(CONFIG_HEIGHT);
69     
70     /* Get the resolution list. */
71     resolutions = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
72
73     if ((int)resolutions == -1)
74     {
75         resolutions = NULL;
76         printf("Any resolution\n");
77     }
78     else if (resolutions == NULL)
79     {
80         printf("No resolution\n");
81     }
82
83     if ((id = gui_harray(0)))
84     {
85         if ((jd = gui_varray(id)))
86         {
87             if ((kd = gui_harray(jd)))
88             {
89                 gui_label(kd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
90                 gui_filler(kd);
91                 gui_start(kd, _("Back"),     GUI_SML, LANG_BACK, 0);
92             }
93             
94             if (resolutions != NULL)
95             {
96                 hp = wp = -1;
97                 c = 0;
98                 for(i=0; resolutions[i]; i++)
99                 {
100                     if (wp!=resolutions[i]->w || hp!=resolutions[i]->h)
101                     {
102                         static char st[100];
103                         wp = resolutions[i]->w;
104                         hp = resolutions[i]->h;
105                         sprintf(st, "%d x %d", wp, hp);
106                         if (c % 4 == 0)
107                                 kd = gui_harray(jd);
108                         gui_state(kd, st,   GUI_SML, i+1, (w==wp) && (h==hp));
109                         c++;
110                     }
111                 }
112                 
113                 for(; c%4!=0; c++)
114                         gui_filler(kd);
115             }
116         }
117         gui_layout(id, 0, 0);
118     }
119
120     audio_music_fade_to(0.5f, "bgm/inter.ogg");
121
122     return id;
123 }
124
125 static void resol_leave(int id)
126 {
127     back_free();
128     gui_delete(id);
129 }
130
131 static void resol_paint(int id, float st)
132 {
133     config_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
134     {
135         back_draw(0);
136     }
137     config_pop_matrix();
138     gui_paint(id);
139 }
140
141 static void resol_timer(int id, float dt)
142 {
143     gui_timer(id, dt);
144     audio_timer(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 < 0 && 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     resol_click,
197     resol_keybd,
198     resol_buttn,
199     1, 0
200 };
201