2
0

style_box.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 <[email protected]>
  37. */
  38. class CanvasItem;
  39. class StyleBox : public Resource {
  40. GDCLASS(StyleBox, Resource);
  41. RES_BASE_EXTENSION("stylebox");
  42. OBJ_SAVE_TYPE(StyleBox);
  43. float margin[4];
  44. protected:
  45. virtual float get_style_margin(Margin p_margin) const = 0;
  46. static void _bind_methods();
  47. public:
  48. virtual bool test_mask(const Point2 &p_point, const Rect2 &p_rect) const;
  49. void set_default_margin(Margin p_margin, float p_value);
  50. float get_default_margin(Margin p_margin) const;
  51. float get_margin(Margin p_margin) const;
  52. virtual Size2 get_center_size() const;
  53. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const = 0;
  54. CanvasItem *get_current_item_drawn() const;
  55. Size2 get_minimum_size() const;
  56. Point2 get_offset() const;
  57. StyleBox();
  58. };
  59. class StyleBoxEmpty : public StyleBox {
  60. GDCLASS(StyleBoxEmpty, StyleBox);
  61. virtual float get_style_margin(Margin p_margin) const { return 0; }
  62. public:
  63. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const {}
  64. StyleBoxEmpty() {}
  65. };
  66. class StyleBoxTexture : public StyleBox {
  67. GDCLASS(StyleBoxTexture, StyleBox);
  68. public:
  69. enum AxisStretchMode {
  70. AXIS_STRETCH_MODE_STRETCH,
  71. AXIS_STRETCH_MODE_TILE,
  72. AXIS_STRETCH_MODE_TILE_FIT,
  73. };
  74. private:
  75. float expand_margin[4];
  76. float margin[4];
  77. Rect2 region_rect;
  78. Ref<Texture> texture;
  79. Ref<Texture> normal_map;
  80. bool draw_center;
  81. Color modulate;
  82. AxisStretchMode axis_h;
  83. AxisStretchMode axis_v;
  84. protected:
  85. virtual float get_style_margin(Margin p_margin) const;
  86. static void _bind_methods();
  87. public:
  88. void set_expand_margin_size(Margin p_expand_margin, float p_size);
  89. void set_expand_margin_size_all(float p_expand_margin_size);
  90. void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom);
  91. float get_expand_margin_size(Margin p_expand_margin) const;
  92. void set_margin_size(Margin p_margin, float p_size);
  93. float get_margin_size(Margin p_margin) const;
  94. void set_region_rect(const Rect2 &p_region_rect);
  95. Rect2 get_region_rect() const;
  96. void set_texture(Ref<Texture> p_texture);
  97. Ref<Texture> get_texture() const;
  98. void set_normal_map(Ref<Texture> p_normal_map);
  99. Ref<Texture> get_normal_map() const;
  100. void set_draw_center(bool p_enabled);
  101. bool is_draw_center_enabled() const;
  102. virtual Size2 get_center_size() const;
  103. void set_h_axis_stretch_mode(AxisStretchMode p_mode);
  104. AxisStretchMode get_h_axis_stretch_mode() const;
  105. void set_v_axis_stretch_mode(AxisStretchMode p_mode);
  106. AxisStretchMode get_v_axis_stretch_mode() const;
  107. void set_modulate(const Color &p_modulate);
  108. Color get_modulate() const;
  109. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
  110. StyleBoxTexture();
  111. ~StyleBoxTexture();
  112. };
  113. VARIANT_ENUM_CAST(StyleBoxTexture::AxisStretchMode)
  114. class StyleBoxFlat : public StyleBox {
  115. GDCLASS(StyleBoxFlat, StyleBox);
  116. Color bg_color;
  117. Color shadow_color;
  118. PoolVector<Color> border_color;
  119. int border_width[4];
  120. int expand_margin[4];
  121. int corner_radius[4];
  122. bool draw_center;
  123. bool blend_border;
  124. bool anti_aliased;
  125. int corner_detail;
  126. int shadow_size;
  127. int aa_size;
  128. protected:
  129. virtual float get_style_margin(Margin p_margin) const;
  130. static void _bind_methods();
  131. public:
  132. //Color
  133. void set_bg_color(const Color &p_color);
  134. Color get_bg_color() const;
  135. //Border Color
  136. void set_border_color_all(const Color &p_color);
  137. Color get_border_color_all() const;
  138. void set_border_color(Margin p_border, const Color &p_color);
  139. Color get_border_color(Margin p_border) const;
  140. //BORDER
  141. //width
  142. void set_border_width_all(int p_size);
  143. int get_border_width_min() const;
  144. void set_border_width(Margin p_margin, int p_width);
  145. int get_border_width(Margin p_margin) const;
  146. //blend
  147. void set_border_blend(bool p_blend);
  148. bool get_border_blend() const;
  149. //CORNER
  150. void set_corner_radius_all(int radius);
  151. 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);
  152. int get_corner_radius_min() const;
  153. void set_corner_radius(Corner p_corner, const int radius);
  154. int get_corner_radius(Corner p_corner) const;
  155. void set_corner_detail(const int &p_corner_detail);
  156. int get_corner_detail() const;
  157. //EXPANDS
  158. void set_expand_margin_size(Margin p_expand_margin, float p_size);
  159. void set_expand_margin_size_all(float p_expand_margin_size);
  160. void set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom);
  161. float get_expand_margin_size(Margin p_expand_margin) const;
  162. //DRAW CENTER
  163. void set_draw_center(bool p_enabled);
  164. bool is_draw_center_enabled() const;
  165. //SHADOW
  166. void set_shadow_color(const Color &p_color);
  167. Color get_shadow_color() const;
  168. void set_shadow_size(const int &p_size);
  169. int get_shadow_size() const;
  170. //ANTI_ALIASING
  171. void set_anti_aliased(const bool &p_anti_aliased);
  172. bool is_anti_aliased() const;
  173. //tempAA
  174. void set_aa_size(const int &p_aa_size);
  175. int get_aa_size() const;
  176. virtual Size2 get_center_size() const;
  177. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
  178. StyleBoxFlat();
  179. ~StyleBoxFlat();
  180. };
  181. // just used to draw lines.
  182. class StyleBoxLine : public StyleBox {
  183. GDCLASS(StyleBoxLine, StyleBox);
  184. Color color;
  185. int thickness;
  186. bool vertical;
  187. float grow_begin;
  188. float grow_end;
  189. protected:
  190. virtual float get_style_margin(Margin p_margin) const;
  191. static void _bind_methods();
  192. public:
  193. void set_color(const Color &p_color);
  194. Color get_color() const;
  195. void set_thickness(int p_thickness);
  196. int get_thickness() const;
  197. void set_vertical(bool p_vertical);
  198. bool is_vertical() const;
  199. void set_grow_begin(float p_grow);
  200. float get_grow_begin() const;
  201. void set_grow_end(float p_grow);
  202. float get_grow_end() const;
  203. virtual Size2 get_center_size() const;
  204. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
  205. StyleBoxLine();
  206. ~StyleBoxLine();
  207. };
  208. #endif