summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2006-09-26 23:48:23 +0000
committerSimon Howard2006-09-26 23:48:23 +0000
commitd3d4f6587f48f4047099bfcae2aba84a634edcf4 (patch)
tree016e6519ed704467578dedf37a4fd5b59df33521
parent0755f5ac88fa3ea3074e1d1e46b5e101de59abdb (diff)
downloadchocolate-doom-d3d4f6587f48f4047099bfcae2aba84a634edcf4.tar.gz
chocolate-doom-d3d4f6587f48f4047099bfcae2aba84a634edcf4.tar.bz2
chocolate-doom-d3d4f6587f48f4047099bfcae2aba84a634edcf4.zip
Add TXT_NewButton2 for creating a button with a callback (for convenience).
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 673
-rw-r--r--textscreen/examples/calculator.c16
-rw-r--r--textscreen/examples/guitest.c6
-rw-r--r--textscreen/txt_button.c14
-rw-r--r--textscreen/txt_button.h2
4 files changed, 21 insertions, 17 deletions
diff --git a/textscreen/examples/calculator.c b/textscreen/examples/calculator.c
index e9ed1bf7..968d3ef4 100644
--- a/textscreen/examples/calculator.c
+++ b/textscreen/examples/calculator.c
@@ -44,7 +44,6 @@ void InsertNumber(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(value))
void AddNumberButton(txt_table_t *table, int value)
{
- txt_button_t *button;
char buf[10];
int *val_copy;
@@ -53,9 +52,7 @@ void AddNumberButton(txt_table_t *table, int value)
sprintf(buf, " %i ", value);
- button = TXT_NewButton(buf);
- TXT_AddWidget(table, button);
- TXT_SignalConnect(button, "pressed", InsertNumber, val_copy);
+ TXT_AddWidget(table, TXT_NewButton2(buf, InsertNumber, val_copy));
}
void Operator(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(op))
@@ -69,7 +66,6 @@ void Operator(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(op))
void AddOperatorButton(txt_table_t *table, char *label, operator_t op)
{
- txt_button_t *button;
char buf[10];
operator_t *op_copy;
@@ -77,10 +73,8 @@ void AddOperatorButton(txt_table_t *table, char *label, operator_t op)
*op_copy = op;
sprintf(buf, " %s ", label);
- button = TXT_NewButton(buf);
- TXT_AddWidget(table, button);
- TXT_SignalConnect(button, "pressed", Operator, op_copy);
+ TXT_AddWidget(table, TXT_NewButton2(buf, Operator, op_copy));
}
void Calculate(TXT_UNCAST_ARG(button), void *unused)
@@ -113,7 +107,6 @@ void BuildGUI()
{
txt_window_t *window;
txt_table_t *table;
- txt_button_t *equals_button;
window = TXT_NewWindow("Calculator");
@@ -141,9 +134,8 @@ void BuildGUI()
AddOperatorButton(table, "+", OP_PLUS);
AddNumberButton(table, 0);
TXT_AddWidget(table, NULL);
- equals_button = TXT_NewButton(" = ");
- TXT_SignalConnect(equals_button, "pressed", Calculate, NULL);
- TXT_AddWidget(table, equals_button);
+
+ TXT_AddWidget(table, TXT_NewButton2(" = ", Calculate, NULL));
AddOperatorButton(table, "/", OP_DIV);
TXT_AddWidget(window, TXT_NewStrut(0, 1));
diff --git a/textscreen/examples/guitest.c b/textscreen/examples/guitest.c
index d3cce119..e385ca84 100644
--- a/textscreen/examples/guitest.c
+++ b/textscreen/examples/guitest.c
@@ -65,7 +65,6 @@ void SetupWindow(void)
txt_window_t *window;
txt_table_t *table;
txt_table_t *rightpane;
- txt_button_t *button;
txt_checkbox_t *cheesy_checkbox;
txt_window_action_t *pwn;
txt_label_t *toplabel;
@@ -121,10 +120,7 @@ void SetupWindow(void)
UpdateLabel(NULL, NULL);
- button = TXT_NewButton("Close Window");
- TXT_AddWidget(window, button);
-
- TXT_SignalConnect(button, "pressed", CloseWindow, NULL);
+ TXT_AddWidget(window, TXT_NewButton2("Close Window", CloseWindow, NULL));
pwn = TXT_NewWindowAction(KEY_F1, "PWN!");
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, pwn);
diff --git a/textscreen/txt_button.c b/textscreen/txt_button.c
index e4fd7509..a7a2d25a 100644
--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -122,3 +122,17 @@ txt_button_t *TXT_NewButton(char *label)
return button;
}
+// Button with a callback set automatically
+
+txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
+ void *user_data)
+{
+ txt_button_t *button;
+
+ button = TXT_NewButton(label);
+
+ TXT_SignalConnect(button, "pressed", func, user_data);
+
+ return button;
+}
+
diff --git a/textscreen/txt_button.h b/textscreen/txt_button.h
index 330782f7..11040f2f 100644
--- a/textscreen/txt_button.h
+++ b/textscreen/txt_button.h
@@ -33,6 +33,8 @@ struct txt_button_s
};
txt_button_t *TXT_NewButton(char *label);
+txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
+ void *user_data);
void TXT_SetButtonLabel(txt_button_t *button, char *label);
#endif /* #ifndef TXT_BUTTON_H */