summaryrefslogtreecommitdiff
path: root/textscreen/txt_label.c
diff options
context:
space:
mode:
authorSimon Howard2006-05-29 21:39:12 +0000
committerSimon Howard2006-05-29 21:39:12 +0000
commitb3e5170bbba1c3048da86a5291cd45524abfeac2 (patch)
treecc272ff689b826eac099e3cb7d53070c7da50c44 /textscreen/txt_label.c
parent64b2890756bc7f48fdf2fd0ef8c25dd8f0fd1c22 (diff)
downloadchocolate-doom-b3e5170bbba1c3048da86a5291cd45524abfeac2.tar.gz
chocolate-doom-b3e5170bbba1c3048da86a5291cd45524abfeac2.tar.bz2
chocolate-doom-b3e5170bbba1c3048da86a5291cd45524abfeac2.zip
Add ability to make widgets right aligned or centered within tables.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 546
Diffstat (limited to 'textscreen/txt_label.c')
-rw-r--r--textscreen/txt_label.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/textscreen/txt_label.c b/textscreen/txt_label.c
index 7a8658f9..f92eba82 100644
--- a/textscreen/txt_label.c
+++ b/textscreen/txt_label.c
@@ -20,6 +20,7 @@ static void TXT_LabelDrawer(TXT_UNCAST_ARG(label), int w, int selected)
TXT_CAST_ARG(txt_label_t, label);
int x, y;
int origin_x, origin_y;
+ int align_indent;
TXT_BGColor(label->bgcolor, 0);
TXT_FGColor(label->fgcolor);
@@ -28,10 +29,41 @@ static void TXT_LabelDrawer(TXT_UNCAST_ARG(label), int w, int selected)
for (y=0; y<label->h; ++y)
{
+ // Calculate the amount to indent this line due to the align
+ // setting
+
+ switch (label->widget.align)
+ {
+ case TXT_HORIZ_LEFT:
+ align_indent = 0;
+ break;
+ case TXT_HORIZ_CENTER:
+ align_indent = (label->w - strlen(label->lines[y])) / 2;
+ break;
+ case TXT_HORIZ_RIGHT:
+ align_indent = label->w - strlen(label->lines[y]);
+ break;
+ }
+
+ // Draw this line
+
TXT_GotoXY(origin_x, origin_y + y);
+
+ // Gap at the start
+
+ for (x=0; x<align_indent; ++x)
+ {
+ TXT_DrawString(" ");
+ }
+
+ // The string itself
+
TXT_DrawString(label->lines[y]);
+ x += strlen(label->lines[y]);
+
+ // Gap at the end
- for (x=strlen(label->lines[y]); x<w; ++x)
+ for (; x<w; ++x)
{
TXT_DrawString(" ");
}