Makefile: use mingw-list-dlls from MinGW cross scripts
[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
26 #include "st_resol.h"
27
28 extern struct state st_conf;
29 extern struct state st_null;
30
31 static SDL_Rect **modes;
32
33 /*---------------------------------------------------------------------------*/
34
35 #define RESOL_BACK -1
36
37 static int resol_action(int i)
38 {
39     int r = 1;
40
41     switch (i)
42     {
43     case RESOL_BACK:
44         goto_state(&st_conf);
45         break;
46
47     default:
48         goto_state(&st_null);
49         r = config_mode(config_get_d(CONFIG_FULLSCREEN),
50                         modes[i]->w, modes[i]->h);
51         goto_state(&st_resol);
52         break;
53     }
54
55     return r;
56 }
57
58 static int resol_enter(void)
59 {
60     int id, jd;
61
62     back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
63
64     modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
65
66     if (modes == (SDL_Rect **) -1)
67         modes = NULL;
68
69     if ((id = gui_vstack(0)))
70     {
71         if ((jd = gui_harray(id)))
72         {
73             gui_label(jd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
74             gui_space(jd);
75             gui_start(jd, _("Back"),       GUI_SML, RESOL_BACK, 0);
76         }
77
78         gui_space(id);
79
80         if (modes)
81         {
82             int i;
83
84             for (i = 0; modes[i]; i++)
85             {
86                 char s[20];
87
88                 sprintf(s, "%d x %d", modes[i]->w, modes[i]->h);
89
90                 if (i % 4 == 0)
91                     jd = gui_harray(id);
92
93                 gui_state(jd, s, GUI_SML, i,
94                           config_get_d(CONFIG_WIDTH)  == modes[i]->w &&
95                           config_get_d(CONFIG_HEIGHT) == modes[i]->h);
96             }
97
98             for(; i % 4 != 0; i++)
99                 gui_space(jd);
100         }
101
102         gui_layout(id, 0, 0);
103     }
104
105     audio_music_fade_to(0.5f, "bgm/inter.ogg");
106
107     return id;
108 }
109
110 static void resol_leave(int id)
111 {
112     back_free();
113     gui_delete(id);
114 }
115
116 static void resol_paint(int id, float st)
117 {
118     config_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
119     {
120         back_draw(0);
121     }
122     config_pop_matrix();
123     gui_paint(id);
124 }
125
126 static void resol_timer(int id, float dt)
127 {
128     gui_timer(id, dt);
129 }
130
131 static void resol_point(int id, int x, int y, int dx, int dy)
132 {
133     gui_pulse(gui_point(id, x, y), 1.2f);
134 }
135
136 static void resol_stick(int id, int a, int v)
137 {
138     if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
139         gui_pulse(gui_stick(id, v, 0), 1.2f);
140     if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
141         gui_pulse(gui_stick(id, 0, v), 1.2f);
142 }
143
144 static int resol_click(int b, int d)
145 {
146     if (b < 0 && d == 1)
147         return resol_action(gui_token(gui_click()));
148     return 1;
149 }
150
151 static int resol_keybd(int c, int d)
152 {
153     return (d && c == SDLK_ESCAPE) ? goto_state(&st_conf) : 1;
154 }
155
156 static int resol_buttn(int b, int d)
157 {
158     if (d)
159     {
160         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
161             return resol_action(gui_token(gui_click()));
162         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
163             return goto_state(&st_conf);
164         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
165             return goto_state(&st_conf);
166     }
167     return 1;
168 }
169
170 /*---------------------------------------------------------------------------*/
171
172
173 struct state st_resol = {
174     resol_enter,
175     resol_leave,
176     resol_paint,
177     resol_timer,
178     resol_point,
179     resol_stick,
180     NULL,
181     resol_click,
182     resol_keybd,
183     resol_buttn,
184     1, 0
185 };
186