shithub: choc

Download patch

ref: 4fba2ab2ddda75a05c70ac95531504edfafdf8c8
parent: e5336a1bdc44021605c20f9c50876b6cb5c90f9a
author: Simon Howard <[email protected]>
date: Tue Sep 20 16:47:19 EDT 2011

Add TXT_MessageBox convenience function.

Subversion-branch: /branches/v2-branch
Subversion-revision: 2388

--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -270,19 +270,9 @@
 
 static void NoJoystick(void)
 {
-    txt_window_t *window;
-
-    window = TXT_NewWindow(NULL);
-
-    TXT_AddWidget(window,
-                  TXT_NewLabel("No joysticks could be opened.\n\n"
-                               "Try configuring your joystick from within\n"
-                               "your OS first."));
-
-    TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
-    TXT_SetWindowAction(window, TXT_HORIZ_CENTER, 
-                        TXT_NewWindowEscapeAction(window));
-    TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL);
+    TXT_MessageBox(NULL, "No joysticks could be opened.\n\n"
+                         "Try configuring your joystick from within\n"
+                         "your OS first.");
 
     joystick_index = -1;
     SetJoystickButtonLabel();
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -20,10 +20,12 @@
 //
 
 #include <stdlib.h>
+#include <stdarg.h>
 #include <string.h>
 
 #include "doomkeys.h"
 
+#include "txt_label.h"
 #include "txt_desktop.h"
 #include "txt_gui.h"
 #include "txt_main.h"
@@ -470,5 +472,26 @@
 {
     window->mouse_listener = mouse_listener;
     window->mouse_listener_data = user_data;
+}
+
+txt_window_t *TXT_MessageBox(char *title, char *message, ...)
+{
+    txt_window_t *window;
+    char buf[256];
+    va_list args;
+
+    va_start(args, message);
+    vsnprintf(buf, sizeof(buf), message, args);
+    va_end(args);
+
+    window = TXT_NewWindow(title);
+    TXT_AddWidget(window, TXT_NewLabel(buf));
+
+    TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
+    TXT_SetWindowAction(window, TXT_HORIZ_CENTER, 
+                        TXT_NewWindowEscapeAction(window));
+    TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL);
+
+    return window;
 }
 
--- a/textscreen/txt_window.h
+++ b/textscreen/txt_window.h
@@ -176,6 +176,16 @@
                           TxtWindowMousePress mouse_listener,
                           void *user_data);
 
+/**
+ * Open a window displaying a message.
+ *
+ * @param title           Title of the window.
+ * @param message         The message to display in the window.
+ * @return                The new window.
+ */
+
+txt_window_t *TXT_MessageBox(char *title, char *message, ...);
+
 #endif /* #ifndef TXT_WINDOW_T */