X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=otk%2Flabel.cc;h=8757d8a9d08f18881285844ed51fe35e73a59a98;hb=3fe7bded58fb82fd2c1c2a5f9ad2e8f453fa0609;hp=40a85bb39ca922e0ea145b54c3ea3df591f53209;hpb=77342413efd183bd1c0681a57b68acc836022923;p=chaz%2Fopenbox diff --git a/otk/label.cc b/otk/label.cc index 40a85bb3..8757d8a9 100644 --- a/otk/label.cc +++ b/otk/label.cc @@ -1,57 +1,66 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + #include "label.hh" namespace otk { -OtkLabel::OtkLabel(OtkWidget *parent) - : OtkWidget(parent), _text("") +Label::Label(Widget *parent) + : Widget(parent), _text("") { - setTexture(getStyle()->getLabelUnfocus()); } -OtkLabel::~OtkLabel() +Label::~Label() { } -void OtkLabel::update(void) +void Label::setStyle(RenderStyle *style) { - if (_dirty) { - const BFont &ft = getStyle()->getFont(); - unsigned int bevel = getStyle()->getBevelWidth(); - - std::string t = _text; // the actual text to draw - int x = bevel; // x coord for the text - - // find a string that will fit inside the area for text - int max_length = width() - getBevelWidth() * 2; - if (max_length <= 0) { - t = ""; // can't fit anything - } else { - size_t text_len = t.size(); - int length; + Widget::setStyle(style); + + setTexture(style->labelUnfocusBackground()); +} + + +void Label::renderForeground(void) +{ + const Font *ft = style()->labelFont(); + unsigned int sidemargin = style()->bevelWidth() * 2; + + ustring t = _text; // the actual text to draw + int x = sidemargin; // x coord for the text + + // 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; - do { - t.resize(text_len); - length = ft.measureString(t); - } while (length > max_length && text_len-- > 0); - - // justify the text - switch (getStyle()->textJustify()) { - case Style::RightJustify: - x += max_length - length; - break; - case Style::CenterJustify: - x += (max_length - length) / 2; - break; - case Style::LeftJustify: - break; - } - } + do { + t.resize(text_len); + length = ft->measureString(t); + } while (length > max_length && text_len-- > 0); - OtkWidget::update(); + // justify the text + switch (style()->labelTextJustify()) { + case RenderStyle::RightJustify: + x += max_length - length; + break; + case RenderStyle::CenterJustify: + x += (max_length - length) / 2; + break; + case RenderStyle::LeftJustify: + break; + } + } - ft.drawString(getWindow(), x, bevel, *getStyle()->getTextUnfocus(), t); - } else - OtkWidget::update(); + display->renderControl(_screen)-> + drawString(*_surface, *ft, x, 0, *style()->textUnfocusColor(), t); } }