summaryrefslogtreecommitdiff
path: root/src/labelwidget.cc
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2002-12-25 22:02:34 +0000
committerDana Jansens <danakj@orodu.net>2002-12-25 22:02:34 +0000
commit2ae2b257d39ea62640c2590f794e4275c6db1cd4 (patch)
treef26abe4a0601d263fbc460eddc012c1d674c868b /src/labelwidget.cc
parent3c61812e588fb3c34d0713d7f82ccbf21091f032 (diff)
might not compile... ob uses its own widgets now, which subclass only the base otk widget. working on compressing focus events and handling them etc.
Diffstat (limited to 'src/labelwidget.cc')
-rw-r--r--src/labelwidget.cc92
1 files changed, 85 insertions, 7 deletions
diff --git a/src/labelwidget.cc b/src/labelwidget.cc
index 9b18c0a9..5a33cf3d 100644
--- a/src/labelwidget.cc
+++ b/src/labelwidget.cc
@@ -4,37 +4,115 @@
# 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),
+ : otk::OtkWidget(parent),
OBWidget(type)
{
+ const otk::ScreenInfo *info = otk::OBDisplay::screenInfo(_screen);
+ _xftdraw = XftDrawCreate(otk::OBDisplay::display, _window, info->visual(),
+ info->colormap());
}
OBLabelWidget::~OBLabelWidget()
{
+ XftDrawDestroy(_xftdraw);
+}
+
+
+void OBLabelWidget::setText(const std::string &text)
+{
+ _text = text;
+ _dirty = true;
+}
+
+
+void OBLabelWidget::setTextures()
+{
+ if (_focused) {
+ setTexture(_style->getLabelFocus());
+ _text_color = _style->getTextFocus();
+ } else {
+ setTexture(_style->getLabelUnfocus());
+ _text_color = _style->getTextUnfocus();
+ }
}
void OBLabelWidget::setStyle(otk::Style *style)
{
- setTexture(style->getLabelFocus());
- setUnfocusTexture(style->getLabelUnfocus());
+ OtkWidget::setStyle(style);
+ setTextures();
+ _font = style->getFont();
+ assert(_font);
+ _sidemargin = style->getBevelWidth() * 2;
+ _justify = style->textJustify();
+}
+
- otk::OtkFocusLabel::setStyle(style);
+void OBLabelWidget::focus()
+{
+ otk::OtkWidget::focus();
+ setTextures();
}
-void OBLabelWidget::adjust()
+void OBLabelWidget::unfocus()
{
- otk::OtkFocusLabel::adjust();
+ otk::OtkWidget::unfocus();
+ setTextures();
+}
- // XXX: adjust shit
+
+void OBLabelWidget::update()
+{
+ if (_dirty) {
+ std::string 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;
+ }
+ }
+
+ OtkWidget::update();
+
+ _font->drawString(_xftdraw, x, 0, *_text_color, t);
+ } else
+ OtkWidget::update();
}
+void OBLabelWidget::adjust()
+{
+ // XXX: adjust shit
+}
+
}