draw only when needed

This commit is contained in:
Dana Jansens 2002-12-27 16:29:32 +00:00
parent 5fdd493d0d
commit d222c56543
2 changed files with 66 additions and 59 deletions

View file

@ -81,49 +81,52 @@ void OBButtonWidget::update()
{ {
otk::PixmapMask *pm; otk::PixmapMask *pm;
int width; int width;
bool draw = _dirty;
otk::OtkWidget::update(); otk::OtkWidget::update();
switch (type()) { if (draw) {
case Type_StickyButton: switch (type()) {
pm = _style->getStickyButtonMask(); case Type_StickyButton:
break; pm = _style->getStickyButtonMask();
case Type_CloseButton: break;
pm = _style->getCloseButtonMask(); case Type_CloseButton:
break; pm = _style->getCloseButtonMask();
case Type_MaximizeButton: break;
pm = _style->getMaximizeButtonMask(); case Type_MaximizeButton:
break; pm = _style->getMaximizeButtonMask();
case Type_IconifyButton: break;
pm = _style->getIconifyButtonMask(); case Type_IconifyButton:
break; pm = _style->getIconifyButtonMask();
case Type_LeftGrip: break;
case Type_RightGrip: case Type_LeftGrip:
return; // no drawing case Type_RightGrip:
default: return; // no drawing
assert(false); // there's no other button widgets! default:
} assert(false); // there's no other button widgets!
}
if (pm->mask == None) return; // no mask for the button, leave it empty if (pm->mask == None) return; // no mask for the button, leave it empty
width = _rect.width(); width = _rect.width();
otk::BPen pen(_focused ? *_style->getButtonPicFocus() : otk::BPen pen(_focused ? *_style->getButtonPicFocus() :
*_style->getButtonPicUnfocus()); *_style->getButtonPicUnfocus());
// set the clip region // set the clip region
XSetClipMask(otk::OBDisplay::display, pen.gc(), pm->mask); XSetClipMask(otk::OBDisplay::display, pen.gc(), pm->mask);
XSetClipOrigin(otk::OBDisplay::display, pen.gc(), XSetClipOrigin(otk::OBDisplay::display, pen.gc(),
(width - pm->w)/2, (width - pm->h)/2); (width - pm->w)/2, (width - pm->h)/2);
// fill in the clipped region // fill in the clipped region
XFillRectangle(otk::OBDisplay::display, _window, pen.gc(), XFillRectangle(otk::OBDisplay::display, _window, pen.gc(),
(width - pm->w)/2, (width - pm->h)/2, (width - pm->w)/2, (width - pm->h)/2,
(width + pm->w)/2, (width + pm->h)/2); (width + pm->w)/2, (width + pm->h)/2);
// unset the clip region // unset the clip region
XSetClipMask(otk::OBDisplay::display, pen.gc(), None); XSetClipMask(otk::OBDisplay::display, pen.gc(), None);
XSetClipOrigin(otk::OBDisplay::display, pen.gc(), 0, 0); XSetClipOrigin(otk::OBDisplay::display, pen.gc(), 0, 0);
}
} }

View file

@ -72,38 +72,42 @@ void OBLabelWidget::unfocus()
void OBLabelWidget::update() void OBLabelWidget::update()
{ {
bool draw = _dirty;
OtkWidget::update(); OtkWidget::update();
std::string t = _text; if (draw) {
int x = _sidemargin; // x coord for the text std::string t = _text;
int x = _sidemargin; // x coord for the text
// find a string that will fit inside the area for text // find a string that will fit inside the area for text
int max_length = width() - _sidemargin * 2; int max_length = width() - _sidemargin * 2;
if (max_length <= 0) { if (max_length <= 0) {
t = ""; // can't fit anything t = ""; // can't fit anything
} else { } else {
size_t text_len = t.size(); size_t text_len = t.size();
int length; int length;
do { do {
t.resize(text_len); t.resize(text_len);
length = _font->measureString(t); length = _font->measureString(t);
} while (length > max_length && text_len-- > 0); } while (length > max_length && text_len-- > 0);
// justify the text // justify the text
switch (_justify) { switch (_justify) {
case otk::Style::RightJustify: case otk::Style::RightJustify:
x += max_length - length; x += max_length - length;
break; break;
case otk::Style::CenterJustify: case otk::Style::CenterJustify:
x += (max_length - length) / 2; x += (max_length - length) / 2;
break; break;
case otk::Style::LeftJustify: case otk::Style::LeftJustify:
break; break;
}
} }
}
_font->drawString(_xftdraw, x, 0, *_text_color, t); _font->drawString(_xftdraw, x, 0, *_text_color, t);
}
} }