openbox/otk/focuslabel.cc

74 lines
1.5 KiB
C++
Raw Normal View History

// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
2002-11-16 13:02:29 +00:00
#include "focuslabel.hh"
2002-12-03 08:54:51 +00:00
#include "display.hh"
#include "screeninfo.hh"
2002-11-16 13:02:29 +00:00
namespace otk {
FocusLabel::FocusLabel(Widget *parent)
: FocusWidget(parent), _text("")
2002-11-16 13:02:29 +00:00
{
}
FocusLabel::~FocusLabel()
2002-11-16 13:02:29 +00:00
{
}
void FocusLabel::setStyle(Style *style)
{
FocusWidget::setStyle(style);
2003-01-20 06:11:12 +00:00
// XXX: do this again
//setTexture(style->getLabelFocus());
//setUnfocusTexture(style->getLabelUnfocus());
}
2003-01-20 06:11:12 +00:00
void FocusLabel::renderForeground(void)
2002-11-16 13:02:29 +00:00
{
2003-01-20 06:11:12 +00:00
const Font *ft = style()->getFont();
Color *text_color = (isFocused() ? style()->getTextFocus()
: style()->getTextUnfocus());
unsigned int sidemargin = style()->getBevelWidth() * 2;
2002-11-16 13:02:29 +00:00
2003-01-20 06:11:12 +00:00
ustring t = _text; // the actual text to draw
int x = sidemargin; // x coord for the text
2002-11-16 13:02:29 +00:00
2003-01-20 06:11:12 +00:00
// find a string that will fit inside the area for text
int max_length = width() - sidemargin * 2;
if (max_length <= 0) {
t = ""; // can't fit anything
} else {
size_t text_len = t.size();
int length;
2002-11-16 13:02:29 +00:00
2003-01-20 06:11:12 +00:00
do {
t.resize(text_len);
length = ft->measureString(t);
} while (length > max_length && text_len-- > 0);
2002-11-16 13:02:29 +00:00
2003-01-20 06:11:12 +00:00
// justify the text
switch (style()->textJustify()) {
case Style::RightJustify:
x += max_length - length;
break;
case Style::CenterJustify:
x += (max_length - length) / 2;
break;
case Style::LeftJustify:
break;
2002-11-16 13:02:29 +00:00
}
2003-01-20 06:11:12 +00:00
}
2002-11-16 13:02:29 +00:00
2003-01-20 06:11:12 +00:00
display->renderControl(_screen)->
drawString(_surface, *ft, x, 0, *text_color, t);
2002-11-16 13:02:29 +00:00
}
}