+static void renderButton(int screen, bool focus, bool press, Window win,
+ otk::Surface **sur, int butsize,
+ const otk::PixmapMask *mask)
+{
+ const otk::RenderStyle *style = otk::RenderStyle::style(screen);
+ const otk::RenderControl *control = otk::display->renderControl(screen);
+ otk::Surface *s = new otk::Surface(screen, otk::Size(butsize, butsize));
+
+ const otk::RenderTexture *tx = (focus ?
+ (press ?
+ style->buttonPressFocusBackground() :
+ style->buttonUnpressFocusBackground()) :
+ (press ?
+ style->buttonPressUnfocusBackground() :
+ style->buttonUnpressUnfocusBackground()));
+ const otk::RenderColor *maskcolor = (focus ?
+ style->buttonFocusColor() :
+ style->buttonUnfocusColor());
+ control->drawBackground(*s, *tx);
+ control->drawMask(*s, *maskcolor, *mask);
+
+ XSetWindowBackgroundPixmap(**otk::display, win, s->pixmap());
+ XClearWindow(**otk::display, win);
+ if (*sur) delete *sur;
+ s->freePixelData();
+ *sur = s;
+}
+
+void Frame::renderMax()
+{
+ if (!(_decorations & Client::Decor_Maximize)) return;
+ bool press = _max_press || _client->maxVert() || _client->maxHorz();
+ renderButton(_client->screen(), _client->focused(), press, _max,
+ &_max_sur, geom.button_size,
+ otk::RenderStyle::style(_client->screen())->maximizeMask());
+}
+
+void Frame::renderDesk()
+{
+ if (!(_decorations & Client::Decor_AllDesktops)) return;
+ bool press = _desk_press || _client->desktop() == 0xffffffff;
+ renderButton(_client->screen(), _client->focused(), press, _desk,
+ &_desk_sur, geom.button_size,
+ otk::RenderStyle::style(_client->screen())->alldesktopsMask());
+}
+
+void Frame::renderIconify()
+{
+ if (!(_decorations & Client::Decor_Iconify)) return;
+ renderButton(_client->screen(), _client->focused(), _iconify_press, _iconify,
+ &_iconify_sur, geom.button_size,
+ otk::RenderStyle::style(_client->screen())->iconifyMask());
+}
+
+void Frame::renderClose()
+{
+ if (!(_decorations & Client::Decor_Close)) return;
+ renderButton(_client->screen(), _client->focused(), _close_press, _close,
+ &_close_sur, geom.button_size,
+ otk::RenderStyle::style(_client->screen())->closeMask());
+}
+
+void Frame::renderIcon()
+{
+ if (!(_decorations & Client::Decor_Icon)) return;
+ const int screen = _client->screen();
+ const otk::RenderControl *control = otk::display->renderControl(screen);
+
+ otk::Surface *s = new otk::Surface(screen, otk::Size(geom.button_size,
+ geom.button_size));
+ otk::pixel32 *dest = s->pixelData(), *src;
+ int w = _title_sur->size().width();
+
+ src = _title_sur->pixelData() + w * (geom.bevel + 1) + geom.icon_x;
+
+ // get the background under the icon button
+ for (int y = 0; y < geom.button_size; ++y, src += w - geom.button_size)
+ for (int x = 0; x < geom.button_size; ++x, ++dest, ++src)
+ *dest = *src;
+ // draw the icon over it
+ const Icon *icon = _client->icon(otk::Size(geom.button_size,
+ geom.button_size));
+ control->drawImage(*s, icon->w, icon->h, icon->data);
+
+ XSetWindowBackgroundPixmap(**otk::display, _icon, s->pixmap());
+ XClearWindow(**otk::display, _icon);
+ if (_icon_sur) delete _icon_sur;
+ _icon_sur = s;
+}
+