]> icculus.org git repositories - mikachu/openbox.git/blob - otk/label.cc
ignore more focus events, and also crossing events from grabs
[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 Label::Label(Widget *parent)
12   : Widget(parent), _text("")
13 {
14   setStyle(_style);
15 }
16
17 Label::~Label()
18 {
19 }
20
21 void Label::setStyle(RenderStyle *style)
22 {
23   Widget::setStyle(style);
24
25   setTexture(style->labelUnfocusBackground());
26 }
27
28
29 void Label::renderForeground(void)
30 {
31   otk::Widget::renderForeground();
32
33   const Font *ft = style()->labelFont();
34   unsigned int sidemargin = style()->bevelWidth() * 2;
35
36   ustring t = _text; // the actual text to draw
37   int x = sidemargin;    // x coord for the text
38
39   // find a string that will fit inside the area for text
40   int max_length = width() - sidemargin * 2;
41   if (max_length <= 0) {
42     t = ""; // can't fit anything
43   } else {
44     size_t text_len = t.size();
45     int length;
46       
47     do {
48       t.resize(text_len);
49       length = ft->measureString(t);
50     } while (length > max_length && text_len-- > 0);
51
52     // justify the text
53     switch (style()->labelTextJustify()) {
54     case RenderStyle::RightJustify:
55       x += max_length - length;
56       break;
57     case RenderStyle::CenterJustify:
58       x += (max_length - length) / 2;
59       break;
60     case RenderStyle::LeftJustify:
61       break;
62     }
63   }
64
65   display->renderControl(_screen)->
66     drawString(*_surface, *ft, x, 0, *style()->textUnfocusColor(), t);
67 }
68
69 }