]>
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 OtkFocusLabel::OtkFocusLabel(OtkWidget
*parent
)
14 : OtkFocusWidget(parent
), _text("")
16 const ScreenInfo
*info
= OBDisplay::screenInfo(getScreen());
17 _xftdraw
= XftDrawCreate(OBDisplay::display
, getWindow(), info
->getVisual(),
22 OtkFocusLabel::~OtkFocusLabel()
24 XftDrawDestroy(_xftdraw
);
28 void OtkFocusLabel::setStyle(Style
*style
)
30 OtkFocusWidget::setStyle(style
);
32 setTexture(getStyle()->getLabelFocus());
33 setUnfocusTexture(getStyle()->getLabelUnfocus());
37 void OtkFocusLabel::update(void)
40 const BFont
&ft
= getStyle()->getFont();
41 BColor
*text_color
= (isFocused() ? getStyle()->getTextFocus()
42 : getStyle()->getTextUnfocus());
43 unsigned int sidemargin
= getStyle()->getBevelWidth() * 2;
45 std::string t
= _text
; // the actual text to draw
46 int x
= sidemargin
; // x coord for the text
48 // find a string that will fit inside the area for text
49 int max_length
= width() - sidemargin
* 2;
50 if (max_length
<= 0) {
51 t
= ""; // can't fit anything
53 size_t text_len
= t
.size();
58 length
= ft
.measureString(t
);
59 } while (length
> max_length
&& text_len
-- > 0);
62 switch (getStyle()->textJustify()) {
63 case Style::RightJustify
:
64 x
+= max_length
- length
;
66 case Style::CenterJustify
:
67 x
+= (max_length
- length
) / 2;
69 case Style::LeftJustify
:
74 OtkFocusWidget::update();
76 ft
.drawString(_xftdraw
, x
, 0, *text_color
, t
);
78 OtkFocusWidget::update();
This page took 0.04021 seconds and 4 git commands to generate.