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