6 #include "SDL_rotozoom.h"
15 static void resize_options_images(struct options_data_t
*data
,
16 struct smode_t
*smode
, struct font_t
*font
, struct theme_t
*theme
,
18 static void resize_theme_fontsample(struct options_data_t
*data
,
20 static int set_options_widget_sel(int xp
, int yp
, int click
,
21 struct options_data_t
*data
, struct smode_t
*smode
,
22 struct theme_t
*theme
, struct gui_t
*gui
);
23 static int options_perform_click(int id
, enum loop_mode_t
*mode
,
24 enum options_mode_t
*omode
, struct options_data_t
*data
,
25 struct smode_t
*smode
, struct gui_t
*gui
);
26 static void paint_theme_fontsample(struct smode_t
*smode
,
27 struct options_data_t
*data
);
28 static void free_resize_options(struct options_data_t
*data
,
31 void init_options(struct options_data_t
*data
, struct smode_t
*smode
,
32 struct font_t
*font
, struct theme_t
*theme
, struct gui_t
*gui
) {
34 data
->mode
= OMODE_NORMAL
;
37 resize_options_images(data
, smode
, font
, theme
, gui
);
41 static void resize_options_images(struct options_data_t
*data
,
42 struct smode_t
*smode
, struct font_t
*font
, struct theme_t
*theme
,
45 if(data
->loaded
) free_resize_options(data
, gui
);
47 /* Initialize the options menu widgets. */
48 add_widget(gui
->panel
[PANEL_OPTIONS
],
49 allocate_button(0, font
->sans
, "Graphics",
50 (smode
->width
- smode
->width
/ 4) / 2,
52 smode
->width
/ 4, smode
->height
/ 15));
53 add_widget(gui
->panel
[PANEL_OPTIONS
],
54 allocate_button(1, font
->sans
, "Theme",
55 (smode
->width
- smode
->width
/ 4) / 2,
56 smode
->height
/ 8 + smode
->height
/ 15 * 1.3,
57 smode
->width
/ 4, smode
->height
/ 15));
58 add_widget(gui
->panel
[PANEL_OPTIONS
],
59 allocate_button(2, font
->sans
, "Return to main menu",
60 (smode
->width
- smode
->width
/ 4) / 2,
61 smode
->height
/ 8 + smode
->height
/ 15 * 1.3 * 2,
62 smode
->width
/ 4, smode
->height
/ 15));
64 /* Initialize the graphics widgets. */
65 add_widget(gui
->panel
[PANEL_OPTIONS_GRAPHICS
],
66 allocate_button(100, font
->sans
, "Return to options",
67 (smode
->width
- smode
->width
/ 4) / 2,
68 smode
->height
/ 8 + smode
->height
/ 15 * 1.3,
69 smode
->width
/ 4, smode
->height
/ 15));
70 add_widget(gui
->panel
[PANEL_OPTIONS_GRAPHICS
],
71 allocate_checkbox(101, font
->sans
, "Fullscreen",
72 theme
, smode
->fullscreen
, (smode
->width
- smode
->width
/ 4) / 2,
73 smode
->height
/ 8 + smode
->height
/ 15 * 1.3 * 2,
74 smode
->width
/ 3, smode
->height
/ 15, smode
->width
/ 20));
75 add_widget(gui
->panel
[PANEL_OPTIONS_GRAPHICS
],
76 allocate_checkbox(102, font
->sans
, "Restrict cursor",
77 theme
, smode
->fullscreen
, (smode
->width
- smode
->width
/ 4) / 2,
78 smode
->height
/ 8 + smode
->height
/ 15 * 1.3 * 3,
79 smode
->width
/ 3, smode
->height
/ 15, smode
->width
/ 20));
82 sprintf(buffer
, "%ix%ix%i", smode
->width
, smode
->height
, smode
->depth
);
84 add_widget(gui
->panel
[PANEL_OPTIONS_GRAPHICS
],
85 allocate_textbox(103, font
->sans
, buffer
, strlen(buffer
),
86 theme
, (smode
->width
- smode
->width
/ 4) / 2,
87 smode
->height
/ 8 + smode
->height
/ 15 * 1.3 * 4,
88 smode
->width
/ 3, smode
->height
/ 15));
91 /* Initialize the theme widgets. */
92 add_widget(gui
->panel
[PANEL_OPTIONS_THEME
],
93 allocate_button(200, font
->sans
, "Return to options",
94 (smode
->width
- smode
->width
/ 4) / 2,
95 smode
->height
/ 8 + smode
->height
/ 15 * 1.3,
96 smode
->width
/ 4, smode
->height
/ 15));
98 resize_theme_fontsample(data
, font
);
100 /*data->text.menu = TTF_RenderText_Blended(font->sans, "Menu", white);*/
103 static void resize_theme_fontsample(struct options_data_t
*data
,
104 struct font_t
*font
) {
106 static const char *fontsample_text
[] = {
108 "abcdefghijklmnopqrstuvwxyz",
109 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
110 "How quickly daft jumping zebras vex.",
111 "!@#$%^&*()`~-_=+[{]}\\|;:'\",<.>/?"
115 for(x
= 0; x
< sizeof(fontsample_text
)/sizeof(*fontsample_text
); x
++) {
116 data
->gui
.theme
.fontsample
[x
] = render_white_text(font
->sans
,
121 void start_options(struct options_data_t
*data
) {
122 set_caption("Options and preferences");
124 data
->mode
= OMODE_NORMAL
;
127 int options_event(enum loop_mode_t
*mode
, SDL_Event
*event
,
128 struct options_data_t
*data
, struct smode_t
*smode
, struct font_t
*font
,
129 struct theme_t
*theme
, struct gui_t
*gui
) {
133 switch(event
->type
) {
135 switch(event
->key
.keysym
.sym
) {
137 if(gui
->active
.widget
) {
140 revert_widget(gui
->active
.widget
);
142 clear_active(&gui
->active
);
144 else if(data
->mode
!= OMODE_NORMAL
) {
145 data
->mode
= OMODE_NORMAL
;
149 else *mode
= MODE_MENU
;
155 case SDL_MOUSEBUTTONDOWN
:
156 if(event
->button
.button
!= 1) break;
158 repaint
= set_options_widget_sel(event
->button
.x
, event
->button
.y
, 1,
159 data
, smode
, theme
, gui
);
161 case SDL_MOUSEBUTTONUP
:
162 if(event
->button
.button
!= 1) break;
165 && in_sdl_rect(event
->button
.x
, event
->button
.y
,
166 &gui
->sel
.p
.widget
->pos
)) {
168 if(gui
->sel
.clickin
) {
169 options_perform_click(gui
->sel
.p
.widget
->id
, mode
,
170 &data
->mode
, data
, smode
, gui
);
172 gui
->sel
.clickin
= 0;
179 && widget_can_be_active(gui
->sel
.p
.widget
->type
)) {
181 gui
->active
= gui
->sel
.p
;
182 activate_widget(gui
->sel
.p
.widget
);
183 enable_unicode(gui
->active
.widget
->type
);
187 repaint
= set_options_widget_sel(event
->button
.x
, event
->button
.y
,
188 0, data
, smode
, theme
, gui
);
190 if(gui
->active
.widget
) {
193 deactivate_widget(gui
->active
.widget
);
195 clear_active(&gui
->active
);
200 case SDL_MOUSEMOTION
:
201 repaint
= set_options_widget_sel(event
->button
.x
, event
->button
.y
,
202 gui
->sel
.clickin
, data
, smode
, theme
, gui
);
203 /*t = options_handle_click(event->motion.x, event->motion.y, data,
205 if(data->gui.lastid != t) {
206 data->gui.lastid = t;
213 case SDL_VIDEORESIZE
:
214 resize_options_images(data
, smode
, font
, theme
, gui
);
223 static int set_options_widget_sel(int xp
, int yp
, int click
,
224 struct options_data_t
*data
, struct smode_t
*smode
,
225 struct theme_t
*theme
, struct gui_t
*gui
) {
227 if(data
->mode
== OMODE_NORMAL
) {
228 if(set_widget_sel_repaint(&gui
->sel
, xp
, yp
, click
,
229 gui
->panel
[PANEL_OPTIONS
]->widget
,
230 gui
->panel
[PANEL_OPTIONS
]->widgets
)) {
235 else if(data
->mode
== OMODE_GRAPHICS
) {
236 if(set_widget_sel_repaint(&gui
->sel
, xp
, yp
, click
,
237 gui
->panel
[PANEL_OPTIONS_GRAPHICS
]->widget
,
238 gui
->panel
[PANEL_OPTIONS_GRAPHICS
]->widgets
)) {
243 else if(data
->mode
== OMODE_THEME
) {
244 if(set_widget_sel_repaint(&gui
->sel
, xp
, yp
, click
,
245 gui
->panel
[PANEL_OPTIONS_THEME
]->widget
,
246 gui
->panel
[PANEL_OPTIONS_THEME
]->widgets
)) {
255 static int options_perform_click(int id
, enum loop_mode_t
*mode
,
256 enum options_mode_t
*omode
, struct options_data_t
*data
,
257 struct smode_t
*smode
, struct gui_t
*gui
) {
260 perform_widget_click(gui
->panel
[PANEL_OPTIONS
]->widget
[id
]);
263 perform_widget_click(
264 gui
->panel
[PANEL_OPTIONS_GRAPHICS
]->widget
[id
-100]);
267 perform_widget_click(gui
->panel
[PANEL_OPTIONS_THEME
]->widget
[id
-200]);
272 *omode
= OMODE_GRAPHICS
;
276 *omode
= OMODE_THEME
;
283 *omode
= OMODE_NORMAL
;
286 case 101: /* paint_widget() !!! */
287 /*data->gui.graphics.widget[1].p.checkbox->checked
288 = !data->gui.graphics.widget[1].p.checkbox->checked;*/
289 toggle_fullscreen(smode
); /* !!! Use return value for repaint */
291 case 102: /* toggle restrict cursor */
292 smode
->restrictfocus
= set_focus(!smode
->restrictfocus
);
295 *omode
= OMODE_NORMAL
;
304 void paint_options(struct options_data_t
*data
, struct smode_t
*smode
,
305 struct font_t
*font
, struct theme_t
*theme
, struct gui_t
*gui
) {
307 /*if(gui->active.widget) printf("%s\n", gui->active.widget->p.textbox->data);*/
309 gui
->panel
[PANEL_OPTIONS_GRAPHICS
]->widget
[1]->p
.checkbox
->checked
311 gui
->panel
[PANEL_OPTIONS_GRAPHICS
]->widget
[2]->p
.checkbox
->checked
312 = (smode
->restrictfocus
== SDL_GRAB_ON
);
314 SDL_FillRect(smode
->screen
, NULL
,
315 SDL_MapRGB(smode
->screen
->format
, 0, 0, 0));
317 if(data
->mode
== OMODE_NORMAL
) {
318 paint_widget_array(smode
, font
, theme
, gui
,
319 gui
->panel
[PANEL_OPTIONS
]->widget
,
320 gui
->panel
[PANEL_OPTIONS
]->widgets
);
322 else if(data
->mode
== OMODE_GRAPHICS
) {
323 paint_widget_array(smode
, font
, theme
, gui
,
324 gui
->panel
[PANEL_OPTIONS_GRAPHICS
]->widget
,
325 gui
->panel
[PANEL_OPTIONS_GRAPHICS
]->widgets
);
327 else if(data
->mode
== OMODE_THEME
) {
328 paint_widget_array(smode
, font
, theme
, gui
,
329 gui
->panel
[PANEL_OPTIONS_THEME
]->widget
,
330 gui
->panel
[PANEL_OPTIONS_THEME
]->widgets
);
332 paint_theme_fontsample(smode
, data
);
335 paint_menu_fps(smode
->screen
, font
);
337 SDL_UpdateRect(smode
->screen
, 0, 0, 0, 0);
340 static void paint_theme_fontsample(struct smode_t
*smode
,
341 struct options_data_t
*data
) {
346 for(x
= 0; x
< sizeof(data
->gui
.theme
.fontsample
)
347 / sizeof(*data
->gui
.theme
.fontsample
); x
++) {
349 if(data
->gui
.theme
.fontsample
[x
]->w
> maxw
) {
350 maxw
= data
->gui
.theme
.fontsample
[x
]->w
;
354 for(x
= 0; x
< sizeof(data
->gui
.theme
.fontsample
)
355 / sizeof(*data
->gui
.theme
.fontsample
); x
++) {
357 blit_surface(smode
->screen
, data
->gui
.theme
.fontsample
[x
],
358 (smode
->width
- maxw
) / 2,
359 200 + data
->gui
.theme
.fontsample
[x
]->h
* x
);
363 static void free_resize_options(struct options_data_t
*data
,
368 /*free_panel(gui->panel[PANEL_OPTIONS]);
369 free_panel(gui->panel[PANEL_OPTIONS_GRAPHICS]);
370 free_panel(gui->panel[PANEL_OPTIONS_THEME]);*/
372 for(x
= 0; x
< sizeof(data
->gui
.theme
.fontsample
)
373 / sizeof(*data
->gui
.theme
.fontsample
); x
++) {
375 SDL_FreeSurface(data
->gui
.theme
.fontsample
[x
]);
379 void free_options(struct options_data_t
*data
, struct gui_t
*gui
) {
380 free_resize_options(data
, gui
);