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

CEGUIImageset_xmlHandler.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 filename:       CEGUIImageset_xmlHandler.cpp
00003 created:        21/2/2004
00004 author:         Paul D Turner
00005 
00006 purpose:        Implements the Imageset 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 "CEGUIImageset_xmlHandler.h"
00027 
00028 #include "CEGUIExceptions.h"
00029 #include "CEGUISystem.h"
00030 #include "CEGUILogger.h"
00031 #include "CEGUIXMLAttributes.h"
00032 
00033 // Start of CEGUI namespace section
00034 namespace CEGUI
00035 {
00036 
00037 /*************************************************************************
00038 Definition of constant data for Imageset (and sub-classes)
00039 *************************************************************************/
00040 // Declared in Imageset::xmlHandler
00041 const String Imageset_xmlHandler::ImagesetElement( (utf8*)"Imageset" );
00042 const String Imageset_xmlHandler::ImageElement( (utf8*)"Image" );
00043 const char      Imageset_xmlHandler::ImagesetImageFileAttribute[]               = "Imagefile";
00044 const char      Imageset_xmlHandler::ImagesetResourceGroupAttribute[]   = "ResourceGroup";
00045 const char      Imageset_xmlHandler::ImagesetNameAttribute[]                    = "Name";
00046 const char      Imageset_xmlHandler::ImagesetNativeHorzResAttribute[]   = "NativeHorzRes";
00047 const char      Imageset_xmlHandler::ImagesetNativeVertResAttribute[]   = "NativeVertRes";
00048 const char      Imageset_xmlHandler::ImagesetAutoScaledAttribute[]              = "AutoScaled";
00049 const char      Imageset_xmlHandler::ImageNameAttribute[]                               = "Name";
00050 const char      Imageset_xmlHandler::ImageXPosAttribute[]                               = "XPos";
00051 const char      Imageset_xmlHandler::ImageYPosAttribute[]                               = "YPos";
00052 const char      Imageset_xmlHandler::ImageWidthAttribute[]                              = "Width";
00053 const char      Imageset_xmlHandler::ImageHeightAttribute[]                             = "Height";
00054 const char      Imageset_xmlHandler::ImageXOffsetAttribute[]                    = "XOffset";
00055 const char      Imageset_xmlHandler::ImageYOffsetAttribute[]                    = "YOffset";
00056 
00057 /*************************************************************************
00058 SAX2 Handler methods
00059 *************************************************************************/
00060 void Imageset_xmlHandler::elementStart(const String& element, const XMLAttributes& attributes)
00061 {
00062         // handle an Image element (extract all element attributes and use data to define an Image for the Imageset)
00063         if (element == ImageElement)
00064         {
00065                 String  name(attributes.getValueAsString(ImageNameAttribute));
00066 
00067                 Rect    rect;
00068         rect.d_left     = (float)attributes.getValueAsInteger(ImageXPosAttribute);
00069         rect.d_top      = (float)attributes.getValueAsInteger(ImageYPosAttribute);
00070         rect.setWidth((float)attributes.getValueAsInteger(ImageWidthAttribute));
00071         rect.setHeight((float)attributes.getValueAsInteger(ImageHeightAttribute));
00072 
00073                 Point   offset;
00074         offset.d_x      = (float)attributes.getValueAsInteger(ImageXOffsetAttribute, 0);
00075         offset.d_y      = (float)attributes.getValueAsInteger(ImageYOffsetAttribute, 0);
00076 
00077                 d_imageset->defineImage(name, rect, offset);
00078         }
00079         // handle root Imageset element
00080         else if (element == ImagesetElement)
00081         {
00082         d_imageset->d_name = attributes.getValueAsString(ImagesetNameAttribute);
00083 
00084                 Logger::getSingleton().logEvent("Started creation of Imageset '" + d_imageset->d_name + "' via XML file.", Informative);
00085 
00086                 //
00087                 // load auto-scaling configuration
00088                 //
00089                 float hres, vres;
00090 
00091                 // get native horizontal resolution
00092         hres = (float)attributes.getValueAsInteger(ImagesetNativeHorzResAttribute, 640);
00093 
00094                 // get native vertical resolution
00095         vres = (float)attributes.getValueAsInteger(ImagesetNativeVertResAttribute, 480);
00096 
00097                 d_imageset->setNativeResolution(Size(hres, vres));
00098 
00099                 // enable / disable auto-scaling for this Imageset according to the setting
00100         d_imageset->setAutoScalingEnabled(attributes.getValueAsBool(ImagesetAutoScaledAttribute, false));
00101 
00102                 //
00103                 // Create a Texture object via the specified filename, and set it as the texture for the Imageset
00104                 //
00105         String filename(attributes.getValueAsString(ImagesetImageFileAttribute));
00106         String resourceGroup(attributes.getValueAsString(ImagesetResourceGroupAttribute));
00107 
00108                 try
00109                 {
00110                         d_imageset->d_texture = System::getSingleton().getRenderer()->createTexture(filename, resourceGroup);
00111                 }
00112                 catch(...)
00113                 {
00114                         throw RendererException((utf8*)"Imageset::xmlHandler::startElement - An unexpected error occurred while creating a Texture object from file '" + filename + "'");
00115                 }
00116 
00117         d_imageset->d_textureFilename = filename;
00118         }
00119         // anything else is an error which *should* have already been caught by XML validation
00120         else
00121         {
00122                 throw FileIOException("Imageset::xmlHandler::startElement - Unexpected data was found while parsing the Imageset file: '" + element + "' is unknown.");
00123         }
00124 
00125 }
00126 
00127 void Imageset_xmlHandler::elementEnd(const String& element)
00128 {
00129         if (element == ImagesetElement)
00130         {
00131                 Logger::getSingleton().logEvent("Finished creation of Imageset '" + d_imageset->d_name + "' via XML file.", Informative);
00132         }
00133 }
00134 
00135 } // End of  CEGUI namespace section

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