Include and link physfs properly.
[tuxanci.git] / src / client / yes_no_dialog.c
blobd982933f39a70eb908763301deaeea36070b1b64
1 #include <stdlib.h>
2 #include <assert.h>
4 #include "main.h"
5 #include "list.h"
7 #include "interface.h"
8 #include "hotKey.h"
9 #include "yes_no_dialog.h"
10 #include "image.h"
11 #include "font.h"
13 #include "widget.h"
14 #include "widget_label.h"
15 #include "widget_button.h"
17 static image_t *g_background;
19 static widget_t *widgetLabelMsg;
21 static widget_t *widgetButtonYes;
22 static widget_t *widgetButtonNo;
24 static void (*handle_yes)(void *param);
25 static void (*handle_no)(void *param);
26 static void *param;
27 static bool_t active_dialog;
29 static void eventWidget(void *p)
31 widget_t *button;
33 button = (widget_t *) p;
35 yes_no_dialog_set_active(FALSE);
37 if (button == widgetButtonYes) {
38 handle_yes(param);
41 if (button == widgetButtonNo) {
42 handle_no(param);
46 void yes_no_dialog_init()
48 active_dialog = FALSE;
50 g_background = image_get(IMAGE_GROUP_BASE, "screen_main");
52 widgetLabelMsg = label_new("empty label", WINDOW_SIZE_X / 2,
53 YES_NO_DIALOG_LOCATIN_Y + 20,
54 WIDGET_LABEL_CENTER);
56 widgetButtonYes = button_new(_("Yes"), YES_NO_DIALOG_LOCATIN_X + 20,
57 YES_NO_DIALOG_LOCATIN_Y + 60,
58 eventWidget);
60 widgetButtonNo = button_new(_("No"), YES_NO_DIALOG_LOCATIN_X + 20 +
61 WIDGET_BUTTON_WIDTH + 20,
62 YES_NO_DIALOG_LOCATIN_Y + 60,
63 eventWidget);
66 static void hotkey_escape()
68 yes_no_dialog_set_active(FALSE);
69 handle_no(param);
72 void yes_no_dialog_set_active(bool_t active)
74 active_dialog = active;
76 if (active_dialog == TRUE) {
77 hot_key_register(SDLK_ESCAPE, hotkey_escape);
78 } else {
79 hot_key_unregister(SDLK_ESCAPE);
83 bool_t yes_no_dialog_is_active()
85 return active_dialog;
88 void yes_no_dialog_set(char *label, void *function_yes, void *function_no, void *p_param)
90 label_destroy(widgetLabelMsg);
92 widgetLabelMsg = label_new(label, WINDOW_SIZE_X / 2,
93 YES_NO_DIALOG_LOCATIN_Y + 20,
94 WIDGET_LABEL_CENTER);
96 handle_yes = function_yes;
97 handle_no = function_no;
98 param = p_param;
101 void yes_no_dialog_draw()
103 if (active_dialog == FALSE) {
104 return;
107 image_draw(g_background, YES_NO_DIALOG_LOCATIN_X,
108 YES_NO_DIALOG_LOCATIN_Y,
109 YES_NO_DIALOG_LOCATIN_X,
110 YES_NO_DIALOG_LOCATIN_Y,
111 YES_NO_DIALOG_SIZE_X,
112 YES_NO_DIALOG_SIZE_Y);
114 label_draw(widgetLabelMsg);
115 button_draw(widgetButtonYes);
116 button_draw(widgetButtonNo);
119 void yes_no_dialog_event()
121 if (active_dialog == FALSE) {
122 return;
125 button_event(widgetButtonYes);
126 button_event(widgetButtonNo);
129 void yes_no_dialog_quit()
131 label_destroy(widgetLabelMsg);
132 button_destroy(widgetButtonYes);
133 button_destroy(widgetButtonNo);