1 #include "display_options.h"
2
3 #include "game/settings.h"
4 #include "game/system.h"
5 #include "graphics/generic_button.h"
6 #include "graphics/graphics.h"
7 #include "graphics/lang_text.h"
8 #include "graphics/panel.h"
9 #include "graphics/window.h"
10 #include "input/input.h"
11
12 static void button_fullscreen(int param1, int param2);
13 static void button_set_resolution(int id, int param2);
14 static void button_cancel(int param1, int param2);
15
16 static generic_button buttons[] = {
17 {128, 136, 224, 20, button_fullscreen, button_none, 1, 0},
18 {128, 160, 224, 20, button_set_resolution, button_none, 1, 0},
19 {128, 184, 224, 20, button_set_resolution, button_none, 2, 0},
20 {128, 208, 224, 20, button_set_resolution, button_none, 3, 0},
21 {128, 232, 224, 20, button_cancel, button_none, 1, 0},
22 };
23
24 static struct {
25 int focus_button_id;
26 void (*close_callback)(void);
27 } data;
28
init(void (* close_callback)(void))29 static void init(void (*close_callback)(void))
30 {
31 data.focus_button_id = 0;
32 data.close_callback = close_callback;
33 }
34
draw_foreground(void)35 static void draw_foreground(void)
36 {
37 graphics_in_dialog();
38
39 outer_panel_draw(96, 80, 18, 12);
40
41 label_draw(128, 136, 14, data.focus_button_id == 1 ? 1 : 2);
42 label_draw(128, 160, 14, data.focus_button_id == 2 ? 1 : 2);
43 label_draw(128, 184, 14, data.focus_button_id == 3 ? 1 : 2);
44 label_draw(128, 208, 14, data.focus_button_id == 4 ? 1 : 2);
45 label_draw(128, 232, 14, data.focus_button_id == 5 ? 1 : 2);
46
47 lang_text_draw_centered(42, 0, 128, 94, 224, FONT_LARGE_BLACK);
48
49 lang_text_draw_centered(42, setting_fullscreen() ? 2 : 1, 128, 140, 224, FONT_NORMAL_GREEN);
50
51 lang_text_draw_centered(42, 3, 128, 164, 224, FONT_NORMAL_GREEN);
52 lang_text_draw_centered(42, 4, 128, 188, 224, FONT_NORMAL_GREEN);
53 lang_text_draw_centered(42, 5, 128, 212, 224, FONT_NORMAL_GREEN);
54 lang_text_draw_centered(42, 6, 128, 236, 224, FONT_NORMAL_GREEN);
55
56 graphics_reset_dialog();
57 }
58
handle_input(const mouse * m,const hotkeys * h)59 static void handle_input(const mouse *m, const hotkeys *h)
60 {
61 if (generic_buttons_handle_mouse(mouse_in_dialog(m), 0, 0, buttons, 5, &data.focus_button_id)) {
62 return;
63 }
64 if (input_go_back_requested(m, h)) {
65 data.close_callback();
66 }
67 }
68
button_fullscreen(int param1,int param2)69 static void button_fullscreen(int param1, int param2)
70 {
71 system_set_fullscreen(!setting_fullscreen());
72 data.close_callback();
73 }
74
button_set_resolution(int id,int param2)75 static void button_set_resolution(int id, int param2)
76 {
77 switch (id) {
78 case 1: system_resize(640, 480); break;
79 case 2: system_resize(800, 600); break;
80 case 3: system_resize(1024, 768); break;
81 }
82 data.close_callback();
83 }
84
button_cancel(int param1,int param2)85 static void button_cancel(int param1, int param2)
86 {
87 data.close_callback();
88 }
89
window_display_options_show(void (* close_callback)(void))90 void window_display_options_show(void (*close_callback)(void))
91 {
92 window_type window = {
93 WINDOW_DISPLAY_OPTIONS,
94 window_draw_underlying_window,
95 draw_foreground,
96 handle_input
97 };
98 init(close_callback);
99 window_show(&window);
100 }
101