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

CEGUIImage.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIImage.cpp
00003         created:        13/3/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of Image class members
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 "CEGUIImage.h"
00027 #include "CEGUIExceptions.h"
00028 #include "CEGUITexture.h"
00029 #include "CEGUIImageset.h"
00030 #include "CEGUIRenderer.h"
00031 #include "CEGUIPropertyHelper.h"
00032 #include <cmath>
00033 #include <iostream>
00034 
00035 // Start of CEGUI namespace section
00036 namespace CEGUI
00037 {
00038 
00039 /*************************************************************************
00040         Constructor
00041 *************************************************************************/
00042 Image::Image(const Imageset* owner, const String& name, const Rect& area, const Point& render_offset, float horzScaling, float vertScaling) :
00043         d_owner(owner),
00044         d_area(area),
00045         d_offset(render_offset),
00046         d_name(name)
00047 {
00048         if (d_owner == NULL)
00049         {
00050                 throw NullObjectException((utf8*)"Image::Image - Imageset pointer passed to Image constructor must not be null.");
00051         }
00052 
00053         // setup initial image scaling
00054         setHorzScaling(horzScaling);
00055         setVertScaling(vertScaling);
00056 
00057         // TODO: if we ever store texture co-ordinates, they should be calculated here.
00058 }
00059 
00060 /*************************************************************************
00061         Copy constructor
00062 *************************************************************************/
00063 Image::Image(const Image& image) :
00064         d_owner(image.d_owner),
00065         d_area(image.d_area),
00066         d_offset(image.d_offset),
00067         d_scaledWidth(image.d_scaledWidth),
00068         d_scaledHeight(image.d_scaledHeight),
00069         d_scaledOffset(image.d_scaledOffset),
00070         d_name(image.d_name)
00071 {
00072 }
00073 
00074 /*************************************************************************
00075         destructor
00076 *************************************************************************/
00077 Image::~Image(void)
00078 {
00079 }
00080 
00081 
00082 /*************************************************************************
00083         set the horizontal scaling factor to be applied to this Image
00084 *************************************************************************/
00085 void Image::setHorzScaling(float factor)
00086 {
00087         d_scaledWidth           = PixelAligned(d_area.getWidth() * factor);
00088         d_scaledOffset.d_x      = PixelAligned(d_offset.d_x * factor);
00089 }
00090 
00091 
00092 /*************************************************************************
00093         set the vertical scaling factor to be applied to this Image
00094 *************************************************************************/
00095 void Image::setVertScaling(float factor)
00096 {
00097         d_scaledHeight          = PixelAligned(d_area.getHeight() * factor);
00098         d_scaledOffset.d_y      = PixelAligned(d_offset.d_y * factor);
00099 }
00100 
00101 
00102 /*************************************************************************
00103         Clip and then queue the image to be rendered.
00104 *************************************************************************/
00105 void Image::draw(const Rect& dest_rect, float z, const Rect& clip_rect, const ColourRect& colours, QuadSplitMode quad_split_mode) const
00106 {
00107         Rect dest(dest_rect);
00108 
00109         // apply rendering offset to the destination Rect
00110         dest.offset(d_scaledOffset);
00111 
00112         // draw
00113         d_owner->draw(d_area, dest, z, clip_rect, colours, quad_split_mode);
00114 }
00115 
00116 
00117 /*************************************************************************
00118         String object containing the name of this Image 
00119 *************************************************************************/
00120 const String& Image::getName(void) const
00121 {
00122         return d_name;
00123 }
00124 
00125 
00126 /*************************************************************************
00127         Return the name of the Imageset that contains this Image        
00128 *************************************************************************/
00129 const String& Image::getImagesetName(void) const
00130 {
00131         return d_owner->getName();
00132 }
00133 
00134 /*************************************************************************
00135         Return Rect describing the source texture area used by this Image.
00136 *************************************************************************/
00137 const Rect& Image::getSourceTextureArea(void) const
00138 {
00139     return d_area;
00140 }
00141 
00142 
00143 /*************************************************************************
00144     Output XML <Image ... > element for this image
00145 *************************************************************************/
00146 void Image::writeXMLToStream(OutStream& out_stream) const
00147 {
00148     out_stream << "<Image Name=\"" << d_name.c_str() << "\" ";
00149     out_stream << "XPos=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.d_left)) << "\" ";
00150     out_stream << "YPos=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.d_top)) << "\" ";
00151     out_stream << "Width=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.getWidth())) << "\" ";
00152     out_stream << "Height=\"" << PropertyHelper::uintToString(static_cast<uint>(d_area.getHeight())) << "\" ";
00153 
00154     if (d_offset.d_x != 0.0f)
00155         out_stream << "XOffset=\"" << PropertyHelper::intToString(static_cast<int>(d_offset.d_x)) << "\" ";
00156 
00157     if (d_offset.d_y != 0.0f)
00158         out_stream << "YOffset=\"" << PropertyHelper::intToString(static_cast<int>(d_offset.d_x)) << "\" ";
00159 
00160     out_stream << "/>" << std::endl;
00161 }
00162 
00163 
00164 } // End of  CEGUI namespace section

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