1 /**
2 Control for drawing textures.
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.texturerect;
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 Control for drawing textures.
30 
31 Used to draw icons and sprites in a user interface. The texture's placement can be controlled with the $(D stretchMode) property. It can scale, tile, or stay centered inside its bounding rectangle.
32 $(B Note:) You should enable $(D flipV) when using a TextureRect to display a $(D ViewportTexture). Alternatively, you can enable $(D Viewport.renderTargetVFlip) on the Viewport. Otherwise, the image will appear upside down.
33 */
34 @GodotBaseClass struct TextureRect
35 {
36 	package(godot) enum string _GODOT_internal_name = "TextureRect";
37 public:
38 @nogc nothrow:
39 	union { /** */ godot_object _godot_object; /** */ Control _GODOT_base; }
40 	alias _GODOT_base this;
41 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
42 	package(godot) __gshared bool _classBindingInitialized = false;
43 	package(godot) static struct GDNativeClassBinding
44 	{
45 		__gshared:
46 		@GodotName("_texture_changed") GodotMethod!(void) _textureChanged;
47 		@GodotName("get_stretch_mode") GodotMethod!(TextureRect.StretchMode) getStretchMode;
48 		@GodotName("get_texture") GodotMethod!(Texture) getTexture;
49 		@GodotName("has_expand") GodotMethod!(bool) hasExpand;
50 		@GodotName("is_flipped_h") GodotMethod!(bool) isFlippedH;
51 		@GodotName("is_flipped_v") GodotMethod!(bool) isFlippedV;
52 		@GodotName("set_expand") GodotMethod!(void, bool) setExpand;
53 		@GodotName("set_flip_h") GodotMethod!(void, bool) setFlipH;
54 		@GodotName("set_flip_v") GodotMethod!(void, bool) setFlipV;
55 		@GodotName("set_stretch_mode") GodotMethod!(void, long) setStretchMode;
56 		@GodotName("set_texture") GodotMethod!(void, Texture) setTexture;
57 	}
58 	/// 
59 	pragma(inline, true) bool opEquals(in TextureRect 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 TextureRect.
71 	/// Note: use `memnew!TextureRect` instead.
72 	static TextureRect _new()
73 	{
74 		static godot_class_constructor constructor;
75 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TextureRect");
76 		if(constructor is null) return typeof(this).init;
77 		return cast(TextureRect)(constructor());
78 	}
79 	@disable new(size_t s);
80 	/// 
81 	enum StretchMode : int
82 	{
83 		/**
84 		Scale to fit the node's bounding rectangle, only if `expand` is `true`. Default `stretch_mode`, for backwards compatibility. Until you set `expand` to `true`, the texture will behave like $(D constant STRETCH_KEEP).
85 		*/
86 		stretchScaleOnExpand = 0,
87 		/**
88 		Scale to fit the node's bounding rectangle.
89 		*/
90 		stretchScale = 1,
91 		/**
92 		Tile inside the node's bounding rectangle.
93 		*/
94 		stretchTile = 2,
95 		/**
96 		The texture keeps its original size and stays in the bounding rectangle's top-left corner.
97 		*/
98 		stretchKeep = 3,
99 		/**
100 		The texture keeps its original size and stays centered in the node's bounding rectangle.
101 		*/
102 		stretchKeepCentered = 4,
103 		/**
104 		Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio.
105 		*/
106 		stretchKeepAspect = 5,
107 		/**
108 		Scale the texture to fit the node's bounding rectangle, center it and maintain its aspect ratio.
109 		*/
110 		stretchKeepAspectCentered = 6,
111 		/**
112 		Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node's limits.
113 		*/
114 		stretchKeepAspectCovered = 7,
115 	}
116 	/// 
117 	enum Constants : int
118 	{
119 		stretchScaleOnExpand = 0,
120 		stretchScale = 1,
121 		stretchTile = 2,
122 		stretchKeep = 3,
123 		stretchKeepCentered = 4,
124 		stretchKeepAspect = 5,
125 		stretchKeepAspectCentered = 6,
126 		stretchKeepAspectCovered = 7,
127 	}
128 	/**
129 	
130 	*/
131 	void _textureChanged()
132 	{
133 		Array _GODOT_args = Array.make();
134 		String _GODOT_method_name = String("_texture_changed");
135 		this.callv(_GODOT_method_name, _GODOT_args);
136 	}
137 	/**
138 	
139 	*/
140 	TextureRect.StretchMode getStretchMode() const
141 	{
142 		checkClassBinding!(typeof(this))();
143 		return ptrcall!(TextureRect.StretchMode)(GDNativeClassBinding.getStretchMode, _godot_object);
144 	}
145 	/**
146 	
147 	*/
148 	Ref!Texture getTexture() const
149 	{
150 		checkClassBinding!(typeof(this))();
151 		return ptrcall!(Texture)(GDNativeClassBinding.getTexture, _godot_object);
152 	}
153 	/**
154 	
155 	*/
156 	bool hasExpand() const
157 	{
158 		checkClassBinding!(typeof(this))();
159 		return ptrcall!(bool)(GDNativeClassBinding.hasExpand, _godot_object);
160 	}
161 	/**
162 	
163 	*/
164 	bool isFlippedH() const
165 	{
166 		checkClassBinding!(typeof(this))();
167 		return ptrcall!(bool)(GDNativeClassBinding.isFlippedH, _godot_object);
168 	}
169 	/**
170 	
171 	*/
172 	bool isFlippedV() const
173 	{
174 		checkClassBinding!(typeof(this))();
175 		return ptrcall!(bool)(GDNativeClassBinding.isFlippedV, _godot_object);
176 	}
177 	/**
178 	
179 	*/
180 	void setExpand(in bool enable)
181 	{
182 		checkClassBinding!(typeof(this))();
183 		ptrcall!(void)(GDNativeClassBinding.setExpand, _godot_object, enable);
184 	}
185 	/**
186 	
187 	*/
188 	void setFlipH(in bool enable)
189 	{
190 		checkClassBinding!(typeof(this))();
191 		ptrcall!(void)(GDNativeClassBinding.setFlipH, _godot_object, enable);
192 	}
193 	/**
194 	
195 	*/
196 	void setFlipV(in bool enable)
197 	{
198 		checkClassBinding!(typeof(this))();
199 		ptrcall!(void)(GDNativeClassBinding.setFlipV, _godot_object, enable);
200 	}
201 	/**
202 	
203 	*/
204 	void setStretchMode(in long stretch_mode)
205 	{
206 		checkClassBinding!(typeof(this))();
207 		ptrcall!(void)(GDNativeClassBinding.setStretchMode, _godot_object, stretch_mode);
208 	}
209 	/**
210 	
211 	*/
212 	void setTexture(Texture texture)
213 	{
214 		checkClassBinding!(typeof(this))();
215 		ptrcall!(void)(GDNativeClassBinding.setTexture, _godot_object, texture);
216 	}
217 	/**
218 	If `true`, the texture scales to fit its bounding rectangle.
219 	*/
220 	@property bool expand()
221 	{
222 		return hasExpand();
223 	}
224 	/// ditto
225 	@property void expand(bool v)
226 	{
227 		setExpand(v);
228 	}
229 	/**
230 	If `true`, texture is flipped horizontally.
231 	*/
232 	@property bool flipH()
233 	{
234 		return isFlippedH();
235 	}
236 	/// ditto
237 	@property void flipH(bool v)
238 	{
239 		setFlipH(v);
240 	}
241 	/**
242 	If `true`, texture is flipped vertically.
243 	*/
244 	@property bool flipV()
245 	{
246 		return isFlippedV();
247 	}
248 	/// ditto
249 	@property void flipV(bool v)
250 	{
251 		setFlipV(v);
252 	}
253 	/**
254 	Controls the texture's behavior when resizing the node's bounding rectangle. See $(D stretchmode).
255 	*/
256 	@property TextureRect.StretchMode stretchMode()
257 	{
258 		return getStretchMode();
259 	}
260 	/// ditto
261 	@property void stretchMode(long v)
262 	{
263 		setStretchMode(v);
264 	}
265 	/**
266 	The node's $(D Texture) resource.
267 	*/
268 	@property Texture texture()
269 	{
270 		return getTexture();
271 	}
272 	/// ditto
273 	@property void texture(Texture v)
274 	{
275 		setTexture(v);
276 	}
277 }