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