1 /**
2 A 2D polygon.
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.polygon2d;
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.node2d;
25 import godot.canvasitem;
26 import godot.node;
27 import godot.texture;
28 /**
29 A 2D polygon.
30 
31 A Polygon2D is defined by a set of points. Each point is connected to the next, with the final point being connected to the first, resulting in a closed polygon. Polygon2Ds can be filled with color (solid or gradient) or filled with a given texture.
32 $(B Note:) By default, Godot can only draw up to 4,096 polygon points at a time. To increase this limit, open the Project Settings and increase $(D ProjectSettings.rendering/limits/buffers/canvasPolygonBufferSizeKb) and $(D ProjectSettings.rendering/limits/buffers/canvasPolygonIndexBufferSizeKb).
33 */
34 @GodotBaseClass struct Polygon2D
35 {
36 	package(godot) enum string _GODOT_internal_name = "Polygon2D";
37 public:
38 @nogc nothrow:
39 	union { /** */ godot_object _godot_object; /** */ Node2D _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("_get_bones") GodotMethod!(Array) _getBones;
47 		@GodotName("_set_bones") GodotMethod!(void, Array) _setBones;
48 		@GodotName("_skeleton_bone_setup_changed") GodotMethod!(void) _skeletonBoneSetupChanged;
49 		@GodotName("add_bone") GodotMethod!(void, NodePath, PoolRealArray) addBone;
50 		@GodotName("clear_bones") GodotMethod!(void) clearBones;
51 		@GodotName("erase_bone") GodotMethod!(void, long) eraseBone;
52 		@GodotName("get_antialiased") GodotMethod!(bool) getAntialiased;
53 		@GodotName("get_bone_count") GodotMethod!(long) getBoneCount;
54 		@GodotName("get_bone_path") GodotMethod!(NodePath, long) getBonePath;
55 		@GodotName("get_bone_weights") GodotMethod!(PoolRealArray, long) getBoneWeights;
56 		@GodotName("get_color") GodotMethod!(Color) getColor;
57 		@GodotName("get_internal_vertex_count") GodotMethod!(long) getInternalVertexCount;
58 		@GodotName("get_invert") GodotMethod!(bool) getInvert;
59 		@GodotName("get_invert_border") GodotMethod!(double) getInvertBorder;
60 		@GodotName("get_offset") GodotMethod!(Vector2) getOffset;
61 		@GodotName("get_polygon") GodotMethod!(PoolVector2Array) getPolygon;
62 		@GodotName("get_polygons") GodotMethod!(Array) getPolygons;
63 		@GodotName("get_skeleton") GodotMethod!(NodePath) getSkeleton;
64 		@GodotName("get_texture") GodotMethod!(Texture) getTexture;
65 		@GodotName("get_texture_offset") GodotMethod!(Vector2) getTextureOffset;
66 		@GodotName("get_texture_rotation") GodotMethod!(double) getTextureRotation;
67 		@GodotName("get_texture_rotation_degrees") GodotMethod!(double) getTextureRotationDegrees;
68 		@GodotName("get_texture_scale") GodotMethod!(Vector2) getTextureScale;
69 		@GodotName("get_uv") GodotMethod!(PoolVector2Array) getUv;
70 		@GodotName("get_vertex_colors") GodotMethod!(PoolColorArray) getVertexColors;
71 		@GodotName("set_antialiased") GodotMethod!(void, bool) setAntialiased;
72 		@GodotName("set_bone_path") GodotMethod!(void, long, NodePath) setBonePath;
73 		@GodotName("set_bone_weights") GodotMethod!(void, long, PoolRealArray) setBoneWeights;
74 		@GodotName("set_color") GodotMethod!(void, Color) setColor;
75 		@GodotName("set_internal_vertex_count") GodotMethod!(void, long) setInternalVertexCount;
76 		@GodotName("set_invert") GodotMethod!(void, bool) setInvert;
77 		@GodotName("set_invert_border") GodotMethod!(void, double) setInvertBorder;
78 		@GodotName("set_offset") GodotMethod!(void, Vector2) setOffset;
79 		@GodotName("set_polygon") GodotMethod!(void, PoolVector2Array) setPolygon;
80 		@GodotName("set_polygons") GodotMethod!(void, Array) setPolygons;
81 		@GodotName("set_skeleton") GodotMethod!(void, NodePath) setSkeleton;
82 		@GodotName("set_texture") GodotMethod!(void, Texture) setTexture;
83 		@GodotName("set_texture_offset") GodotMethod!(void, Vector2) setTextureOffset;
84 		@GodotName("set_texture_rotation") GodotMethod!(void, double) setTextureRotation;
85 		@GodotName("set_texture_rotation_degrees") GodotMethod!(void, double) setTextureRotationDegrees;
86 		@GodotName("set_texture_scale") GodotMethod!(void, Vector2) setTextureScale;
87 		@GodotName("set_uv") GodotMethod!(void, PoolVector2Array) setUv;
88 		@GodotName("set_vertex_colors") GodotMethod!(void, PoolColorArray) setVertexColors;
89 	}
90 	/// 
91 	pragma(inline, true) bool opEquals(in Polygon2D other) const
92 	{ return _godot_object.ptr is other._godot_object.ptr; }
93 	/// 
94 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
95 	{ _godot_object.ptr = n; return null; }
96 	/// 
97 	pragma(inline, true) bool opEquals(typeof(null) n) const
98 	{ return _godot_object.ptr is n; }
99 	/// 
100 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
101 	mixin baseCasts;
102 	/// Construct a new instance of Polygon2D.
103 	/// Note: use `memnew!Polygon2D` instead.
104 	static Polygon2D _new()
105 	{
106 		static godot_class_constructor constructor;
107 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Polygon2D");
108 		if(constructor is null) return typeof(this).init;
109 		return cast(Polygon2D)(constructor());
110 	}
111 	@disable new(size_t s);
112 	/**
113 	
114 	*/
115 	Array _getBones() const
116 	{
117 		Array _GODOT_args = Array.make();
118 		String _GODOT_method_name = String("_get_bones");
119 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array);
120 	}
121 	/**
122 	
123 	*/
124 	void _setBones(in Array bones)
125 	{
126 		Array _GODOT_args = Array.make();
127 		_GODOT_args.append(bones);
128 		String _GODOT_method_name = String("_set_bones");
129 		this.callv(_GODOT_method_name, _GODOT_args);
130 	}
131 	/**
132 	
133 	*/
134 	void _skeletonBoneSetupChanged()
135 	{
136 		Array _GODOT_args = Array.make();
137 		String _GODOT_method_name = String("_skeleton_bone_setup_changed");
138 		this.callv(_GODOT_method_name, _GODOT_args);
139 	}
140 	/**
141 	Adds a bone with the specified `path` and `weights`.
142 	*/
143 	void addBone(NodePathArg0)(in NodePathArg0 path, in PoolRealArray weights)
144 	{
145 		checkClassBinding!(typeof(this))();
146 		ptrcall!(void)(GDNativeClassBinding.addBone, _godot_object, path, weights);
147 	}
148 	/**
149 	Removes all bones from this $(D Polygon2D).
150 	*/
151 	void clearBones()
152 	{
153 		checkClassBinding!(typeof(this))();
154 		ptrcall!(void)(GDNativeClassBinding.clearBones, _godot_object);
155 	}
156 	/**
157 	Removes the specified bone from this $(D Polygon2D).
158 	*/
159 	void eraseBone(in long index)
160 	{
161 		checkClassBinding!(typeof(this))();
162 		ptrcall!(void)(GDNativeClassBinding.eraseBone, _godot_object, index);
163 	}
164 	/**
165 	
166 	*/
167 	bool getAntialiased() const
168 	{
169 		checkClassBinding!(typeof(this))();
170 		return ptrcall!(bool)(GDNativeClassBinding.getAntialiased, _godot_object);
171 	}
172 	/**
173 	Returns the number of bones in this $(D Polygon2D).
174 	*/
175 	long getBoneCount() const
176 	{
177 		checkClassBinding!(typeof(this))();
178 		return ptrcall!(long)(GDNativeClassBinding.getBoneCount, _godot_object);
179 	}
180 	/**
181 	Returns the path to the node associated with the specified bone.
182 	*/
183 	NodePath getBonePath(in long index) const
184 	{
185 		checkClassBinding!(typeof(this))();
186 		return ptrcall!(NodePath)(GDNativeClassBinding.getBonePath, _godot_object, index);
187 	}
188 	/**
189 	Returns the height values of the specified bone.
190 	*/
191 	PoolRealArray getBoneWeights(in long index) const
192 	{
193 		checkClassBinding!(typeof(this))();
194 		return ptrcall!(PoolRealArray)(GDNativeClassBinding.getBoneWeights, _godot_object, index);
195 	}
196 	/**
197 	
198 	*/
199 	Color getColor() const
200 	{
201 		checkClassBinding!(typeof(this))();
202 		return ptrcall!(Color)(GDNativeClassBinding.getColor, _godot_object);
203 	}
204 	/**
205 	
206 	*/
207 	long getInternalVertexCount() const
208 	{
209 		checkClassBinding!(typeof(this))();
210 		return ptrcall!(long)(GDNativeClassBinding.getInternalVertexCount, _godot_object);
211 	}
212 	/**
213 	
214 	*/
215 	bool getInvert() const
216 	{
217 		checkClassBinding!(typeof(this))();
218 		return ptrcall!(bool)(GDNativeClassBinding.getInvert, _godot_object);
219 	}
220 	/**
221 	
222 	*/
223 	double getInvertBorder() const
224 	{
225 		checkClassBinding!(typeof(this))();
226 		return ptrcall!(double)(GDNativeClassBinding.getInvertBorder, _godot_object);
227 	}
228 	/**
229 	
230 	*/
231 	Vector2 getOffset() const
232 	{
233 		checkClassBinding!(typeof(this))();
234 		return ptrcall!(Vector2)(GDNativeClassBinding.getOffset, _godot_object);
235 	}
236 	/**
237 	
238 	*/
239 	PoolVector2Array getPolygon() const
240 	{
241 		checkClassBinding!(typeof(this))();
242 		return ptrcall!(PoolVector2Array)(GDNativeClassBinding.getPolygon, _godot_object);
243 	}
244 	/**
245 	
246 	*/
247 	Array getPolygons() const
248 	{
249 		checkClassBinding!(typeof(this))();
250 		return ptrcall!(Array)(GDNativeClassBinding.getPolygons, _godot_object);
251 	}
252 	/**
253 	
254 	*/
255 	NodePath getSkeleton() const
256 	{
257 		checkClassBinding!(typeof(this))();
258 		return ptrcall!(NodePath)(GDNativeClassBinding.getSkeleton, _godot_object);
259 	}
260 	/**
261 	
262 	*/
263 	Ref!Texture getTexture() const
264 	{
265 		checkClassBinding!(typeof(this))();
266 		return ptrcall!(Texture)(GDNativeClassBinding.getTexture, _godot_object);
267 	}
268 	/**
269 	
270 	*/
271 	Vector2 getTextureOffset() const
272 	{
273 		checkClassBinding!(typeof(this))();
274 		return ptrcall!(Vector2)(GDNativeClassBinding.getTextureOffset, _godot_object);
275 	}
276 	/**
277 	
278 	*/
279 	double getTextureRotation() const
280 	{
281 		checkClassBinding!(typeof(this))();
282 		return ptrcall!(double)(GDNativeClassBinding.getTextureRotation, _godot_object);
283 	}
284 	/**
285 	
286 	*/
287 	double getTextureRotationDegrees() const
288 	{
289 		checkClassBinding!(typeof(this))();
290 		return ptrcall!(double)(GDNativeClassBinding.getTextureRotationDegrees, _godot_object);
291 	}
292 	/**
293 	
294 	*/
295 	Vector2 getTextureScale() const
296 	{
297 		checkClassBinding!(typeof(this))();
298 		return ptrcall!(Vector2)(GDNativeClassBinding.getTextureScale, _godot_object);
299 	}
300 	/**
301 	
302 	*/
303 	PoolVector2Array getUv() const
304 	{
305 		checkClassBinding!(typeof(this))();
306 		return ptrcall!(PoolVector2Array)(GDNativeClassBinding.getUv, _godot_object);
307 	}
308 	/**
309 	
310 	*/
311 	PoolColorArray getVertexColors() const
312 	{
313 		checkClassBinding!(typeof(this))();
314 		return ptrcall!(PoolColorArray)(GDNativeClassBinding.getVertexColors, _godot_object);
315 	}
316 	/**
317 	
318 	*/
319 	void setAntialiased(in bool antialiased)
320 	{
321 		checkClassBinding!(typeof(this))();
322 		ptrcall!(void)(GDNativeClassBinding.setAntialiased, _godot_object, antialiased);
323 	}
324 	/**
325 	Sets the path to the node associated with the specified bone.
326 	*/
327 	void setBonePath(NodePathArg1)(in long index, in NodePathArg1 path)
328 	{
329 		checkClassBinding!(typeof(this))();
330 		ptrcall!(void)(GDNativeClassBinding.setBonePath, _godot_object, index, path);
331 	}
332 	/**
333 	Sets the weight values for the specified bone.
334 	*/
335 	void setBoneWeights(in long index, in PoolRealArray weights)
336 	{
337 		checkClassBinding!(typeof(this))();
338 		ptrcall!(void)(GDNativeClassBinding.setBoneWeights, _godot_object, index, weights);
339 	}
340 	/**
341 	
342 	*/
343 	void setColor(in Color color)
344 	{
345 		checkClassBinding!(typeof(this))();
346 		ptrcall!(void)(GDNativeClassBinding.setColor, _godot_object, color);
347 	}
348 	/**
349 	
350 	*/
351 	void setInternalVertexCount(in long internal_vertex_count)
352 	{
353 		checkClassBinding!(typeof(this))();
354 		ptrcall!(void)(GDNativeClassBinding.setInternalVertexCount, _godot_object, internal_vertex_count);
355 	}
356 	/**
357 	
358 	*/
359 	void setInvert(in bool invert)
360 	{
361 		checkClassBinding!(typeof(this))();
362 		ptrcall!(void)(GDNativeClassBinding.setInvert, _godot_object, invert);
363 	}
364 	/**
365 	
366 	*/
367 	void setInvertBorder(in double invert_border)
368 	{
369 		checkClassBinding!(typeof(this))();
370 		ptrcall!(void)(GDNativeClassBinding.setInvertBorder, _godot_object, invert_border);
371 	}
372 	/**
373 	
374 	*/
375 	void setOffset(in Vector2 offset)
376 	{
377 		checkClassBinding!(typeof(this))();
378 		ptrcall!(void)(GDNativeClassBinding.setOffset, _godot_object, offset);
379 	}
380 	/**
381 	
382 	*/
383 	void setPolygon(in PoolVector2Array polygon)
384 	{
385 		checkClassBinding!(typeof(this))();
386 		ptrcall!(void)(GDNativeClassBinding.setPolygon, _godot_object, polygon);
387 	}
388 	/**
389 	
390 	*/
391 	void setPolygons(in Array polygons)
392 	{
393 		checkClassBinding!(typeof(this))();
394 		ptrcall!(void)(GDNativeClassBinding.setPolygons, _godot_object, polygons);
395 	}
396 	/**
397 	
398 	*/
399 	void setSkeleton(NodePathArg0)(in NodePathArg0 skeleton)
400 	{
401 		checkClassBinding!(typeof(this))();
402 		ptrcall!(void)(GDNativeClassBinding.setSkeleton, _godot_object, skeleton);
403 	}
404 	/**
405 	
406 	*/
407 	void setTexture(Texture texture)
408 	{
409 		checkClassBinding!(typeof(this))();
410 		ptrcall!(void)(GDNativeClassBinding.setTexture, _godot_object, texture);
411 	}
412 	/**
413 	
414 	*/
415 	void setTextureOffset(in Vector2 texture_offset)
416 	{
417 		checkClassBinding!(typeof(this))();
418 		ptrcall!(void)(GDNativeClassBinding.setTextureOffset, _godot_object, texture_offset);
419 	}
420 	/**
421 	
422 	*/
423 	void setTextureRotation(in double texture_rotation)
424 	{
425 		checkClassBinding!(typeof(this))();
426 		ptrcall!(void)(GDNativeClassBinding.setTextureRotation, _godot_object, texture_rotation);
427 	}
428 	/**
429 	
430 	*/
431 	void setTextureRotationDegrees(in double texture_rotation)
432 	{
433 		checkClassBinding!(typeof(this))();
434 		ptrcall!(void)(GDNativeClassBinding.setTextureRotationDegrees, _godot_object, texture_rotation);
435 	}
436 	/**
437 	
438 	*/
439 	void setTextureScale(in Vector2 texture_scale)
440 	{
441 		checkClassBinding!(typeof(this))();
442 		ptrcall!(void)(GDNativeClassBinding.setTextureScale, _godot_object, texture_scale);
443 	}
444 	/**
445 	
446 	*/
447 	void setUv(in PoolVector2Array uv)
448 	{
449 		checkClassBinding!(typeof(this))();
450 		ptrcall!(void)(GDNativeClassBinding.setUv, _godot_object, uv);
451 	}
452 	/**
453 	
454 	*/
455 	void setVertexColors(in PoolColorArray vertex_colors)
456 	{
457 		checkClassBinding!(typeof(this))();
458 		ptrcall!(void)(GDNativeClassBinding.setVertexColors, _godot_object, vertex_colors);
459 	}
460 	/**
461 	If `true`, polygon edges will be anti-aliased.
462 	*/
463 	@property bool antialiased()
464 	{
465 		return getAntialiased();
466 	}
467 	/// ditto
468 	@property void antialiased(bool v)
469 	{
470 		setAntialiased(v);
471 	}
472 	/**
473 	
474 	*/
475 	@property Array bones()
476 	{
477 		return _getBones();
478 	}
479 	/// ditto
480 	@property void bones(Array v)
481 	{
482 		_setBones(v);
483 	}
484 	/**
485 	The polygon's fill color. If `texture` is defined, it will be multiplied by this color. It will also be the default color for vertices not set in `vertex_colors`.
486 	*/
487 	@property Color color()
488 	{
489 		return getColor();
490 	}
491 	/// ditto
492 	@property void color(Color v)
493 	{
494 		setColor(v);
495 	}
496 	/**
497 	
498 	*/
499 	@property long internalVertexCount()
500 	{
501 		return getInternalVertexCount();
502 	}
503 	/// ditto
504 	@property void internalVertexCount(long v)
505 	{
506 		setInternalVertexCount(v);
507 	}
508 	/**
509 	Added padding applied to the bounding box when using `invert`. Setting this value too small may result in a "Bad Polygon" error.
510 	*/
511 	@property double invertBorder()
512 	{
513 		return getInvertBorder();
514 	}
515 	/// ditto
516 	@property void invertBorder(double v)
517 	{
518 		setInvertBorder(v);
519 	}
520 	/**
521 	If `true`, polygon will be inverted, containing the area outside the defined points and extending to the `invert_border`.
522 	*/
523 	@property bool invertEnable()
524 	{
525 		return getInvert();
526 	}
527 	/// ditto
528 	@property void invertEnable(bool v)
529 	{
530 		setInvert(v);
531 	}
532 	/**
533 	The offset applied to each vertex.
534 	*/
535 	@property Vector2 offset()
536 	{
537 		return getOffset();
538 	}
539 	/// ditto
540 	@property void offset(Vector2 v)
541 	{
542 		setOffset(v);
543 	}
544 	/**
545 	The polygon's list of vertices. The final point will be connected to the first.
546 	$(B Note:) This returns a copy of the $(D PoolVector2Array) rather than a reference.
547 	*/
548 	@property PoolVector2Array polygon()
549 	{
550 		return getPolygon();
551 	}
552 	/// ditto
553 	@property void polygon(PoolVector2Array v)
554 	{
555 		setPolygon(v);
556 	}
557 	/**
558 	
559 	*/
560 	@property Array polygons()
561 	{
562 		return getPolygons();
563 	}
564 	/// ditto
565 	@property void polygons(Array v)
566 	{
567 		setPolygons(v);
568 	}
569 	/**
570 	
571 	*/
572 	@property NodePath skeleton()
573 	{
574 		return getSkeleton();
575 	}
576 	/// ditto
577 	@property void skeleton(NodePath v)
578 	{
579 		setSkeleton(v);
580 	}
581 	/**
582 	The polygon's fill texture. Use `uv` to set texture coordinates.
583 	*/
584 	@property Texture texture()
585 	{
586 		return getTexture();
587 	}
588 	/// ditto
589 	@property void texture(Texture v)
590 	{
591 		setTexture(v);
592 	}
593 	/**
594 	Amount to offset the polygon's `texture`. If `(0, 0)` the texture's origin (its top-left corner) will be placed at the polygon's `position`.
595 	*/
596 	@property Vector2 textureOffset()
597 	{
598 		return getTextureOffset();
599 	}
600 	/// ditto
601 	@property void textureOffset(Vector2 v)
602 	{
603 		setTextureOffset(v);
604 	}
605 	/**
606 	The texture's rotation in radians.
607 	*/
608 	@property double textureRotation()
609 	{
610 		return getTextureRotation();
611 	}
612 	/// ditto
613 	@property void textureRotation(double v)
614 	{
615 		setTextureRotation(v);
616 	}
617 	/**
618 	The texture's rotation in degrees.
619 	*/
620 	@property double textureRotationDegrees()
621 	{
622 		return getTextureRotationDegrees();
623 	}
624 	/// ditto
625 	@property void textureRotationDegrees(double v)
626 	{
627 		setTextureRotationDegrees(v);
628 	}
629 	/**
630 	Amount to multiply the `uv` coordinates when using a `texture`. Larger values make the texture smaller, and vice versa.
631 	*/
632 	@property Vector2 textureScale()
633 	{
634 		return getTextureScale();
635 	}
636 	/// ditto
637 	@property void textureScale(Vector2 v)
638 	{
639 		setTextureScale(v);
640 	}
641 	/**
642 	Texture coordinates for each vertex of the polygon. There should be one `uv` per polygon vertex. If there are fewer, undefined vertices will use `(0, 0)`.
643 	*/
644 	@property PoolVector2Array uv()
645 	{
646 		return getUv();
647 	}
648 	/// ditto
649 	@property void uv(PoolVector2Array v)
650 	{
651 		setUv(v);
652 	}
653 	/**
654 	Color for each vertex. Colors are interpolated between vertices, resulting in smooth gradients. There should be one per polygon vertex. If there are fewer, undefined vertices will use `color`.
655 	*/
656 	@property PoolColorArray vertexColors()
657 	{
658 		return getVertexColors();
659 	}
660 	/// ditto
661 	@property void vertexColors(PoolColorArray v)
662 	{
663 		setVertexColors(v);
664 	}
665 }