1 /**
2 A 2D line.
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.line2d;
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.curve;
26 import godot.gradient;
27 import godot.texture;
28 /**
29 A 2D line.
30 
31 A line through several points in 2D space.
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 Line2D
35 {
36 	package(godot) enum string _GODOT_internal_name = "Line2D";
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("_curve_changed") GodotMethod!(void) _curveChanged;
47 		@GodotName("_gradient_changed") GodotMethod!(void) _gradientChanged;
48 		@GodotName("add_point") GodotMethod!(void, Vector2, long) addPoint;
49 		@GodotName("clear_points") GodotMethod!(void) clearPoints;
50 		@GodotName("get_antialiased") GodotMethod!(bool) getAntialiased;
51 		@GodotName("get_begin_cap_mode") GodotMethod!(Line2D.LineCapMode) getBeginCapMode;
52 		@GodotName("get_curve") GodotMethod!(Curve) getCurve;
53 		@GodotName("get_default_color") GodotMethod!(Color) getDefaultColor;
54 		@GodotName("get_end_cap_mode") GodotMethod!(Line2D.LineCapMode) getEndCapMode;
55 		@GodotName("get_gradient") GodotMethod!(Gradient) getGradient;
56 		@GodotName("get_joint_mode") GodotMethod!(Line2D.LineJointMode) getJointMode;
57 		@GodotName("get_point_count") GodotMethod!(long) getPointCount;
58 		@GodotName("get_point_position") GodotMethod!(Vector2, long) getPointPosition;
59 		@GodotName("get_points") GodotMethod!(PoolVector2Array) getPoints;
60 		@GodotName("get_round_precision") GodotMethod!(long) getRoundPrecision;
61 		@GodotName("get_sharp_limit") GodotMethod!(double) getSharpLimit;
62 		@GodotName("get_texture") GodotMethod!(Texture) getTexture;
63 		@GodotName("get_texture_mode") GodotMethod!(Line2D.LineTextureMode) getTextureMode;
64 		@GodotName("get_width") GodotMethod!(double) getWidth;
65 		@GodotName("remove_point") GodotMethod!(void, long) removePoint;
66 		@GodotName("set_antialiased") GodotMethod!(void, bool) setAntialiased;
67 		@GodotName("set_begin_cap_mode") GodotMethod!(void, long) setBeginCapMode;
68 		@GodotName("set_curve") GodotMethod!(void, Curve) setCurve;
69 		@GodotName("set_default_color") GodotMethod!(void, Color) setDefaultColor;
70 		@GodotName("set_end_cap_mode") GodotMethod!(void, long) setEndCapMode;
71 		@GodotName("set_gradient") GodotMethod!(void, Gradient) setGradient;
72 		@GodotName("set_joint_mode") GodotMethod!(void, long) setJointMode;
73 		@GodotName("set_point_position") GodotMethod!(void, long, Vector2) setPointPosition;
74 		@GodotName("set_points") GodotMethod!(void, PoolVector2Array) setPoints;
75 		@GodotName("set_round_precision") GodotMethod!(void, long) setRoundPrecision;
76 		@GodotName("set_sharp_limit") GodotMethod!(void, double) setSharpLimit;
77 		@GodotName("set_texture") GodotMethod!(void, Texture) setTexture;
78 		@GodotName("set_texture_mode") GodotMethod!(void, long) setTextureMode;
79 		@GodotName("set_width") GodotMethod!(void, double) setWidth;
80 	}
81 	/// 
82 	pragma(inline, true) bool opEquals(in Line2D other) const
83 	{ return _godot_object.ptr is other._godot_object.ptr; }
84 	/// 
85 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
86 	{ _godot_object.ptr = n; return null; }
87 	/// 
88 	pragma(inline, true) bool opEquals(typeof(null) n) const
89 	{ return _godot_object.ptr is n; }
90 	/// 
91 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
92 	mixin baseCasts;
93 	/// Construct a new instance of Line2D.
94 	/// Note: use `memnew!Line2D` instead.
95 	static Line2D _new()
96 	{
97 		static godot_class_constructor constructor;
98 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Line2D");
99 		if(constructor is null) return typeof(this).init;
100 		return cast(Line2D)(constructor());
101 	}
102 	@disable new(size_t s);
103 	/// 
104 	enum LineTextureMode : int
105 	{
106 		/**
107 		Takes the left pixels of the texture and renders it over the whole line.
108 		*/
109 		lineTextureNone = 0,
110 		/**
111 		Tiles the texture over the line. The texture must be imported with $(B Repeat) enabled for it to work properly.
112 		*/
113 		lineTextureTile = 1,
114 		/**
115 		Stretches the texture across the line. Import the texture with $(B Repeat) disabled for best results.
116 		*/
117 		lineTextureStretch = 2,
118 	}
119 	/// 
120 	enum LineCapMode : int
121 	{
122 		/**
123 		Don't draw a line cap.
124 		*/
125 		lineCapNone = 0,
126 		/**
127 		Draws the line cap as a box.
128 		*/
129 		lineCapBox = 1,
130 		/**
131 		Draws the line cap as a circle.
132 		*/
133 		lineCapRound = 2,
134 	}
135 	/// 
136 	enum LineJointMode : int
137 	{
138 		/**
139 		The line's joints will be pointy. If `sharp_limit` is greater than the rotation of a joint, it becomes a bevel joint instead.
140 		*/
141 		lineJointSharp = 0,
142 		/**
143 		The line's joints will be bevelled/chamfered.
144 		*/
145 		lineJointBevel = 1,
146 		/**
147 		The line's joints will be rounded.
148 		*/
149 		lineJointRound = 2,
150 	}
151 	/// 
152 	enum Constants : int
153 	{
154 		lineCapNone = 0,
155 		lineJointSharp = 0,
156 		lineTextureNone = 0,
157 		lineCapBox = 1,
158 		lineTextureTile = 1,
159 		lineJointBevel = 1,
160 		lineJointRound = 2,
161 		lineTextureStretch = 2,
162 		lineCapRound = 2,
163 	}
164 	/**
165 	
166 	*/
167 	void _curveChanged()
168 	{
169 		Array _GODOT_args = Array.make();
170 		String _GODOT_method_name = String("_curve_changed");
171 		this.callv(_GODOT_method_name, _GODOT_args);
172 	}
173 	/**
174 	
175 	*/
176 	void _gradientChanged()
177 	{
178 		Array _GODOT_args = Array.make();
179 		String _GODOT_method_name = String("_gradient_changed");
180 		this.callv(_GODOT_method_name, _GODOT_args);
181 	}
182 	/**
183 	Adds a point at the `position`. Appends the point at the end of the line.
184 	If `at_position` is given, the point is inserted before the point number `at_position`, moving that point (and every point after) after the inserted point. If `at_position` is not given, or is an illegal value (`at_position < 0` or `at_position >= $(D getPointCount)`), the point will be appended at the end of the point list.
185 	*/
186 	void addPoint(in Vector2 position, in long at_position = -1)
187 	{
188 		checkClassBinding!(typeof(this))();
189 		ptrcall!(void)(GDNativeClassBinding.addPoint, _godot_object, position, at_position);
190 	}
191 	/**
192 	Removes all points from the line.
193 	*/
194 	void clearPoints()
195 	{
196 		checkClassBinding!(typeof(this))();
197 		ptrcall!(void)(GDNativeClassBinding.clearPoints, _godot_object);
198 	}
199 	/**
200 	
201 	*/
202 	bool getAntialiased() const
203 	{
204 		checkClassBinding!(typeof(this))();
205 		return ptrcall!(bool)(GDNativeClassBinding.getAntialiased, _godot_object);
206 	}
207 	/**
208 	
209 	*/
210 	Line2D.LineCapMode getBeginCapMode() const
211 	{
212 		checkClassBinding!(typeof(this))();
213 		return ptrcall!(Line2D.LineCapMode)(GDNativeClassBinding.getBeginCapMode, _godot_object);
214 	}
215 	/**
216 	
217 	*/
218 	Ref!Curve getCurve() const
219 	{
220 		checkClassBinding!(typeof(this))();
221 		return ptrcall!(Curve)(GDNativeClassBinding.getCurve, _godot_object);
222 	}
223 	/**
224 	
225 	*/
226 	Color getDefaultColor() const
227 	{
228 		checkClassBinding!(typeof(this))();
229 		return ptrcall!(Color)(GDNativeClassBinding.getDefaultColor, _godot_object);
230 	}
231 	/**
232 	
233 	*/
234 	Line2D.LineCapMode getEndCapMode() const
235 	{
236 		checkClassBinding!(typeof(this))();
237 		return ptrcall!(Line2D.LineCapMode)(GDNativeClassBinding.getEndCapMode, _godot_object);
238 	}
239 	/**
240 	
241 	*/
242 	Ref!Gradient getGradient() const
243 	{
244 		checkClassBinding!(typeof(this))();
245 		return ptrcall!(Gradient)(GDNativeClassBinding.getGradient, _godot_object);
246 	}
247 	/**
248 	
249 	*/
250 	Line2D.LineJointMode getJointMode() const
251 	{
252 		checkClassBinding!(typeof(this))();
253 		return ptrcall!(Line2D.LineJointMode)(GDNativeClassBinding.getJointMode, _godot_object);
254 	}
255 	/**
256 	Returns the Line2D's amount of points.
257 	*/
258 	long getPointCount() const
259 	{
260 		checkClassBinding!(typeof(this))();
261 		return ptrcall!(long)(GDNativeClassBinding.getPointCount, _godot_object);
262 	}
263 	/**
264 	Returns point `i`'s position.
265 	*/
266 	Vector2 getPointPosition(in long i) const
267 	{
268 		checkClassBinding!(typeof(this))();
269 		return ptrcall!(Vector2)(GDNativeClassBinding.getPointPosition, _godot_object, i);
270 	}
271 	/**
272 	
273 	*/
274 	PoolVector2Array getPoints() const
275 	{
276 		checkClassBinding!(typeof(this))();
277 		return ptrcall!(PoolVector2Array)(GDNativeClassBinding.getPoints, _godot_object);
278 	}
279 	/**
280 	
281 	*/
282 	long getRoundPrecision() const
283 	{
284 		checkClassBinding!(typeof(this))();
285 		return ptrcall!(long)(GDNativeClassBinding.getRoundPrecision, _godot_object);
286 	}
287 	/**
288 	
289 	*/
290 	double getSharpLimit() const
291 	{
292 		checkClassBinding!(typeof(this))();
293 		return ptrcall!(double)(GDNativeClassBinding.getSharpLimit, _godot_object);
294 	}
295 	/**
296 	
297 	*/
298 	Ref!Texture getTexture() const
299 	{
300 		checkClassBinding!(typeof(this))();
301 		return ptrcall!(Texture)(GDNativeClassBinding.getTexture, _godot_object);
302 	}
303 	/**
304 	
305 	*/
306 	Line2D.LineTextureMode getTextureMode() const
307 	{
308 		checkClassBinding!(typeof(this))();
309 		return ptrcall!(Line2D.LineTextureMode)(GDNativeClassBinding.getTextureMode, _godot_object);
310 	}
311 	/**
312 	
313 	*/
314 	double getWidth() const
315 	{
316 		checkClassBinding!(typeof(this))();
317 		return ptrcall!(double)(GDNativeClassBinding.getWidth, _godot_object);
318 	}
319 	/**
320 	Removes the point at index `i` from the line.
321 	*/
322 	void removePoint(in long i)
323 	{
324 		checkClassBinding!(typeof(this))();
325 		ptrcall!(void)(GDNativeClassBinding.removePoint, _godot_object, i);
326 	}
327 	/**
328 	
329 	*/
330 	void setAntialiased(in bool antialiased)
331 	{
332 		checkClassBinding!(typeof(this))();
333 		ptrcall!(void)(GDNativeClassBinding.setAntialiased, _godot_object, antialiased);
334 	}
335 	/**
336 	
337 	*/
338 	void setBeginCapMode(in long mode)
339 	{
340 		checkClassBinding!(typeof(this))();
341 		ptrcall!(void)(GDNativeClassBinding.setBeginCapMode, _godot_object, mode);
342 	}
343 	/**
344 	
345 	*/
346 	void setCurve(Curve curve)
347 	{
348 		checkClassBinding!(typeof(this))();
349 		ptrcall!(void)(GDNativeClassBinding.setCurve, _godot_object, curve);
350 	}
351 	/**
352 	
353 	*/
354 	void setDefaultColor(in Color color)
355 	{
356 		checkClassBinding!(typeof(this))();
357 		ptrcall!(void)(GDNativeClassBinding.setDefaultColor, _godot_object, color);
358 	}
359 	/**
360 	
361 	*/
362 	void setEndCapMode(in long mode)
363 	{
364 		checkClassBinding!(typeof(this))();
365 		ptrcall!(void)(GDNativeClassBinding.setEndCapMode, _godot_object, mode);
366 	}
367 	/**
368 	
369 	*/
370 	void setGradient(Gradient color)
371 	{
372 		checkClassBinding!(typeof(this))();
373 		ptrcall!(void)(GDNativeClassBinding.setGradient, _godot_object, color);
374 	}
375 	/**
376 	
377 	*/
378 	void setJointMode(in long mode)
379 	{
380 		checkClassBinding!(typeof(this))();
381 		ptrcall!(void)(GDNativeClassBinding.setJointMode, _godot_object, mode);
382 	}
383 	/**
384 	Overwrites the position in point `i` with the supplied `position`.
385 	*/
386 	void setPointPosition(in long i, in Vector2 position)
387 	{
388 		checkClassBinding!(typeof(this))();
389 		ptrcall!(void)(GDNativeClassBinding.setPointPosition, _godot_object, i, position);
390 	}
391 	/**
392 	
393 	*/
394 	void setPoints(in PoolVector2Array points)
395 	{
396 		checkClassBinding!(typeof(this))();
397 		ptrcall!(void)(GDNativeClassBinding.setPoints, _godot_object, points);
398 	}
399 	/**
400 	
401 	*/
402 	void setRoundPrecision(in long precision)
403 	{
404 		checkClassBinding!(typeof(this))();
405 		ptrcall!(void)(GDNativeClassBinding.setRoundPrecision, _godot_object, precision);
406 	}
407 	/**
408 	
409 	*/
410 	void setSharpLimit(in double limit)
411 	{
412 		checkClassBinding!(typeof(this))();
413 		ptrcall!(void)(GDNativeClassBinding.setSharpLimit, _godot_object, limit);
414 	}
415 	/**
416 	
417 	*/
418 	void setTexture(Texture texture)
419 	{
420 		checkClassBinding!(typeof(this))();
421 		ptrcall!(void)(GDNativeClassBinding.setTexture, _godot_object, texture);
422 	}
423 	/**
424 	
425 	*/
426 	void setTextureMode(in long mode)
427 	{
428 		checkClassBinding!(typeof(this))();
429 		ptrcall!(void)(GDNativeClassBinding.setTextureMode, _godot_object, mode);
430 	}
431 	/**
432 	
433 	*/
434 	void setWidth(in double width)
435 	{
436 		checkClassBinding!(typeof(this))();
437 		ptrcall!(void)(GDNativeClassBinding.setWidth, _godot_object, width);
438 	}
439 	/**
440 	If `true`, the line's border will be anti-aliased.
441 	*/
442 	@property bool antialiased()
443 	{
444 		return getAntialiased();
445 	}
446 	/// ditto
447 	@property void antialiased(bool v)
448 	{
449 		setAntialiased(v);
450 	}
451 	/**
452 	Controls the style of the line's first point. Use $(D linecapmode) constants.
453 	*/
454 	@property Line2D.LineCapMode beginCapMode()
455 	{
456 		return getBeginCapMode();
457 	}
458 	/// ditto
459 	@property void beginCapMode(long v)
460 	{
461 		setBeginCapMode(v);
462 	}
463 	/**
464 	The line's color. Will not be used if a gradient is set.
465 	*/
466 	@property Color defaultColor()
467 	{
468 		return getDefaultColor();
469 	}
470 	/// ditto
471 	@property void defaultColor(Color v)
472 	{
473 		setDefaultColor(v);
474 	}
475 	/**
476 	Controls the style of the line's last point. Use $(D linecapmode) constants.
477 	*/
478 	@property Line2D.LineCapMode endCapMode()
479 	{
480 		return getEndCapMode();
481 	}
482 	/// ditto
483 	@property void endCapMode(long v)
484 	{
485 		setEndCapMode(v);
486 	}
487 	/**
488 	The gradient is drawn through the whole line from start to finish. The default color will not be used if a gradient is set.
489 	*/
490 	@property Gradient gradient()
491 	{
492 		return getGradient();
493 	}
494 	/// ditto
495 	@property void gradient(Gradient v)
496 	{
497 		setGradient(v);
498 	}
499 	/**
500 	The style for the points between the start and the end.
501 	*/
502 	@property Line2D.LineJointMode jointMode()
503 	{
504 		return getJointMode();
505 	}
506 	/// ditto
507 	@property void jointMode(long v)
508 	{
509 		setJointMode(v);
510 	}
511 	/**
512 	The points that form the lines. The line is drawn between every point set in this array. Points are interpreted as local vectors.
513 	*/
514 	@property PoolVector2Array points()
515 	{
516 		return getPoints();
517 	}
518 	/// ditto
519 	@property void points(PoolVector2Array v)
520 	{
521 		setPoints(v);
522 	}
523 	/**
524 	The smoothness of the rounded joints and caps. This is only used if a cap or joint is set as round.
525 	*/
526 	@property long roundPrecision()
527 	{
528 		return getRoundPrecision();
529 	}
530 	/// ditto
531 	@property void roundPrecision(long v)
532 	{
533 		setRoundPrecision(v);
534 	}
535 	/**
536 	The direction difference in radians between vector points. This value is only used if `joint mode` is set to $(D constant LINE_JOINT_SHARP).
537 	*/
538 	@property double sharpLimit()
539 	{
540 		return getSharpLimit();
541 	}
542 	/// ditto
543 	@property void sharpLimit(double v)
544 	{
545 		setSharpLimit(v);
546 	}
547 	/**
548 	The texture used for the line's texture. Uses `texture_mode` for drawing style.
549 	*/
550 	@property Texture texture()
551 	{
552 		return getTexture();
553 	}
554 	/// ditto
555 	@property void texture(Texture v)
556 	{
557 		setTexture(v);
558 	}
559 	/**
560 	The style to render the `texture` on the line. Use $(D linetexturemode) constants.
561 	*/
562 	@property Line2D.LineTextureMode textureMode()
563 	{
564 		return getTextureMode();
565 	}
566 	/// ditto
567 	@property void textureMode(long v)
568 	{
569 		setTextureMode(v);
570 	}
571 	/**
572 	The line's width.
573 	*/
574 	@property double width()
575 	{
576 		return getWidth();
577 	}
578 	/// ditto
579 	@property void width(double v)
580 	{
581 		setWidth(v);
582 	}
583 	/**
584 	The line's width varies with the curve. The original width is simply multiply by the value of the Curve.
585 	*/
586 	@property Curve widthCurve()
587 	{
588 		return getCurve();
589 	}
590 	/// ditto
591 	@property void widthCurve(Curve v)
592 	{
593 		setCurve(v);
594 	}
595 }