Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIStatic.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIStatic.cpp
00003         created:        13/4/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of Static widget base class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "elements/CEGUIStatic.h"
00027 #include "CEGUIImagesetManager.h"
00028 #include "CEGUIImageset.h"
00029 
00030 
00031 // Start of CEGUI namespace section
00032 namespace CEGUI
00033 {
00034 const String Static::EventNamespace("Static");
00035 
00036 /*************************************************************************
00037         Definitions of Properties for this class
00038 *************************************************************************/
00039 StaticProperties::FrameEnabled                          Static::d_frameEnabledProperty;
00040 StaticProperties::BackgroundEnabled                     Static::d_backgroundEnabledProperty;
00041 StaticProperties::FrameColours                          Static::d_frameColoursProperty;
00042 StaticProperties::BackgroundColours                     Static::d_backgroundColoursProperty;
00043 StaticProperties::BackgroundImage                       Static::d_backgroundImageProperty;
00044 StaticProperties::TopLeftFrameImage                     Static::d_topLeftFrameProperty;
00045 StaticProperties::TopRightFrameImage            Static::d_topRightFrameProperty;
00046 StaticProperties::BottomLeftFrameImage          Static::d_bottomLeftFrameProperty;
00047 StaticProperties::BottomRightFrameImage         Static::d_bottomRightFrameProperty;
00048 StaticProperties::LeftFrameImage                        Static::d_leftFrameProperty;
00049 StaticProperties::RightFrameImage                       Static::d_rightFrameProperty;
00050 StaticProperties::TopFrameImage                         Static::d_topFrameProperty;
00051 StaticProperties::BottomFrameImage                      Static::d_bottomFrameProperty;
00052 
00053 
00054 /*************************************************************************
00055         Constructor for static widget base class
00056 *************************************************************************/
00057 Static::Static(const String& type, const String& name) :
00058         Window(type, name),
00059         d_frameEnabled(false),
00060         d_frameCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
00061         d_backgroundEnabled(false),
00062         d_backgroundCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF),
00063         d_background(NULL),
00064         d_left_width(0),
00065         d_right_width(0),
00066         d_top_height(0),
00067         d_bottom_height(0)
00068 {
00069         addStaticProperties();
00070 }
00071 
00072 
00073 /*************************************************************************
00074         Destructor for static widget base class.
00075 *************************************************************************/
00076 Static::~Static(void)
00077 {
00078 }
00079 
00080 
00081 /*************************************************************************
00082         overridden so derived classes are auto-clipped to within the inner
00083         area of the frame when it's active.
00084 *************************************************************************/
00085 Rect Static::getUnclippedInnerRect(void) const
00086 {
00087         // if frame is enabled, return rect for area inside frame
00088         if (d_frameEnabled)
00089         {
00090                 Rect tmp(Window::getUnclippedInnerRect());
00091                 tmp.d_left              += d_left_width;
00092                 tmp.d_right             -= d_right_width;
00093                 tmp.d_top               += d_top_height;
00094                 tmp.d_bottom    -= d_bottom_height;
00095                 return tmp;
00096         }
00097         // no frame, so return default inner rect.
00098         else
00099         {
00100                 return Window::getUnclippedInnerRect();
00101         }
00102 
00103 }
00104 
00105 
00106 /*************************************************************************
00107         Enable or disable rendering of the frame for this static widget.
00108 *************************************************************************/
00109 void Static::setFrameEnabled(bool setting)
00110 {
00111         if (d_frameEnabled != setting)
00112         {
00113                 d_frameEnabled = setting;
00114                 WindowEventArgs args(this);
00115                 onStaticFrameChanged(args);
00116                 requestRedraw();
00117         }
00118 }
00119 
00120 
00121 /*************************************************************************
00122         specify the Image objects to use for each part of the frame.
00123         A NULL may be used to omit any part.    
00124 *************************************************************************/
00125 void Static::setFrameImages(const Image* topleft, const Image* topright, const Image* bottomleft, const Image* bottomright, const Image* left, const Image* top, const Image* right, const Image* bottom)
00126 {
00127         // install the new images into the RenderableFrame
00128         d_frame.setImages(topleft, topright, bottomleft, bottomright, left, top, right, bottom);
00129 
00130         // get sizes of frame edges
00131         d_left_width    = (left != NULL) ? left->getWidth() : 0.0f;
00132         d_right_width   = (right != NULL) ? right->getWidth() : 0.0f;
00133         d_top_height    = (top != NULL) ? top->getHeight() : 0.0f;
00134         d_bottom_height = (bottom != NULL) ? bottom->getHeight() : 0.0f;
00135 
00136         // redraw only if change would be seen.
00137         if (d_frameEnabled)
00138         {
00139                 WindowEventArgs args(this);
00140                 onStaticFrameChanged(args);
00141                 requestRedraw();
00142         }
00143 
00144 }
00145 
00146 
00147 /*************************************************************************
00148         Sets the colours to be applied when rendering the frame 
00149 *************************************************************************/
00150 void Static::setFrameColours(const ColourRect& colours)
00151 {
00152         d_frameCols = colours;
00153         updateRenderableFrameColours();
00154 
00155         // redraw only if change would be seen.
00156         if (d_frameEnabled)
00157         {
00158                 WindowEventArgs args(this);
00159                 onStaticFrameChanged(args);
00160                 requestRedraw();
00161         }
00162 
00163 }
00164 
00165 
00166 /*************************************************************************
00167         Sets the colours to be applied when rendering the frame 
00168 *************************************************************************/
00169 void Static::setFrameColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00170 {
00171         d_frameCols.d_top_left          = top_left_colour;
00172         d_frameCols.d_top_right         = top_right_colour;
00173         d_frameCols.d_bottom_left       = bottom_left_colour;
00174         d_frameCols.d_bottom_right      = bottom_right_colour;
00175         updateRenderableFrameColours();
00176 
00177         // redraw only if change would be seen.
00178         if (d_frameEnabled)
00179         {
00180                 WindowEventArgs args(this);
00181                 onStaticFrameChanged(args);
00182                 requestRedraw();
00183         }
00184 
00185 }
00186 
00187 
00188 /*************************************************************************
00189         Enable or disable rendering of the background for this static widget.   
00190 *************************************************************************/
00191 void Static::setBackgroundEnabled(bool setting)
00192 {
00193         if (d_backgroundEnabled != setting)
00194         {
00195                 d_backgroundEnabled = setting;
00196                 requestRedraw();
00197         }
00198 
00199 }
00200 
00201 
00202 /*************************************************************************
00203         Set the image to use as the background for the static widget.
00204 *************************************************************************/
00205 void Static::setBackgroundImage(const Image* image)
00206 {
00207         d_background = image;
00208 
00209         if (d_backgroundEnabled)
00210         {
00211                 requestRedraw();
00212         }
00213 
00214 }
00215 
00216 
00217 /*************************************************************************
00218         Set the image to use as the background for the static widget.   
00219 *************************************************************************/
00220 void Static::setBackgroundImage(const String& imageset, const String& image)
00221 {
00222         setBackgroundImage(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image));
00223 }
00224 
00225 
00226 /*************************************************************************
00227         Sets the colours to be applied when rendering the background.   
00228 *************************************************************************/
00229 void Static::setBackgroundColours(const ColourRect& colours)
00230 {
00231         d_backgroundCols = colours;
00232 
00233         if (d_backgroundEnabled)
00234         {
00235                 requestRedraw();
00236         }
00237 
00238 }
00239 
00240 
00241 /*************************************************************************
00242         Sets the colours to be applied when rendering the background.   
00243 *************************************************************************/
00244 void Static::setBackgroundColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00245 {
00246         d_backgroundCols.d_top_left             = top_left_colour;
00247         d_backgroundCols.d_top_right    = top_right_colour;
00248         d_backgroundCols.d_bottom_left  = bottom_left_colour;
00249         d_backgroundCols.d_bottom_right = bottom_right_colour;
00250 
00251         if (d_backgroundEnabled)
00252         {
00253                 requestRedraw();
00254         }
00255 
00256 }
00257 
00258 
00259 /*************************************************************************
00260         update the internal RenderableFrame with currently set colours and
00261         alpha settings.
00262 *************************************************************************/
00263 void Static::updateRenderableFrameColours(void)
00264 {
00265         float alpha = getEffectiveAlpha();
00266 
00267         d_frame.setColours(
00268                 calculateModulatedAlphaColour(d_frameCols.d_top_left, alpha),
00269                 calculateModulatedAlphaColour(d_frameCols.d_top_right, alpha),
00270                 calculateModulatedAlphaColour(d_frameCols.d_bottom_left, alpha),
00271                 calculateModulatedAlphaColour(d_frameCols.d_bottom_right, alpha)
00272         );
00273 
00274 }
00275 
00276 
00277 /*************************************************************************
00278         given an ARGB colour value and a alpha float value return the colour
00279         value with the alpha component modulated by the given alpha float.
00280 *************************************************************************/
00281 colour Static::calculateModulatedAlphaColour(const colour& col, float alpha) const
00282 {
00283         colour temp(col);
00284         temp.setAlpha(temp.getAlpha() * alpha);
00285         return temp;
00286 }
00287 
00288 
00289 /*************************************************************************
00290         Perform the actual rendering for this Window.   
00291 *************************************************************************/
00292 void Static::populateRenderCache()
00293 {
00294         Rect backgroundRect(Point(0,0), getAbsoluteSize());
00295 
00296         // draw frame
00297         if (d_frameEnabled)
00298         {
00299         d_frame.draw(d_renderCache);
00300 
00301         // adjust destination area for backfrop image.
00302         backgroundRect.d_left           += d_left_width;
00303         backgroundRect.d_right          -= d_right_width;
00304         backgroundRect.d_top            += d_top_height;
00305         backgroundRect.d_bottom -= d_bottom_height;
00306         }
00307 
00308         // draw backdrop
00309         if (d_backgroundEnabled && (d_background != NULL))
00310         {
00311         // factor window alpha into colours to use when rendering background
00312         ColourRect colours(d_backgroundCols);
00313         colours.modulateAlpha(getEffectiveAlpha());
00314         // cache image for drawing
00315         d_renderCache.cacheImage(*d_background, backgroundRect, 0, colours);
00316         }
00317 
00318 }
00319 
00320 
00321 /*************************************************************************
00322         Handler for when window is sized
00323 *************************************************************************/
00324 void Static::onSized(WindowEventArgs& e)
00325 {
00326         // base class processing
00327         Window::onSized(e);
00328 
00329         // update frame size.
00330         d_frame.setSize(getAbsoluteSize());
00331 
00332         e.handled = true;
00333 }
00334 
00335 
00336 /*************************************************************************
00337         Handler for when alpha value changes
00338 *************************************************************************/
00339 void Static::onAlphaChanged(WindowEventArgs& e)
00340 {
00341         // base class processing
00342         Window::onAlphaChanged(e);
00343 
00344         // update frame colours to use new alpha value
00345         updateRenderableFrameColours();
00346 
00347         e.handled = true;
00348 }
00349 
00350 
00351 /*************************************************************************
00352         Return the Image being used for the specified location of the frame.    
00353 *************************************************************************/
00354 const Image* Static::getImageForFrameLocation(FrameLocation location) const
00355 {
00356         return d_frame.getImageForLocation(location);
00357 }
00358 
00359 
00360 /*************************************************************************
00361         Return the Image currently set as the background image for the widget.
00362 *************************************************************************/
00363 const Image* Static::getBackgroundImage(void) const
00364 {
00365         return d_background;
00366 }
00367 
00368 
00369 /*************************************************************************
00370         Set the Image to use for the specified location of the frame.   
00371 *************************************************************************/
00372 void Static::setImageForFrameLocation(FrameLocation location, const Image* image)
00373 {
00374         d_frame.setImageForLocation(location, image);
00375 
00376         // update our record of image size
00377         switch (location)
00378         {
00379         case LeftEdge:
00380                 d_left_width = (image != NULL) ? image->getWidth() : 0;
00381                 break;
00382 
00383         case RightEdge:
00384                 d_right_width = (image != NULL) ? image->getWidth() : 0;
00385                 break;
00386 
00387         case TopEdge:
00388                 d_top_height = (image != NULL) ? image->getHeight() : 0;
00389                 break;
00390 
00391         case BottomEdge:
00392                 d_bottom_height = (image != NULL) ? image->getHeight() : 0;
00393                 break;
00394 
00395         default:
00396                 break;
00397         }
00398 
00399 }
00400 
00401 /*************************************************************************
00402         Adds properties for the static widget base class
00403 *************************************************************************/
00404 void Static::addStaticProperties(void)
00405 {
00406         addProperty(&d_frameEnabledProperty);
00407         addProperty(&d_backgroundEnabledProperty);
00408         addProperty(&d_frameColoursProperty);
00409         addProperty(&d_backgroundColoursProperty);
00410         addProperty(&d_backgroundImageProperty);
00411         addProperty(&d_topLeftFrameProperty);
00412         addProperty(&d_topRightFrameProperty);
00413         addProperty(&d_bottomLeftFrameProperty);
00414         addProperty(&d_bottomRightFrameProperty);
00415         addProperty(&d_leftFrameProperty);
00416         addProperty(&d_topFrameProperty);
00417         addProperty(&d_rightFrameProperty);
00418         addProperty(&d_bottomFrameProperty);
00419 }
00420 
00421 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:33 2005 for Crazy Eddies GUI System by  doxygen 1.4.3