]> Dogcows Code - chaz/openbox/blob - otk/label.cc
xft2 works. and works good.
[chaz/openbox] / 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 OtkLabel::OtkLabel(OtkWidget *parent)
12 : OtkWidget(parent), _text("")
13 {
14 const ScreenInfo *info = OBDisplay::screenInfo(getScreen());
15 _xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(),
16 info->getColormap());
17
18 setTexture(getStyle()->getLabelUnfocus());
19 }
20
21 OtkLabel::~OtkLabel()
22 {
23 XftDrawDestroy(_xftdraw);
24 }
25
26 void OtkLabel::update(void)
27 {
28 if (_dirty) {
29 const BFont &ft = getStyle()->getFont();
30 unsigned int bevel = getStyle()->getBevelWidth();
31
32 std::string t = _text; // the actual text to draw
33 int x = bevel; // x coord for the text
34
35 // find a string that will fit inside the area for text
36 int max_length = width() - getBevelWidth() * 2;
37 if (max_length <= 0) {
38 t = ""; // can't fit anything
39 } else {
40 size_t text_len = t.size();
41 int length;
42
43 do {
44 t.resize(text_len);
45 length = ft.measureString(t);
46 } while (length > max_length && text_len-- > 0);
47
48 // justify the text
49 switch (getStyle()->textJustify()) {
50 case Style::RightJustify:
51 x += max_length - length;
52 break;
53 case Style::CenterJustify:
54 x += (max_length - length) / 2;
55 break;
56 case Style::LeftJustify:
57 break;
58 }
59 }
60
61 OtkWidget::update();
62
63 ft.drawString(_xftdraw, x, bevel, *getStyle()->getTextUnfocus(), t);
64 } else
65 OtkWidget::update();
66 }
67
68 }
This page took 0.033757 seconds and 4 git commands to generate.