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
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Author : $Author: maroy $
Version : $Revision: 1.7 $
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/Widgets/CornerImages.h"
#include "LiveSupport/Widgets/CornerBitmaps.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.
*
* @author $Author: fgerlits $
* @version $Revision: 1.6 $
* @author $Author: maroy $
* @version $Revision: 1.7 $
*/
class BlueBin : public Gtk::Bin
{
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.
*/
@ -94,6 +102,11 @@ class BlueBin : public Gtk::Bin
*/
Ptr<CornerImages>::Ref cornerImages;
/**
* The corner bitmaps, for masking for transparency.
*/
Ptr<CornerBitmaps>::Ref cornerBitmaps;
/**
* Default constructor.
*/
@ -221,9 +234,13 @@ class BlueBin : public Gtk::Bin
*
* @param backgroundColor the RGB value for the background color.
* @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,
Ptr<CornerImages>::Ref cornerImages)
Ptr<CornerImages>::Ref cornerImages,
bool transparentBorder = false)
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 $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
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.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class ImageButton : public Gtk::Button
{
@ -95,6 +95,16 @@ class ImageButton : public Gtk::Button
*/
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.
*/

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.11 $
Author : $Author: maroy $
Version : $Revision: 1.12 $
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 >
* </code></pre>
*
* @author $Author: fgerlits $
* @version $Revision: 1.11 $
* @author $Author: maroy $
* @version $Revision: 1.12 $
*/
class WidgetFactory :
virtual public Configurable
@ -102,7 +102,8 @@ class WidgetFactory :
* The types of available image buttons.
*/
typedef enum { deleteButton,
smallPlayButton, smallPauseButton, smallStopButton }
smallPlayButton, smallPauseButton, smallStopButton,
hugePlayButton }
ImageButtonType;
/**

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.8 $
Author : $Author: maroy $
Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/BlueBin.cxx,v $
------------------------------------------------------------------------------*/
@ -55,16 +55,31 @@ using namespace LiveSupport::Widgets;
* Constructor.
*----------------------------------------------------------------------------*/
BlueBin :: BlueBin(Colors::ColorName backgroundColor,
Ptr<CornerImages>::Ref cornerImages)
Ptr<CornerImages>::Ref cornerImages,
bool transparentBorder)
throw ()
{
set_flags(Gtk::NO_WINDOW);
this->cornerImages = cornerImages;
this->cornerImages = cornerImages;
this->transparentBorder = transparentBorder;
child = 0;
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) {
// create the Gdk::Window, if it didn't exist before
Gtk::Allocation allocation = get_allocation();
GdkWindowAttr attributes;
memset(&attributes, 0, sizeof(attributes));
Gtk::Allocation allocation = get_allocation();
// set initial position and size of the Gdk::Window
attributes.x = allocation.get_x();
attributes.y = allocation.get_y();
@ -282,11 +296,43 @@ BlueBin :: on_expose_event(GdkEventExpose* event) throw ()
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) {
gdkWindow->clear();
int width = get_width();
int height = get_height();
int x;
int maxX;
int y;

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Author : $Author: maroy $
Version : $Revision: 1.6 $
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;
this->passiveImage = image;
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;
this->passiveImage = passiveImage;
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,17 +269,23 @@ ImageButton :: on_expose_event(GdkEventExpose* event) throw ()
gdkWindow->clear();
Glib::RefPtr<Gdk::Pixbuf> image;
Glib::RefPtr<Gdk::Bitmap> mask;
switch (state) {
case passiveState:
default:
image = passiveImage;
mask = passiveMask;
break;
case rollState:
image = rollImage ? rollImage : passiveImage;
mask = rollMask ? rollMask : passiveMask;
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
int x = (get_width() - image->get_width()) / 2;

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.13 $
Author : $Author: maroy $
Version : $Revision: 1.14 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $
------------------------------------------------------------------------------*/
@ -66,7 +66,7 @@ TestWindow :: TestWindow (void)
// init the imageButton
imageButton = Gtk::manage(
widgetFactory->createButton(WidgetFactory::deleteButton));
widgetFactory->createButton(WidgetFactory::hugePlayButton));
// create a button
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
Author : $Author: fgerlits $
Version : $Revision: 1.11 $
Author : $Author: maroy $
Version : $Revision: 1.12 $
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
blueBin = Gtk::manage(new BlueBin(backgroundColor, cornerImages));
blueBin = Gtk::manage(new BlueBin(backgroundColor, cornerImages, true));
blueBin->add(*layout);
Gtk::Window::add(*blueBin);

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.13 $
Author : $Author: maroy $
Version : $Revision: 1.14 $
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
= "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.
*/
@ -333,6 +345,11 @@ WidgetFactory :: createButton(ImageButtonType type) throw ()
rollImage = loadImage(smallStopButtonRollName);
break;
case hugePlayButton:
passiveImage = loadImage(hugePlayButtonPassiveName);
rollImage = loadImage(hugePlayButtonRollName);
break;
default:
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB