made windows and the image buttons transparent, at last

fix for issue #793, see http://bugs.campware.org/view.php?id=793
This commit is contained in:
maroy 2005-04-13 14:47:55 +00:00
parent a7baf17231
commit 7cbec7fbf2
11 changed files with 274 additions and 30 deletions

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/BlueBin.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/BlueBin.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -44,6 +44,7 @@
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Widgets/CornerImages.h" #include "LiveSupport/Widgets/CornerImages.h"
#include "LiveSupport/Widgets/CornerBitmaps.h"
#include "LiveSupport/Widgets/Colors.h" #include "LiveSupport/Widgets/Colors.h"
@ -63,12 +64,19 @@ using namespace LiveSupport::Core;
/** /**
* A container holding exactly one child, habing a light blue border to it. * A container holding exactly one child, habing a light blue border to it.
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.6 $ * @version $Revision: 1.7 $
*/ */
class BlueBin : public Gtk::Bin class BlueBin : public Gtk::Bin
{ {
private: private:
/**
* Flag to indicate if the bin should try to make its border
* transparent (only where the border images are transparent,
* of course).
*/
bool transparentBorder;
/** /**
* The Gdk::Window object, used to draw inside this button. * The Gdk::Window object, used to draw inside this button.
*/ */
@ -94,6 +102,11 @@ class BlueBin : public Gtk::Bin
*/ */
Ptr<CornerImages>::Ref cornerImages; Ptr<CornerImages>::Ref cornerImages;
/**
* The corner bitmaps, for masking for transparency.
*/
Ptr<CornerBitmaps>::Ref cornerBitmaps;
/** /**
* Default constructor. * Default constructor.
*/ */
@ -221,9 +234,13 @@ class BlueBin : public Gtk::Bin
* *
* @param backgroundColor the RGB value for the background color. * @param backgroundColor the RGB value for the background color.
* @param cornerImages the corner images. * @param cornerImages the corner images.
* @param transparentBorder flag to indicate if the widget should
* make its border transparent, where the border images
* are transparent themselves
*/ */
BlueBin(Colors::ColorName backgroundColor, BlueBin(Colors::ColorName backgroundColor,
Ptr<CornerImages>::Ref cornerImages) Ptr<CornerImages>::Ref cornerImages,
bool transparentBorder = false)
throw (); throw ();
/** /**

View file

@ -0,0 +1,138 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/CornerBitmaps.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Widgets_CornerBitmaps_h
#define LiveSupport_Widgets_CornerBitmaps_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "gdkmm/bitmap.h"
namespace LiveSupport {
namespace Widgets {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A helper class to hold a set of corner bitmaps.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class CornerBitmaps
{
public:
/**
* The top left image.
*/
Glib::RefPtr<Gdk::Bitmap> topLeftBitmap;
/**
* The top right image.
*/
Glib::RefPtr<Gdk::Bitmap> topRightBitmap;
/**
* The bottom left image.
*/
Glib::RefPtr<Gdk::Bitmap> bottomLeftBitmap;
/**
* The bottom right image.
*/
Glib::RefPtr<Gdk::Bitmap> bottomRightBitmap;
/**
* The default constructor.
*/
CornerBitmaps(void) throw ()
{
}
/**
* Constructor with image references.
* If any of the images is not available, the result is undefined.
*
* @param topLeftBitmap the top left bitmap of the border
* @param topRightBitmap the top right bitmap of the border
* @param bottomLeftBitmap the bottom left bitmap of the border
* @param bottomRightBitmap the bottom right bitmap of the border
*/
CornerBitmaps(Glib::RefPtr<Gdk::Bitmap> topLeftBitmap,
Glib::RefPtr<Gdk::Bitmap> topRightBitmap,
Glib::RefPtr<Gdk::Bitmap> bottomLeftBitmap,
Glib::RefPtr<Gdk::Bitmap> bottomRightBitmap)
throw ()
{
this->topLeftBitmap = topLeftBitmap;
this->topRightBitmap = topRightBitmap;
this->bottomLeftBitmap = bottomLeftBitmap;
this->bottomRightBitmap = bottomRightBitmap;
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~CornerBitmaps(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Widgets
} // namespace LiveSupport
#endif // LiveSupport_Widgets_CornerBitmaps_h

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.1 $ Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ImageButton.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ImageButton.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -60,7 +60,7 @@ namespace Widgets {
* to represent it. * to represent it.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.1 $ * @version $Revision: 1.2 $
*/ */
class ImageButton : public Gtk::Button class ImageButton : public Gtk::Button
{ {
@ -95,6 +95,16 @@ class ImageButton : public Gtk::Button
*/ */
Glib::RefPtr<Gdk::Pixbuf> rollImage; Glib::RefPtr<Gdk::Pixbuf> rollImage;
/**
* The transparency mask for the button, in passive state.
*/
Glib::RefPtr<Gdk::Bitmap> passiveMask;
/**
* The transparency mask for the button, in rollover state.
*/
Glib::RefPtr<Gdk::Bitmap> rollMask;
/** /**
* Default constructor. * Default constructor.
*/ */

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -86,8 +86,8 @@ using namespace LiveSupport::Core;
* <!ATTLIST widgetFactory path CDATA #REQUIRED > * <!ATTLIST widgetFactory path CDATA #REQUIRED >
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.11 $ * @version $Revision: 1.12 $
*/ */
class WidgetFactory : class WidgetFactory :
virtual public Configurable virtual public Configurable
@ -102,7 +102,8 @@ class WidgetFactory :
* The types of available image buttons. * The types of available image buttons.
*/ */
typedef enum { deleteButton, typedef enum { deleteButton,
smallPlayButton, smallPauseButton, smallStopButton } smallPlayButton, smallPauseButton, smallStopButton,
hugePlayButton }
ImageButtonType; ImageButtonType;
/** /**

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/BlueBin.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/BlueBin.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -55,16 +55,31 @@ using namespace LiveSupport::Widgets;
* Constructor. * Constructor.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
BlueBin :: BlueBin(Colors::ColorName backgroundColor, BlueBin :: BlueBin(Colors::ColorName backgroundColor,
Ptr<CornerImages>::Ref cornerImages) Ptr<CornerImages>::Ref cornerImages,
bool transparentBorder)
throw () throw ()
{ {
set_flags(Gtk::NO_WINDOW); set_flags(Gtk::NO_WINDOW);
this->cornerImages = cornerImages; this->cornerImages = cornerImages;
this->transparentBorder = transparentBorder;
child = 0; child = 0;
bgColor = Colors::getColor(backgroundColor); bgColor = Colors::getColor(backgroundColor);
// generate the transparency mask bitmaps for the corners.
cornerBitmaps.reset(new CornerBitmaps());
Glib::RefPtr<Gdk::Pixmap> pixmap;
cornerImages->topLeftImage->render_pixmap_and_mask(pixmap,
cornerBitmaps->topLeftBitmap, 100);
cornerImages->topRightImage->render_pixmap_and_mask(pixmap,
cornerBitmaps->topRightBitmap, 100);
cornerImages->bottomLeftImage->render_pixmap_and_mask(pixmap,
cornerBitmaps->bottomLeftBitmap, 100);
cornerImages->bottomRightImage->render_pixmap_and_mask(pixmap,
cornerBitmaps->bottomRightBitmap, 100);
} }
@ -225,12 +240,11 @@ BlueBin :: on_realize() throw ()
if (!gdkWindow) { if (!gdkWindow) {
// create the Gdk::Window, if it didn't exist before // create the Gdk::Window, if it didn't exist before
Gtk::Allocation allocation = get_allocation();
GdkWindowAttr attributes; GdkWindowAttr attributes;
memset(&attributes, 0, sizeof(attributes)); memset(&attributes, 0, sizeof(attributes));
Gtk::Allocation allocation = get_allocation();
// set initial position and size of the Gdk::Window // set initial position and size of the Gdk::Window
attributes.x = allocation.get_x(); attributes.x = allocation.get_x();
attributes.y = allocation.get_y(); attributes.y = allocation.get_y();
@ -282,11 +296,43 @@ BlueBin :: on_expose_event(GdkEventExpose* event) throw ()
return false; return false;
} }
int width = get_width();
int height = get_height();
if (transparentBorder) {
unsigned int bitmapSize = 1 + (width * height);
char * bitmapData = new char[bitmapSize];
memset(bitmapData, 0xff, bitmapSize);
Glib::RefPtr<Gdk::Bitmap> mask = Gdk::Bitmap::create(bitmapData,
width,
height);
delete[] bitmapData;
Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(mask);
Glib::RefPtr<Gdk::Bitmap> borderMask;
mask->draw_drawable(gc, cornerBitmaps->topLeftBitmap, 0, 0, 0, 0);
mask->draw_drawable(gc, cornerBitmaps->topRightBitmap, 0, 0,
width - cornerImages->topRightImage->get_width(),
0);
mask->draw_drawable(gc, cornerBitmaps->bottomLeftBitmap, 0, 0,
0,
height - cornerImages->bottomLeftImage->get_height());
mask->draw_drawable(gc, cornerBitmaps->bottomRightBitmap, 0, 0,
width - cornerImages->bottomRightImage->get_width(),
height - cornerImages->bottomRightImage->get_height());
get_parent_window()->shape_combine_mask(mask, 0, 0);
}
if (gdkWindow) { if (gdkWindow) {
gdkWindow->clear(); gdkWindow->clear();
int width = get_width();
int height = get_height();
int x; int x;
int maxX; int maxX;
int y; int y;

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ImageButton.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ImageButton.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -61,6 +61,10 @@ ImageButton :: ImageButton(Glib::RefPtr<Gdk::Pixbuf> image)
state = passiveState; state = passiveState;
this->passiveImage = image; this->passiveImage = image;
this->rollImage.clear(); this->rollImage.clear();
// read the mask from a transparent PNG, and set it to this widget
Glib::RefPtr<Gdk::Pixmap> pixmap;
passiveImage->render_pixmap_and_mask(pixmap, passiveMask, 100);
} }
@ -76,6 +80,11 @@ ImageButton :: ImageButton(Glib::RefPtr<Gdk::Pixbuf> passiveImage,
state = passiveState; state = passiveState;
this->passiveImage = passiveImage; this->passiveImage = passiveImage;
this->rollImage = rollImage; this->rollImage = rollImage;
// read the mask from a transparent PNG, and set it to this widget
Glib::RefPtr<Gdk::Pixmap> pixmap;
passiveImage->render_pixmap_and_mask(pixmap, passiveMask, 100);
rollImage->render_pixmap_and_mask(pixmap, rollMask, 100);
} }
@ -260,18 +269,24 @@ ImageButton :: on_expose_event(GdkEventExpose* event) throw ()
gdkWindow->clear(); gdkWindow->clear();
Glib::RefPtr<Gdk::Pixbuf> image; Glib::RefPtr<Gdk::Pixbuf> image;
Glib::RefPtr<Gdk::Bitmap> mask;
switch (state) { switch (state) {
case passiveState: case passiveState:
default: default:
image = passiveImage; image = passiveImage;
mask = passiveMask;
break; break;
case rollState: case rollState:
image = rollImage ? rollImage : passiveImage; image = rollImage ? rollImage : passiveImage;
mask = rollMask ? rollMask : passiveMask;
break; break;
} }
// set the transparency mask
get_window()->shape_combine_mask(mask, 0, 0);
// just draw the button image at the centre of the available space // just draw the button image at the centre of the available space
int x = (get_width() - image->get_width()) / 2; int x = (get_width() - image->get_width()) / 2;
int y = (get_height() - image->get_height()) / 2; int y = (get_height() - image->get_height()) / 2;

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.13 $ Version : $Revision: 1.14 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -66,7 +66,7 @@ TestWindow :: TestWindow (void)
// init the imageButton // init the imageButton
imageButton = Gtk::manage( imageButton = Gtk::manage(
widgetFactory->createButton(WidgetFactory::deleteButton)); widgetFactory->createButton(WidgetFactory::hugePlayButton));
// create a button // create a button
button = Gtk::manage(widgetFactory->createButton("Hello, World!")); button = Gtk::manage(widgetFactory->createButton("Hello, World!"));

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WhiteWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WhiteWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -146,7 +146,7 @@ WhiteWindow :: constructWindow(Colors::ColorName backgroundColor,
} }
// add the corners // add the corners
blueBin = Gtk::manage(new BlueBin(backgroundColor, cornerImages)); blueBin = Gtk::manage(new BlueBin(backgroundColor, cornerImages, true));
blueBin->add(*layout); blueBin->add(*layout);
Gtk::Window::add(*blueBin); Gtk::Window::add(*blueBin);

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.13 $ Version : $Revision: 1.14 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WidgetFactory.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WidgetFactory.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -138,6 +138,18 @@ static const std::string smallStopButtonPassiveName
static const std::string smallStopButtonRollName static const std::string smallStopButtonRollName
= "imageButton/smallStopRoll.png"; = "imageButton/smallStopRoll.png";
/**
* The name of the passive image for the huge play button.
*/
static const std::string hugePlayButtonPassiveName
= "imageButton/hugePlay.png";
/**
* The name of the rollover image for the huge play button.
*/
static const std::string hugePlayButtonRollName
= "imageButton/hugePlayRoll.png";
/** /**
* The name of the combo box left image. * The name of the combo box left image.
*/ */
@ -333,6 +345,11 @@ WidgetFactory :: createButton(ImageButtonType type) throw ()
rollImage = loadImage(smallStopButtonRollName); rollImage = loadImage(smallStopButtonRollName);
break; break;
case hugePlayButton:
passiveImage = loadImage(hugePlayButtonPassiveName);
rollImage = loadImage(hugePlayButtonRollName);
break;
default: default:
return 0; return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB