From c8f9cf1177b6de1cc210f0706dae302b9aa4f7b5 Mon Sep 17 00:00:00 2001 From: akir Date: Fri, 10 Sep 2004 16:48:15 +0000 Subject: cosmetic + avoid unneeded App::instance()->display() calls --- src/FbTk/MenuItem.cc | 61 +++++++++++++++++++------------------------------ src/FbTk/Transparent.cc | 46 ++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 60 deletions(-) diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc index ee997bb..69a2000 100644 --- a/src/FbTk/MenuItem.cc +++ b/src/FbTk/MenuItem.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: MenuItem.cc,v 1.8 2004/09/01 08:00:24 akir Exp $ +// $Id: MenuItem.cc,v 1.9 2004/09/10 16:48:15 akir Exp $ #include "MenuItem.hh" #include "Command.hh" @@ -37,11 +37,13 @@ void MenuItem::click(int button, int time) { m_command->execute(); } -void MenuItem::draw(FbDrawable &draw, +void MenuItem::draw(FbDrawable &draw, const MenuTheme &theme, bool highlight, - int x, int y, + int x, int y, unsigned int width, unsigned int height) const { + + Display *disp = App::instance()->display(); // // Icon // @@ -58,11 +60,8 @@ void MenuItem::draw(FbDrawable &draw, int icon_x = x + theme.bevelWidth(); int icon_y = y + theme.bevelWidth(); // enable clip mask - XSetClipMask(FbTk::App::instance()->display(), - gc, - m_icon->pixmap->mask().drawable()); - XSetClipOrigin(FbTk::App::instance()->display(), - gc, icon_x, icon_y); + XSetClipMask(disp, gc, m_icon->pixmap->mask().drawable()); + XSetClipOrigin(disp, gc, icon_x, icon_y); draw.copyArea(m_icon->pixmap->pixmap().drawable(), gc, @@ -71,9 +70,7 @@ void MenuItem::draw(FbDrawable &draw, m_icon->pixmap->width(), m_icon->pixmap->height()); // restore clip mask - XSetClipMask(FbTk::App::instance()->display(), - gc, - None); + XSetClipMask(disp, gc, None); } } @@ -90,7 +87,7 @@ void MenuItem::draw(FbDrawable &draw, int text_y = y, text_x = x; int text_w = theme.frameFont().textWidth(label().c_str(), label().size()); - + int height_offset = theme.itemHeight() - (theme.frameFont().height() + 2*theme.bevelWidth()); text_y = y + theme.bevelWidth() + theme.frameFont().ascent() + height_offset/2; ///2 + height/2; @@ -98,15 +95,15 @@ void MenuItem::draw(FbDrawable &draw, case FbTk::LEFT: text_x = x + theme.bevelWidth() + height + 1; break; - + case FbTk::RIGHT: text_x = x + width - (height + theme.bevelWidth() + text_w); - break; + break; default: //center text_x = x + ((width + 1 - text_w) / 2); break; } - + theme.frameFont().drawText(draw.drawable(), // drawable theme.screenNum(), tgc.gc(), @@ -127,11 +124,8 @@ void MenuItem::draw(FbDrawable &draw, // ToggleItem // if (isToggleItem() && theme.unselectedPixmap().pixmap().drawable() != 0) { - XSetClipMask(FbTk::App::instance()->display(), - gc, - theme.unselectedPixmap().mask().drawable()); - XSetClipOrigin(FbTk::App::instance()->display(), - gc, sel_x, y); + XSetClipMask(disp, gc, theme.unselectedPixmap().mask().drawable()); + XSetClipOrigin(disp, gc, sel_x, y); // copy bullet pixmap to drawable draw.copyArea(theme.unselectedPixmap().pixmap().drawable(), gc, @@ -140,22 +134,17 @@ void MenuItem::draw(FbDrawable &draw, theme.unselectedPixmap().width(), theme.unselectedPixmap().height()); // disable clip mask - XSetClipMask(FbTk::App::instance()->display(), - gc, - None); + XSetClipMask(disp, gc, None); } - // + // // Submenu // if (submenu()) { if (theme.bulletPixmap().pixmap().drawable() != 0) { // enable clip mask - XSetClipMask(FbTk::App::instance()->display(), - gc, - theme.bulletPixmap().mask().drawable()); - XSetClipOrigin(FbTk::App::instance()->display(), - gc, sel_x, y); + XSetClipMask(disp, gc, theme.bulletPixmap().mask().drawable()); + XSetClipOrigin(disp, gc, sel_x, y); // copy bullet pixmap to frame draw.copyArea(theme.bulletPixmap().pixmap().drawable(), gc, @@ -164,9 +153,7 @@ void MenuItem::draw(FbDrawable &draw, theme.bulletPixmap().width(), theme.bulletPixmap().height()); // disable clip mask - XSetClipMask(FbTk::App::instance()->display(), - gc, - None); + XSetClipMask(disp, gc, None); } else { unsigned int half_w = height / 2, quarter_w = height / 4; int sel_y = y + height/4; @@ -193,11 +180,11 @@ void MenuItem::draw(FbDrawable &draw, tri[2].x = 0; tri[2].y = -4; } - + draw.fillPolygon(gc, tri, 3, Convex, CoordModePrevious); break; - + case MenuTheme::DIAMOND: XPoint dia[4]; @@ -233,7 +220,7 @@ void MenuItem::setIcon(const std::string &filename, int screen_num) { m_icon.reset(new Icon); m_icon->filename = FbTk::StringUtil::expandFilename(filename); - m_icon->pixmap.reset(Image::load(m_icon->filename.c_str(), + m_icon->pixmap.reset(Image::load(m_icon->filename.c_str(), screen_num)); } @@ -245,8 +232,8 @@ unsigned int MenuItem::width(const MenuTheme &theme) const { // textwidth + bevel width on each side of the text const unsigned int icon_width = height(theme); const unsigned int normal = theme.frameFont().textWidth(label().c_str(), label().size()) + - 2 * (theme.bevelWidth() + icon_width); - + 2 * (theme.bevelWidth() + icon_width); + return m_icon.get() == 0 ? normal : normal + icon_width; } diff --git a/src/FbTk/Transparent.cc b/src/FbTk/Transparent.cc index ab6b4d9..9cc377e 100644 --- a/src/FbTk/Transparent.cc +++ b/src/FbTk/Transparent.cc @@ -1,6 +1,6 @@ // Transparent.cc for FbTk - Fluxbox Toolkit // Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) -// +// // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Transparent.cc,v 1.6 2004/06/07 11:46:05 rathnor Exp $ +// $Id: Transparent.cc,v 1.7 2004/09/10 16:48:15 akir Exp $ #include "Transparent.hh" #include "App.hh" @@ -47,7 +47,7 @@ Picture createAlphaPic(Window drawable, unsigned char alpha) { XRenderPictFormat pic_format; pic_format.type = PictTypeDirect; pic_format.depth = 8; // alpha with bit depth 8 - pic_format.direct.alphaMask = 0xff; + pic_format.direct.alphaMask = 0xff; XRenderPictFormat *format = XRenderFindFormat(disp, PictFormatType | PictFormatDepth | PictFormatAlphaMask, &pic_format, 0); @@ -109,8 +109,8 @@ Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int s // check for RENDER support if (!s_init) { int major_opcode, first_event, first_error; - if (XQueryExtension(disp, "RENDER", - &major_opcode, + if (XQueryExtension(disp, "RENDER", + &major_opcode, &first_event, &first_error) == False) { s_render = false; } else { // we got RENDER support @@ -119,7 +119,7 @@ Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int s s_init = true; } - + #ifdef HAVE_XRENDER if (!s_render) return; @@ -127,13 +127,13 @@ Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int s allocAlpha(m_alpha); - XRenderPictFormat *format = - XRenderFindVisualFormat(disp, + XRenderPictFormat *format = + XRenderFindVisualFormat(disp, DefaultVisual(disp, screen_num)); if (src != 0 && format != 0) { - m_src_pic = XRenderCreatePicture(disp, src, format, + m_src_pic = XRenderCreatePicture(disp, src, format, 0, 0); } @@ -181,8 +181,8 @@ void Transparent::setDest(Drawable dest, int screen_num) { // create new dest pic if we have a valid dest drawable if (dest != 0) { - XRenderPictFormat *format = - XRenderFindVisualFormat(disp, + XRenderPictFormat *format = + XRenderFindVisualFormat(disp, DefaultVisual(disp, screen_num)); if (format == 0) { _FB_USES_NLS; @@ -191,7 +191,7 @@ void Transparent::setDest(Drawable dest, int screen_num) { cerr<display(); + Display *disp = FbTk::App::instance()->display(); if (m_src_pic != 0) { XRenderFreePicture(disp, m_src_pic); @@ -220,8 +220,8 @@ void Transparent::setSource(Drawable source, int screen_num) { // create new source pic if we have a valid source drawable if (m_source != 0) { - XRenderPictFormat *format = - XRenderFindVisualFormat(disp, + XRenderPictFormat *format = + XRenderFindVisualFormat(disp, DefaultVisual(disp, screen_num)); if (format == 0) { _FB_USES_NLS; @@ -229,8 +229,8 @@ void Transparent::setSource(Drawable source, int screen_num) { fprintf(stderr, _FBTKTEXT(Error, NoRenderVisualFormat, "Failed to find format for screen(%d)", "XRenderFindVisualFormat failed... include %d for screen number"), screen_num); cerr<display(), - PictOpOver, + XRenderComposite(FbTk::App::instance()->display(), + PictOpOver, m_src_pic, - m_alpha_pic, - m_dest_pic, + m_alpha_pic, + m_dest_pic, src_x, src_y, - 0, 0, + 0, 0, dest_x, dest_y, width, height); @@ -284,4 +284,4 @@ void Transparent::freeAlpha() { }; // end namespace FbTk - + -- cgit v0.11.2