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