]> icculus.org git repositories - dana/openbox.git/blob - otk/focuslabel.cc
remove debug printfs
[dana/openbox.git] / otk / focuslabel.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 "focuslabel.hh"
8 #include "display.hh"
9 #include "screeninfo.hh"
10
11 namespace otk {
12
13 FocusLabel::FocusLabel(Widget *parent)
14   : FocusWidget(parent), _text("")
15 {
16 }
17
18 FocusLabel::~FocusLabel()
19 {
20 }
21
22
23 void FocusLabel::setStyle(RenderStyle *style)
24 {
25   FocusWidget::setStyle(style);
26
27   setTexture(style->labelFocusBackground());
28   setUnfocusTexture(style->labelUnfocusBackground());
29 }
30
31
32 void FocusLabel::renderForeground()
33 {
34   otk::Widget::renderForeground();
35
36   const Font *ft = style()->labelFont();
37   RenderColor *text_color = (isFocused() ? style()->textFocusColor()
38                              : style()->textUnfocusColor());
39   unsigned int sidemargin = style()->bevelWidth() * 2;
40
41   ustring t = _text; // the actual text to draw
42   int x = sidemargin;    // x coord for the text
43
44   // find a string that will fit inside the area for text
45   int max_length = width() - sidemargin * 2;
46   if (max_length <= 0) {
47     t = ""; // can't fit anything
48   } else {
49     size_t text_len = t.size();
50     int length;
51       
52     do {
53       t.resize(text_len);
54       length = ft->measureString(t);
55     } while (length > max_length && text_len-- > 0);
56
57     // justify the text
58     switch (style()->labelTextJustify()) {
59     case RenderStyle::RightJustify:
60       x += max_length - length;
61       break;
62     case RenderStyle::CenterJustify:
63       x += (max_length - length) / 2;
64       break;
65     case RenderStyle::LeftJustify:
66       break;
67     }
68   }
69
70   display->renderControl(_screen)->
71     drawString(*_surface, *ft, x, 0, *text_color, t);
72 }
73
74 }