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