shithub: choc

Download patch

ref: f6e8d4c46e9ffebe43a3ea84df3e544417266091
parent: 978ddf539803405ab8fed17e21014ee1ae69fac8
author: Simon Howard <[email protected]>
date: Thu May 18 14:55:24 EDT 2006

Make TXT_AddWidget take a NULL pointer so different widget types can
be passed to it.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 481

--- a/textscreen/guitest.c
+++ b/textscreen/guitest.c
@@ -1,6 +1,6 @@
 #include <stdlib.h>
+#include <string.h>
 
-
 #include "txt_main.h"
 
 #include "txt_button.h"
@@ -19,34 +19,21 @@
 
     strcpy(buf, "This is a button label: ");
 
-    {
-        txt_separator_t *sep;
-        sep = TXT_NewSeparator("Main Section");
-        TXT_AddWidget(window, &sep->widget);
-    }
+    TXT_AddWidget(window, TXT_NewSeparator("Main Section"));
 
     for (i=0; i<8; ++i)
     {
-        txt_button_t *button;
-
-        button = TXT_NewButton(buf);
         strcat(buf, "a");
-        TXT_AddWidget(window, &button->widget);
+        TXT_AddWidget(window, TXT_NewButton(buf));
 
         if (i == 4)
         {
-            txt_separator_t *sep;
-
-            sep = TXT_NewSeparator("Section");
-            TXT_AddWidget(window, &sep->widget);
+            TXT_AddWidget(window, TXT_NewSeparator("Section"));
         }
 
         if (i == 6)
         {
-            txt_separator_t *sep;
-
-            sep = TXT_NewSeparator(NULL);
-            TXT_AddWidget(window, &sep->widget);
+            TXT_AddWidget(window, TXT_NewSeparator(NULL));
         }
     }
 
@@ -62,10 +49,7 @@
 
     for (i=0; i<5; ++i)
     {
-        txt_button_t *button;
-
-        button = TXT_NewButton("hello there blah blah blah blah");
-        TXT_AddWidget(window, &button->widget);
+        TXT_AddWidget(window, TXT_NewButton("hello there blah blah blah blah"));
     }
 }
 
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -166,8 +166,12 @@
     TXT_UpdateScreen();
 }
 
-void TXT_AddWidget(txt_window_t *window, txt_widget_t *widget)
+void TXT_AddWidget(txt_window_t *window, void *uncast_widget)
 {
+    txt_widget_t *widget;
+
+    widget = (txt_widget_t *) uncast_widget;
+
     if (window->num_widgets == 0)
     {
         // This is the first widget added.
--- a/textscreen/txt_window.h
+++ b/textscreen/txt_window.h
@@ -51,7 +51,7 @@
 
 txt_window_t *TXT_NewWindow(char *title, int x, int y);
 void TXT_CloseWindow(txt_window_t *window);
-void TXT_AddWidget(txt_window_t *window, txt_widget_t *widget);
+void TXT_AddWidget(txt_window_t *window, void *widget);
 
 void TXT_DrawAllWindows(void);