]> Dogcows Code - chaz/openbox/blob - otk/focuslabel.cc
add an OBBackgroundWidget and use it for setting colors so far.
[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 OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
14 : OtkFocusWidget(parent), _text("")
15 {
16 const ScreenInfo *info = OBDisplay::screenInfo(getScreen());
17 _xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(),
18 info->getColormap());
19 }
20
21 OtkFocusLabel::~OtkFocusLabel()
22 {
23 XftDrawDestroy(_xftdraw);
24 }
25
26
27 void OtkFocusLabel::setStyle(Style *style)
28 {
29 OtkFocusWidget::setStyle(style);
30
31 setTexture(getStyle()->getLabelFocus());
32 setUnfocusTexture(getStyle()->getLabelUnfocus());
33 }
34
35
36 void OtkFocusLabel::update(void)
37 {
38 if (_dirty) {
39 const BFont &ft = getStyle()->getFont();
40 BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
41 : getStyle()->getTextUnfocus());
42 unsigned int sidemargin = getStyle()->getBevelWidth() * 2;
43
44 std::string t = _text; // the actual text to draw
45 int x = sidemargin; // x coord for the text
46
47 // find a string that will fit inside the area for text
48 int max_length = width() - sidemargin * 2;
49 if (max_length <= 0) {
50 t = ""; // can't fit anything
51 } else {
52 size_t text_len = t.size();
53 int length;
54
55 do {
56 t.resize(text_len);
57 length = ft.measureString(t);
58 } while (length > max_length && text_len-- > 0);
59
60 // justify the text
61 switch (getStyle()->textJustify()) {
62 case Style::RightJustify:
63 x += max_length - length;
64 break;
65 case Style::CenterJustify:
66 x += (max_length - length) / 2;
67 break;
68 case Style::LeftJustify:
69 break;
70 }
71 }
72
73 OtkFocusWidget::update();
74
75 ft.drawString(_xftdraw, x, 0, *text_color, t);
76 } else
77 OtkFocusWidget::update();
78 }
79
80 }
This page took 0.035018 seconds and 4 git commands to generate.