1 /** 2 Point sampler for a $(D Path2D). 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.pathfollow2d; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.node2d; 24 import godot.canvasitem; 25 import godot.node; 26 /** 27 Point sampler for a $(D Path2D). 28 29 This node takes its parent $(D Path2D), and returns the coordinates of a point within it, given a distance from the first vertex. 30 It is useful for making other nodes follow a path, without coding the movement pattern. For that, the nodes must be descendants of this node. Then, when setting an offset in this node, the descendant nodes will move accordingly. 31 */ 32 @GodotBaseClass struct PathFollow2D 33 { 34 enum string _GODOT_internal_name = "PathFollow2D"; 35 public: 36 @nogc nothrow: 37 union { godot_object _godot_object; Node2D _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct _classBinding 42 { 43 __gshared: 44 @GodotName("set_offset") GodotMethod!(void, double) setOffset; 45 @GodotName("get_offset") GodotMethod!(double) getOffset; 46 @GodotName("set_h_offset") GodotMethod!(void, double) setHOffset; 47 @GodotName("get_h_offset") GodotMethod!(double) getHOffset; 48 @GodotName("set_v_offset") GodotMethod!(void, double) setVOffset; 49 @GodotName("get_v_offset") GodotMethod!(double) getVOffset; 50 @GodotName("set_unit_offset") GodotMethod!(void, double) setUnitOffset; 51 @GodotName("get_unit_offset") GodotMethod!(double) getUnitOffset; 52 @GodotName("set_rotate") GodotMethod!(void, bool) setRotate; 53 @GodotName("is_rotating") GodotMethod!(bool) isRotating; 54 @GodotName("set_cubic_interpolation") GodotMethod!(void, bool) setCubicInterpolation; 55 @GodotName("get_cubic_interpolation") GodotMethod!(bool) getCubicInterpolation; 56 @GodotName("set_loop") GodotMethod!(void, bool) setLoop; 57 @GodotName("has_loop") GodotMethod!(bool) hasLoop; 58 @GodotName("set_lookahead") GodotMethod!(void, double) setLookahead; 59 @GodotName("get_lookahead") GodotMethod!(double) getLookahead; 60 } 61 bool opEquals(in PathFollow2D other) const { return _godot_object.ptr is other._godot_object.ptr; } 62 PathFollow2D opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 63 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 64 mixin baseCasts; 65 static PathFollow2D _new() 66 { 67 static godot_class_constructor constructor; 68 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PathFollow2D"); 69 if(constructor is null) return typeof(this).init; 70 return cast(PathFollow2D)(constructor()); 71 } 72 @disable new(size_t s); 73 /** 74 75 */ 76 void setOffset(in double offset) 77 { 78 checkClassBinding!(typeof(this))(); 79 ptrcall!(void)(_classBinding.setOffset, _godot_object, offset); 80 } 81 /** 82 83 */ 84 double getOffset() const 85 { 86 checkClassBinding!(typeof(this))(); 87 return ptrcall!(double)(_classBinding.getOffset, _godot_object); 88 } 89 /** 90 91 */ 92 void setHOffset(in double h_offset) 93 { 94 checkClassBinding!(typeof(this))(); 95 ptrcall!(void)(_classBinding.setHOffset, _godot_object, h_offset); 96 } 97 /** 98 99 */ 100 double getHOffset() const 101 { 102 checkClassBinding!(typeof(this))(); 103 return ptrcall!(double)(_classBinding.getHOffset, _godot_object); 104 } 105 /** 106 107 */ 108 void setVOffset(in double v_offset) 109 { 110 checkClassBinding!(typeof(this))(); 111 ptrcall!(void)(_classBinding.setVOffset, _godot_object, v_offset); 112 } 113 /** 114 115 */ 116 double getVOffset() const 117 { 118 checkClassBinding!(typeof(this))(); 119 return ptrcall!(double)(_classBinding.getVOffset, _godot_object); 120 } 121 /** 122 123 */ 124 void setUnitOffset(in double unit_offset) 125 { 126 checkClassBinding!(typeof(this))(); 127 ptrcall!(void)(_classBinding.setUnitOffset, _godot_object, unit_offset); 128 } 129 /** 130 131 */ 132 double getUnitOffset() const 133 { 134 checkClassBinding!(typeof(this))(); 135 return ptrcall!(double)(_classBinding.getUnitOffset, _godot_object); 136 } 137 /** 138 139 */ 140 void setRotate(in bool enable) 141 { 142 checkClassBinding!(typeof(this))(); 143 ptrcall!(void)(_classBinding.setRotate, _godot_object, enable); 144 } 145 /** 146 147 */ 148 bool isRotating() const 149 { 150 checkClassBinding!(typeof(this))(); 151 return ptrcall!(bool)(_classBinding.isRotating, _godot_object); 152 } 153 /** 154 155 */ 156 void setCubicInterpolation(in bool enable) 157 { 158 checkClassBinding!(typeof(this))(); 159 ptrcall!(void)(_classBinding.setCubicInterpolation, _godot_object, enable); 160 } 161 /** 162 163 */ 164 bool getCubicInterpolation() const 165 { 166 checkClassBinding!(typeof(this))(); 167 return ptrcall!(bool)(_classBinding.getCubicInterpolation, _godot_object); 168 } 169 /** 170 171 */ 172 void setLoop(in bool loop) 173 { 174 checkClassBinding!(typeof(this))(); 175 ptrcall!(void)(_classBinding.setLoop, _godot_object, loop); 176 } 177 /** 178 179 */ 180 bool hasLoop() const 181 { 182 checkClassBinding!(typeof(this))(); 183 return ptrcall!(bool)(_classBinding.hasLoop, _godot_object); 184 } 185 /** 186 187 */ 188 void setLookahead(in double lookahead) 189 { 190 checkClassBinding!(typeof(this))(); 191 ptrcall!(void)(_classBinding.setLookahead, _godot_object, lookahead); 192 } 193 /** 194 195 */ 196 double getLookahead() const 197 { 198 checkClassBinding!(typeof(this))(); 199 return ptrcall!(double)(_classBinding.getLookahead, _godot_object); 200 } 201 /** 202 The distance along the path in pixels. 203 */ 204 @property double offset() 205 { 206 return getOffset(); 207 } 208 /// ditto 209 @property void offset(double v) 210 { 211 setOffset(v); 212 } 213 /** 214 The distance along the path as a number in the range 0.0 (for the first vertex) to 1.0 (for the last). This is just another way of expressing the offset within the path, as the offset supplied is multiplied internally by the path's length. 215 */ 216 @property double unitOffset() 217 { 218 return getUnitOffset(); 219 } 220 /// ditto 221 @property void unitOffset(double v) 222 { 223 setUnitOffset(v); 224 } 225 /** 226 The node's offset along the curve. 227 */ 228 @property double hOffset() 229 { 230 return getHOffset(); 231 } 232 /// ditto 233 @property void hOffset(double v) 234 { 235 setHOffset(v); 236 } 237 /** 238 The node's offset perpendicular to the curve. 239 */ 240 @property double vOffset() 241 { 242 return getVOffset(); 243 } 244 /// ditto 245 @property void vOffset(double v) 246 { 247 setVOffset(v); 248 } 249 /** 250 If `true`, this node rotates to follow the path, making its descendants rotate. 251 */ 252 @property bool rotate() 253 { 254 return isRotating(); 255 } 256 /// ditto 257 @property void rotate(bool v) 258 { 259 setRotate(v); 260 } 261 /** 262 If `true` the position between two cached points is interpolated cubically, and linearly otherwise. 263 The points along the $(D Curve2D) of the $(D Path2D) are precomputed before use, for faster calculations. The point at the requested offset is then calculated interpolating between two adjacent cached points. This may present a problem if the curve makes sharp turns, as the cached points may not follow the curve closely enough. 264 There are two answers to this problem: Either increase the number of cached points and increase memory consumption, or make a cubic interpolation between two points at the cost of (slightly) slower calculations. 265 */ 266 @property bool cubicInterp() 267 { 268 return getCubicInterpolation(); 269 } 270 /// ditto 271 @property void cubicInterp(bool v) 272 { 273 setCubicInterpolation(v); 274 } 275 /** 276 If `true`, any offset outside the path's length will wrap around, instead of stopping at the ends. Use it for cyclic paths. 277 */ 278 @property bool loop() 279 { 280 return hasLoop(); 281 } 282 /// ditto 283 @property void loop(bool v) 284 { 285 setLoop(v); 286 } 287 /** 288 How far to look ahead of the curve to calculate the tangent if the node is rotating. E.g. shorter lookaheads will lead to faster rotations. Default value: `4`. 289 */ 290 @property double lookahead() 291 { 292 return getLookahead(); 293 } 294 /// ditto 295 @property void lookahead(double v) 296 { 297 setLookahead(v); 298 } 299 }