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