]> Dogcows Code - chaz/openbox/blob - otk/focuslabel.cc
6869d231c081a3ce21f0476cf99796e5f8d6bd1b
[chaz/openbox] / 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(Style *style)
24 {
25 FocusWidget::setStyle(style);
26
27 // XXX: do this again
28 //setTexture(style->getLabelFocus());
29 //setUnfocusTexture(style->getLabelUnfocus());
30 }
31
32
33 void FocusLabel::renderForeground(void)
34 {
35 const Font *ft = style()->getFont();
36 Color *text_color = (isFocused() ? style()->getTextFocus()
37 : style()->getTextUnfocus());
38 unsigned int sidemargin = style()->getBevelWidth() * 2;
39
40 ustring t = _text; // the actual text to draw
41 int x = sidemargin; // x coord for the text
42
43 // find a string that will fit inside the area for text
44 int max_length = width() - sidemargin * 2;
45 if (max_length <= 0) {
46 t = ""; // can't fit anything
47 } else {
48 size_t text_len = t.size();
49 int length;
50
51 do {
52 t.resize(text_len);
53 length = ft->measureString(t);
54 } while (length > max_length && text_len-- > 0);
55
56 // justify the text
57 switch (style()->textJustify()) {
58 case Style::RightJustify:
59 x += max_length - length;
60 break;
61 case Style::CenterJustify:
62 x += (max_length - length) / 2;
63 break;
64 case Style::LeftJustify:
65 break;
66 }
67 }
68
69 display->renderControl(_screen)->
70 drawString(*_surface, *ft, x, 0, *text_color, t);
71 }
72
73 }
This page took 0.039314 seconds and 4 git commands to generate.