shithub: choc

Download patch

ref: 1f101a63a60428230549243931356a4c0ee5ca7d
parent: b03198720a635d32908c98dc0e11bb9d87ee32f2
author: Simon Howard <[email protected]>
date: Wed May 24 17:35:45 EDT 2006

Move textscreen GUI demos into an examples/ subdir.

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

--- a/configure.in
+++ b/configure.in
@@ -52,6 +52,7 @@
 AC_OUTPUT([
 Makefile
 textscreen/Makefile
+textscreen/examples/Makefile
 src/Makefile
 src/chocolate-doom-res.rc
 ])
--- a/textscreen/Makefile.am
+++ b/textscreen/Makefile.am
@@ -1,9 +1,10 @@
 
 AM_CFLAGS = @SDL_CFLAGS@ -I../src
+SUBDIRS=examples
 
 noinst_LIBRARIES=libtextscreen.a
-bin_PROGRAMS=guitest calculator
 
+libtextscreen_a_LIBADD = @SDL_LIBS@
 libtextscreen_a_SOURCES =                                 \
 	txt_checkbox.c           txt_checkbox.h           \
 	txt_desktop.c            txt_desktop.h            \
@@ -20,10 +21,4 @@
 	txt_window.c             txt_window.h             \
 	txt_window_action.c      txt_window_action.h      \
 	txt_font.h
-
-guitest_LDADD = @SDL_LIBS@ libtextscreen.a
-guitest_SOURCES = guitest.c
-
-calculator_LDADD = @SDL_LIBS@ libtextscreen.a
-calculator_SOURCES = calculator.c
 
--- a/textscreen/calculator.c
+++ /dev/null
@@ -1,160 +1,0 @@
-
-#include <stdio.h>
-#include <string.h>
-#include "txt_button.h"
-#include "txt_desktop.h"
-#include "txt_label.h"
-
-typedef enum
-{
-    OP_NONE,
-    OP_PLUS,
-    OP_MINUS,
-    OP_MULT,
-    OP_DIV,
-} operator_t;
-
-int starting_input = 0;
-int input_value = 0;
-txt_label_t *input_box;
-int first_operand;
-operator_t operator = OP_NONE;
-
-void UpdateInputBox(void)
-{
-    char buf[20];
-
-    sprintf(buf, " %i", input_value);
-    TXT_SetLabel(input_box, buf);
-}
-
-void InsertNumber(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(value))
-{
-    TXT_CAST_ARG(int, value);
-
-    if (starting_input)
-    {
-        input_value = 0;
-        starting_input = 0;
-    }
-    
-    input_value *= 10;
-    input_value += *value;
-    UpdateInputBox();
-}
-
-void AddNumberButton(txt_table_t *table, int value)
-{
-    txt_button_t *button;
-    char buf[10];
-    int *val_copy;
-
-    val_copy = malloc(sizeof(int));
-    *val_copy = value;
-
-    sprintf(buf, "  %i  ", value);
-
-    button = TXT_NewButton(buf);
-    TXT_AddWidget(table, button);
-    TXT_SignalConnect(button, "pressed", InsertNumber, val_copy);
-}
-
-void Operator(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(op))
-{
-    TXT_CAST_ARG(operator_t, op);
-
-    first_operand = input_value;
-    operator = *op;
-    starting_input = 1;
-}
-
-void AddOperatorButton(txt_table_t *table, char *label, operator_t op)
-{
-    txt_button_t *button;
-    char buf[10];
-    operator_t *op_copy;
-
-    op_copy = malloc(sizeof(operator_t));
-    *op_copy = op;
-
-    sprintf(buf, "  %s  ", label);
-    button = TXT_NewButton(buf);
-
-    TXT_AddWidget(table, button);
-    TXT_SignalConnect(button, "pressed", Operator, op_copy);
-}
-
-void Calculate(TXT_UNCAST_ARG(button), void *unused)
-{
-    switch (operator)
-    {
-        case OP_PLUS:
-            input_value = first_operand + input_value;
-            break;
-        case OP_MINUS:
-            input_value = first_operand - input_value;
-            break;
-        case OP_MULT:
-            input_value = first_operand * input_value;
-            break;
-        case OP_DIV:
-            input_value = first_operand / input_value;
-            break;
-    }
-
-    UpdateInputBox();
-
-    operator = OP_NONE;
-    starting_input = 1;
-}
-
-void BuildGUI()
-{
-    txt_window_t *window;
-    txt_table_t *table;
-    txt_button_t *equals_button;
-    
-    window = TXT_NewWindow("Calculator");
-
-    TXT_AddWidget(window, TXT_NewSeparator(NULL));
-    input_box = TXT_NewLabel("asdf");
-    TXT_AddWidget(window, input_box);
-    TXT_AddWidget(window, TXT_NewSeparator(NULL));
-    TXT_AddWidget(window, TXT_NewLabel(""));
-
-    table = TXT_NewTable(4);
-    TXT_AddWidget(window, table);
-
-    AddNumberButton(table, 7);
-    AddNumberButton(table, 8);
-    AddNumberButton(table, 9);
-    AddOperatorButton(table, "*", OP_MULT);
-    AddNumberButton(table, 4);
-    AddNumberButton(table, 5);
-    AddNumberButton(table, 6);
-    AddOperatorButton(table, "-", OP_MINUS);
-    AddNumberButton(table, 1);
-    AddNumberButton(table, 2);
-    AddNumberButton(table, 3);
-    AddOperatorButton(table, "+", OP_PLUS);
-    AddNumberButton(table, 0);
-    TXT_AddWidget(table, TXT_NewLabel(""));
-    equals_button = TXT_NewButton("  =  ");
-    TXT_SignalConnect(equals_button, "pressed", Calculate, NULL);
-    TXT_AddWidget(table, equals_button);
-    AddOperatorButton(table, "/", OP_DIV);
-    
-    TXT_AddWidget(window, TXT_NewLabel(""));
-    UpdateInputBox();
-}
-
-int main()
-{
-    TXT_Init();
-    TXT_SetDesktopTitle("Calculator demo");
-
-    BuildGUI();
-
-    TXT_GUIMainLoop();
-}
-
--- /dev/null
+++ b/textscreen/examples/Makefile.am
@@ -1,0 +1,11 @@
+
+AM_CFLAGS = @SDL_CFLAGS@ -I.. -I../../src
+
+noinst_PROGRAMS=guitest calculator
+
+guitest_LDADD = @LDFLAGS@ @SDL_LIBS@ ../libtextscreen.a
+guitest_SOURCES = guitest.c
+
+calculator_LDADD = @LDFLAGS@ @SDL_LIBS@ ../libtextscreen.a
+calculator_SOURCES = calculator.c
+
--- /dev/null
+++ b/textscreen/examples/calculator.c
@@ -1,0 +1,160 @@
+
+#include <stdio.h>
+#include <string.h>
+#include "txt_button.h"
+#include "txt_desktop.h"
+#include "txt_label.h"
+
+typedef enum
+{
+    OP_NONE,
+    OP_PLUS,
+    OP_MINUS,
+    OP_MULT,
+    OP_DIV,
+} operator_t;
+
+int starting_input = 0;
+int input_value = 0;
+txt_label_t *input_box;
+int first_operand;
+operator_t operator = OP_NONE;
+
+void UpdateInputBox(void)
+{
+    char buf[20];
+
+    sprintf(buf, " %i", input_value);
+    TXT_SetLabel(input_box, buf);
+}
+
+void InsertNumber(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(value))
+{
+    TXT_CAST_ARG(int, value);
+
+    if (starting_input)
+    {
+        input_value = 0;
+        starting_input = 0;
+    }
+    
+    input_value *= 10;
+    input_value += *value;
+    UpdateInputBox();
+}
+
+void AddNumberButton(txt_table_t *table, int value)
+{
+    txt_button_t *button;
+    char buf[10];
+    int *val_copy;
+
+    val_copy = malloc(sizeof(int));
+    *val_copy = value;
+
+    sprintf(buf, "  %i  ", value);
+
+    button = TXT_NewButton(buf);
+    TXT_AddWidget(table, button);
+    TXT_SignalConnect(button, "pressed", InsertNumber, val_copy);
+}
+
+void Operator(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(op))
+{
+    TXT_CAST_ARG(operator_t, op);
+
+    first_operand = input_value;
+    operator = *op;
+    starting_input = 1;
+}
+
+void AddOperatorButton(txt_table_t *table, char *label, operator_t op)
+{
+    txt_button_t *button;
+    char buf[10];
+    operator_t *op_copy;
+
+    op_copy = malloc(sizeof(operator_t));
+    *op_copy = op;
+
+    sprintf(buf, "  %s  ", label);
+    button = TXT_NewButton(buf);
+
+    TXT_AddWidget(table, button);
+    TXT_SignalConnect(button, "pressed", Operator, op_copy);
+}
+
+void Calculate(TXT_UNCAST_ARG(button), void *unused)
+{
+    switch (operator)
+    {
+        case OP_PLUS:
+            input_value = first_operand + input_value;
+            break;
+        case OP_MINUS:
+            input_value = first_operand - input_value;
+            break;
+        case OP_MULT:
+            input_value = first_operand * input_value;
+            break;
+        case OP_DIV:
+            input_value = first_operand / input_value;
+            break;
+    }
+
+    UpdateInputBox();
+
+    operator = OP_NONE;
+    starting_input = 1;
+}
+
+void BuildGUI()
+{
+    txt_window_t *window;
+    txt_table_t *table;
+    txt_button_t *equals_button;
+    
+    window = TXT_NewWindow("Calculator");
+
+    TXT_AddWidget(window, TXT_NewSeparator(NULL));
+    input_box = TXT_NewLabel("asdf");
+    TXT_AddWidget(window, input_box);
+    TXT_AddWidget(window, TXT_NewSeparator(NULL));
+    TXT_AddWidget(window, TXT_NewLabel(""));
+
+    table = TXT_NewTable(4);
+    TXT_AddWidget(window, table);
+
+    AddNumberButton(table, 7);
+    AddNumberButton(table, 8);
+    AddNumberButton(table, 9);
+    AddOperatorButton(table, "*", OP_MULT);
+    AddNumberButton(table, 4);
+    AddNumberButton(table, 5);
+    AddNumberButton(table, 6);
+    AddOperatorButton(table, "-", OP_MINUS);
+    AddNumberButton(table, 1);
+    AddNumberButton(table, 2);
+    AddNumberButton(table, 3);
+    AddOperatorButton(table, "+", OP_PLUS);
+    AddNumberButton(table, 0);
+    TXT_AddWidget(table, TXT_NewLabel(""));
+    equals_button = TXT_NewButton("  =  ");
+    TXT_SignalConnect(equals_button, "pressed", Calculate, NULL);
+    TXT_AddWidget(table, equals_button);
+    AddOperatorButton(table, "/", OP_DIV);
+    
+    TXT_AddWidget(window, TXT_NewLabel(""));
+    UpdateInputBox();
+}
+
+int main()
+{
+    TXT_Init();
+    TXT_SetDesktopTitle("Calculator demo");
+
+    BuildGUI();
+
+    TXT_GUIMainLoop();
+}
+
--- /dev/null
+++ b/textscreen/examples/guitest.c
@@ -1,0 +1,201 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "doomkeys.h"
+
+#include "txt_main.h"
+
+#include "txt_checkbox.h"
+#include "txt_button.h"
+#include "txt_desktop.h"
+#include "txt_inputbox.h"
+#include "txt_label.h"
+#include "txt_radiobutton.h"
+#include "txt_separator.h"
+#include "txt_table.h"
+#include "txt_window.h"
+
+enum 
+{
+    RADIO_VALUE_BADGER,
+    RADIO_VALUE_MUSHROOM,
+    RADIO_VALUE_SNAKE,
+};
+char *radio_values[] = { "Badger", "Mushroom", "Snake" };
+char *textbox_value = NULL;
+int numbox_value = 0;
+int radiobutton_value;
+txt_label_t *value_label;
+txt_window_t *firstwin;
+int cheesy;
+
+void ClosePwnBox(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window))
+{
+    TXT_CAST_ARG(txt_window_t, window);
+
+    TXT_CloseWindow(window);
+}
+
+void PwnBox(TXT_UNCAST_ARG(widget), void *user_data)
+{
+    txt_window_t *window;
+    txt_window_action_t *close_button;
+    
+    window = TXT_NewWindow("Pwned!");
+    TXT_AddWidget(window, TXT_NewLabel(" BOOM! HEADSHOT! "));
+
+    close_button = TXT_NewWindowAction(KEY_ENTER, "Close");
+    TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
+
+    TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
+    TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, close_button);
+}
+
+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);
+}
+
+void SetupWindow(void)
+{
+    txt_window_t *window;
+    txt_table_t *table;
+    txt_table_t *leftpane, *rightpane;
+    txt_button_t *button;
+    txt_checkbox_t *cheesy_checkbox;
+    txt_window_action_t *pwn;
+    char buf[100];
+    int i;
+    
+    window = TXT_NewWindow("Window test");
+
+    TXT_AddWidget(window, TXT_NewSeparator("Main section"));
+    table = TXT_NewTable(3);
+
+    TXT_AddWidget(window, TXT_NewLabel(" This is a multiline label.\n"
+                                       " A single label object contains \n"
+                                       " all three of these lines.\n"));
+
+    TXT_AddWidget(window, table);
+
+    for (i=0; i<5; ++i)
+    {
+        sprintf(buf, " Option %i in a table:", i + 1);
+        TXT_AddWidget(table, TXT_NewLabel(buf));
+        sprintf(buf, "Button %i-1", i + 1);
+        TXT_AddWidget(table, TXT_NewButton(buf));
+        sprintf(buf, "Button %i-2", i + 1);
+        TXT_AddWidget(table, TXT_NewButton(buf));
+    }
+
+    TXT_AddWidget(window, TXT_NewLabel(""));
+    value_label = TXT_NewLabel("");
+    TXT_AddWidget(window, value_label);
+
+    table = TXT_NewTable(2);
+    TXT_AddWidget(window, table);
+
+    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);
+
+    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);
+
+    TXT_SignalConnect(button, "pressed", CloseWindow, NULL);
+
+    pwn = TXT_NewWindowAction(KEY_F1, "PWN!");
+    TXT_SetWindowAction(window, TXT_HORIZ_CENTER, pwn);
+    TXT_SignalConnect(pwn, "pressed", PwnBox, NULL);
+
+    firstwin = window;
+}
+
+void Window2(void)
+{
+    txt_window_t *window;
+    txt_table_t *table;
+    int i;
+    
+    window = TXT_NewWindow("Another test");
+    TXT_SetWindowPosition(window, 
+                          TXT_HORIZ_RIGHT, 
+                          TXT_VERT_TOP, 
+                          TXT_SCREEN_W - 1, 1);
+
+    for (i=0; i<5; ++i)
+    {
+        TXT_AddWidget(window, TXT_NewButton("hello there blah blah blah blah"));
+    }
+
+    TXT_AddWidget(window, TXT_NewSeparator("Input boxes"));
+    table = TXT_NewTable(2);
+    TXT_AddWidget(window, table);
+    TXT_AddWidget(table, TXT_NewLabel(" String: "));
+    TXT_AddWidget(table, TXT_NewInputBox(&textbox_value, 30));
+    TXT_AddWidget(table, TXT_NewLabel(" Int: "));
+    TXT_AddWidget(table, TXT_NewIntInputBox(&numbox_value, 10));
+}
+
+void DrawASCIIChart()
+{
+    int x, y;
+
+    TXT_ClearScreen();
+
+    for (y=0; y<16; ++y)
+    {
+        for (x=0; x<16; ++x)
+        {
+            TXT_PutChar(' ');
+            TXT_PutChar(' ');
+            TXT_PutChar(' ');
+            TXT_PutChar(y * 16 + x);
+        }
+        TXT_PutChar('\n');
+    }
+}
+
+int main()
+{
+    TXT_Init();
+
+    TXT_SetDesktopTitle("Not Chocolate Doom Setup");
+
+    Window2();
+    SetupWindow();
+
+    TXT_GUIMainLoop();
+}
+
+
--- a/textscreen/guitest.c
+++ /dev/null
@@ -1,201 +1,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "doomkeys.h"
-
-#include "txt_main.h"
-
-#include "txt_checkbox.h"
-#include "txt_button.h"
-#include "txt_desktop.h"
-#include "txt_inputbox.h"
-#include "txt_label.h"
-#include "txt_radiobutton.h"
-#include "txt_separator.h"
-#include "txt_table.h"
-#include "txt_window.h"
-
-enum 
-{
-    RADIO_VALUE_BADGER,
-    RADIO_VALUE_MUSHROOM,
-    RADIO_VALUE_SNAKE,
-};
-char *radio_values[] = { "Badger", "Mushroom", "Snake" };
-char *textbox_value = NULL;
-int numbox_value = 0;
-int radiobutton_value;
-txt_label_t *value_label;
-txt_window_t *firstwin;
-int cheesy;
-
-void ClosePwnBox(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window))
-{
-    TXT_CAST_ARG(txt_window_t, window);
-
-    TXT_CloseWindow(window);
-}
-
-void PwnBox(TXT_UNCAST_ARG(widget), void *user_data)
-{
-    txt_window_t *window;
-    txt_window_action_t *close_button;
-    
-    window = TXT_NewWindow("Pwned!");
-    TXT_AddWidget(window, TXT_NewLabel(" BOOM! HEADSHOT! "));
-
-    close_button = TXT_NewWindowAction(KEY_ENTER, "Close");
-    TXT_SignalConnect(close_button, "pressed", ClosePwnBox, window);
-
-    TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
-    TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, close_button);
-}
-
-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);
-}
-
-void SetupWindow(void)
-{
-    txt_window_t *window;
-    txt_table_t *table;
-    txt_table_t *leftpane, *rightpane;
-    txt_button_t *button;
-    txt_checkbox_t *cheesy_checkbox;
-    txt_window_action_t *pwn;
-    char buf[100];
-    int i;
-    
-    window = TXT_NewWindow("Window test");
-
-    TXT_AddWidget(window, TXT_NewSeparator("Main section"));
-    table = TXT_NewTable(3);
-
-    TXT_AddWidget(window, TXT_NewLabel(" This is a multiline label.\n"
-                                       " A single label object contains \n"
-                                       " all three of these lines.\n"));
-
-    TXT_AddWidget(window, table);
-
-    for (i=0; i<5; ++i)
-    {
-        sprintf(buf, " Option %i in a table:", i + 1);
-        TXT_AddWidget(table, TXT_NewLabel(buf));
-        sprintf(buf, "Button %i-1", i + 1);
-        TXT_AddWidget(table, TXT_NewButton(buf));
-        sprintf(buf, "Button %i-2", i + 1);
-        TXT_AddWidget(table, TXT_NewButton(buf));
-    }
-
-    TXT_AddWidget(window, TXT_NewLabel(""));
-    value_label = TXT_NewLabel("");
-    TXT_AddWidget(window, value_label);
-
-    table = TXT_NewTable(2);
-    TXT_AddWidget(window, table);
-
-    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);
-
-    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);
-
-    TXT_SignalConnect(button, "pressed", CloseWindow, NULL);
-
-    pwn = TXT_NewWindowAction(KEY_F1, "PWN!");
-    TXT_SetWindowAction(window, TXT_HORIZ_CENTER, pwn);
-    TXT_SignalConnect(pwn, "pressed", PwnBox, NULL);
-
-    firstwin = window;
-}
-
-void Window2(void)
-{
-    txt_window_t *window;
-    txt_table_t *table;
-    int i;
-    
-    window = TXT_NewWindow("Another test");
-    TXT_SetWindowPosition(window, 
-                          TXT_HORIZ_RIGHT, 
-                          TXT_VERT_TOP, 
-                          TXT_SCREEN_W - 1, 1);
-
-    for (i=0; i<5; ++i)
-    {
-        TXT_AddWidget(window, TXT_NewButton("hello there blah blah blah blah"));
-    }
-
-    TXT_AddWidget(window, TXT_NewSeparator("Input boxes"));
-    table = TXT_NewTable(2);
-    TXT_AddWidget(window, table);
-    TXT_AddWidget(table, TXT_NewLabel(" String: "));
-    TXT_AddWidget(table, TXT_NewInputBox(&textbox_value, 30));
-    TXT_AddWidget(table, TXT_NewLabel(" Int: "));
-    TXT_AddWidget(table, TXT_NewIntInputBox(&numbox_value, 10));
-}
-
-void DrawASCIIChart()
-{
-    int x, y;
-
-    TXT_ClearScreen();
-
-    for (y=0; y<16; ++y)
-    {
-        for (x=0; x<16; ++x)
-        {
-            TXT_PutChar(' ');
-            TXT_PutChar(' ');
-            TXT_PutChar(' ');
-            TXT_PutChar(y * 16 + x);
-        }
-        TXT_PutChar('\n');
-    }
-}
-
-int main()
-{
-    TXT_Init();
-
-    TXT_SetDesktopTitle("Not Chocolate Doom Setup");
-
-    Window2();
-    SetupWindow();
-
-    TXT_GUIMainLoop();
-}
-
-