1 /*********************************************************************** 2 created: 21/11/2010 3 author: Martin Preisler (reworked from code by Paul D Turner) 4 5 purpose: Interface to the PropertyHelper class 6 *************************************************************************/ 7 /*************************************************************************** 8 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining 11 * a copy of this software and associated documentation files (the 12 * "Software"), to deal in the Software without restriction, including 13 * without limitation the rights to use, copy, modify, merge, publish, 14 * distribute, sublicense, and/or sell copies of the Software, and to 15 * permit persons to whom the Software is furnished to do so, subject to 16 * the following conditions: 17 * 18 * The above copyright notice and this permission notice shall be 19 * included in all copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 * OTHER DEALINGS IN THE SOFTWARE. 28 ***************************************************************************/ 29 #ifndef _CEGUIPropertyHelper_h_ 30 #define _CEGUIPropertyHelper_h_ 31 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" 40 41 42 #include <cstdio> 43 44 #include <sstream> 45 46 #if defined(_MSC_VER) 47 # pragma warning(push) 48 # pragma warning(disable : 4996) 49 #endif 50 51 #ifdef _MSC_VER 52 #define snprintf _snprintf 53 #endif 54 55 #ifdef __MINGW32__ 56 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 59 #endif 60 61 #pragma GCC diagnostic push 62 63 /* Due to a bug in MinGW-w64, a false warning is sometimes issued when using 64 "%llu" format with the "printf"/"scanf" family of functions. */ 65 #pragma GCC diagnostic ignored "-Wformat" 66 #pragma GCC diagnostic ignored "-Wformat-extra-args" 67 68 #endif 69 70 namespace CEGUI 71 { 72 73 /*! 74 \brief 75 Helper class used to convert various data types to and from the format expected in Property strings 76 77 \par 78 Usage: 79 80 float value = PropertyHelper<float>::fromString("0.1"); 81 String value = PropertyHelper<float>::toString(0.1); 82 */ 83 template<typename T> 84 class PropertyHelper; 85 86 // this redirects PropertyHelper<const T> to PropertyHelper<T> 87 template<typename T> 88 class PropertyHelper<const T> 89 { 90 public: 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; 95 getDataTypeName()96 static inline const String& getDataTypeName() 97 { 98 return PropertyHelper<T>::getDataTypeName(); 99 } 100 fromString(const String & str)101 static inline return_type fromString(const String& str) 102 { 103 return PropertyHelper<T>::fromString(str); 104 } 105 toString(pass_type val)106 static inline String toString(pass_type val) 107 { 108 return PropertyHelper<T>::toString(val); 109 } 110 }; 111 112 // this redirects PropertyHelper<const T&> to PropertyHelper<T> 113 template<typename T> 114 class PropertyHelper<const T&> 115 { 116 public: 117 typedef typename PropertyHelper<T>::return_type return_type; 118 typedef typename PropertyHelper<T>::safe_method_return_type safe_method_return_type; 119 typedef typename PropertyHelper<T>::pass_type pass_type; 120 typedef typename PropertyHelper<T>::string_return_type string_return_type; 121 getDataTypeName()122 static inline const String& getDataTypeName() 123 { 124 return PropertyHelper<T>::getDataTypeName(); 125 } 126 fromString(const String & str)127 static inline return_type fromString(const String& str) 128 { 129 return PropertyHelper<T>::fromString(str); 130 } 131 toString(pass_type val)132 static inline String toString(pass_type val) 133 { 134 return PropertyHelper<T>::toString(val); 135 } 136 }; 137 138 // this redirects PropertyHelper<const T*> to PropertyHelper<T*> 139 template<typename T> 140 class PropertyHelper<const T*> 141 { 142 public: 143 typedef typename PropertyHelper<T*>::return_type return_type; 144 typedef typename PropertyHelper<T*>::safe_method_return_type safe_method_return_type; 145 typedef typename PropertyHelper<T*>::pass_type pass_type; 146 typedef typename PropertyHelper<T*>::string_return_type string_return_type; 147 getDataTypeName()148 static inline const String& getDataTypeName() 149 { 150 return PropertyHelper<T>::getDataTypeName(); 151 } 152 fromString(const String & str)153 static inline return_type fromString(const String& str) 154 { 155 return PropertyHelper<T*>::fromString(str); 156 } 157 toString(pass_type val)158 static inline String toString(pass_type val) 159 { 160 return PropertyHelper<T*>::toString(val); 161 } 162 }; 163 164 template<> 165 class PropertyHelper<String> 166 { 167 public: 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; 172 getDataTypeName()173 static const String& getDataTypeName() 174 { 175 static String type("String"); 176 177 return type; 178 } 179 fromString(const String & str)180 static inline return_type fromString(const String& str) 181 { 182 return str; 183 } 184 toString(pass_type val)185 static inline string_return_type toString(pass_type val) 186 { 187 return val; 188 } 189 }; 190 191 template<> 192 class PropertyHelper<float> 193 { 194 public: 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; 199 getDataTypeName()200 static const String& getDataTypeName() 201 { 202 static String type("float"); 203 204 return type; 205 } 206 fromString(const String & str)207 static inline return_type fromString(const String& str) 208 { 209 float val = 0; 210 sscanf(str.c_str(), " %g", &val); 211 212 return val; 213 } 214 toString(pass_type val)215 static inline string_return_type toString(pass_type val) 216 { 217 char buff[64]; 218 snprintf(buff, sizeof(buff), "%g", val); 219 220 return String(buff); 221 } 222 }; 223 template<> 224 class PropertyHelper<double> 225 { 226 public: 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; 231 getDataTypeName()232 static const String& getDataTypeName() 233 { 234 static String type("double"); 235 236 return type; 237 } 238 fromString(const String & str)239 static inline return_type fromString(const String& str) 240 { 241 double val = 0; 242 sscanf(str.c_str(), " %lg", &val); 243 244 return val; 245 } 246 toString(pass_type val)247 static inline string_return_type toString(pass_type val) 248 { 249 char buff[64]; 250 snprintf(buff, sizeof(buff), "%g", val); 251 252 return String(buff); 253 } 254 }; 255 256 template<> 257 class PropertyHelper<int> 258 { 259 public: 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; 264 getDataTypeName()265 static const String& getDataTypeName() 266 { 267 static String type("int"); 268 269 return type; 270 } 271 fromString(const String & str)272 static inline return_type fromString(const String& str) 273 { 274 int val = 0; 275 sscanf(str.c_str(), " %d", &val); 276 277 return val; 278 } 279 toString(pass_type val)280 static inline string_return_type toString(pass_type val) 281 { 282 char buff[64]; 283 snprintf(buff, sizeof(buff), "%d", val); 284 285 return String(buff); 286 } 287 }; 288 289 template<> 290 class PropertyHelper<uint> 291 { 292 public: 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; 297 getDataTypeName()298 static const String& getDataTypeName() 299 { 300 static String type("uint"); 301 302 return type; 303 } 304 fromString(const String & str)305 static return_type fromString(const String& str) 306 { 307 uint val = 0; 308 sscanf(str.c_str(), " %u", &val); 309 310 return val; 311 } 312 toString(pass_type val)313 static string_return_type toString(pass_type val) 314 { 315 char buff[64]; 316 snprintf(buff, sizeof(buff), "%u", val); 317 318 return String(buff); 319 } 320 }; 321 322 template<> 323 class PropertyHelper<uint64> 324 { 325 public: 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; 330 getDataTypeName()331 static const String& getDataTypeName() 332 { 333 static String type("uint64"); 334 335 return type; 336 } 337 fromString(const String & str)338 static return_type fromString(const String& str) 339 { 340 uint64 val = 0; 341 sscanf(str.c_str(), " %llu", &val); 342 343 return val; 344 } 345 toString(pass_type val)346 static string_return_type toString(pass_type val) 347 { 348 char buff[64]; 349 snprintf(buff, sizeof(buff), "%llu", val); 350 351 return String(buff); 352 } 353 }; 354 355 #if CEGUI_STRING_CLASS != CEGUI_STRING_CLASS_UNICODE 356 357 template<> 358 class PropertyHelper<String::value_type> 359 { 360 public: 361 typedef String::value_type return_type; 362 typedef return_type safe_method_return_type; 363 typedef const String::value_type pass_type; 364 typedef String string_return_type; 365 getDataTypeName()366 static const String& getDataTypeName() 367 { 368 static String type("char"); 369 370 return type; 371 } 372 fromString(const String & str)373 static return_type fromString(const String& str) 374 { 375 return str[0]; 376 } 377 toString(pass_type val)378 static string_return_type toString(pass_type val) 379 { 380 return String("") + val; 381 } 382 }; 383 384 #endif 385 386 template<> 387 class PropertyHelper<unsigned long> 388 { 389 public: 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; 394 getDataTypeName()395 static const String& getDataTypeName() 396 { 397 static String type("unsigned long"); 398 399 return type; 400 } 401 fromString(const String & str)402 static return_type fromString(const String& str) 403 { 404 unsigned long val = 0; 405 sscanf(str.c_str(), " %lu", &val); 406 407 return val; 408 } 409 toString(pass_type val)410 static string_return_type toString(pass_type val) 411 { 412 char buff[64]; 413 snprintf(buff, sizeof(buff), "%lu", val); 414 415 return String(buff); 416 } 417 }; 418 419 template<> 420 class CEGUIEXPORT PropertyHelper<bool> 421 { 422 public: 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; 427 getDataTypeName()428 static const String& getDataTypeName() 429 { 430 static String type("bool"); 431 432 return type; 433 } 434 fromString(const String & str)435 static return_type fromString(const String& str) 436 { 437 return (str == True || str == "True"); 438 } 439 toString(pass_type val)440 static string_return_type toString(pass_type val) 441 { 442 return val ? True : False; 443 } 444 445 //! Definitions of the possible values represented as Strings 446 static const CEGUI::String True; 447 static const CEGUI::String False; 448 }; 449 450 451 452 template<> 453 class CEGUIEXPORT PropertyHelper<AspectMode> 454 { 455 public: 456 typedef AspectMode return_type; 457 typedef return_type safe_method_return_type; 458 typedef AspectMode pass_type; 459 typedef String string_return_type; 460 getDataTypeName()461 static const String& getDataTypeName() 462 { 463 static String type("AspectMode"); 464 465 return type; 466 } 467 fromString(const String & str)468 static return_type fromString(const String& str) 469 { 470 if (str == Shrink) 471 { 472 return AM_SHRINK; 473 } 474 else if (str == Expand) 475 { 476 return AM_EXPAND; 477 } 478 else 479 { 480 return AM_IGNORE; 481 } 482 } 483 toString(pass_type val)484 static string_return_type toString(pass_type val) 485 { 486 if (val == AM_IGNORE) 487 { 488 return Ignore; 489 } 490 else if (val == AM_SHRINK) 491 { 492 return Shrink; 493 } 494 else if (val == AM_EXPAND) 495 { 496 return Expand; 497 } 498 else 499 { 500 assert(false && "Invalid aspect mode"); 501 return Ignore; 502 } 503 } 504 505 //! Definitions of the possible values represented as Strings 506 static const CEGUI::String Shrink; 507 static const CEGUI::String Expand; 508 static const CEGUI::String Ignore; 509 }; 510 511 template<> 512 class PropertyHelper<Sizef > 513 { 514 public: 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; 519 getDataTypeName()520 static const String& getDataTypeName() 521 { 522 static String type("Sizef"); 523 524 return type; 525 } 526 fromString(const String & str)527 static return_type fromString(const String& str) 528 { 529 Sizef val(0, 0); 530 sscanf(str.c_str(), " w:%g h:%g", &val.d_width, &val.d_height); 531 532 return val; 533 } 534 toString(pass_type val)535 static string_return_type toString(pass_type val) 536 { 537 char buff[128]; 538 snprintf(buff, sizeof(buff), "w:%g h:%g", val.d_width, val.d_height); 539 540 return String(buff); 541 } 542 }; 543 544 template<> 545 class PropertyHelper<Vector2f > 546 { 547 public: 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; 552 getDataTypeName()553 static const String& getDataTypeName() 554 { 555 static String type("Vector2f"); 556 557 return type; 558 } 559 fromString(const String & str)560 static return_type fromString(const String& str) 561 { 562 Vector2f val(0, 0) ; 563 sscanf(str.c_str(), " x:%g y:%g", &val.d_x, &val.d_y); 564 565 return val; 566 } 567 toString(pass_type val)568 static string_return_type toString(pass_type val) 569 { 570 char buff[128]; 571 snprintf(buff, sizeof(buff), "x:%g y:%g", val.d_x, val.d_y); 572 573 return String(buff); 574 } 575 }; 576 577 template<> 578 class PropertyHelper<Vector3f > 579 { 580 public: 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; 585 getDataTypeName()586 static const String& getDataTypeName() 587 { 588 static String type("Vector3f"); 589 590 return type; 591 } 592 fromString(const String & str)593 static return_type fromString(const String& str) 594 { 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); 597 598 return val; 599 } 600 toString(pass_type val)601 static string_return_type toString(pass_type val) 602 { 603 char buff[128]; 604 snprintf(buff, sizeof(buff), "x:%g y:%g z:%g", val.d_x, val.d_y, val.d_z); 605 606 return String(buff); 607 } 608 }; 609 610 template<> 611 class PropertyHelper<Quaternion> 612 { 613 public: 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; 618 getDataTypeName()619 static const String& getDataTypeName() 620 { 621 static String type("Quaternion"); 622 623 return type; 624 } 625 fromString(const String & str)626 static return_type fromString(const String& str) 627 { 628 if (strchr(str.c_str(), 'w') || strchr(str.c_str(), 'W')) 629 { 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); 632 633 return val; 634 } 635 else 636 { 637 float x, y, z; 638 sscanf(str.c_str(), " x:%g y:%g z:%g", &x, &y, &z); 639 return Quaternion::eulerAnglesDegrees(x, y, z); 640 } 641 } 642 toString(pass_type val)643 static string_return_type toString(pass_type val) 644 { 645 char buff[128]; 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); 647 648 return String(buff); 649 } 650 }; 651 652 template<> 653 class PropertyHelper<Rectf > 654 { 655 public: 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; 660 getDataTypeName()661 static const String& getDataTypeName() 662 { 663 static String type("Rectf"); 664 665 return type; 666 } 667 fromString(const String & str)668 static return_type fromString(const String& str) 669 { 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); 672 673 return val; 674 } 675 toString(pass_type val)676 static string_return_type toString(pass_type val) 677 { 678 char buff[256]; 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); 681 682 return String(buff); 683 } 684 }; 685 686 template<> 687 class CEGUIEXPORT PropertyHelper<Image*> 688 { 689 public: 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; 694 getDataTypeName()695 static const String& getDataTypeName() 696 { 697 static String type("Image"); 698 699 return type; 700 } 701 702 static return_type fromString(const String& str); 703 704 static string_return_type toString(pass_type val); 705 }; 706 707 template<> 708 class PropertyHelper<Colour> 709 { 710 public: 711 typedef Colour return_type; 712 typedef return_type safe_method_return_type; 713 typedef const Colour& pass_type; 714 typedef String string_return_type; 715 getDataTypeName()716 static const String& getDataTypeName() 717 { 718 static String type("Colour"); 719 720 return type; 721 } 722 fromString(const String & str)723 static return_type fromString(const String& str) 724 { 725 argb_t val = 0xFF000000; 726 sscanf(str.c_str(), " %8X", &val); 727 728 return Colour(val); 729 } 730 toString(pass_type val)731 static string_return_type toString(pass_type val) 732 { 733 char buff[16]; 734 sprintf(buff, "%.8X", val.getARGB()); 735 736 return String(buff); 737 } 738 }; 739 740 template<> 741 class PropertyHelper<ColourRect> 742 { 743 public: 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; 748 getDataTypeName()749 static const String& getDataTypeName() 750 { 751 static String type("ColourRect"); 752 753 return type; 754 } 755 fromString(const String & str)756 static return_type fromString(const String& str) 757 { 758 if (str.length() == 8) 759 { 760 argb_t all = 0xFF000000; 761 sscanf(str.c_str(), "%8X", &all); 762 return ColourRect(all); 763 } 764 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); 767 768 return ColourRect(topLeft, topRight, bottomLeft, bottomRight); 769 } 770 toString(pass_type val)771 static string_return_type toString(pass_type val) 772 { 773 char buff[64]; 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()); 775 776 return String(buff); 777 } 778 }; 779 780 template<> 781 class PropertyHelper<UDim> 782 { 783 public: 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; 788 getDataTypeName()789 static const String& getDataTypeName() 790 { 791 static String type("UDim"); 792 793 return type; 794 } 795 fromString(const String & str)796 static return_type fromString(const String& str) 797 { 798 UDim ud; 799 sscanf(str.c_str(), " { %g , %g }", &ud.d_scale, &ud.d_offset); 800 801 return ud; 802 } 803 toString(pass_type val)804 static string_return_type toString(pass_type val) 805 { 806 char buff[128]; 807 snprintf(buff, sizeof(buff), "{%g,%g}", val.d_scale, val.d_offset); 808 809 return String(buff); 810 } 811 }; 812 813 template<> 814 class PropertyHelper<UVector2> 815 { 816 public: 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; 821 getDataTypeName()822 static const String& getDataTypeName() 823 { 824 static String type("UVector2"); 825 826 return type; 827 } 828 fromString(const String & str)829 static return_type fromString(const String& str) 830 { 831 UVector2 uv; 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); 835 836 return uv; 837 } 838 toString(pass_type val)839 static string_return_type toString(pass_type val) 840 { 841 char buff[256]; 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); 844 845 return String(buff); 846 } 847 }; 848 849 template<> 850 class PropertyHelper<USize> 851 { 852 public: 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; 857 getDataTypeName()858 static const String& getDataTypeName() 859 { 860 static String type("USize"); 861 862 return type; 863 } 864 fromString(const String & str)865 static return_type fromString(const String& str) 866 { 867 USize uv; 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); 871 872 return uv; 873 } 874 toString(pass_type val)875 static string_return_type toString(pass_type val) 876 { 877 char buff[256]; 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); 880 881 return String(buff); 882 } 883 }; 884 885 template<> 886 class PropertyHelper<URect> 887 { 888 public: 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; 893 getDataTypeName()894 static const String& getDataTypeName() 895 { 896 static String type("URect"); 897 898 return type; 899 } 900 fromString(const String & str)901 static return_type fromString(const String& str) 902 { 903 URect ur; 904 sscanf( 905 str.c_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 911 ); 912 913 return ur; 914 } 915 toString(pass_type val)916 static string_return_type toString(pass_type val) 917 { 918 char buff[512]; 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); 924 925 return String(buff); 926 } 927 }; 928 929 template<> 930 class PropertyHelper<UBox> 931 { 932 public: 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; 937 getDataTypeName()938 static const String& getDataTypeName() 939 { 940 static String type("UBox"); 941 942 return type; 943 } 944 fromString(const String & str)945 static return_type fromString(const String& str) 946 { 947 UBox ret; 948 sscanf( 949 str.c_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 955 ); 956 957 return ret; 958 } 959 toString(pass_type val)960 static string_return_type toString(pass_type val) 961 { 962 char buff[512]; 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); 968 969 return String(buff); 970 } 971 }; 972 973 974 template<> 975 class CEGUIEXPORT PropertyHelper<Font*> 976 { 977 public: 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; 982 getDataTypeName()983 static const String& getDataTypeName() 984 { 985 static String type("Font"); 986 987 return type; 988 } 989 990 static return_type fromString(const String& str); 991 static string_return_type toString(pass_type val); 992 }; 993 994 } 995 996 #ifdef __MINGW32__ 997 #pragma GCC diagnostic pop 998 #endif 999 1000 #if defined(_MSC_VER) 1001 #pragma warning(pop) 1002 #endif 1003 1004 #endif 1005