]>
Dogcows Code - chaz/openbox/blob - otk/focuslabel.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "focuslabel.hh"
9 #include "screeninfo.hh"
13 FocusLabel::FocusLabel(Widget
*parent
)
14 : FocusWidget(parent
), _text("")
19 FocusLabel::~FocusLabel()
24 void FocusLabel::setStyle(RenderStyle
*style
)
26 FocusWidget::setStyle(style
);
28 setTexture(style
->labelFocusBackground());
29 setUnfocusTexture(style
->labelUnfocusBackground());
32 void FocusLabel::fitString(const std::string
&str
)
34 const Font
*ft
= style()->labelFont();
35 fitSize(ft
->measureString(str
), ft
->height());
38 void FocusLabel::fitSize(int w
, int h
)
40 unsigned int sidemargin
= style()->bevelWidth() * 2;
41 resize(w
+ sidemargin
* 2, h
);
44 void FocusLabel::update()
47 int w
= _rect
.width(), h
= _rect
.height();
48 const Font
*ft
= style()->labelFont();
49 unsigned int sidemargin
= style()->bevelWidth() * 2;
51 w
= ft
->measureString(_text
) + sidemargin
* 2;
56 FocusWidget::update();
60 void FocusLabel::renderForeground()
62 FocusWidget::renderForeground();
64 const Font
*ft
= style()->labelFont();
65 RenderColor
*text_color
= (isFocused() ? style()->textFocusColor()
66 : style()->textUnfocusColor());
67 unsigned int sidemargin
= style()->bevelWidth() * 2;
69 ustring t
= _text
; // the actual text to draw
70 int x
= sidemargin
; // x coord for the text
72 // find a string that will fit inside the area for text
73 int max_length
= width() - sidemargin
* 2;
74 if (max_length
<= 0) {
75 t
= ""; // can't fit anything
77 size_t text_len
= t
.size();
82 length
= ft
->measureString(t
);
83 } while (length
> max_length
&& text_len
-- > 0);
86 switch (style()->labelTextJustify()) {
87 case RenderStyle::RightJustify
:
88 x
+= max_length
- length
;
90 case RenderStyle::CenterJustify
:
91 x
+= (max_length
- length
) / 2;
93 case RenderStyle::LeftJustify
:
98 display
->renderControl(_screen
)->
99 drawString(*_surface
, *ft
, x
, 0, *text_color
, t
);
This page took 0.039294 seconds and 4 git commands to generate.