]>
Dogcows Code - chaz/openbox/blob - focuslabel.cc
c4f124e682d1d989fd459f17ac592e9907a6675c
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(),
21 OtkFocusLabel::~OtkFocusLabel()
23 XftDrawDestroy(_xftdraw
);
27 void OtkFocusLabel::setStyle(Style
*style
)
29 OtkFocusWidget::setStyle(style
);
31 setTexture(getStyle()->getLabelFocus());
32 setUnfocusTexture(getStyle()->getLabelUnfocus());
36 void OtkFocusLabel::update(void)
39 const BFont
&ft
= getStyle()->getFont();
40 BColor
*text_color
= (isFocused() ? getStyle()->getTextFocus()
41 : getStyle()->getTextUnfocus());
42 unsigned int sidemargin
= getStyle()->getBevelWidth() * 2;
44 std::string t
= _text
; // the actual text to draw
45 int x
= sidemargin
; // x coord for the text
47 // find a string that will fit inside the area for text
48 int max_length
= width() - sidemargin
* 2;
49 if (max_length
<= 0) {
50 t
= ""; // can't fit anything
52 size_t text_len
= t
.size();
57 length
= ft
.measureString(t
);
58 } while (length
> max_length
&& text_len
-- > 0);
61 switch (getStyle()->textJustify()) {
62 case Style::RightJustify
:
63 x
+= max_length
- length
;
65 case Style::CenterJustify
:
66 x
+= (max_length
- length
) / 2;
68 case Style::LeftJustify
:
73 OtkFocusWidget::update();
75 ft
.drawString(_xftdraw
, x
, 0, *text_color
, t
);
77 OtkFocusWidget::update();
This page took 0.040152 seconds and 3 git commands to generate.