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