cosmetic + avoid unneeded App::instance()->display() calls
This commit is contained in:
parent
df0c942aa2
commit
c8f9cf1177
2 changed files with 47 additions and 60 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<<endl;
|
||||
}
|
||||
m_dest_pic = XRenderCreatePicture(disp, dest, format, 0, 0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
m_dest = dest;
|
||||
|
@ -208,7 +208,7 @@ void Transparent::setSource(Drawable source, int screen_num) {
|
|||
if (m_alpha_pic != 0)
|
||||
freeAlpha();
|
||||
|
||||
Display *disp = FbTk::App::instance()->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<<endl;
|
||||
}
|
||||
m_src_pic = XRenderCreatePicture(disp, m_source, format,
|
||||
0, 0);
|
||||
m_src_pic = XRenderCreatePicture(disp, m_source, format,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
// recreate new alpha
|
||||
|
@ -247,13 +247,13 @@ void Transparent::render(int src_x, int src_y,
|
|||
m_alpha_pic == 0 || !s_render)
|
||||
return;
|
||||
// render src+alpha to dest picture
|
||||
XRenderComposite(FbTk::App::instance()->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
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue