29 #ifndef _CEGUIPropertyHelper_h_
30 #define _CEGUIPropertyHelper_h_
32 #include "CEGUI/String.h"
33 #include "CEGUI/Size.h"
34 #include "CEGUI/Vector.h"
35 #include "CEGUI/Quaternion.h"
36 #include "CEGUI/Colour.h"
37 #include "CEGUI/ColourRect.h"
38 #include "CEGUI/UDim.h"
39 #include "CEGUI/Rect.h"
47 # pragma warning(push)
48 # pragma warning(disable : 4996)
52 #define snprintf _snprintf
57 #if __USE_MINGW_ANSI_STDIO != 1
58 #warning __USE_MINGW_ANSI_STDIO must be set to 1 for sscanf and snprintf to work with 64bit integers
61 #pragma GCC diagnostic push
65 #pragma GCC diagnostic ignored "-Wformat"
66 #pragma GCC diagnostic ignored "-Wformat-extra-args"
88 class PropertyHelper<const T>
91 typedef typename PropertyHelper<T>::return_type return_type;
92 typedef typename PropertyHelper<T>::safe_method_return_type safe_method_return_type;
93 typedef typename PropertyHelper<T>::pass_type pass_type;
94 typedef typename PropertyHelper<T>::string_return_type string_return_type;
96 static inline const String& getDataTypeName()
98 return PropertyHelper<T>::getDataTypeName();
101 static inline return_type fromString(
const String& str)
103 return PropertyHelper<T>::fromString(str);
106 static inline String toString(pass_type val)
108 return PropertyHelper<T>::toString(val);
122 static inline const String& getDataTypeName()
127 static inline return_type fromString(
const String& str)
129 return PropertyHelper<T>::fromString(str);
132 static inline String toString(pass_type val)
134 return PropertyHelper<T>::toString(val);
148 static inline const String& getDataTypeName()
153 static inline return_type fromString(
const String& str)
155 return PropertyHelper<T*>::fromString(str);
158 static inline String toString(pass_type val)
160 return PropertyHelper<T*>::toString(val);
168 typedef const String& return_type;
169 typedef String safe_method_return_type;
170 typedef const String& pass_type;
171 typedef const String& string_return_type;
173 static const String& getDataTypeName()
175 static String type(
"String");
180 static inline return_type fromString(
const String& str)
185 static inline string_return_type toString(pass_type val)
192 class PropertyHelper<float>
195 typedef float return_type;
196 typedef return_type safe_method_return_type;
197 typedef const float pass_type;
198 typedef String string_return_type;
200 static const String& getDataTypeName()
202 static String type(
"float");
207 static inline return_type fromString(
const String& str)
210 sscanf(str.c_str(),
" %g", &val);
218 snprintf(buff,
sizeof(buff),
"%g", val);
224 class PropertyHelper<double>
227 typedef double return_type;
228 typedef return_type safe_method_return_type;
229 typedef const double pass_type;
230 typedef String string_return_type;
232 static const String& getDataTypeName()
234 static String type(
"double");
239 static inline return_type fromString(
const String& str)
242 sscanf(str.c_str(),
" %lg", &val);
250 snprintf(buff,
sizeof(buff),
"%g", val);
257 class PropertyHelper<int>
260 typedef int return_type;
261 typedef return_type safe_method_return_type;
262 typedef const int pass_type;
263 typedef String string_return_type;
265 static const String& getDataTypeName()
267 static String type(
"int");
272 static inline return_type fromString(
const String& str)
275 sscanf(str.c_str(),
" %d", &val);
283 snprintf(buff,
sizeof(buff),
"%d", val);
290 class PropertyHelper<uint>
293 typedef uint return_type;
294 typedef return_type safe_method_return_type;
295 typedef const uint pass_type;
296 typedef String string_return_type;
298 static const String& getDataTypeName()
300 static String type(
"uint");
305 static return_type fromString(
const String& str)
308 sscanf(str.c_str(),
" %u", &val);
316 snprintf(buff,
sizeof(buff),
"%u", val);
323 class PropertyHelper<uint64>
326 typedef uint64 return_type;
327 typedef return_type safe_method_return_type;
328 typedef const uint64 pass_type;
329 typedef String string_return_type;
331 static const String& getDataTypeName()
333 static String type(
"uint64");
338 static return_type fromString(
const String& str)
341 sscanf(str.c_str(),
" %llu", &val);
349 snprintf(buff,
sizeof(buff),
"%llu", val);
355 #if CEGUI_STRING_CLASS != CEGUI_STRING_CLASS_UNICODE
358 class PropertyHelper<String::value_type>
362 typedef return_type safe_method_return_type;
364 typedef String string_return_type;
366 static const String& getDataTypeName()
368 static String type(
"char");
373 static return_type fromString(
const String& str)
378 static string_return_type toString(pass_type val)
380 return String(
"") + val;
387 class PropertyHelper<unsigned long>
390 typedef unsigned long return_type;
391 typedef return_type safe_method_return_type;
392 typedef const unsigned long pass_type;
393 typedef String string_return_type;
395 static const String& getDataTypeName()
397 static String type(
"unsigned long");
402 static return_type fromString(
const String& str)
404 unsigned long val = 0;
405 sscanf(str.c_str(),
" %lu", &val);
413 snprintf(buff,
sizeof(buff),
"%lu", val);
420 class CEGUIEXPORT PropertyHelper<bool>
423 typedef bool return_type;
424 typedef return_type safe_method_return_type;
425 typedef const bool pass_type;
426 typedef const String& string_return_type;
428 static const String& getDataTypeName()
430 static String type(
"bool");
435 static return_type fromString(
const String& str)
437 return (str == True || str ==
"True");
440 static string_return_type toString(pass_type val)
442 return val ? True : False;
457 typedef return_type safe_method_return_type;
459 typedef String string_return_type;
461 static const String& getDataTypeName()
463 static String type(
"AspectMode");
468 static return_type fromString(
const String& str)
474 else if (str == Expand)
484 static string_return_type toString(pass_type val)
500 assert(
false &&
"Invalid aspect mode");
512 class PropertyHelper<Sizef >
515 typedef Sizef return_type;
516 typedef return_type safe_method_return_type;
517 typedef const Sizef& pass_type;
518 typedef String string_return_type;
520 static const String& getDataTypeName()
522 static String type(
"Sizef");
527 static return_type fromString(
const String& str)
530 sscanf(str.c_str(),
" w:%g h:%g", &val.d_width, &val.d_height);
538 snprintf(buff,
sizeof(buff),
"w:%g h:%g", val.d_width, val.d_height);
545 class PropertyHelper<Vector2f >
548 typedef Vector2f return_type;
549 typedef return_type safe_method_return_type;
550 typedef const Vector2f& pass_type;
551 typedef String string_return_type;
553 static const String& getDataTypeName()
555 static String type(
"Vector2f");
560 static return_type fromString(
const String& str)
563 sscanf(str.c_str(),
" x:%g y:%g", &val.d_x, &val.d_y);
571 snprintf(buff,
sizeof(buff),
"x:%g y:%g", val.d_x, val.d_y);
578 class PropertyHelper<Vector3f >
581 typedef Vector3f return_type;
582 typedef return_type safe_method_return_type;
583 typedef const Vector3f& pass_type;
584 typedef String string_return_type;
586 static const String& getDataTypeName()
588 static String type(
"Vector3f");
593 static return_type fromString(
const String& str)
595 Vector3f val(0, 0, 0);
596 sscanf(str.c_str(),
" x:%g y:%g z:%g", &val.d_x, &val.d_y, &val.d_z);
604 snprintf(buff,
sizeof(buff),
"x:%g y:%g z:%g", val.d_x, val.d_y, val.d_z);
611 class PropertyHelper<Quaternion>
614 typedef Quaternion return_type;
615 typedef return_type safe_method_return_type;
616 typedef const Quaternion& pass_type;
617 typedef String string_return_type;
619 static const String& getDataTypeName()
621 static String type(
"Quaternion");
626 static return_type fromString(
const String& str)
628 if (strchr(str.c_str(),
'w') || strchr(str.c_str(),
'W'))
630 Quaternion val(1, 0, 0, 0);
631 sscanf(str.c_str(),
" w:%g x:%g y:%g z:%g", &val.d_w, &val.d_x, &val.d_y, &val.d_z);
638 sscanf(str.c_str(),
" x:%g y:%g z:%g", &x, &y, &z);
643 static string_return_type toString(pass_type val)
646 snprintf(buff,
sizeof(buff),
"w:%g x:%g y:%g z:%g", val.d_w, val.d_x, val.d_y, val.d_z);
653 class PropertyHelper<Rectf >
656 typedef Rectf return_type;
657 typedef return_type safe_method_return_type;
658 typedef const Rectf& pass_type;
659 typedef String string_return_type;
661 static const String& getDataTypeName()
663 static String type(
"Rectf");
668 static return_type fromString(
const String& str)
670 Rectf val(0, 0, 0, 0);
671 sscanf(str.c_str(),
" l:%g t:%g r:%g b:%g", &val.d_min.d_x, &val.d_min.d_y, &val.d_max.d_x, &val.d_max.d_y);
679 snprintf(buff,
sizeof(buff),
"l:%g t:%g r:%g b:%g",
680 val.d_min.d_x, val.d_min.d_y, val.d_max.d_x, val.d_max.d_y);
687 class CEGUIEXPORT PropertyHelper<Image*>
690 typedef const Image* return_type;
691 typedef return_type safe_method_return_type;
692 typedef const Image*
const pass_type;
693 typedef String string_return_type;
695 static const String& getDataTypeName()
697 static String type(
"Image");
702 static return_type fromString(
const String& str);
704 static string_return_type toString(pass_type val);
708 class PropertyHelper<Colour>
711 typedef Colour return_type;
712 typedef return_type safe_method_return_type;
713 typedef const Colour& pass_type;
716 static const String& getDataTypeName()
718 static String type(
"Colour");
723 static return_type fromString(
const String& str)
726 sscanf(str.
c_str(),
" %8X", &val);
734 sprintf(buff,
"%.8X", val.getARGB());
741 class PropertyHelper<ColourRect>
744 typedef ColourRect return_type;
745 typedef return_type safe_method_return_type;
746 typedef const ColourRect& pass_type;
747 typedef String string_return_type;
749 static const String& getDataTypeName()
751 static String type(
"ColourRect");
756 static return_type fromString(
const String& str)
758 if (str.length() == 8)
761 sscanf(str.c_str(),
"%8X", &all);
762 return ColourRect(all);
765 argb_t topLeft = 0xFF000000, topRight = 0xFF000000, bottomLeft = 0xFF000000, bottomRight = 0xFF000000;
766 sscanf(str.c_str(),
"tl:%8X tr:%8X bl:%8X br:%8X", &topLeft, &topRight, &bottomLeft, &bottomRight);
768 return ColourRect(topLeft, topRight, bottomLeft, bottomRight);
771 static string_return_type toString(pass_type val)
774 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());
781 class PropertyHelper<UDim>
784 typedef UDim return_type;
785 typedef return_type safe_method_return_type;
786 typedef const UDim& pass_type;
787 typedef String string_return_type;
789 static const String& getDataTypeName()
791 static String type(
"UDim");
796 static return_type fromString(
const String& str)
799 sscanf(str.c_str(),
" { %g , %g }", &ud.d_scale, &ud.d_offset);
807 snprintf(buff,
sizeof(buff),
"{%g,%g}", val.d_scale, val.d_offset);
814 class PropertyHelper<UVector2>
817 typedef UVector2 return_type;
818 typedef return_type safe_method_return_type;
819 typedef const UVector2& pass_type;
820 typedef String string_return_type;
822 static const String& getDataTypeName()
824 static String type(
"UVector2");
829 static return_type fromString(
const String& str)
832 sscanf(str.c_str(),
" { { %g , %g } , { %g , %g } }",
833 &uv.d_x.d_scale, &uv.d_x.d_offset,
834 &uv.d_y.d_scale, &uv.d_y.d_offset);
839 static string_return_type toString(pass_type val)
842 snprintf(buff,
sizeof(buff),
"{{%g,%g},{%g,%g}}",
843 val.d_x.d_scale, val.d_x.d_offset, val.d_y.d_scale, val.d_y.d_offset);
850 class PropertyHelper<USize>
853 typedef USize return_type;
854 typedef return_type safe_method_return_type;
855 typedef const USize& pass_type;
856 typedef String string_return_type;
858 static const String& getDataTypeName()
860 static String type(
"USize");
865 static return_type fromString(
const String& str)
868 sscanf(str.c_str(),
" { { %g , %g } , { %g , %g } }",
869 &uv.d_width.d_scale, &uv.d_width.d_offset,
870 &uv.d_height.d_scale, &uv.d_height.d_offset);
875 static string_return_type toString(pass_type val)
878 snprintf(buff,
sizeof(buff),
"{{%g,%g},{%g,%g}}",
879 val.d_width.d_scale, val.d_width.d_offset, val.d_height.d_scale, val.d_height.d_offset);
886 class PropertyHelper<URect>
889 typedef URect return_type;
890 typedef return_type safe_method_return_type;
891 typedef const URect& pass_type;
892 typedef String string_return_type;
894 static const String& getDataTypeName()
896 static String type(
"URect");
901 static return_type fromString(
const String& str)
906 " { { %g , %g } , { %g , %g } , { %g , %g } , { %g , %g } }",
907 &ur.d_min.d_x.d_scale, &ur.d_min.d_x.d_offset,
908 &ur.d_min.d_y.d_scale, &ur.d_min.d_y.d_offset,
909 &ur.d_max.d_x.d_scale, &ur.d_max.d_x.d_offset,
910 &ur.d_max.d_y.d_scale, &ur.d_max.d_y.d_offset
916 static string_return_type toString(pass_type val)
919 snprintf(buff,
sizeof(buff),
"{{%g,%g},{%g,%g},{%g,%g},{%g,%g}}",
920 val.d_min.d_x.d_scale, val.d_min.d_x.d_offset,
921 val.d_min.d_y.d_scale, val.d_min.d_y.d_offset,
922 val.d_max.d_x.d_scale, val.d_max.d_x.d_offset,
923 val.d_max.d_y.d_scale, val.d_max.d_y.d_offset);
930 class PropertyHelper<UBox>
933 typedef UBox return_type;
934 typedef return_type safe_method_return_type;
935 typedef const UBox& pass_type;
936 typedef String string_return_type;
938 static const String& getDataTypeName()
940 static String type(
"UBox");
945 static return_type fromString(
const String& str)
950 " { top: { %g , %g } , left: { %g , %g } , bottom: { %g , %g } , right: { %g , %g } }",
951 &ret.d_top.d_scale, &ret.d_top.d_offset,
952 &ret.d_left.d_scale, &ret.d_left.d_offset,
953 &ret.d_bottom.d_scale, &ret.d_bottom.d_offset,
954 &ret.d_right.d_scale, &ret.d_right.d_offset
960 static string_return_type toString(pass_type val)
963 snprintf(buff,
sizeof(buff),
"{top:{%g,%g},left:{%g,%g},bottom:{%g,%g},right:{%g,%g}}",
964 val.d_top.d_scale, val.d_top.d_offset,
965 val.d_left.d_scale, val.d_left.d_offset,
966 val.d_bottom.d_scale, val.d_bottom.d_offset,
967 val.d_right.d_scale, val.d_right.d_offset);
975 class CEGUIEXPORT PropertyHelper<Font*>
978 typedef const Font* return_type;
979 typedef return_type safe_method_return_type;
980 typedef const Font*
const pass_type;
981 typedef String string_return_type;
983 static const String& getDataTypeName()
985 static String type(
"Font");
990 static return_type fromString(
const String& str);
991 static string_return_type toString(pass_type val);
997 #pragma GCC diagnostic pop
1000 #if defined(_MSC_VER)
1001 #pragma warning(pop)