line_2d.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**************************************************************************/
  2. /* line_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 LINE_2D_H
  31. #define LINE_2D_H
  32. #include "node_2d.h"
  33. class Line2D : public Node2D {
  34. GDCLASS(Line2D, Node2D);
  35. public:
  36. enum LineJointMode {
  37. LINE_JOINT_SHARP = 0,
  38. LINE_JOINT_BEVEL,
  39. LINE_JOINT_ROUND
  40. };
  41. enum LineCapMode {
  42. LINE_CAP_NONE = 0,
  43. LINE_CAP_BOX,
  44. LINE_CAP_ROUND
  45. };
  46. enum LineTextureMode {
  47. LINE_TEXTURE_NONE = 0,
  48. LINE_TEXTURE_TILE,
  49. LINE_TEXTURE_STRETCH
  50. };
  51. #ifdef DEBUG_ENABLED
  52. virtual Rect2 _edit_get_rect() const override;
  53. virtual bool _edit_use_rect() const override;
  54. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
  55. #endif
  56. Line2D();
  57. void set_points(const Vector<Vector2> &p_points);
  58. Vector<Vector2> get_points() const;
  59. void set_point_position(int i, Vector2 pos);
  60. Vector2 get_point_position(int i) const;
  61. int get_point_count() const;
  62. void clear_points();
  63. void add_point(Vector2 pos, int atpos = -1);
  64. void remove_point(int i);
  65. void set_closed(bool p_closed);
  66. bool is_closed() const;
  67. void set_width(float width);
  68. float get_width() const;
  69. void set_curve(const Ref<Curve> &curve);
  70. Ref<Curve> get_curve() const;
  71. void set_default_color(Color color);
  72. Color get_default_color() const;
  73. void set_gradient(const Ref<Gradient> &gradient);
  74. Ref<Gradient> get_gradient() const;
  75. void set_texture(const Ref<Texture2D> &texture);
  76. Ref<Texture2D> get_texture() const;
  77. void set_texture_mode(const LineTextureMode mode);
  78. LineTextureMode get_texture_mode() const;
  79. void set_joint_mode(LineJointMode mode);
  80. LineJointMode get_joint_mode() const;
  81. void set_begin_cap_mode(LineCapMode mode);
  82. LineCapMode get_begin_cap_mode() const;
  83. void set_end_cap_mode(LineCapMode mode);
  84. LineCapMode get_end_cap_mode() const;
  85. void set_sharp_limit(float limit);
  86. float get_sharp_limit() const;
  87. void set_round_precision(int precision);
  88. int get_round_precision() const;
  89. void set_antialiased(bool p_antialiased);
  90. bool get_antialiased() const;
  91. protected:
  92. void _notification(int p_what);
  93. void _draw();
  94. static void _bind_methods();
  95. private:
  96. void _gradient_changed();
  97. void _curve_changed();
  98. private:
  99. Vector<Vector2> _points;
  100. LineJointMode _joint_mode = LINE_JOINT_SHARP;
  101. LineCapMode _begin_cap_mode = LINE_CAP_NONE;
  102. LineCapMode _end_cap_mode = LINE_CAP_NONE;
  103. bool _closed = false;
  104. float _width = 10.0;
  105. Ref<Curve> _curve;
  106. Color _default_color = Color(1, 1, 1);
  107. Ref<Gradient> _gradient;
  108. Ref<Texture2D> _texture;
  109. LineTextureMode _texture_mode = LINE_TEXTURE_NONE;
  110. float _sharp_limit = 2.f;
  111. int _round_precision = 8;
  112. bool _antialiased = false;
  113. };
  114. // Needed so we can bind functions
  115. VARIANT_ENUM_CAST(Line2D::LineJointMode)
  116. VARIANT_ENUM_CAST(Line2D::LineCapMode)
  117. VARIANT_ENUM_CAST(Line2D::LineTextureMode)
  118. #endif // LINE_2D_H