style_box.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*************************************************************************/
  2. /* style_box.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef STYLE_BOX_H
  31. #define STYLE_BOX_H
  32. #include "core/resource.h"
  33. #include "scene/resources/texture.h"
  34. #include "servers/visual_server.h"
  35. /**
  36. @author Juan Linietsky <reduzio@gmail.com>
  37. */
  38. class StyleBox : public Resource {
  39. GDCLASS(StyleBox, Resource);
  40. RES_BASE_EXTENSION("stylebox");
  41. OBJ_SAVE_TYPE(StyleBox);
  42. float margin[4];
  43. protected:
  44. virtual float get_style_margin(Margin p_margin) const = 0;
  45. static void _bind_methods();
  46. public:
  47. virtual bool test_mask(const Point2 &p_point, const Rect2 &p_rect) const;
  48. void set_default_margin(Margin p_margin, float p_value);
  49. float get_default_margin(Margin p_margin) const;
  50. float get_margin(Margin p_margin) const;
  51. virtual Size2 get_center_size() const;
  52. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const = 0;
  53. Size2 get_minimum_size() const;
  54. Point2 get_offset() const;
  55. StyleBox();
  56. };
  57. class StyleBoxEmpty : public StyleBox {
  58. GDCLASS(StyleBoxEmpty, StyleBox);
  59. virtual float get_style_margin(Margin p_margin) const { return 0; }
  60. public:
  61. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const {}
  62. StyleBoxEmpty() {}
  63. };
  64. class StyleBoxTexture : public StyleBox {
  65. GDCLASS(StyleBoxTexture, StyleBox);
  66. public:
  67. enum AxisStretchMode {
  68. AXIS_STRETCH_MODE_STRETCH,
  69. AXIS_STRETCH_MODE_TILE,
  70. AXIS_STRETCH_MODE_TILE_FIT,
  71. };
  72. private:
  73. float expand_margin[4];
  74. float margin[4];
  75. Rect2 region_rect;
  76. Ref<Texture> texture;
  77. Ref<Texture> normal_map;
  78. bool draw_center;
  79. Color modulate;
  80. AxisStretchMode axis_h;
  81. AxisStretchMode axis_v;
  82. protected:
  83. virtual float get_style_margin(Margin p_margin) const;
  84. static void _bind_methods();
  85. public:
  86. void set_expand_margin_size(Margin p_expand_margin, float p_size);
  87. void set_expand_margin_size_all(float p_expand_margin_size);
  88. void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom);
  89. float get_expand_margin_size(Margin p_expand_margin) const;
  90. void set_margin_size(Margin p_margin, float p_size);
  91. float get_margin_size(Margin p_margin) const;
  92. void set_region_rect(const Rect2 &p_region_rect);
  93. Rect2 get_region_rect() const;
  94. void set_texture(Ref<Texture> p_texture);
  95. Ref<Texture> get_texture() const;
  96. void set_normal_map(Ref<Texture> p_normal_map);
  97. Ref<Texture> get_normal_map() const;
  98. void set_draw_center(bool p_enabled);
  99. bool is_draw_center_enabled() const;
  100. virtual Size2 get_center_size() const;
  101. void set_h_axis_stretch_mode(AxisStretchMode p_mode);
  102. AxisStretchMode get_h_axis_stretch_mode() const;
  103. void set_v_axis_stretch_mode(AxisStretchMode p_mode);
  104. AxisStretchMode get_v_axis_stretch_mode() const;
  105. void set_modulate(const Color &p_modulate);
  106. Color get_modulate() const;
  107. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
  108. StyleBoxTexture();
  109. ~StyleBoxTexture();
  110. };
  111. VARIANT_ENUM_CAST(StyleBoxTexture::AxisStretchMode)
  112. class StyleBoxFlat : public StyleBox {
  113. GDCLASS(StyleBoxFlat, StyleBox);
  114. Color bg_color;
  115. Color shadow_color;
  116. PoolVector<Color> border_color;
  117. int border_width[4];
  118. int expand_margin[4];
  119. int corner_radius[4];
  120. bool draw_center;
  121. bool blend_border;
  122. bool anti_aliased;
  123. int corner_detail;
  124. int shadow_size;
  125. int aa_size;
  126. protected:
  127. virtual float get_style_margin(Margin p_margin) const;
  128. static void _bind_methods();
  129. public:
  130. //Color
  131. void set_bg_color(const Color &p_color);
  132. Color get_bg_color() const;
  133. //Border Color
  134. void set_border_color_all(const Color &p_color);
  135. Color get_border_color_all() const;
  136. void set_border_color(Margin p_border, const Color &p_color);
  137. Color get_border_color(Margin p_border) const;
  138. //BORDER
  139. //width
  140. void set_border_width_all(int p_size);
  141. int get_border_width_min() const;
  142. void set_border_width(Margin p_margin, int p_width);
  143. int get_border_width(Margin p_margin) const;
  144. //blend
  145. void set_border_blend(bool p_blend);
  146. bool get_border_blend() const;
  147. //CORNER
  148. void set_corner_radius_all(int radius);
  149. void set_corner_radius_individual(const int radius_top_left, const int radius_top_right, const int radius_botton_right, const int radius_bottom_left);
  150. int get_corner_radius_min() const;
  151. void set_corner_radius(Corner p_corner, const int radius);
  152. int get_corner_radius(Corner p_corner) const;
  153. void set_corner_detail(const int &p_corner_detail);
  154. int get_corner_detail() const;
  155. //EXPANDS
  156. void set_expand_margin_size(Margin p_expand_margin, float p_size);
  157. void set_expand_margin_size_all(float p_expand_margin_size);
  158. void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom);
  159. float get_expand_margin_size(Margin p_expand_margin) const;
  160. //DRAW CENTER
  161. void set_draw_center(bool p_enabled);
  162. bool is_draw_center_enabled() const;
  163. //SHADOW
  164. void set_shadow_color(const Color &p_color);
  165. Color get_shadow_color() const;
  166. void set_shadow_size(const int &p_size);
  167. int get_shadow_size() const;
  168. //ANTI_ALIASING
  169. void set_anti_aliased(const bool &p_anti_aliased);
  170. bool is_anti_aliased() const;
  171. //tempAA
  172. void set_aa_size(const int &p_aa_size);
  173. int get_aa_size() const;
  174. virtual Size2 get_center_size() const;
  175. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
  176. StyleBoxFlat();
  177. ~StyleBoxFlat();
  178. };
  179. // just used to draw lines.
  180. class StyleBoxLine : public StyleBox {
  181. GDCLASS(StyleBoxLine, StyleBox);
  182. Color color;
  183. int thickness;
  184. bool vertical;
  185. float grow_begin;
  186. float grow_end;
  187. protected:
  188. virtual float get_style_margin(Margin p_margin) const;
  189. static void _bind_methods();
  190. public:
  191. void set_color(const Color &p_color);
  192. Color get_color() const;
  193. void set_thickness(int p_thickness);
  194. int get_thickness() const;
  195. void set_vertical(bool p_vertical);
  196. bool is_vertical() const;
  197. void set_grow_begin(float p_grow);
  198. float get_grow_begin() const;
  199. void set_grow_end(float p_grow);
  200. float get_grow_end() const;
  201. virtual Size2 get_center_size() const;
  202. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
  203. StyleBoxLine();
  204. ~StyleBoxLine();
  205. };
  206. #endif