line_2d.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*************************************************************************/
  2. /* line_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. Line2D();
  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. void set_points(const PoolVector<Vector2> &p_points);
  56. PoolVector<Vector2> get_points() const;
  57. void set_point_position(int i, Vector2 pos);
  58. Vector2 get_point_position(int i) const;
  59. int get_point_count() const;
  60. void add_point(Vector2 pos);
  61. void remove_point(int i);
  62. void set_width(float width);
  63. float get_width() const;
  64. void set_default_color(Color color);
  65. Color get_default_color() const;
  66. void set_gradient(const Ref<Gradient> &gradient);
  67. Ref<Gradient> get_gradient() const;
  68. void set_texture(const Ref<Texture> &texture);
  69. Ref<Texture> get_texture() const;
  70. void set_texture_mode(const LineTextureMode mode);
  71. LineTextureMode get_texture_mode() const;
  72. void set_joint_mode(LineJointMode mode);
  73. LineJointMode get_joint_mode() const;
  74. void set_begin_cap_mode(LineCapMode mode);
  75. LineCapMode get_begin_cap_mode() const;
  76. void set_end_cap_mode(LineCapMode mode);
  77. LineCapMode get_end_cap_mode() const;
  78. void set_sharp_limit(float limit);
  79. float get_sharp_limit() const;
  80. void set_round_precision(int precision);
  81. int get_round_precision() const;
  82. protected:
  83. void _notification(int p_what);
  84. void _draw();
  85. static void _bind_methods();
  86. private:
  87. void _gradient_changed();
  88. private:
  89. PoolVector<Vector2> _points;
  90. LineJointMode _joint_mode;
  91. LineCapMode _begin_cap_mode;
  92. LineCapMode _end_cap_mode;
  93. float _width;
  94. Color _default_color;
  95. Ref<Gradient> _gradient;
  96. Ref<Texture> _texture;
  97. LineTextureMode _texture_mode;
  98. float _sharp_limit;
  99. int _round_precision;
  100. };
  101. #endif // LINE2D_H