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

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 {
00065         addStaticProperties();
00066 }
00067 
00068 
00069 /*************************************************************************
00070         Destructor for static widget base class.
00071 *************************************************************************/
00072 Static::~Static(void)
00073 {
00074 }
00075 
00076 
00077 /*************************************************************************
00078         overridden so derived classes are auto-clipped to within the inner
00079         area of the frame when it's active.
00080 *************************************************************************/
00081 Rect Static::getUnclippedInnerRect(void) const
00082 {
00083         // if frame is enabled, return rect for area inside frame
00084         if (d_frameEnabled)
00085         {
00086                 Rect tmp(Window::getUnclippedInnerRect());
00087                 tmp.d_left              += d_left_width;
00088                 tmp.d_right             -= d_right_width;
00089                 tmp.d_top               += d_top_height;
00090                 tmp.d_bottom    -= d_bottom_height;
00091                 return tmp;
00092         }
00093         // no frame, so return default inner rect.
00094         else
00095         {
00096                 return Window::getUnclippedInnerRect();
00097         }
00098 
00099 }
00100 
00101 
00102 /*************************************************************************
00103         Enable or disable rendering of the frame for this static widget.
00104 *************************************************************************/
00105 void Static::setFrameEnabled(bool setting)
00106 {
00107         if (d_frameEnabled != setting)
00108         {
00109                 d_frameEnabled = setting;
00110                 WindowEventArgs args(this);
00111                 onStaticFrameChanged(args);
00112                 requestRedraw();
00113         }
00114 }
00115 
00116 
00117 /*************************************************************************
00118         specify the Image objects to use for each part of the frame.
00119         A NULL may be used to omit any part.    
00120 *************************************************************************/
00121 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)
00122 {
00123         // install the new images into the RenderableFrame
00124         d_frame.setImages(topleft, topright, bottomleft, bottomright, left, top, right, bottom);
00125 
00126         // get sizes of frame edges
00127         d_left_width    = (left != NULL) ? left->getWidth() : 0.0f;
00128         d_right_width   = (right != NULL) ? right->getWidth() : 0.0f;
00129         d_top_height    = (top != NULL) ? top->getHeight() : 0.0f;
00130         d_bottom_height = (bottom != NULL) ? bottom->getHeight() : 0.0f;
00131 
00132         // redraw only if change would be seen.
00133         if (d_frameEnabled)
00134         {
00135                 WindowEventArgs args(this);
00136                 onStaticFrameChanged(args);
00137                 requestRedraw();
00138         }
00139 
00140 }
00141 
00142 
00143 /*************************************************************************
00144         Sets the colours to be applied when rendering the frame 
00145 *************************************************************************/
00146 void Static::setFrameColours(const ColourRect& colours)
00147 {
00148         d_frameCols = colours;
00149         updateRenderableFrameColours();
00150 
00151         // redraw only if change would be seen.
00152         if (d_frameEnabled)
00153         {
00154                 WindowEventArgs args(this);
00155                 onStaticFrameChanged(args);
00156                 requestRedraw();
00157         }
00158 
00159 }
00160 
00161 
00162 /*************************************************************************
00163         Sets the colours to be applied when rendering the frame 
00164 *************************************************************************/
00165 void Static::setFrameColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00166 {
00167         d_frameCols.d_top_left          = top_left_colour;
00168         d_frameCols.d_top_right         = top_right_colour;
00169         d_frameCols.d_bottom_left       = bottom_left_colour;
00170         d_frameCols.d_bottom_right      = bottom_right_colour;
00171         updateRenderableFrameColours();
00172 
00173         // redraw only if change would be seen.
00174         if (d_frameEnabled)
00175         {
00176                 WindowEventArgs args(this);
00177                 onStaticFrameChanged(args);
00178                 requestRedraw();
00179         }
00180 
00181 }
00182 
00183 
00184 /*************************************************************************
00185         Enable or disable rendering of the background for this static widget.   
00186 *************************************************************************/
00187 void Static::setBackgroundEnabled(bool setting)
00188 {
00189         if (d_backgroundEnabled != setting)
00190         {
00191                 d_backgroundEnabled = setting;
00192                 requestRedraw();
00193         }
00194 
00195 }
00196 
00197 
00198 /*************************************************************************
00199         Set the image to use as the background for the static widget.
00200 *************************************************************************/
00201 void Static::setBackgroundImage(const Image* image)
00202 {
00203         d_background = image;
00204 
00205         if (d_backgroundEnabled)
00206         {
00207                 requestRedraw();
00208         }
00209 
00210 }
00211 
00212 
00213 /*************************************************************************
00214         Set the image to use as the background for the static widget.   
00215 *************************************************************************/
00216 void Static::setBackgroundImage(const String& imageset, const String& image)
00217 {
00218         setBackgroundImage(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image));
00219 }
00220 
00221 
00222 /*************************************************************************
00223         Sets the colours to be applied when rendering the background.   
00224 *************************************************************************/
00225 void Static::setBackgroundColours(const ColourRect& colours)
00226 {
00227         d_backgroundCols = colours;
00228 
00229         if (d_backgroundEnabled)
00230         {
00231                 requestRedraw();
00232         }
00233 
00234 }
00235 
00236 
00237 /*************************************************************************
00238         Sets the colours to be applied when rendering the background.   
00239 *************************************************************************/
00240 void Static::setBackgroundColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00241 {
00242         d_backgroundCols.d_top_left             = top_left_colour;
00243         d_backgroundCols.d_top_right    = top_right_colour;
00244         d_backgroundCols.d_bottom_left  = bottom_left_colour;
00245         d_backgroundCols.d_bottom_right = bottom_right_colour;
00246 
00247         if (d_backgroundEnabled)
00248         {
00249                 requestRedraw();
00250         }
00251 
00252 }
00253 
00254 
00255 /*************************************************************************
00256         update the internal RenderableFrame with currently set colours and
00257         alpha settings.
00258 *************************************************************************/
00259 void Static::updateRenderableFrameColours(void)
00260 {
00261         float alpha = getEffectiveAlpha();
00262 
00263         d_frame.setColours(
00264                 calculateModulatedAlphaColour(d_frameCols.d_top_left, alpha),
00265                 calculateModulatedAlphaColour(d_frameCols.d_top_right, alpha),
00266                 calculateModulatedAlphaColour(d_frameCols.d_bottom_left, alpha),
00267                 calculateModulatedAlphaColour(d_frameCols.d_bottom_right, alpha)
00268         );
00269 
00270 }
00271 
00272 
00273 /*************************************************************************
00274         given an ARGB colour value and a alpha float value return the colour
00275         value with the alpha component modulated by the given alpha float.
00276 *************************************************************************/
00277 colour Static::calculateModulatedAlphaColour(const colour& col, float alpha) const
00278 {
00279         colour temp(col);
00280         temp.setAlpha(temp.getAlpha() * alpha);
00281         return temp;
00282 }
00283 
00284 
00285 /*************************************************************************
00286         Perform the actual rendering for this Window.   
00287 *************************************************************************/
00288 void Static::drawSelf(float z)
00289 {
00290         Rect clipper(getPixelRect());
00291 
00292         // do nothing if the widget is totally clipped.
00293         if (clipper.getWidth() == 0)
00294         {
00295                 return;
00296         }
00297 
00298         Rect absrect(getUnclippedPixelRect());
00299 
00300         // draw frame
00301         if (d_frameEnabled)
00302         {
00303                 d_frame.draw(Vector3(absrect.d_left, absrect.d_top, z), clipper);
00304 
00305                 // adjust absrect and clipper so that later stages of render to not overwite frame
00306                 absrect.d_left          += d_left_width;
00307                 absrect.d_right         -= d_right_width;
00308                 absrect.d_top           += d_top_height;
00309                 absrect.d_bottom        -= d_bottom_height;
00310 
00311                 clipper = clipper.getIntersection(absrect);
00312         }
00313 
00314         // draw backdrop
00315         if (d_backgroundEnabled && (d_background != NULL))
00316         {
00317                 // factor window alpha into colours to use when rendering background
00318                 float alpha = getEffectiveAlpha();
00319                 ColourRect colours;
00320                 colours.d_top_left              = calculateModulatedAlphaColour(d_backgroundCols.d_top_left, alpha);
00321                 colours.d_top_right             = calculateModulatedAlphaColour(d_backgroundCols.d_top_right, alpha);
00322                 colours.d_bottom_left   = calculateModulatedAlphaColour(d_backgroundCols.d_bottom_left, alpha);
00323                 colours.d_bottom_right  = calculateModulatedAlphaColour(d_backgroundCols.d_bottom_right, alpha);
00324 
00325                 d_background->draw(absrect, z, clipper, colours);
00326         }
00327 
00328 }
00329 
00330 
00331 /*************************************************************************
00332         Handler for when window is sized
00333 *************************************************************************/
00334 void Static::onSized(WindowEventArgs& e)
00335 {
00336         // base class processing
00337         Window::onSized(e);
00338 
00339         // update frame size.
00340         d_frame.setSize(getAbsoluteSize());
00341 
00342         e.handled = true;
00343 }
00344 
00345 
00346 /*************************************************************************
00347         Handler for when alpha value changes
00348 *************************************************************************/
00349 void Static::onAlphaChanged(WindowEventArgs& e)
00350 {
00351         // base class processing
00352         Window::onAlphaChanged(e);
00353 
00354         // update frame colours to use new alpha value
00355         updateRenderableFrameColours();
00356 
00357         e.handled = true;
00358 }
00359 
00360 
00361 /*************************************************************************
00362         Return the Image being used for the specified location of the frame.    
00363 *************************************************************************/
00364 const Image* Static::getImageForFrameLocation(FrameLocation location) const
00365 {
00366         return d_frame.getImageForLocation(location);
00367 }
00368 
00369 
00370 /*************************************************************************
00371         Return the Image currently set as the background image for the widget.
00372 *************************************************************************/
00373 const Image* Static::getBackgroundImage(void) const
00374 {
00375         return d_background;
00376 }
00377 
00378 
00379 /*************************************************************************
00380         Set the Image to use for the specified location of the frame.   
00381 *************************************************************************/
00382 void Static::setImageForFrameLocation(FrameLocation location, const Image* image)
00383 {
00384         d_frame.setImageForLocation(location, image);
00385 
00386         // update our record of image size
00387         switch (location)
00388         {
00389         case LeftEdge:
00390                 d_left_width = (image != NULL) ? image->getWidth() : 0;
00391                 break;
00392 
00393         case RightEdge:
00394                 d_right_width = (image != NULL) ? image->getWidth() : 0;
00395                 break;
00396 
00397         case TopEdge:
00398                 d_top_height = (image != NULL) ? image->getHeight() : 0;
00399                 break;
00400 
00401         case BottomEdge:
00402                 d_bottom_height = (image != NULL) ? image->getHeight() : 0;
00403                 break;
00404 
00405         default:
00406                 break;
00407         }
00408 
00409 }
00410 
00411 /*************************************************************************
00412         Adds properties for the static widget base class
00413 *************************************************************************/
00414 void Static::addStaticProperties(void)
00415 {
00416         addProperty(&d_frameEnabledProperty);
00417         addProperty(&d_backgroundEnabledProperty);
00418         addProperty(&d_frameColoursProperty);
00419         addProperty(&d_backgroundColoursProperty);
00420         addProperty(&d_backgroundImageProperty);
00421         addProperty(&d_topLeftFrameProperty);
00422         addProperty(&d_topRightFrameProperty);
00423         addProperty(&d_bottomLeftFrameProperty);
00424         addProperty(&d_bottomRightFrameProperty);
00425         addProperty(&d_leftFrameProperty);
00426         addProperty(&d_topFrameProperty);
00427         addProperty(&d_rightFrameProperty);
00428         addProperty(&d_bottomFrameProperty);
00429 }
00430 
00431 } // End of  CEGUI namespace section

Generated on Wed Feb 16 12:41:07 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1