X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Flabelwidget.cc;h=d76bd3f13f522046659adac6ef7e4855625ee2af;hb=53001eebae2c5623cce6b865e616c66e8b998dbd;hp=491deadccdf75120f0c938b664acb3b7f4e1d94a;hpb=5fdd493d0d2255f134114e69f028371366f4dfd3;p=chaz%2Fopenbox diff --git a/src/labelwidget.cc b/src/labelwidget.cc index 491deadc..d76bd3f1 100644 --- a/src/labelwidget.cc +++ b/src/labelwidget.cc @@ -10,30 +10,30 @@ namespace ob { -OBLabelWidget::OBLabelWidget(otk::OtkWidget *parent, OBWidget::WidgetType type) - : otk::OtkWidget(parent), - OBWidget(type) +LabelWidget::LabelWidget(otk::Widget *parent, WidgetBase::WidgetType type) + : otk::Widget(parent), + WidgetBase(type) { - const otk::ScreenInfo *info = otk::OBDisplay::screenInfo(_screen); - _xftdraw = XftDrawCreate(otk::OBDisplay::display, _window, info->visual(), + const otk::ScreenInfo *info = otk::display->screenInfo(_screen); + _xftdraw = XftDrawCreate(**otk::display, _window, info->visual(), info->colormap()); } -OBLabelWidget::~OBLabelWidget() +LabelWidget::~LabelWidget() { XftDrawDestroy(_xftdraw); } -void OBLabelWidget::setText(const std::string &text) +void LabelWidget::setText(const otk::ustring &text) { _text = text; _dirty = true; } -void OBLabelWidget::setTextures() +void LabelWidget::setTextures() { if (_focused) { setTexture(_style->getLabelFocus()); @@ -45,9 +45,9 @@ void OBLabelWidget::setTextures() } -void OBLabelWidget::setStyle(otk::Style *style) +void LabelWidget::setStyle(otk::Style *style) { - OtkWidget::setStyle(style); + otk::Widget::setStyle(style); setTextures(); _font = style->getFont(); assert(_font); @@ -56,60 +56,64 @@ void OBLabelWidget::setStyle(otk::Style *style) } -void OBLabelWidget::focus() +void LabelWidget::focus() { - otk::OtkWidget::focus(); + otk::Widget::focus(); setTextures(); } -void OBLabelWidget::unfocus() +void LabelWidget::unfocus() { - otk::OtkWidget::unfocus(); + otk::Widget::unfocus(); setTextures(); } -void OBLabelWidget::update() +void LabelWidget::update() { - OtkWidget::update(); + bool draw = _dirty; - std::string t = _text; - int x = _sidemargin; // x coord for the text + otk::Widget::update(); - // 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; + 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::Style::RightJustify: - x += max_length - length; - break; - case otk::Style::CenterJustify: - x += (max_length - length) / 2; - break; - case otk::Style::LeftJustify: - break; + do { + t.resize(text_len); + length = _font->measureString(t); + } while (length > max_length && text_len-- > 0); + + // justify the text + switch (_justify) { + case otk::Style::RightJustify: + x += max_length - length; + break; + case otk::Style::CenterJustify: + x += (max_length - length) / 2; + break; + case otk::Style::LeftJustify: + break; + } } - } - _font->drawString(_xftdraw, x, 0, *_text_color, t); + _font->drawString(_xftdraw, x, 0, *_text_color, t); + } } -void OBLabelWidget::adjust() +void LabelWidget::adjust() { - // XXX: adjust shit + // nothing to adjust. no children. } }