shithub: choc

Download patch

ref: aafc38483ef50980170f713fe62a0b471fd34c8d
parent: 2ad24f982e76e487e7c7f6543c2236723903a22d
author: Simon Howard <fraggle@gmail.com>
date: Mon May 22 15:25:19 EDT 2006

Updated GUI test which demonstrates signals used to update a label.

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

--- a/textscreen/guitest.c
+++ b/textscreen/guitest.c
@@ -19,10 +19,27 @@
     RADIO_VALUE_MUSHROOM,
     RADIO_VALUE_SNAKE,
 };
+char *radio_values[] = { "Badger", "Mushroom", "Snake" };
 int radiobutton_value;
+txt_label_t *value_label;
 txt_window_t *firstwin;
-int checkbox_value;
+int cheesy;
 
+void UpdateLabel(TXT_UNCAST_ARG(widget), void *user_data)
+{
+    char buf[40];
+    
+    strcpy(buf, " Current value: ");
+    if (cheesy)
+    {
+        strcat(buf, "Cheesy ");
+    }
+    strcat(buf, radio_values[radiobutton_value]);
+    strcat(buf, "\n");
+
+    TXT_SetLabel(value_label, buf);
+}
+
 void CloseWindow(TXT_UNCAST_ARG(button), void *user_data)
 {
     TXT_CloseWindow(firstwin);
@@ -34,6 +51,7 @@
     txt_table_t *table;
     txt_table_t *leftpane, *rightpane;
     txt_button_t *button;
+    txt_checkbox_t *cheesy_checkbox;
     char buf[100];
     int i;
     
@@ -59,20 +77,29 @@
     }
 
     TXT_AddWidget(window, TXT_NewLabel(""));
+    value_label = TXT_NewLabel("");
+    TXT_AddWidget(window, value_label);
 
     table = TXT_NewTable(2);
     TXT_AddWidget(window, table);
 
-    TXT_AddWidget(table, TXT_NewCheckBox("Checkbox", &checkbox_value));
+    cheesy_checkbox = TXT_NewCheckBox("Cheesy", &cheesy);
+    TXT_AddWidget(table, cheesy_checkbox);
+    TXT_SignalConnect(cheesy_checkbox, "changed", UpdateLabel, NULL);
 
     rightpane = TXT_NewTable(1);
     TXT_AddWidget(table, rightpane);
-    TXT_AddWidget(rightpane, TXT_NewRadioButton("Badger", &radiobutton_value,
-                                                RADIO_VALUE_BADGER));
-    TXT_AddWidget(rightpane, TXT_NewRadioButton("Mushroom", &radiobutton_value,
-                                                RADIO_VALUE_MUSHROOM));
-    TXT_AddWidget(rightpane, TXT_NewRadioButton("Snake", &radiobutton_value,
-                                                RADIO_VALUE_SNAKE));
+
+    for (i=0; i<3; ++i)
+    {
+        txt_radiobutton_t *rbut;
+
+        rbut = TXT_NewRadioButton(radio_values[i], &radiobutton_value, i);
+        TXT_AddWidget(rightpane, rbut);
+        TXT_SignalConnect(rbut, "selected", UpdateLabel, NULL);
+    }
+
+    UpdateLabel(NULL, NULL);
                                      
     button = TXT_NewButton("Close Window");
     TXT_AddWidget(window, button);