Theme.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Theme.cpp
  3. */
  4. #include "Theme.h"
  5. namespace gameplay
  6. {
  7. Theme::Theme()
  8. //: _texture(NULL)
  9. {
  10. }
  11. Theme::Theme(const Theme* theme)
  12. {
  13. }
  14. Theme::~Theme()
  15. {
  16. // Destroy all the cursors, styles and , fonts.
  17. for (unsigned int i = 0, count = _cursors.size(); i < count; ++i)
  18. {
  19. Cursor* cursor = _cursors[i];
  20. if (cursor)
  21. {
  22. delete cursor;
  23. }
  24. }
  25. for (unsigned int i = 0, count = _styles.size(); i < count; ++i)
  26. {
  27. Style* style = _styles[i];
  28. if (style)
  29. {
  30. delete style;
  31. }
  32. }
  33. for (unsigned int i = 0, count = _fonts.size(); i < count; ++i)
  34. {
  35. Font* font = _fonts[i];
  36. if (font)
  37. {
  38. SAFE_RELEASE(font);
  39. }
  40. }
  41. }
  42. Theme::Style::Overlay::~Overlay()
  43. {
  44. SAFE_RELEASE(_font);
  45. }
  46. Theme* Theme::create(const char* path)
  47. {
  48. assert(path);
  49. // Load theme properties from file path.
  50. Properties* properties = Properties::create(path);
  51. assert(properties);
  52. if (properties == NULL)
  53. {
  54. return NULL;
  55. }
  56. // Check if the Properties is valid and has a valid namespace.
  57. Properties* themeProperties = properties->getNextNamespace();
  58. assert(themeProperties);
  59. if (!themeProperties || !(strcmp(themeProperties->getNamespace(), "theme") == 0))
  60. {
  61. SAFE_DELETE(properties);
  62. return NULL;
  63. }
  64. // Create a new theme.
  65. Theme* theme = new Theme();
  66. return theme;
  67. }
  68. const Theme::Style* Theme::getStyle(const char* name) const
  69. {
  70. for (unsigned int i = 0, count = _styles.size(); i < count; ++i)
  71. {
  72. if (strcmp(name, _styles[i]->getId()) == 0)
  73. {
  74. return _styles[i];
  75. }
  76. }
  77. return NULL;
  78. }
  79. const char* Theme::Cursor::getId() const
  80. {
  81. return _id.data();
  82. }
  83. const Rectangle& Theme::Cursor::getRegion() const
  84. {
  85. return _region;
  86. }
  87. const Theme::UVs& Theme::Cursor::getUVs() const
  88. {
  89. return _uvs;
  90. }
  91. const char* Theme::Style::getId() const
  92. {
  93. return _id.data();
  94. }
  95. const Theme::Style::Overlay& Theme::Style::getOverlay(OverlayType overlayType) const
  96. {
  97. return _overlays[overlayType];
  98. }
  99. const Theme::Border& Theme::Style::getBorder() const
  100. {
  101. return _border;
  102. }
  103. const Theme::Padding& Theme::Style::getPadding() const
  104. {
  105. return _padding;
  106. }
  107. Theme::Style::OverlayType Theme::Style::Overlay::getId()
  108. {
  109. return _id;
  110. }
  111. const Rectangle& Theme::Style::Overlay::getRegion() const
  112. {
  113. return _region;
  114. }
  115. const Theme::UVs& Theme::Style::Overlay::getUVs() const
  116. {
  117. return _uvs;
  118. }
  119. const Font* Theme::Style::Overlay::getFont() const
  120. {
  121. return _font;
  122. }
  123. const Theme::Cursor& Theme::Style::Overlay::getCursor() const
  124. {
  125. return _cursor;
  126. }
  127. }