ThemeStyle.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #ifndef THEMESTYLE_H_
  2. #define THEMESTYLE_H_
  3. #include "Base.h"
  4. #include "Ref.h"
  5. #include "Font.h"
  6. #include "Rectangle.h"
  7. #include "Texture.h"
  8. #include "Properties.h"
  9. #include "Theme.h"
  10. namespace gameplay
  11. {
  12. /**
  13. * This class represents the appearance of a control. A style can have padding and margin values,
  14. * as well as overlays for each of the control's states. Each overlay in turn can reference
  15. * other theme classes to determine the border, background, cursor, and image settings to use for
  16. * a particular state, as well as color and font settings, etcetera.
  17. */
  18. class Theme::Style
  19. {
  20. friend class Theme;
  21. friend class Control;
  22. friend class Container;
  23. friend class Form;
  24. public:
  25. /**
  26. * Get the theme this style belongs to.
  27. *
  28. * @return The theme this style belongs to.
  29. */
  30. Theme* getTheme() const;
  31. private:
  32. /**
  33. * A style has one overlay for each possible control state.
  34. */
  35. enum OverlayType
  36. {
  37. OVERLAY_NORMAL,
  38. OVERLAY_FOCUS,
  39. OVERLAY_ACTIVE,
  40. OVERLAY_DISABLED,
  41. OVERLAY_HOVER,
  42. OVERLAY_MAX
  43. };
  44. /**
  45. * This class represents a control's overlay for one of its states.
  46. */
  47. class Overlay : public Ref, public AnimationTarget
  48. {
  49. friend class Theme;
  50. friend class Theme::Style;
  51. friend class Control;
  52. friend class Container;
  53. friend class Form;
  54. private:
  55. static const int ANIMATE_OPACITY = 1;
  56. Overlay();
  57. Overlay(const Overlay& copy);
  58. ~Overlay();
  59. /**
  60. * Hidden copy assignment operator.
  61. */
  62. Overlay& operator=(const Overlay&);
  63. static Overlay* create();
  64. OverlayType getType();
  65. float getOpacity() const;
  66. void setOpacity(float opacity);
  67. void setBorder(float top, float bottom, float left, float right);
  68. const Theme::Border& getBorder() const;
  69. void setSkinColor(const Vector4& color);
  70. const Vector4& getSkinColor() const;
  71. void setSkinRegion(const Rectangle& region, float tw, float th);
  72. const Rectangle& getSkinRegion() const;
  73. const Theme::UVs& getSkinUVs(Theme::Skin::SkinArea area) const;
  74. Font* getFont() const;
  75. void setFont(Font* font);
  76. unsigned int getFontSize() const;
  77. void setFontSize(unsigned int fontSize);
  78. Font::Justify getTextAlignment() const;
  79. void setTextAlignment(Font::Justify alignment);
  80. bool getTextRightToLeft() const;
  81. void setTextRightToLeft(bool rightToLeft);
  82. const Vector4& getTextColor() const;
  83. void setTextColor(const Vector4& color);
  84. const Rectangle& getImageRegion(const char* id) const;
  85. void setImageRegion(const char* id, const Rectangle& region, float tw, float th);
  86. const Vector4& getImageColor(const char* id) const;
  87. void setImageColor(const char* id, const Vector4& color);
  88. const Theme::UVs& getImageUVs(const char* id) const;
  89. const Rectangle& getCursorRegion() const;
  90. void setCursorRegion(const Rectangle& region, float tw, float th);
  91. const Vector4& getCursorColor() const;
  92. void setCursorColor(const Vector4& color);
  93. const Theme::UVs& getCursorUVs() const;
  94. /**
  95. * @see AnimationTarget::getAnimationPropertyComponentCount
  96. */
  97. unsigned int getAnimationPropertyComponentCount(int propertyId) const;
  98. /**
  99. * @see AnimationTarget::getAnimationProperty
  100. */
  101. void getAnimationPropertyValue(int propertyId, AnimationValue* value);
  102. /**
  103. * @see AnimationTarget::setAnimationProperty
  104. */
  105. void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f);
  106. void setSkin(Theme::Skin* Skin);
  107. Theme::Skin* getSkin() const;
  108. void setCursor(Theme::ThemeImage* cursor);
  109. Theme::ThemeImage* getCursor() const;
  110. void setImageList(Theme::ImageList* imageList);
  111. Theme::ImageList* getImageList() const;
  112. Skin* _skin;
  113. Theme::ThemeImage* _cursor;
  114. Theme::ImageList* _imageList;
  115. Font* _font;
  116. unsigned int _fontSize;
  117. Font::Justify _alignment;
  118. bool _textRightToLeft;
  119. Vector4 _textColor;
  120. float _opacity;
  121. };
  122. /**
  123. * Constructor.
  124. */
  125. Style(Theme* theme, const char* id, float tw, float th,
  126. const Theme::Margin& margin, const Theme::Padding& padding,
  127. Overlay* normal, Overlay* focus, Overlay* active, Overlay* disabled, Overlay* hover);
  128. /**
  129. * Constructor.
  130. */
  131. Style(const Style& style);
  132. /**
  133. * Destructor.
  134. */
  135. ~Style();
  136. /**
  137. * Hidden copy assignment operator.
  138. */
  139. Style& operator=(const Style&);
  140. /**
  141. * Returns the Id of this Style.
  142. */
  143. const char* getId() const;
  144. /**
  145. * Gets an overlay from the overlay type.
  146. */
  147. Overlay* getOverlay(OverlayType overlayType) const;
  148. /**
  149. * Gets the Padding region of this style.
  150. */
  151. const Theme::Padding& getPadding() const;
  152. /**
  153. * Gets the Margin region of this style.
  154. */
  155. const Theme::Margin& getMargin() const;
  156. /**
  157. * Set this size of this Style's padding.
  158. *
  159. * Padding is the space between a Control's content (all icons and text) and its border.
  160. */
  161. void setPadding(float top, float bottom, float left, float right);
  162. /**
  163. * Set the size of this Style's margin.
  164. *
  165. * The margin is used by Layouts other than AbsoluteLayout to put space between Controls.
  166. */
  167. void setMargin(float top, float bottom, float left, float right);
  168. Theme* _theme;
  169. std::string _id;
  170. float _tw;
  171. float _th;
  172. Theme::Margin _margin;
  173. Theme::Padding _padding;
  174. Overlay* _overlays[OVERLAY_MAX];
  175. };
  176. }
  177. #endif