path_2d.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**************************************************************************/
  2. /* path_2d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef PATH_2D_H
  31. #define PATH_2D_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/resources/curve.h"
  34. class Timer;
  35. class Path2D : public Node2D {
  36. GDCLASS(Path2D, Node2D);
  37. Ref<Curve2D> curve;
  38. void _curve_changed();
  39. protected:
  40. void _notification(int p_what);
  41. static void _bind_methods();
  42. public:
  43. #ifdef DEBUG_ENABLED
  44. virtual Rect2 _edit_get_rect() const override;
  45. virtual bool _edit_use_rect() const override;
  46. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
  47. #endif
  48. void set_curve(const Ref<Curve2D> &p_curve);
  49. Ref<Curve2D> get_curve() const;
  50. Path2D() {}
  51. };
  52. class PathFollow2D : public Node2D {
  53. GDCLASS(PathFollow2D, Node2D);
  54. public:
  55. private:
  56. Path2D *path = nullptr;
  57. real_t progress = 0.0;
  58. Timer *update_timer = nullptr;
  59. real_t h_offset = 0.0;
  60. real_t v_offset = 0.0;
  61. bool cubic = true;
  62. bool loop = true;
  63. bool rotates = true;
  64. void _update_transform();
  65. protected:
  66. void _validate_property(PropertyInfo &p_property) const;
  67. void _notification(int p_what);
  68. static void _bind_methods();
  69. public:
  70. void path_changed();
  71. void set_progress(real_t p_progress);
  72. real_t get_progress() const;
  73. void set_h_offset(real_t p_h_offset);
  74. real_t get_h_offset() const;
  75. void set_v_offset(real_t p_v_offset);
  76. real_t get_v_offset() const;
  77. void set_progress_ratio(real_t p_ratio);
  78. real_t get_progress_ratio() const;
  79. void set_loop(bool p_loop);
  80. bool has_loop() const;
  81. void set_rotation_enabled(bool p_enabled);
  82. bool is_rotation_enabled() const;
  83. void set_cubic_interpolation_enabled(bool p_enabled);
  84. bool is_cubic_interpolation_enabled() const;
  85. PackedStringArray get_configuration_warnings() const override;
  86. PathFollow2D() {}
  87. };
  88. #endif // PATH_2D_H