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