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

CEGUIPropertyHelper.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIPropertyHelper.cpp
00003         created:        6/7/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of PropertyHelper methods
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 "CEGUIPropertyHelper.h"
00027 #include "CEGUIImagesetManager.h"
00028 #include "CEGUIImageset.h"
00029 #include "CEGUIExceptions.h"
00030 
00031 #include <cstdio>
00032 
00033 // Start of CEGUI namespace section
00034 namespace CEGUI
00035 {
00036 float PropertyHelper::stringToFloat(const String& str)
00037 {
00038         using namespace std;
00039 
00040         float val = 0;
00041         sscanf(str.c_str(), " %f", &val);
00042 
00043         return val;
00044 }
00045 
00046 
00047 uint PropertyHelper::stringToUint(const String& str)
00048 {
00049         using namespace std;
00050 
00051         uint val = 0;
00052         sscanf(str.c_str(), " %u", &val);
00053 
00054         return val;
00055 }
00056 
00057 
00058 int PropertyHelper::stringToInt(const String& str)
00059 {
00060         using namespace std;
00061 
00062         uint val = 0;
00063         sscanf(str.c_str(), " %d", &val);
00064 
00065         return val;
00066 }
00067 
00068 
00069 bool PropertyHelper::stringToBool(const String& str)
00070 {
00071         if ((str == (utf8*)"True") || (str == (utf8*)"true"))
00072         {
00073                 return true;
00074         }
00075         else
00076         {
00077                 return false;
00078         }
00079 
00080 }
00081 
00082 
00083 Size PropertyHelper::stringToSize(const String& str)
00084 {
00085         using namespace std;
00086 
00087         Size val(0,0);
00088         sscanf(str.c_str(), " w:%f h:%f", &val.d_width, &val.d_height);
00089 
00090         return val;
00091 }
00092 
00093 
00094 Point PropertyHelper::stringToPoint(const String& str)
00095 {
00096         using namespace std;
00097 
00098         Point val(0,0) ;
00099         sscanf(str.c_str(), " x:%f y:%f", &val.d_x, &val.d_y);
00100 
00101         return val;
00102 }
00103 
00104 
00105 Rect PropertyHelper::stringToRect(const String& str)
00106 {
00107         using namespace std;
00108 
00109         Rect val(0, 0, 0, 0);
00110         sscanf(str.c_str(), " l:%f t:%f r:%f b:%f", &val.d_left, &val.d_top, &val.d_right, &val.d_bottom);
00111 
00112         return val;
00113 }
00114 
00115 
00116 MetricsMode PropertyHelper::stringToMetricsMode(const String& str)
00117 {
00118         if (str == (utf8*)"Relative")
00119         {
00120                 return Relative;
00121         }
00122         else if (str == (utf8*)"Absolute")
00123         {
00124                 return Absolute;
00125         }
00126         else
00127         {
00128                 return Inherited;
00129         }
00130 
00131 }
00132 
00133 
00134 const Image* PropertyHelper::stringToImage(const String& str)
00135 {
00136         using namespace std;
00137 
00138         char imageSet[128];
00139         char imageName[128];
00140 
00141         sscanf(str.c_str(), " set:%127s image:%127s", imageSet, imageName);
00142 
00143         const Image* image;
00144 
00145         try
00146         {
00147                 image = &ImagesetManager::getSingleton().getImageset((utf8*)imageSet)->getImage((utf8*)imageName);
00148         }
00149         catch (UnknownObjectException)
00150         {
00151                 image = NULL;
00152         }
00153 
00154         return image;
00155 }
00156 
00157 
00158 UDim PropertyHelper::stringToUDim(const String& str)
00159 {
00160         using namespace std;
00161 
00162         UDim ud;
00163         sscanf(str.c_str()," {%f,%f}", &ud.d_scale, &ud.d_offset);
00164 
00165         return ud;
00166 }
00167 
00168 
00169 UVector2 PropertyHelper::stringToUVector2(const String& str)
00170 {
00171         using namespace std;
00172 
00173         UVector2 uv;
00174         sscanf(str.c_str(), " {{%f,%f},{%f,%f}}", &uv.d_x.d_scale,&uv.d_x.d_offset, &uv.d_y.d_scale,&uv.d_y.d_offset);
00175 
00176         return uv;
00177 }
00178 
00179 
00180 URect PropertyHelper::stringToURect(const String& str)
00181 {
00182         using namespace std;
00183 
00184         URect ur;
00185         sscanf(
00186                 str.c_str(),
00187                 " {{%f,%f},{%f,%f},{%f,%f},{%f,%f}}",
00188                 &ur.d_min.d_x.d_scale, &ur.d_min.d_x.d_offset,
00189                 &ur.d_min.d_y.d_scale, &ur.d_min.d_y.d_offset,
00190                 &ur.d_max.d_x.d_scale, &ur.d_max.d_x.d_offset,
00191                 &ur.d_max.d_y.d_scale, &ur.d_max.d_y.d_offset
00192         );
00193 
00194         return ur;
00195 }
00196 
00197 
00198 String PropertyHelper::floatToString(float val)
00199 {
00200         using namespace std;
00201 
00202         char buff[64];
00203         sprintf(buff, "%f", val);
00204 
00205         return String((utf8*)buff);
00206 }
00207 
00208 
00209 String PropertyHelper::uintToString(uint val)
00210 {
00211         using namespace std;
00212 
00213         char buff[64];
00214         sprintf(buff, "%u", val);
00215 
00216         return String((utf8*)buff);
00217 }
00218 
00219 
00220 String PropertyHelper::intToString(int val)
00221 {
00222         using namespace std;
00223 
00224         char buff[64];
00225         sprintf(buff, "%d", val);
00226 
00227         return String((utf8*)buff);
00228 }
00229 
00230 
00231 String PropertyHelper::boolToString(bool val)
00232 {
00233         if (val)
00234         {
00235                 return String((utf8*)"True");
00236         }
00237         else
00238         {
00239                 return String ((utf8*)"False");
00240         }
00241 
00242 }
00243 
00244 
00245 String PropertyHelper::sizeToString(const Size& val)
00246 {
00247         using namespace std;
00248 
00249         char buff[128];
00250         sprintf(buff, "w:%f h:%f", val.d_width, val.d_height);
00251 
00252         return String((utf8*)buff);
00253 }
00254 
00255 
00256 String PropertyHelper::pointToString(const Point& val)
00257 {
00258         using namespace std;
00259 
00260         char buff[128];
00261         sprintf(buff, "x:%f y:%f", val.d_x, val.d_y);
00262 
00263         return String((utf8*)buff);
00264 }
00265 
00266 
00267 String PropertyHelper::rectToString(const Rect& val)
00268 {
00269         using namespace std;
00270 
00271         char buff[256];
00272         sprintf(buff, "l:%f t:%f r:%f b:%f", val.d_left, val.d_top, val.d_right, val.d_bottom);
00273 
00274         return String((utf8*)buff);
00275 }
00276 
00277 
00278 String PropertyHelper::metricsModeToString(MetricsMode val)
00279 {
00280         if (val == Relative)
00281         {
00282                 return String((utf8*)"Relative");
00283         }
00284         else if (val == Absolute)
00285         {
00286                 return String((utf8*)"Absolute");
00287         }
00288         else
00289         {
00290                 return String((utf8*)"Inherited");
00291         }
00292 
00293 }
00294 
00295 
00296 String PropertyHelper::imageToString(const Image* const val)
00297 {
00298         if (val != NULL)
00299         {
00300                 return String((utf8*)"set:" + val->getImagesetName() + (utf8*)" image:" + val->getName());
00301         }
00302 
00303         return String((utf8*)"");
00304 }
00305 
00306 
00307 String PropertyHelper::udimToString(const UDim& val)
00308 {
00309         using namespace std;
00310 
00311         char buff[128];
00312         sprintf(buff, "{%f,%f}", val.d_scale, val.d_offset);
00313 
00314         return String((utf8*)buff);
00315 }
00316 
00317 
00318 String PropertyHelper::uvector2ToString(const UVector2& val)
00319 {
00320         using namespace std;
00321 
00322         char buff[256];
00323         sprintf(buff, "{{%f,%f},{%f,%f}}", val.d_x.d_scale, val.d_x.d_offset, val.d_y.d_scale, val.d_y.d_offset);
00324 
00325         return String((utf8*)buff);
00326 }
00327 
00328 
00329 String PropertyHelper::urectToString(const URect& val)
00330 {
00331         using namespace std;
00332 
00333         char buff[512];
00334         sprintf(
00335                 buff,
00336                 "{{%f,%f},{%f,%f},{%f,%f},{%f,%f}}",
00337                 val.d_min.d_x.d_scale,val.d_min.d_x.d_offset,
00338                 val.d_min.d_y.d_scale,val.d_min.d_y.d_offset,
00339                 val.d_max.d_x.d_scale,val.d_max.d_x.d_offset,
00340                 val.d_max.d_y.d_scale,val.d_max.d_y.d_offset
00341         );
00342 
00343         return String((utf8*)buff);
00344 }
00345 
00346 
00347 String PropertyHelper::colourToString(const colour& val)
00348 {
00349         using namespace std;
00350 
00351         char buff[16];
00352         sprintf(buff, "%.8X", val.getARGB());
00353 
00354         return String((utf8*)buff);
00355 }
00356 
00357 
00358 colour PropertyHelper::stringToColour(const String& str)
00359 {
00360         using namespace std;
00361 
00362         argb_t val = 0xFF000000;
00363         sscanf(str.c_str(), " %8X", &val);
00364 
00365         return colour(val);
00366 
00367 }
00368 
00369 
00370 String PropertyHelper::colourRectToString(const ColourRect& val)
00371 {
00372         using namespace std;
00373 
00374         char buff[64];
00375         sprintf(buff, "tl:%.8X tr:%.8X bl:%.8X br:%.8X", val.d_top_left.getARGB(), val.d_top_right.getARGB(), val.d_bottom_left.getARGB(), val.d_bottom_right.getARGB());
00376 
00377         return String((utf8*)buff);
00378 }
00379 
00380 
00381 ColourRect PropertyHelper::stringToColourRect(const String& str)
00382 {
00383         using namespace std;
00384 
00385         argb_t topLeft = 0xFF000000, topRight = 0xFF000000, bottomLeft = 0xFF000000, bottomRight = 0xFF000000;
00386         sscanf(str.c_str(), "tl:%8X tr:%8X bl:%8X br:%8X", &topLeft, &topRight, &bottomLeft, &bottomRight);
00387 
00388         return ColourRect(topLeft, topRight, bottomLeft, bottomRight);
00389 }
00390 
00391 } // End of  CEGUI namespace section

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