]> icculus.org git repositories - mikachu/openbox.git/blob - otk/label.cc
change how the widgets' _dirty flag works so that all inheritence levels of the widge...
[mikachu/openbox.git] / otk / label.cc
1 #include "label.hh"
2
3 namespace otk {
4
5 OtkLabel::OtkLabel(OtkWidget *parent)
6   : OtkWidget(parent), _text("")
7 {
8   setTexture(getStyle()->getLabelUnfocus());
9 }
10
11 OtkLabel::~OtkLabel()
12 {
13 }
14
15 void OtkLabel::update(void)
16 {
17   if (_dirty) {
18     const BFont &ft = getStyle()->getFont();
19     unsigned int bevel = getStyle()->getBevelWidth();
20
21     std::string t = _text; // the actual text to draw
22     int x = bevel;         // x coord for the text
23
24     // find a string that will fit inside the area for text
25     int max_length = width() - getBevelWidth() * 2;
26     if (max_length <= 0) {
27       t = ""; // can't fit anything
28     } else {
29       size_t text_len = t.size();
30       int length;
31       
32       do {
33         t.resize(text_len);
34         length = ft.measureString(t);
35       } while (length > max_length && text_len-- > 0);
36
37       // justify the text
38       switch (getStyle()->textJustify()) {
39       case Style::RightJustify:
40         x += max_length - length;
41         break;
42       case Style::CenterJustify:
43         x += (max_length - length) / 2;
44         break;
45       case Style::LeftJustify:
46         break;
47       }
48     }
49
50     OtkWidget::update();
51
52     ft.drawString(getWindow(), x, bevel, *getStyle()->getTextUnfocus(), t);
53   } else
54     OtkWidget::update();
55 }
56
57 }