00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "CEGUIPropertyHelper.h"
00027 #include "CEGUIImagesetManager.h"
00028 #include "CEGUIImageset.h"
00029 #include "CEGUIExceptions.h"
00030
00031 #include <cstdio>
00032
00033
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 bool PropertyHelper::stringToBool(const String& str)
00059 {
00060 if ((str == (utf8*)"True") || (str == (utf8*)"true"))
00061 {
00062 return true;
00063 }
00064 else
00065 {
00066 return false;
00067 }
00068
00069 }
00070
00071
00072 Size PropertyHelper::stringToSize(const String& str)
00073 {
00074 using namespace std;
00075
00076 Size val(0,0);
00077 sscanf(str.c_str(), " w:%f h:%f", &val.d_width, &val.d_height);
00078
00079 return val;
00080 }
00081
00082
00083 Point PropertyHelper::stringToPoint(const String& str)
00084 {
00085 using namespace std;
00086
00087 Point val(0,0) ;
00088 sscanf(str.c_str(), " x:%f y:%f", &val.d_x, &val.d_y);
00089
00090 return val;
00091 }
00092
00093
00094 Rect PropertyHelper::stringToRect(const String& str)
00095 {
00096 using namespace std;
00097
00098 Rect val(0, 0, 0, 0);
00099 sscanf(str.c_str(), " l:%f t:%f r:%f b:%f", &val.d_left, &val.d_top, &val.d_right, &val.d_bottom);
00100
00101 return val;
00102 }
00103
00104
00105 MetricsMode PropertyHelper::stringToMetricsMode(const String& str)
00106 {
00107 if (str == (utf8*)"Relative")
00108 {
00109 return Relative;
00110 }
00111 else if (str == (utf8*)"Absolute")
00112 {
00113 return Absolute;
00114 }
00115 else
00116 {
00117 return Inherited;
00118 }
00119
00120 }
00121
00122
00123 const Image* PropertyHelper::stringToImage(const String& str)
00124 {
00125 using namespace std;
00126
00127 char imageSet[128];
00128 char imageName[128];
00129
00130 sscanf(str.c_str(), " set:%127s image:%127s", imageSet, imageName);
00131
00132 const Image* image;
00133
00134 try
00135 {
00136 image = &ImagesetManager::getSingleton().getImageset((utf8*)imageSet)->getImage((utf8*)imageName);
00137 }
00138 catch (UnknownObjectException)
00139 {
00140 image = NULL;
00141 }
00142
00143 return image;
00144 }
00145
00146
00147 String PropertyHelper::floatToString(float val)
00148 {
00149 using namespace std;
00150
00151 char buff[64];
00152 sprintf(buff, "%f", val);
00153
00154 return String((utf8*)buff);
00155 }
00156
00157
00158 String PropertyHelper::uintToString(uint val)
00159 {
00160 using namespace std;
00161
00162 char buff[64];
00163 sprintf(buff, "%u", val);
00164
00165 return String((utf8*)buff);
00166 }
00167
00168
00169 String PropertyHelper::boolToString(bool val)
00170 {
00171 if (val)
00172 {
00173 return String((utf8*)"True");
00174 }
00175 else
00176 {
00177 return String ((utf8*)"False");
00178 }
00179
00180 }
00181
00182
00183 String PropertyHelper::sizeToString(const Size& val)
00184 {
00185 using namespace std;
00186
00187 char buff[128];
00188 sprintf(buff, "w:%f h:%f", val.d_width, val.d_height);
00189
00190 return String((utf8*)buff);
00191 }
00192
00193
00194 String PropertyHelper::pointToString(const Point& val)
00195 {
00196 using namespace std;
00197
00198 char buff[128];
00199 sprintf(buff, "x:%f y:%f", val.d_x, val.d_y);
00200
00201 return String((utf8*)buff);
00202 }
00203
00204
00205 String PropertyHelper::rectToString(const Rect& val)
00206 {
00207 using namespace std;
00208
00209 char buff[256];
00210 sprintf(buff, "l:%f t:%f r:%f b:%f", val.d_left, val.d_top, val.d_right, val.d_bottom);
00211
00212 return String((utf8*)buff);
00213 }
00214
00215
00216 String PropertyHelper::metricsModeToString(MetricsMode val)
00217 {
00218 if (val == Relative)
00219 {
00220 return String((utf8*)"Relative");
00221 }
00222 else if (val == Absolute)
00223 {
00224 return String((utf8*)"Absolute");
00225 }
00226 else
00227 {
00228 return String((utf8*)"Inherited");
00229 }
00230
00231 }
00232
00233
00234 String PropertyHelper::imageToString(const Image* const val)
00235 {
00236 if (val != NULL)
00237 {
00238 return String((utf8*)"set:" + val->getImagesetName() + (utf8*)" image:" + val->getName());
00239 }
00240
00241 return String((utf8*)"");
00242 }
00243
00244
00245 String PropertyHelper::colourToString(const colour& val)
00246 {
00247 using namespace std;
00248
00249 char buff[16];
00250 sprintf(buff, "%.8X", val.getARGB());
00251
00252 return String((utf8*)buff);
00253 }
00254
00255
00256 colour PropertyHelper::stringToColour(const String& str)
00257 {
00258 using namespace std;
00259
00260 ulong val = 0xFF000000;
00261 sscanf(str.c_str(), " %8X", &val);
00262
00263 return colour(val);
00264
00265 }
00266
00267
00268 String PropertyHelper::colourRectToString(const ColourRect& val)
00269 {
00270 using namespace std;
00271
00272 char buff[64];
00273 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());
00274
00275 return String((utf8*)buff);
00276 }
00277
00278
00279 ColourRect PropertyHelper::stringToColourRect(const String& str)
00280 {
00281 using namespace std;
00282
00283 ulong topLeft = 0xFF000000, topRight = 0xFF000000, bottomLeft = 0xFF000000, bottomRight = 0xFF000000;
00284 sscanf(str.c_str(), "tl:%8X tr:%8X bl:%8X br:%8X", &topLeft, &topRight, &bottomLeft, &bottomRight);
00285
00286 return ColourRect(topLeft, topRight, bottomLeft, bottomRight);
00287 }
00288
00289 }