style_box.h
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-2016 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 
32 #include "resource.h"
33 #include "servers/visual_server.h"
34 #include "scene/resources/texture.h"
38 class StyleBox : public Resource {
39 
40  OBJ_TYPE( StyleBox, Resource );
41  RES_BASE_EXTENSION("sbx");
42  OBJ_SAVE_TYPE( StyleBox );
43  float margin[4];
44 
45 protected:
46 
47  virtual float get_style_margin(Margin p_margin) const=0;
48  static void _bind_methods();
49 public:
50 
51  virtual bool test_mask(const Point2& p_point, const Rect2& p_rect) const;
52 
53  void set_default_margin(Margin p_margin, float p_value);
54  float get_default_margin(Margin p_margin) const;
55  float get_margin(Margin p_margin) const;
56  virtual Size2 get_center_size() const;
57 
58  virtual void draw(RID p_canvas_item,const Rect2& p_rect) const=0;
59 
60  Size2 get_minimum_size() const;
61  Point2 get_offset() const;
62 
63  StyleBox();
64 };
65 
66 class StyleBoxEmpty : public StyleBox {
67 
68  OBJ_TYPE( StyleBoxEmpty, StyleBox );
69  virtual float get_style_margin(Margin p_margin) const { return 0; }
70 public:
71 
72  virtual void draw(RID p_canvas_item,const Rect2& p_rect) const {}
73  StyleBoxEmpty() {}
74 
75 };
76 
77 class StyleBoxTexture : public StyleBox {
78 
79  OBJ_TYPE( StyleBoxTexture, StyleBox );
80 
81 
82  float expand_margin[4];
83  float margin[4];
84  Ref<Texture> texture;
85  bool draw_center;
86 
87 
88 protected:
89 
90  virtual float get_style_margin(Margin p_margin) const;
91  static void _bind_methods();
92 
93 public:
94 
95  void set_expand_margin_size(Margin p_expand_margin,float p_size);
96  float get_expand_margin_size(Margin p_expand_margin) const;
97 
98  void set_margin_size(Margin p_margin,float p_size);
99  float get_margin_size(Margin p_margin) const;
100 
101  void set_texture(RES p_texture);
102  RES get_texture() const;
103 
104  void set_draw_center(bool p_draw);
105  bool get_draw_center() const;
106  virtual Size2 get_center_size() const;
107 
108 
109  virtual void draw(RID p_canvas_item,const Rect2& p_rect) const;
110 
111  StyleBoxTexture();
112  ~StyleBoxTexture();
113 
114 };
115 
116 class StyleBoxFlat : public StyleBox {
117 
118  OBJ_TYPE( StyleBoxFlat, StyleBox );
119 
120  Color bg_color;
121  Color light_color;
122  Color dark_color;
123 
124  int border_size;
125 
126  bool draw_center;
127  bool blend;
128 
129 protected:
130 
131  virtual float get_style_margin(Margin p_margin) const;
132  static void _bind_methods();
133 
134 public:
135 
136  void set_bg_color(const Color& p_color);
137  void set_light_color(const Color& p_color);
138  void set_dark_color(const Color& p_color);
139 
140  Color get_bg_color() const;
141  Color get_light_color() const;
142  Color get_dark_color() const;
143 
144  void set_border_size(int p_size);
145  int get_border_size() const;
146 
147  void set_border_blend(bool p_blend);
148  bool get_border_blend() const;
149 
150  void set_draw_center(bool p_draw);
151  bool get_draw_center() const;
152  virtual Size2 get_center_size() const;
153 
154  virtual void draw(RID p_canvas_item,const Rect2& p_rect) const;
155 
156  StyleBoxFlat();
157  ~StyleBoxFlat();
158 
159 };
160 
161 
162 class StyleBoxImageMask : public StyleBox {
163 
164  OBJ_TYPE( StyleBoxImageMask, StyleBox );
165  virtual float get_style_margin(Margin p_margin) const { return 0; }
166 
167  Image image;
168  float expand_margin[4];
169  bool expand;
170 
171 protected:
172 
173  static void _bind_methods();
174 
175 public:
176 
177  virtual void draw(RID p_canvas_item,const Rect2& p_rect) const {}
178  virtual bool test_mask(const Point2& p_point, const Rect2& p_rect) const;
179 
180  void set_image(const Image& p_image);
181  Image get_image() const;
182 
183  void set_expand(bool p_expand);
184  bool get_expand() const;
185  void set_expand_margin_size(Margin p_expand_margin,float p_size);
186  float get_expand_margin_size(Margin p_expand_margin) const;
187 
189 
190 };
191 
192 
193 #endif
Definition: color.h:37
Definition: math_2d.h:204
Definition: image.h:47
Definition: resource.h:89
Definition: rid.h:47
Definition: style_box.h:116
Definition: math_2d.h:65
Definition: style_box.h:66
Definition: style_box.h:162
Definition: style_box.h:77
Definition: style_box.h:38