line_2d.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*************************************************************************/
  2. /* line_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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 LINE2D_H
  31. #define LINE2D_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 TOOLS_ENABLED
  52. virtual Rect2 _edit_get_rect() const;
  53. virtual bool _edit_use_rect() const;
  54. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
  55. #endif
  56. Line2D();
  57. void set_points(const PoolVector<Vector2> &p_points);
  58. PoolVector<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_width(float width);
  66. float get_width() const;
  67. void set_curve(const Ref<Curve> &curve);
  68. Ref<Curve> get_curve() const;
  69. void set_default_color(Color color);
  70. Color get_default_color() const;
  71. void set_gradient(const Ref<Gradient> &gradient);
  72. Ref<Gradient> get_gradient() const;
  73. void set_texture(const Ref<Texture> &texture);
  74. Ref<Texture> get_texture() const;
  75. void set_texture_mode(const LineTextureMode mode);
  76. LineTextureMode get_texture_mode() const;
  77. void set_joint_mode(LineJointMode mode);
  78. LineJointMode get_joint_mode() const;
  79. void set_begin_cap_mode(LineCapMode mode);
  80. LineCapMode get_begin_cap_mode() const;
  81. void set_end_cap_mode(LineCapMode mode);
  82. LineCapMode get_end_cap_mode() const;
  83. void set_sharp_limit(float limit);
  84. float get_sharp_limit() const;
  85. void set_round_precision(int precision);
  86. int get_round_precision() const;
  87. void set_antialiased(bool p_antialiased);
  88. bool get_antialiased() const;
  89. protected:
  90. void _notification(int p_what);
  91. void _draw();
  92. static void _bind_methods();
  93. private:
  94. void _gradient_changed();
  95. void _curve_changed();
  96. private:
  97. PoolVector<Vector2> _points;
  98. LineJointMode _joint_mode;
  99. LineCapMode _begin_cap_mode;
  100. LineCapMode _end_cap_mode;
  101. float _width;
  102. Ref<Curve> _curve;
  103. Color _default_color;
  104. Ref<Gradient> _gradient;
  105. Ref<Texture> _texture;
  106. LineTextureMode _texture_mode;
  107. float _sharp_limit;
  108. int _round_precision;
  109. bool _antialiased;
  110. };
  111. #endif // LINE2D_H