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

CEGUIStaticImage.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIStaticImage.cpp
00003         created:        4/6/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of the static image widget 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/CEGUIStaticImage.h"
00027 #include "CEGUIImagesetManager.h"
00028 #include "CEGUIImageset.h"
00029 
00030 // Start of CEGUI namespace section
00031 namespace CEGUI
00032 {
00033 const String StaticImage::EventNamespace("StaticImage");
00034 
00035 /*************************************************************************
00036         Definitions of Properties for this class
00037 *************************************************************************/
00038 StaticImageProperties::Image                    StaticImage::d_imageProperty;
00039 StaticImageProperties::ImageColours             StaticImage::d_imageColoursProperty;
00040 StaticImageProperties::VertFormatting   StaticImage::d_vertFormattingProperty;
00041 StaticImageProperties::HorzFormatting   StaticImage::d_horzFormattingProperty;
00042 
00043 
00044 /*************************************************************************
00045         Constructor for static image widgets.   
00046 *************************************************************************/
00047 StaticImage::StaticImage(const String& type, const String& name) :
00048         Static(type, name),
00049         d_imageCols(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)
00050 {
00051         addStaticImageProperties();
00052 
00053         // default to stretched image
00054         d_image.setHorzFormatting(RenderableImage::HorzStretched);
00055         d_image.setVertFormatting(RenderableImage::VertStretched);
00056 }
00057 
00058 
00059 /*************************************************************************
00060         Destructor for static image widgets.
00061 *************************************************************************/
00062 StaticImage::~StaticImage(void)
00063 {
00064 }
00065 
00066 
00067 /*************************************************************************
00068         Set the Image object to be drawn by this widget.        
00069 *************************************************************************/
00070 void StaticImage::setImage(const Image* image)
00071 {
00072         d_image.setImage(image);
00073         requestRedraw();
00074 }
00075 
00076 
00077 /*************************************************************************
00078         Set the Image object to be drawn by this widget.        
00079 *************************************************************************/
00080 void StaticImage::setImage(const String& imageset, const String& image)
00081 {
00082         setImage(&ImagesetManager::getSingleton().getImageset(imageset)->getImage(image));
00083 }
00084 
00085 
00086 /*************************************************************************
00087         Sets the colours to be applied when rendering the image.
00088 *************************************************************************/
00089 void StaticImage::setImageColours(const ColourRect& colours)
00090 {
00091         d_imageCols = colours;
00092         updateRenderableImageColours();
00093 
00094         requestRedraw();
00095 }
00096 
00097 
00098 /*************************************************************************
00099         Sets the colours to be applied when rendering the image.        
00100 *************************************************************************/
00101 void StaticImage::setImageColours(const colour& top_left_colour, const colour& top_right_colour, const colour& bottom_left_colour, const colour& bottom_right_colour)
00102 {
00103         d_imageCols.d_top_left          = top_left_colour;
00104         d_imageCols.d_top_right         = top_right_colour;
00105         d_imageCols.d_bottom_left       = bottom_left_colour;
00106         d_imageCols.d_bottom_right      = bottom_right_colour;
00107         updateRenderableImageColours();
00108 
00109         requestRedraw();
00110 }
00111 
00112 
00113 /*************************************************************************
00114         Set the formatting required for the image.      
00115 *************************************************************************/
00116 void StaticImage::setFormatting(HorzFormatting h_fmt, VertFormatting v_fmt)
00117 {
00118         d_image.setHorzFormatting((RenderableImage::HorzFormatting)h_fmt);
00119         d_image.setVertFormatting((RenderableImage::VertFormatting)v_fmt);
00120 
00121         requestRedraw();
00122 }
00123 
00124 
00125 /*************************************************************************
00126         Set the formatting required for the image.      
00127 *************************************************************************/
00128 void StaticImage::setVerticalFormatting(VertFormatting v_fmt)
00129 {
00130         d_image.setVertFormatting((RenderableImage::VertFormatting)v_fmt);
00131         
00132         requestRedraw();
00133 }
00134 
00135 
00136 /*************************************************************************
00137         Set the formatting required for the image.
00138 *************************************************************************/
00139 void StaticImage::setHorizontalFormatting(HorzFormatting h_fmt)
00140 {
00141         d_image.setHorzFormatting((RenderableImage::HorzFormatting)h_fmt);
00142 
00143         requestRedraw();
00144 }
00145 
00146 
00147 /*************************************************************************
00148         update the internal RenderableImage with currently set colours and
00149         alpha settings.
00150 *************************************************************************/
00151 void StaticImage::updateRenderableImageColours(void)
00152 {
00153         float alpha = getEffectiveAlpha();
00154 
00155         d_image.setColours(
00156                 calculateModulatedAlphaColour(d_imageCols.d_top_left, alpha),
00157                 calculateModulatedAlphaColour(d_imageCols.d_top_right, alpha),
00158                 calculateModulatedAlphaColour(d_imageCols.d_bottom_left, alpha),
00159                 calculateModulatedAlphaColour(d_imageCols.d_bottom_right, alpha)
00160         );
00161 
00162 }
00163 
00164 
00165 /*************************************************************************
00166         Perform the actual rendering for this Window.
00167 *************************************************************************/
00168 void StaticImage::drawSelf(float z)
00169 {
00170         // get whatever base class needs to render.
00171         Static::drawSelf(z);
00172 
00173         //
00174         // Render image.
00175         //
00176         Rect area(getUnclippedInnerRect());
00177         d_image.draw(Vector3(area.d_left, area.d_top, z), getPixelRect().getIntersection(area));
00178 }
00179 
00180 
00181 /*************************************************************************
00182         Handler for when window is sized.
00183 *************************************************************************/
00184 void StaticImage::onSized(WindowEventArgs& e)
00185 {
00186         // base class handling.
00187         Static::onSized(e);
00188 
00189         d_image.setSize(getUnclippedInnerRect().getSize());
00190 
00191         e.handled = true;
00192 }
00193 
00194 
00195 /*************************************************************************
00196         Handler for when window alpha changes
00197 *************************************************************************/
00198 void StaticImage::onAlphaChanged(WindowEventArgs& e)
00199 {
00200         // base class handling
00201         Static::onAlphaChanged(e);
00202 
00203         // Update image alpha values.
00204         updateRenderableImageColours();
00205 
00206         e.handled = true;
00207 }
00208 
00209 
00210 /*************************************************************************
00211         Handler for when frame state changes.
00212 *************************************************************************/
00213 void StaticImage::onStaticFrameChanged(WindowEventArgs& e)
00214 {
00215         // base class processing
00216         Static::onStaticFrameChanged(e);
00217 
00218         // update the size of the image to reflect changes made to the frame in the base class
00219         d_image.setSize(getUnclippedInnerRect().getSize());
00220 
00221         e.handled = true;
00222 }
00223 
00224 /*************************************************************************
00225         Add properties for static image
00226 *************************************************************************/
00227 void StaticImage::addStaticImageProperties(void)
00228 {
00229         addProperty(&d_imageProperty);
00230         addProperty(&d_imageColoursProperty);
00231         addProperty(&d_vertFormattingProperty);
00232         addProperty(&d_horzFormattingProperty);
00233 }
00234 
00235 
00236 } // 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