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.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 /** 28 Point sampler for a $(D Path2D). 29 30 This node takes its parent $(D Path2D), and returns the coordinates of a point within it, given a distance from the first vertex. 31 It is useful for making other nodes follow a path, without coding the movement pattern. For that, the nodes must be children of this node. The descendant nodes will then move accordingly when setting an offset in this node. 32 */ 33 @GodotBaseClass struct PathFollow2D 34 { 35 package(godot) enum string _GODOT_internal_name = "PathFollow2D"; 36 public: 37 @nogc nothrow: 38 union { /** */ godot_object _godot_object; /** */ Node2D _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_cubic_interpolation") GodotMethod!(bool) getCubicInterpolation; 46 @GodotName("get_h_offset") GodotMethod!(double) getHOffset; 47 @GodotName("get_lookahead") GodotMethod!(double) getLookahead; 48 @GodotName("get_offset") GodotMethod!(double) getOffset; 49 @GodotName("get_unit_offset") GodotMethod!(double) getUnitOffset; 50 @GodotName("get_v_offset") GodotMethod!(double) getVOffset; 51 @GodotName("has_loop") GodotMethod!(bool) hasLoop; 52 @GodotName("is_rotating") GodotMethod!(bool) isRotating; 53 @GodotName("set_cubic_interpolation") GodotMethod!(void, bool) setCubicInterpolation; 54 @GodotName("set_h_offset") GodotMethod!(void, double) setHOffset; 55 @GodotName("set_lookahead") GodotMethod!(void, double) setLookahead; 56 @GodotName("set_loop") GodotMethod!(void, bool) setLoop; 57 @GodotName("set_offset") GodotMethod!(void, double) setOffset; 58 @GodotName("set_rotate") GodotMethod!(void, bool) setRotate; 59 @GodotName("set_unit_offset") GodotMethod!(void, double) setUnitOffset; 60 @GodotName("set_v_offset") GodotMethod!(void, double) setVOffset; 61 } 62 /// 63 pragma(inline, true) bool opEquals(in PathFollow2D other) const 64 { return _godot_object.ptr is other._godot_object.ptr; } 65 /// 66 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 67 { _godot_object.ptr = n; return null; } 68 /// 69 pragma(inline, true) bool opEquals(typeof(null) n) const 70 { return _godot_object.ptr is n; } 71 /// 72 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 73 mixin baseCasts; 74 /// Construct a new instance of PathFollow2D. 75 /// Note: use `memnew!PathFollow2D` instead. 76 static PathFollow2D _new() 77 { 78 static godot_class_constructor constructor; 79 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PathFollow2D"); 80 if(constructor is null) return typeof(this).init; 81 return cast(PathFollow2D)(constructor()); 82 } 83 @disable new(size_t s); 84 /** 85 86 */ 87 bool getCubicInterpolation() const 88 { 89 checkClassBinding!(typeof(this))(); 90 return ptrcall!(bool)(GDNativeClassBinding.getCubicInterpolation, _godot_object); 91 } 92 /** 93 94 */ 95 double getHOffset() const 96 { 97 checkClassBinding!(typeof(this))(); 98 return ptrcall!(double)(GDNativeClassBinding.getHOffset, _godot_object); 99 } 100 /** 101 102 */ 103 double getLookahead() const 104 { 105 checkClassBinding!(typeof(this))(); 106 return ptrcall!(double)(GDNativeClassBinding.getLookahead, _godot_object); 107 } 108 /** 109 110 */ 111 double getOffset() const 112 { 113 checkClassBinding!(typeof(this))(); 114 return ptrcall!(double)(GDNativeClassBinding.getOffset, _godot_object); 115 } 116 /** 117 118 */ 119 double getUnitOffset() const 120 { 121 checkClassBinding!(typeof(this))(); 122 return ptrcall!(double)(GDNativeClassBinding.getUnitOffset, _godot_object); 123 } 124 /** 125 126 */ 127 double getVOffset() const 128 { 129 checkClassBinding!(typeof(this))(); 130 return ptrcall!(double)(GDNativeClassBinding.getVOffset, _godot_object); 131 } 132 /** 133 134 */ 135 bool hasLoop() const 136 { 137 checkClassBinding!(typeof(this))(); 138 return ptrcall!(bool)(GDNativeClassBinding.hasLoop, _godot_object); 139 } 140 /** 141 142 */ 143 bool isRotating() const 144 { 145 checkClassBinding!(typeof(this))(); 146 return ptrcall!(bool)(GDNativeClassBinding.isRotating, _godot_object); 147 } 148 /** 149 150 */ 151 void setCubicInterpolation(in bool enable) 152 { 153 checkClassBinding!(typeof(this))(); 154 ptrcall!(void)(GDNativeClassBinding.setCubicInterpolation, _godot_object, enable); 155 } 156 /** 157 158 */ 159 void setHOffset(in double h_offset) 160 { 161 checkClassBinding!(typeof(this))(); 162 ptrcall!(void)(GDNativeClassBinding.setHOffset, _godot_object, h_offset); 163 } 164 /** 165 166 */ 167 void setLookahead(in double lookahead) 168 { 169 checkClassBinding!(typeof(this))(); 170 ptrcall!(void)(GDNativeClassBinding.setLookahead, _godot_object, lookahead); 171 } 172 /** 173 174 */ 175 void setLoop(in bool loop) 176 { 177 checkClassBinding!(typeof(this))(); 178 ptrcall!(void)(GDNativeClassBinding.setLoop, _godot_object, loop); 179 } 180 /** 181 182 */ 183 void setOffset(in double offset) 184 { 185 checkClassBinding!(typeof(this))(); 186 ptrcall!(void)(GDNativeClassBinding.setOffset, _godot_object, offset); 187 } 188 /** 189 190 */ 191 void setRotate(in bool enable) 192 { 193 checkClassBinding!(typeof(this))(); 194 ptrcall!(void)(GDNativeClassBinding.setRotate, _godot_object, enable); 195 } 196 /** 197 198 */ 199 void setUnitOffset(in double unit_offset) 200 { 201 checkClassBinding!(typeof(this))(); 202 ptrcall!(void)(GDNativeClassBinding.setUnitOffset, _godot_object, unit_offset); 203 } 204 /** 205 206 */ 207 void setVOffset(in double v_offset) 208 { 209 checkClassBinding!(typeof(this))(); 210 ptrcall!(void)(GDNativeClassBinding.setVOffset, _godot_object, v_offset); 211 } 212 /** 213 If `true`, the position between two cached points is interpolated cubically, and linearly otherwise. 214 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. 215 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. 216 */ 217 @property bool cubicInterp() 218 { 219 return getCubicInterpolation(); 220 } 221 /// ditto 222 @property void cubicInterp(bool v) 223 { 224 setCubicInterpolation(v); 225 } 226 /** 227 The node's offset along the curve. 228 */ 229 @property double hOffset() 230 { 231 return getHOffset(); 232 } 233 /// ditto 234 @property void hOffset(double v) 235 { 236 setHOffset(v); 237 } 238 /** 239 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. 240 */ 241 @property double lookahead() 242 { 243 return getLookahead(); 244 } 245 /// ditto 246 @property void lookahead(double v) 247 { 248 setLookahead(v); 249 } 250 /** 251 If `true`, any offset outside the path's length will wrap around, instead of stopping at the ends. Use it for cyclic paths. 252 */ 253 @property bool loop() 254 { 255 return hasLoop(); 256 } 257 /// ditto 258 @property void loop(bool v) 259 { 260 setLoop(v); 261 } 262 /** 263 The distance along the path in pixels. 264 */ 265 @property double offset() 266 { 267 return getOffset(); 268 } 269 /// ditto 270 @property void offset(double v) 271 { 272 setOffset(v); 273 } 274 /** 275 If `true`, this node rotates to follow the path, making its descendants rotate. 276 */ 277 @property bool rotate() 278 { 279 return isRotating(); 280 } 281 /// ditto 282 @property void rotate(bool v) 283 { 284 setRotate(v); 285 } 286 /** 287 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. 288 */ 289 @property double unitOffset() 290 { 291 return getUnitOffset(); 292 } 293 /// ditto 294 @property void unitOffset(double v) 295 { 296 setUnitOffset(v); 297 } 298 /** 299 The node's offset perpendicular to the curve. 300 */ 301 @property double vOffset() 302 { 303 return getVOffset(); 304 } 305 /// ditto 306 @property void vOffset(double v) 307 { 308 setVOffset(v); 309 } 310 }