style_box.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*************************************************************************/
  2. /* style_box.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef STYLE_BOX_H
  30. #define STYLE_BOX_H
  31. #include "resource.h"
  32. #include "servers/visual_server.h"
  33. #include "scene/resources/texture.h"
  34. /**
  35. @author Juan Linietsky <[email protected]>
  36. */
  37. class StyleBox : public Resource {
  38. OBJ_TYPE( StyleBox, Resource );
  39. RES_BASE_EXTENSION("sbx");
  40. OBJ_SAVE_TYPE( StyleBox );
  41. float margin[4];
  42. protected:
  43. virtual float get_style_margin(Margin p_margin) const=0;
  44. static void _bind_methods();
  45. public:
  46. virtual bool test_mask(const Point2& p_point, const Rect2& p_rect) const;
  47. void set_default_margin(Margin p_margin, float p_value);
  48. float get_default_margin(Margin p_margin) const;
  49. float get_margin(Margin p_margin) const;
  50. virtual Size2 get_center_size() const;
  51. virtual void draw(RID p_canvas_item,const Rect2& p_rect) const=0;
  52. Size2 get_minimum_size() const;
  53. Point2 get_offset() const;
  54. StyleBox();
  55. };
  56. class StyleBoxEmpty : public StyleBox {
  57. OBJ_TYPE( StyleBoxEmpty, StyleBox );
  58. virtual float get_style_margin(Margin p_margin) const { return 0; }
  59. public:
  60. virtual void draw(RID p_canvas_item,const Rect2& p_rect) const {}
  61. StyleBoxEmpty() {}
  62. };
  63. class StyleBoxTexture : public StyleBox {
  64. OBJ_TYPE( StyleBoxTexture, StyleBox );
  65. float expand_margin[4];
  66. float margin[4];
  67. Ref<Texture> texture;
  68. bool draw_center;
  69. protected:
  70. virtual float get_style_margin(Margin p_margin) const;
  71. static void _bind_methods();
  72. public:
  73. void set_expand_margin_size(Margin p_expand_margin,float p_size);
  74. float get_expand_margin_size(Margin p_expand_margin) const;
  75. void set_margin_size(Margin p_margin,float p_size);
  76. float get_margin_size(Margin p_margin) const;
  77. void set_texture(RES p_texture);
  78. RES get_texture() const;
  79. void set_draw_center(bool p_draw);
  80. bool get_draw_center() const;
  81. virtual Size2 get_center_size() const;
  82. virtual void draw(RID p_canvas_item,const Rect2& p_rect) const;
  83. StyleBoxTexture();
  84. ~StyleBoxTexture();
  85. };
  86. class StyleBoxFlat : public StyleBox {
  87. OBJ_TYPE( StyleBoxFlat, StyleBox );
  88. Color bg_color;
  89. Color light_color;
  90. Color dark_color;
  91. int border_size;
  92. bool draw_center;
  93. bool blend;
  94. protected:
  95. virtual float get_style_margin(Margin p_margin) const;
  96. static void _bind_methods();
  97. public:
  98. void set_bg_color(const Color& p_color);
  99. void set_light_color(const Color& p_color);
  100. void set_dark_color(const Color& p_color);
  101. Color get_bg_color() const;
  102. Color get_light_color() const;
  103. Color get_dark_color() const;
  104. void set_border_size(int p_size);
  105. int get_border_size() const;
  106. void set_border_blend(bool p_blend);
  107. bool get_border_blend() const;
  108. void set_draw_center(bool p_draw);
  109. bool get_draw_center() const;
  110. virtual Size2 get_center_size() const;
  111. virtual void draw(RID p_canvas_item,const Rect2& p_rect) const;
  112. StyleBoxFlat();
  113. ~StyleBoxFlat();
  114. };
  115. class StyleBoxImageMask : public StyleBox {
  116. OBJ_TYPE( StyleBoxImageMask, StyleBox );
  117. virtual float get_style_margin(Margin p_margin) const { return 0; }
  118. Image image;
  119. float expand_margin[4];
  120. bool expand;
  121. protected:
  122. static void _bind_methods();
  123. public:
  124. virtual void draw(RID p_canvas_item,const Rect2& p_rect) const {}
  125. virtual bool test_mask(const Point2& p_point, const Rect2& p_rect) const;
  126. void set_image(const Image& p_image);
  127. Image get_image() const;
  128. void set_expand(bool p_expand);
  129. bool get_expand() const;
  130. void set_expand_margin_size(Margin p_expand_margin,float p_size);
  131. float get_expand_margin_size(Margin p_expand_margin) const;
  132. StyleBoxImageMask();
  133. };
  134. #endif