]>
Dogcows Code - chaz/openbox/blob - focuslabel.cc
846d035ebb78de0317161796e1009535b505db32
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
= _bevel_width
* 2;
41 resize(w
+ sidemargin
* 2, h
+ _bevel_width
* 2);
44 void FocusLabel::update()
47 int w
= _rect
.width(), h
= _rect
.height();
48 const Font
*ft
= style()->labelFont();
49 unsigned int sidemargin
= _bevel_width
* 2;
51 w
= ft
->measureString(_text
) + sidemargin
* 2;
55 // enforce a minimum size
56 if (w
> _rect
.width()) {
57 if (h
> _rect
.height())
60 internalResize(w
, _rect
.height());
61 } else if (h
> _rect
.height())
62 internalResize(_rect
.width(), h
);
64 FocusWidget::update();
68 void FocusLabel::renderForeground()
70 FocusWidget::renderForeground();
72 const Font
*ft
= style()->labelFont();
73 RenderColor
*text_color
= (isFocused() ? style()->textFocusColor()
74 : style()->textUnfocusColor());
75 unsigned int sidemargin
= _bevel_width
* 2;
77 ustring t
= _text
; // the actual text to draw
78 int x
= sidemargin
; // x coord for the text
80 // find a string that will fit inside the area for text
81 int max_length
= width() - sidemargin
* 2;
82 if (max_length
<= 0) {
83 t
= ""; // can't fit anything
85 size_t text_len
= t
.size();
90 length
= ft
->measureString(t
);
91 } while (length
> max_length
&& text_len
-- > 0);
94 switch (style()->labelTextJustify()) {
95 case RenderStyle::RightJustify
:
96 x
+= max_length
- length
;
98 case RenderStyle::CenterJustify
:
99 x
+= (max_length
- length
) / 2;
101 case RenderStyle::LeftJustify
:
106 display
->renderControl(_screen
)->
107 drawString(*_surface
, *ft
, x
, _bevel_width
, *text_color
, t
);
This page took 0.038156 seconds and 3 git commands to generate.