shithub: choc

Download patch

ref: 2ad24f982e76e487e7c7f6543c2236723903a22d
parent: a94100706700ff6b29f6ff3d8a6be7daf46f4dfc
author: Simon Howard <[email protected]>
date: Mon May 22 15:23:28 EDT 2006

Add TXT_SetLabel() function to set the label value.

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

--- a/textscreen/txt_label.c
+++ b/textscreen/txt_label.c
@@ -48,16 +48,25 @@
     TXT_LabelDestructor,
 };
 
-static void TXT_SplitLabel(txt_label_t *label)
+void TXT_SetLabel(txt_label_t *label, char *value)
 {
     char *p;
     int y;
 
+    // Free back the old label
+
+    free(label->label);
+    free(label->lines);
+
+    // Set the new value 
+
+    label->label = strdup(value);
+
     // Work out how many lines in this label
 
     label->h = 1;
 
-    for (p = label->label; *p != '\0'; ++p)
+    for (p = value; *p != '\0'; ++p)
     {
         if (*p == '\n')
         {
@@ -98,9 +107,10 @@
 
     TXT_InitWidget(label, &txt_label_class);
     label->widget.selectable = 0;
-    label->label = strdup(text);
+    label->label = NULL;
+    label->lines = NULL;
 
-    TXT_SplitLabel(label);
+    TXT_SetLabel(label, text);
 
     return label;
 }
--- a/textscreen/txt_label.h
+++ b/textscreen/txt_label.h
@@ -38,6 +38,7 @@
 };
 
 txt_label_t *TXT_NewLabel(char *label);
+void TXT_SetLabel(txt_label_t *label, char *value);
 
 #endif /* #ifndef TXT_LABEL_H */