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