]>
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(),
20 setTexture(getStyle()->getLabelFocus());
21 setUnfocusTexture(getStyle()->getLabelUnfocus());
24 OtkFocusLabel::~OtkFocusLabel()
26 XftDrawDestroy(_xftdraw
);
29 void OtkFocusLabel::update(void)
32 const BFont
&ft
= getStyle()->getFont();
33 BColor
*text_color
= (isFocused() ? getStyle()->getTextFocus()
34 : getStyle()->getTextUnfocus());
35 unsigned int bevel
= getStyle()->getBevelWidth() / 2;
37 std::string t
= _text
; // the actual text to draw
38 int x
= bevel
; // x coord for the text
40 // find a string that will fit inside the area for text
41 int max_length
= width() - bevel
* 2;
42 if (max_length
<= 0) {
43 t
= ""; // can't fit anything
45 size_t text_len
= t
.size();
50 length
= ft
.measureString(t
);
51 } while (length
> max_length
&& text_len
-- > 0);
54 switch (getStyle()->textJustify()) {
55 case Style::RightJustify
:
56 x
+= max_length
- length
;
58 case Style::CenterJustify
:
59 x
+= (max_length
- length
) / 2;
61 case Style::LeftJustify
:
66 OtkFocusWidget::update();
68 ft
.drawString(_xftdraw
, x
, bevel
, *text_color
, t
);
70 OtkFocusWidget::update();
This page took 0.041557 seconds and 4 git commands to generate.