1 /**
2 Scalable texture-based frame that tiles the texture's centers and sides, but keeps the corners' original size. Perfect for panels and dialog boxes.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.ninepatchrect;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.control;
25 import godot.canvasitem;
26 import godot.node;
27 import godot.texture;
28 /**
29 Scalable texture-based frame that tiles the texture's centers and sides, but keeps the corners' original size. Perfect for panels and dialog boxes.
30 
31 Also known as 9-slice panels, NinePatchRect produces clean panels of any size, based on a small texture. To do so, it splits the texture in a 3×3 grid. When you scale the node, it tiles the texture's sides horizontally or vertically, the center on both axes but it doesn't scale or tile the corners.
32 */
33 @GodotBaseClass struct NinePatchRect
34 {
35 	package(godot) enum string _GODOT_internal_name = "NinePatchRect";
36 public:
37 @nogc nothrow:
38 	union { /** */ godot_object _godot_object; /** */ Control _GODOT_base; }
39 	alias _GODOT_base this;
40 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
41 	package(godot) __gshared bool _classBindingInitialized = false;
42 	package(godot) static struct GDNativeClassBinding
43 	{
44 		__gshared:
45 		@GodotName("get_h_axis_stretch_mode") GodotMethod!(NinePatchRect.AxisStretchMode) getHAxisStretchMode;
46 		@GodotName("get_patch_margin") GodotMethod!(long, long) getPatchMargin;
47 		@GodotName("get_region_rect") GodotMethod!(Rect2) getRegionRect;
48 		@GodotName("get_texture") GodotMethod!(Texture) getTexture;
49 		@GodotName("get_v_axis_stretch_mode") GodotMethod!(NinePatchRect.AxisStretchMode) getVAxisStretchMode;
50 		@GodotName("is_draw_center_enabled") GodotMethod!(bool) isDrawCenterEnabled;
51 		@GodotName("set_draw_center") GodotMethod!(void, bool) setDrawCenter;
52 		@GodotName("set_h_axis_stretch_mode") GodotMethod!(void, long) setHAxisStretchMode;
53 		@GodotName("set_patch_margin") GodotMethod!(void, long, long) setPatchMargin;
54 		@GodotName("set_region_rect") GodotMethod!(void, Rect2) setRegionRect;
55 		@GodotName("set_texture") GodotMethod!(void, Texture) setTexture;
56 		@GodotName("set_v_axis_stretch_mode") GodotMethod!(void, long) setVAxisStretchMode;
57 	}
58 	/// 
59 	pragma(inline, true) bool opEquals(in NinePatchRect other) const
60 	{ return _godot_object.ptr is other._godot_object.ptr; }
61 	/// 
62 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
63 	{ _godot_object.ptr = n; return null; }
64 	/// 
65 	pragma(inline, true) bool opEquals(typeof(null) n) const
66 	{ return _godot_object.ptr is n; }
67 	/// 
68 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
69 	mixin baseCasts;
70 	/// Construct a new instance of NinePatchRect.
71 	/// Note: use `memnew!NinePatchRect` instead.
72 	static NinePatchRect _new()
73 	{
74 		static godot_class_constructor constructor;
75 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("NinePatchRect");
76 		if(constructor is null) return typeof(this).init;
77 		return cast(NinePatchRect)(constructor());
78 	}
79 	@disable new(size_t s);
80 	/// 
81 	enum AxisStretchMode : int
82 	{
83 		/**
84 		Stretches the center texture across the NinePatchRect. This may cause the texture to be distorted.
85 		*/
86 		axisStretchModeStretch = 0,
87 		/**
88 		Repeats the center texture across the NinePatchRect. This won't cause any visible distortion. The texture must be seamless for this to work without displaying artifacts between edges.
89 		$(B Note:) Only supported when using the GLES3 renderer. When using the GLES2 renderer, this will behave like $(D constant AXIS_STRETCH_MODE_STRETCH).
90 		*/
91 		axisStretchModeTile = 1,
92 		/**
93 		Repeats the center texture across the NinePatchRect, but will also stretch the texture to make sure each tile is visible in full. This may cause the texture to be distorted, but less than $(D constant AXIS_STRETCH_MODE_STRETCH). The texture must be seamless for this to work without displaying artifacts between edges.
94 		$(B Note:) Only supported when using the GLES3 renderer. When using the GLES2 renderer, this will behave like $(D constant AXIS_STRETCH_MODE_STRETCH).
95 		*/
96 		axisStretchModeTileFit = 2,
97 	}
98 	/// 
99 	enum Constants : int
100 	{
101 		axisStretchModeStretch = 0,
102 		axisStretchModeTile = 1,
103 		axisStretchModeTileFit = 2,
104 	}
105 	/**
106 	
107 	*/
108 	NinePatchRect.AxisStretchMode getHAxisStretchMode() const
109 	{
110 		checkClassBinding!(typeof(this))();
111 		return ptrcall!(NinePatchRect.AxisStretchMode)(GDNativeClassBinding.getHAxisStretchMode, _godot_object);
112 	}
113 	/**
114 	Returns the size of the margin identified by the given $(D margin) constant.
115 	*/
116 	long getPatchMargin(in long margin) const
117 	{
118 		checkClassBinding!(typeof(this))();
119 		return ptrcall!(long)(GDNativeClassBinding.getPatchMargin, _godot_object, margin);
120 	}
121 	/**
122 	
123 	*/
124 	Rect2 getRegionRect() const
125 	{
126 		checkClassBinding!(typeof(this))();
127 		return ptrcall!(Rect2)(GDNativeClassBinding.getRegionRect, _godot_object);
128 	}
129 	/**
130 	
131 	*/
132 	Ref!Texture getTexture() const
133 	{
134 		checkClassBinding!(typeof(this))();
135 		return ptrcall!(Texture)(GDNativeClassBinding.getTexture, _godot_object);
136 	}
137 	/**
138 	
139 	*/
140 	NinePatchRect.AxisStretchMode getVAxisStretchMode() const
141 	{
142 		checkClassBinding!(typeof(this))();
143 		return ptrcall!(NinePatchRect.AxisStretchMode)(GDNativeClassBinding.getVAxisStretchMode, _godot_object);
144 	}
145 	/**
146 	
147 	*/
148 	bool isDrawCenterEnabled() const
149 	{
150 		checkClassBinding!(typeof(this))();
151 		return ptrcall!(bool)(GDNativeClassBinding.isDrawCenterEnabled, _godot_object);
152 	}
153 	/**
154 	
155 	*/
156 	void setDrawCenter(in bool draw_center)
157 	{
158 		checkClassBinding!(typeof(this))();
159 		ptrcall!(void)(GDNativeClassBinding.setDrawCenter, _godot_object, draw_center);
160 	}
161 	/**
162 	
163 	*/
164 	void setHAxisStretchMode(in long mode)
165 	{
166 		checkClassBinding!(typeof(this))();
167 		ptrcall!(void)(GDNativeClassBinding.setHAxisStretchMode, _godot_object, mode);
168 	}
169 	/**
170 	Sets the size of the margin identified by the given $(D margin) constant to `value` in pixels.
171 	*/
172 	void setPatchMargin(in long margin, in long value)
173 	{
174 		checkClassBinding!(typeof(this))();
175 		ptrcall!(void)(GDNativeClassBinding.setPatchMargin, _godot_object, margin, value);
176 	}
177 	/**
178 	
179 	*/
180 	void setRegionRect(in Rect2 rect)
181 	{
182 		checkClassBinding!(typeof(this))();
183 		ptrcall!(void)(GDNativeClassBinding.setRegionRect, _godot_object, rect);
184 	}
185 	/**
186 	
187 	*/
188 	void setTexture(Texture texture)
189 	{
190 		checkClassBinding!(typeof(this))();
191 		ptrcall!(void)(GDNativeClassBinding.setTexture, _godot_object, texture);
192 	}
193 	/**
194 	
195 	*/
196 	void setVAxisStretchMode(in long mode)
197 	{
198 		checkClassBinding!(typeof(this))();
199 		ptrcall!(void)(GDNativeClassBinding.setVAxisStretchMode, _godot_object, mode);
200 	}
201 	/**
202 	The stretch mode to use for horizontal stretching/tiling. See $(D NinePatchRect.axisstretchmode) for possible values.
203 	*/
204 	@property NinePatchRect.AxisStretchMode axisStretchHorizontal()
205 	{
206 		return getHAxisStretchMode();
207 	}
208 	/// ditto
209 	@property void axisStretchHorizontal(long v)
210 	{
211 		setHAxisStretchMode(v);
212 	}
213 	/**
214 	The stretch mode to use for vertical stretching/tiling. See $(D NinePatchRect.axisstretchmode) for possible values.
215 	*/
216 	@property NinePatchRect.AxisStretchMode axisStretchVertical()
217 	{
218 		return getVAxisStretchMode();
219 	}
220 	/// ditto
221 	@property void axisStretchVertical(long v)
222 	{
223 		setVAxisStretchMode(v);
224 	}
225 	/**
226 	If `true`, draw the panel's center. Else, only draw the 9-slice's borders.
227 	*/
228 	@property bool drawCenter()
229 	{
230 		return isDrawCenterEnabled();
231 	}
232 	/// ditto
233 	@property void drawCenter(bool v)
234 	{
235 		setDrawCenter(v);
236 	}
237 	/**
238 	The height of the 9-slice's bottom row. A margin of 16 means the 9-slice's bottom corners and side will have a height of 16 pixels. You can set all 4 margin values individually to create panels with non-uniform borders.
239 	*/
240 	@property long patchMarginBottom()
241 	{
242 		return getPatchMargin(3);
243 	}
244 	/// ditto
245 	@property void patchMarginBottom(long v)
246 	{
247 		setPatchMargin(3, v);
248 	}
249 	/**
250 	The width of the 9-slice's left column. A margin of 16 means the 9-slice's left corners and side will have a width of 16 pixels. You can set all 4 margin values individually to create panels with non-uniform borders.
251 	*/
252 	@property long patchMarginLeft()
253 	{
254 		return getPatchMargin(0);
255 	}
256 	/// ditto
257 	@property void patchMarginLeft(long v)
258 	{
259 		setPatchMargin(0, v);
260 	}
261 	/**
262 	The width of the 9-slice's right column. A margin of 16 means the 9-slice's right corners and side will have a width of 16 pixels. You can set all 4 margin values individually to create panels with non-uniform borders.
263 	*/
264 	@property long patchMarginRight()
265 	{
266 		return getPatchMargin(2);
267 	}
268 	/// ditto
269 	@property void patchMarginRight(long v)
270 	{
271 		setPatchMargin(2, v);
272 	}
273 	/**
274 	The height of the 9-slice's top row. A margin of 16 means the 9-slice's top corners and side will have a height of 16 pixels. You can set all 4 margin values individually to create panels with non-uniform borders.
275 	*/
276 	@property long patchMarginTop()
277 	{
278 		return getPatchMargin(1);
279 	}
280 	/// ditto
281 	@property void patchMarginTop(long v)
282 	{
283 		setPatchMargin(1, v);
284 	}
285 	/**
286 	Rectangular region of the texture to sample from. If you're working with an atlas, use this property to define the area the 9-slice should use. All other properties are relative to this one. If the rect is empty, NinePatchRect will use the whole texture.
287 	*/
288 	@property Rect2 regionRect()
289 	{
290 		return getRegionRect();
291 	}
292 	/// ditto
293 	@property void regionRect(Rect2 v)
294 	{
295 		setRegionRect(v);
296 	}
297 	/**
298 	The node's texture resource.
299 	*/
300 	@property Texture texture()
301 	{
302 		return getTexture();
303 	}
304 	/// ditto
305 	@property void texture(Texture v)
306 	{
307 		setTexture(v);
308 	}
309 }