diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/BlueBin.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/BlueBin.h index 3c4fbbb4f..7a9b8eb0b 100644 --- a/livesupport/modules/widgets/include/LiveSupport/Widgets/BlueBin.h +++ b/livesupport/modules/widgets/include/LiveSupport/Widgets/BlueBin.h @@ -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::Ref cornerImages; + /** + * The corner bitmaps, for masking for transparency. + */ + Ptr::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::Ref cornerImages) + Ptr::Ref cornerImages, + bool transparentBorder = false) throw (); /** diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/CornerBitmaps.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/CornerBitmaps.h new file mode 100644 index 000000000..137529aef --- /dev/null +++ b/livesupport/modules/widgets/include/LiveSupport/Widgets/CornerBitmaps.h @@ -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 + +#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 topLeftBitmap; + + /** + * The top right image. + */ + Glib::RefPtr topRightBitmap; + + /** + * The bottom left image. + */ + Glib::RefPtr bottomLeftBitmap; + + /** + * The bottom right image. + */ + Glib::RefPtr 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 topLeftBitmap, + Glib::RefPtr topRightBitmap, + Glib::RefPtr bottomLeftBitmap, + Glib::RefPtr 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 + diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/ImageButton.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/ImageButton.h index d0cc63984..1511aeeb7 100644 --- a/livesupport/modules/widgets/include/LiveSupport/Widgets/ImageButton.h +++ b/livesupport/modules/widgets/include/LiveSupport/Widgets/ImageButton.h @@ -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 rollImage; + /** + * The transparency mask for the button, in passive state. + */ + Glib::RefPtr passiveMask; + + /** + * The transparency mask for the button, in rollover state. + */ + Glib::RefPtr rollMask; + /** * Default constructor. */ diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h index 53dd028e4..0732973f8 100644 --- a/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h +++ b/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h @@ -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; * * * - * @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; /** diff --git a/livesupport/modules/widgets/src/BlueBin.cxx b/livesupport/modules/widgets/src/BlueBin.cxx index deab95860..638fc2a36 100644 --- a/livesupport/modules/widgets/src/BlueBin.cxx +++ b/livesupport/modules/widgets/src/BlueBin.cxx @@ -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::Ref cornerImages) + Ptr::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 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 mask = Gdk::Bitmap::create(bitmapData, + width, + height); + delete[] bitmapData; + + Glib::RefPtr gc = Gdk::GC::create(mask); + Glib::RefPtr 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; diff --git a/livesupport/modules/widgets/src/ImageButton.cxx b/livesupport/modules/widgets/src/ImageButton.cxx index fa33becdb..68bf01de4 100644 --- a/livesupport/modules/widgets/src/ImageButton.cxx +++ b/livesupport/modules/widgets/src/ImageButton.cxx @@ -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 image) state = passiveState; this->passiveImage = image; this->rollImage.clear(); + + // read the mask from a transparent PNG, and set it to this widget + Glib::RefPtr pixmap; + passiveImage->render_pixmap_and_mask(pixmap, passiveMask, 100); } @@ -76,6 +80,11 @@ ImageButton :: ImageButton(Glib::RefPtr passiveImage, state = passiveState; this->passiveImage = passiveImage; this->rollImage = rollImage; + + // read the mask from a transparent PNG, and set it to this widget + Glib::RefPtr 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 image; + Glib::RefPtr 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; diff --git a/livesupport/modules/widgets/src/TestWindow.cxx b/livesupport/modules/widgets/src/TestWindow.cxx index b660ad16b..a4856af40 100644 --- a/livesupport/modules/widgets/src/TestWindow.cxx +++ b/livesupport/modules/widgets/src/TestWindow.cxx @@ -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!")); diff --git a/livesupport/modules/widgets/src/WhiteWindow.cxx b/livesupport/modules/widgets/src/WhiteWindow.cxx index 167c48f03..361ab05af 100644 --- a/livesupport/modules/widgets/src/WhiteWindow.cxx +++ b/livesupport/modules/widgets/src/WhiteWindow.cxx @@ -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); diff --git a/livesupport/modules/widgets/src/WidgetFactory.cxx b/livesupport/modules/widgets/src/WidgetFactory.cxx index c580a70e7..7c6824a8c 100644 --- a/livesupport/modules/widgets/src/WidgetFactory.cxx +++ b/livesupport/modules/widgets/src/WidgetFactory.cxx @@ -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; } diff --git a/livesupport/modules/widgets/var/imageButton/hugePlay.png b/livesupport/modules/widgets/var/imageButton/hugePlay.png new file mode 100644 index 000000000..f1628edfe Binary files /dev/null and b/livesupport/modules/widgets/var/imageButton/hugePlay.png differ diff --git a/livesupport/modules/widgets/var/imageButton/hugePlayRoll.png b/livesupport/modules/widgets/var/imageButton/hugePlayRoll.png new file mode 100644 index 000000000..55ea1ab2a Binary files /dev/null and b/livesupport/modules/widgets/var/imageButton/hugePlayRoll.png differ