1 /** 2 A mathematic curve. 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.curve; 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.resource; 25 /** 26 A mathematic curve. 27 28 A curve that can be saved and re-used for other objects. By default, it ranges between `0` and `1` on the Y axis and positions points relative to the `0.5` Y position. 29 */ 30 @GodotBaseClass struct Curve 31 { 32 package(godot) enum string _GODOT_internal_name = "Curve"; 33 public: 34 @nogc nothrow: 35 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct GDNativeClassBinding 40 { 41 __gshared: 42 @GodotName("_get_data") GodotMethod!(Array) _getData; 43 @GodotName("_set_data") GodotMethod!(void, Array) _setData; 44 @GodotName("add_point") GodotMethod!(long, Vector2, double, double, long, long) addPoint; 45 @GodotName("bake") GodotMethod!(void) bake; 46 @GodotName("clean_dupes") GodotMethod!(void) cleanDupes; 47 @GodotName("clear_points") GodotMethod!(void) clearPoints; 48 @GodotName("get_bake_resolution") GodotMethod!(long) getBakeResolution; 49 @GodotName("get_max_value") GodotMethod!(double) getMaxValue; 50 @GodotName("get_min_value") GodotMethod!(double) getMinValue; 51 @GodotName("get_point_count") GodotMethod!(long) getPointCount; 52 @GodotName("get_point_left_mode") GodotMethod!(Curve.TangentMode, long) getPointLeftMode; 53 @GodotName("get_point_left_tangent") GodotMethod!(double, long) getPointLeftTangent; 54 @GodotName("get_point_position") GodotMethod!(Vector2, long) getPointPosition; 55 @GodotName("get_point_right_mode") GodotMethod!(Curve.TangentMode, long) getPointRightMode; 56 @GodotName("get_point_right_tangent") GodotMethod!(double, long) getPointRightTangent; 57 @GodotName("interpolate") GodotMethod!(double, double) interpolate; 58 @GodotName("interpolate_baked") GodotMethod!(double, double) interpolateBaked; 59 @GodotName("remove_point") GodotMethod!(void, long) removePoint; 60 @GodotName("set_bake_resolution") GodotMethod!(void, long) setBakeResolution; 61 @GodotName("set_max_value") GodotMethod!(void, double) setMaxValue; 62 @GodotName("set_min_value") GodotMethod!(void, double) setMinValue; 63 @GodotName("set_point_left_mode") GodotMethod!(void, long, long) setPointLeftMode; 64 @GodotName("set_point_left_tangent") GodotMethod!(void, long, double) setPointLeftTangent; 65 @GodotName("set_point_offset") GodotMethod!(long, long, double) setPointOffset; 66 @GodotName("set_point_right_mode") GodotMethod!(void, long, long) setPointRightMode; 67 @GodotName("set_point_right_tangent") GodotMethod!(void, long, double) setPointRightTangent; 68 @GodotName("set_point_value") GodotMethod!(void, long, double) setPointValue; 69 } 70 /// 71 pragma(inline, true) bool opEquals(in Curve other) const 72 { return _godot_object.ptr is other._godot_object.ptr; } 73 /// 74 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 75 { _godot_object.ptr = n; return null; } 76 /// 77 pragma(inline, true) bool opEquals(typeof(null) n) const 78 { return _godot_object.ptr is n; } 79 /// 80 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 81 mixin baseCasts; 82 /// Construct a new instance of Curve. 83 /// Note: use `memnew!Curve` instead. 84 static Curve _new() 85 { 86 static godot_class_constructor constructor; 87 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Curve"); 88 if(constructor is null) return typeof(this).init; 89 return cast(Curve)(constructor()); 90 } 91 @disable new(size_t s); 92 /// 93 enum TangentMode : int 94 { 95 /** 96 The tangent on this side of the point is user-defined. 97 */ 98 tangentFree = 0, 99 /** 100 The curve calculates the tangent on this side of the point as the slope halfway towards the adjacent point. 101 */ 102 tangentLinear = 1, 103 /** 104 The total number of available tangent modes. 105 */ 106 tangentModeCount = 2, 107 } 108 /// 109 enum Constants : int 110 { 111 tangentFree = 0, 112 tangentLinear = 1, 113 tangentModeCount = 2, 114 } 115 /** 116 117 */ 118 Array _getData() const 119 { 120 Array _GODOT_args = Array.make(); 121 String _GODOT_method_name = String("_get_data"); 122 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 123 } 124 /** 125 126 */ 127 void _setData(in Array data) 128 { 129 Array _GODOT_args = Array.make(); 130 _GODOT_args.append(data); 131 String _GODOT_method_name = String("_set_data"); 132 this.callv(_GODOT_method_name, _GODOT_args); 133 } 134 /** 135 Adds a point to the curve. For each side, if the `*_mode` is $(D constant TANGENT_LINEAR), the `*_tangent` angle (in degrees) uses the slope of the curve halfway to the adjacent point. Allows custom assignments to the `*_tangent` angle if `*_mode` is set to $(D constant TANGENT_FREE). 136 */ 137 long addPoint(in Vector2 position, in double left_tangent = 0, in double right_tangent = 0, in long left_mode = 0, in long right_mode = 0) 138 { 139 checkClassBinding!(typeof(this))(); 140 return ptrcall!(long)(GDNativeClassBinding.addPoint, _godot_object, position, left_tangent, right_tangent, left_mode, right_mode); 141 } 142 /** 143 Recomputes the baked cache of points for the curve. 144 */ 145 void bake() 146 { 147 checkClassBinding!(typeof(this))(); 148 ptrcall!(void)(GDNativeClassBinding.bake, _godot_object); 149 } 150 /** 151 Removes points that are closer than `CMP_EPSILON` (0.00001) units to their neighbor on the curve. 152 */ 153 void cleanDupes() 154 { 155 checkClassBinding!(typeof(this))(); 156 ptrcall!(void)(GDNativeClassBinding.cleanDupes, _godot_object); 157 } 158 /** 159 Removes all points from the curve. 160 */ 161 void clearPoints() 162 { 163 checkClassBinding!(typeof(this))(); 164 ptrcall!(void)(GDNativeClassBinding.clearPoints, _godot_object); 165 } 166 /** 167 168 */ 169 long getBakeResolution() const 170 { 171 checkClassBinding!(typeof(this))(); 172 return ptrcall!(long)(GDNativeClassBinding.getBakeResolution, _godot_object); 173 } 174 /** 175 176 */ 177 double getMaxValue() const 178 { 179 checkClassBinding!(typeof(this))(); 180 return ptrcall!(double)(GDNativeClassBinding.getMaxValue, _godot_object); 181 } 182 /** 183 184 */ 185 double getMinValue() const 186 { 187 checkClassBinding!(typeof(this))(); 188 return ptrcall!(double)(GDNativeClassBinding.getMinValue, _godot_object); 189 } 190 /** 191 Returns the number of points describing the curve. 192 */ 193 long getPointCount() const 194 { 195 checkClassBinding!(typeof(this))(); 196 return ptrcall!(long)(GDNativeClassBinding.getPointCount, _godot_object); 197 } 198 /** 199 Returns the left $(D tangentmode) for the point at `index`. 200 */ 201 Curve.TangentMode getPointLeftMode(in long index) const 202 { 203 checkClassBinding!(typeof(this))(); 204 return ptrcall!(Curve.TangentMode)(GDNativeClassBinding.getPointLeftMode, _godot_object, index); 205 } 206 /** 207 Returns the left tangent angle (in degrees) for the point at `index`. 208 */ 209 double getPointLeftTangent(in long index) const 210 { 211 checkClassBinding!(typeof(this))(); 212 return ptrcall!(double)(GDNativeClassBinding.getPointLeftTangent, _godot_object, index); 213 } 214 /** 215 Returns the curve coordinates for the point at `index`. 216 */ 217 Vector2 getPointPosition(in long index) const 218 { 219 checkClassBinding!(typeof(this))(); 220 return ptrcall!(Vector2)(GDNativeClassBinding.getPointPosition, _godot_object, index); 221 } 222 /** 223 Returns the right $(D tangentmode) for the point at `index`. 224 */ 225 Curve.TangentMode getPointRightMode(in long index) const 226 { 227 checkClassBinding!(typeof(this))(); 228 return ptrcall!(Curve.TangentMode)(GDNativeClassBinding.getPointRightMode, _godot_object, index); 229 } 230 /** 231 Returns the right tangent angle (in degrees) for the point at `index`. 232 */ 233 double getPointRightTangent(in long index) const 234 { 235 checkClassBinding!(typeof(this))(); 236 return ptrcall!(double)(GDNativeClassBinding.getPointRightTangent, _godot_object, index); 237 } 238 /** 239 Returns the Y value for the point that would exist at the X position `offset` along the curve. 240 */ 241 double interpolate(in double offset) const 242 { 243 checkClassBinding!(typeof(this))(); 244 return ptrcall!(double)(GDNativeClassBinding.interpolate, _godot_object, offset); 245 } 246 /** 247 Returns the Y value for the point that would exist at the X position `offset` along the curve using the baked cache. Bakes the curve's points if not already baked. 248 */ 249 double interpolateBaked(in double offset) 250 { 251 checkClassBinding!(typeof(this))(); 252 return ptrcall!(double)(GDNativeClassBinding.interpolateBaked, _godot_object, offset); 253 } 254 /** 255 Removes the point at `index` from the curve. 256 */ 257 void removePoint(in long index) 258 { 259 checkClassBinding!(typeof(this))(); 260 ptrcall!(void)(GDNativeClassBinding.removePoint, _godot_object, index); 261 } 262 /** 263 264 */ 265 void setBakeResolution(in long resolution) 266 { 267 checkClassBinding!(typeof(this))(); 268 ptrcall!(void)(GDNativeClassBinding.setBakeResolution, _godot_object, resolution); 269 } 270 /** 271 272 */ 273 void setMaxValue(in double max) 274 { 275 checkClassBinding!(typeof(this))(); 276 ptrcall!(void)(GDNativeClassBinding.setMaxValue, _godot_object, max); 277 } 278 /** 279 280 */ 281 void setMinValue(in double min) 282 { 283 checkClassBinding!(typeof(this))(); 284 ptrcall!(void)(GDNativeClassBinding.setMinValue, _godot_object, min); 285 } 286 /** 287 Sets the left $(D tangentmode) for the point at `index` to `mode`. 288 */ 289 void setPointLeftMode(in long index, in long mode) 290 { 291 checkClassBinding!(typeof(this))(); 292 ptrcall!(void)(GDNativeClassBinding.setPointLeftMode, _godot_object, index, mode); 293 } 294 /** 295 Sets the left tangent angle for the point at `index` to `tangent`. 296 */ 297 void setPointLeftTangent(in long index, in double tangent) 298 { 299 checkClassBinding!(typeof(this))(); 300 ptrcall!(void)(GDNativeClassBinding.setPointLeftTangent, _godot_object, index, tangent); 301 } 302 /** 303 Sets the offset from `0.5`. 304 */ 305 long setPointOffset(in long index, in double offset) 306 { 307 checkClassBinding!(typeof(this))(); 308 return ptrcall!(long)(GDNativeClassBinding.setPointOffset, _godot_object, index, offset); 309 } 310 /** 311 Sets the right $(D tangentmode) for the point at `index` to `mode`. 312 */ 313 void setPointRightMode(in long index, in long mode) 314 { 315 checkClassBinding!(typeof(this))(); 316 ptrcall!(void)(GDNativeClassBinding.setPointRightMode, _godot_object, index, mode); 317 } 318 /** 319 Sets the right tangent angle for the point at `index` to `tangent`. 320 */ 321 void setPointRightTangent(in long index, in double tangent) 322 { 323 checkClassBinding!(typeof(this))(); 324 ptrcall!(void)(GDNativeClassBinding.setPointRightTangent, _godot_object, index, tangent); 325 } 326 /** 327 Assigns the vertical position `y` to the point at `index`. 328 */ 329 void setPointValue(in long index, in double y) 330 { 331 checkClassBinding!(typeof(this))(); 332 ptrcall!(void)(GDNativeClassBinding.setPointValue, _godot_object, index, y); 333 } 334 /** 335 336 */ 337 @property Array _data() 338 { 339 return _getData(); 340 } 341 /// ditto 342 @property void _data(Array v) 343 { 344 _setData(v); 345 } 346 /** 347 The number of points to include in the baked (i.e. cached) curve data. 348 */ 349 @property long bakeResolution() 350 { 351 return getBakeResolution(); 352 } 353 /// ditto 354 @property void bakeResolution(long v) 355 { 356 setBakeResolution(v); 357 } 358 /** 359 The maximum value the curve can reach. 360 */ 361 @property double maxValue() 362 { 363 return getMaxValue(); 364 } 365 /// ditto 366 @property void maxValue(double v) 367 { 368 setMaxValue(v); 369 } 370 /** 371 The minimum value the curve can reach. 372 */ 373 @property double minValue() 374 { 375 return getMinValue(); 376 } 377 /// ditto 378 @property void minValue(double v) 379 { 380 setMinValue(v); 381 } 382 }