X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Flabelwidget.cc;h=020e8b73ca50d3e6acaef7ea9f0166a27d021a76;hb=d22a6c6c04cf20bd23efa68ad1202f278f25e113;hp=9b18c0a97ec1c55499f39f4ef2cc4eb943a8a99f;hpb=83727b8e6404f7e00e7369c39da8779dfb85ae09;p=chaz%2Fopenbox diff --git a/src/labelwidget.cc b/src/labelwidget.cc index 9b18c0a9..020e8b73 100644 --- a/src/labelwidget.cc +++ b/src/labelwidget.cc @@ -4,37 +4,114 @@ # include "../config.h" #endif +#include "otk/screeninfo.hh" +#include "otk/display.hh" #include "labelwidget.hh" namespace ob { -OBLabelWidget::OBLabelWidget(otk::OtkWidget *parent, OBWidget::WidgetType type) - : otk::OtkFocusLabel(parent), - OBWidget(type) +LabelWidget::LabelWidget(otk::Widget *parent, WidgetBase::WidgetType type) + : otk::Widget(parent), + WidgetBase(type) { } -OBLabelWidget::~OBLabelWidget() +LabelWidget::~LabelWidget() { } -void OBLabelWidget::setStyle(otk::Style *style) +void LabelWidget::setText(const otk::ustring &text) { - setTexture(style->getLabelFocus()); - setUnfocusTexture(style->getLabelUnfocus()); + _text = text; + _dirty = true; +} + + +void LabelWidget::setTextures() +{ + if (_focused) { + setTexture(_style->labelFocusBackground()); + _text_color = _style->textFocusColor(); + } else { + setTexture(_style->labelUnfocusBackground()); + _text_color = _style->textUnfocusColor(); + } +} + - otk::OtkFocusLabel::setStyle(style); +void LabelWidget::setStyle(otk::RenderStyle *style) +{ + otk::Widget::setStyle(style); + setTextures(); + _font = style->labelFont(); + _sidemargin = style->bevelWidth() * 2; + _justify = style->labelTextJustify(); + + assert(_font); } -void OBLabelWidget::adjust() +void LabelWidget::focus() { - otk::OtkFocusLabel::adjust(); + otk::Widget::focus(); + setTextures(); +} - // XXX: adjust shit + +void LabelWidget::unfocus() +{ + otk::Widget::unfocus(); + setTextures(); } +void LabelWidget::renderForeground() +{ + bool draw = _dirty; + + otk::Widget::renderForeground(); + + if (draw) { + otk::ustring t = _text; + 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 = _font->measureString(t); + } while (length > max_length && text_len-- > 0); + + // justify the text + switch (_justify) { + case otk::RenderStyle::RightJustify: + x += max_length - length; + break; + case otk::RenderStyle::CenterJustify: + x += (max_length - length) / 2; + break; + case otk::RenderStyle::LeftJustify: + break; + } + } + + otk::display->renderControl(_screen)->drawString + (*_surface, *_font, x, 0, *_text_color, t); + } +} + + +void LabelWidget::adjust() +{ + // nothing to adjust. no children. +} + }