1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
4 // Copyright(C) 2006 Simon Howard
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #include "txt_label.h"
29 #include "txt_window.h"
31 static void TXT_LabelSizeCalc(TXT_UNCAST_ARG(label
))
33 TXT_CAST_ARG(txt_label_t
, label
);
35 label
->widget
.w
= label
->w
;
36 label
->widget
.h
= label
->h
;
39 static void TXT_LabelDrawer(TXT_UNCAST_ARG(label
), int selected
)
41 TXT_CAST_ARG(txt_label_t
, label
);
43 int origin_x
, origin_y
;
44 unsigned int align_indent
= 0;
49 TXT_BGColor(label
->bgcolor
, 0);
50 TXT_FGColor(label
->fgcolor
);
52 TXT_GetXY(&origin_x
, &origin_y
);
54 for (y
=0; y
<label
->h
; ++y
)
56 // Calculate the amount to indent this line due to the align
59 switch (label
->widget
.align
)
64 case TXT_HORIZ_CENTER
:
65 align_indent
= (label
->w
- strlen(label
->lines
[y
])) / 2;
68 align_indent
= label
->w
- strlen(label
->lines
[y
]);
74 TXT_GotoXY(origin_x
, origin_y
+ y
);
78 for (x
=0; x
<align_indent
; ++x
)
85 TXT_DrawString(label
->lines
[y
]);
86 x
+= strlen(label
->lines
[y
]);
97 static void TXT_LabelDestructor(TXT_UNCAST_ARG(label
))
99 TXT_CAST_ARG(txt_label_t
, label
);
105 txt_widget_class_t txt_label_class
=
115 void TXT_SetLabel(txt_label_t
*label
, char *value
)
120 // Free back the old label
127 label
->label
= strdup(value
);
129 // Work out how many lines in this label
133 for (p
= value
; *p
!= '\0'; ++p
)
143 label
->lines
= malloc(sizeof(char *) * label
->h
);
144 label
->lines
[0] = label
->label
;
147 for (p
= label
->label
; *p
!= '\0'; ++p
)
151 label
->lines
[y
] = p
+ 1;
159 for (y
=0; y
<label
->h
; ++y
)
161 if (strlen(label
->lines
[y
]) > label
->w
)
162 label
->w
= strlen(label
->lines
[y
]);
166 txt_label_t
*TXT_NewLabel(char *text
)
170 label
= malloc(sizeof(txt_label_t
));
172 TXT_InitWidget(label
, &txt_label_class
);
173 label
->widget
.selectable
= 0;
179 label
->bgcolor
= TXT_COLOR_BLUE
;
180 label
->fgcolor
= TXT_COLOR_BRIGHT_WHITE
;
182 TXT_SetLabel(label
, text
);
187 void TXT_SetFGColor(txt_label_t
*label
, txt_color_t color
)
189 label
->fgcolor
= color
;
192 void TXT_SetBGColor(txt_label_t
*label
, txt_color_t color
)
194 label
->bgcolor
= color
;