Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/2d/line_2d.h
21398 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 "scene/2d/node_2d.h"
34
#include "scene/resources/curve.h"
35
#include "scene/resources/gradient.h"
36
37
class Line2D : public Node2D {
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 DEBUG_ENABLED
60
virtual Rect2 _edit_get_rect() const override;
61
virtual bool _edit_use_rect() const override;
62
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
63
#endif
64
65
Line2D();
66
67
void set_points(const Vector<Vector2> &p_points);
68
Vector<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_closed(bool p_closed);
81
bool is_closed() const;
82
83
void set_width(float width);
84
float get_width() const;
85
86
void set_curve(const Ref<Curve> &curve);
87
Ref<Curve> get_curve() const;
88
89
void set_default_color(Color color);
90
Color get_default_color() const;
91
92
void set_gradient(const Ref<Gradient> &gradient);
93
Ref<Gradient> get_gradient() const;
94
95
void set_texture(const Ref<Texture2D> &texture);
96
Ref<Texture2D> get_texture() const;
97
98
void set_texture_mode(const LineTextureMode mode);
99
LineTextureMode get_texture_mode() const;
100
101
void set_joint_mode(LineJointMode mode);
102
LineJointMode get_joint_mode() const;
103
104
void set_begin_cap_mode(LineCapMode mode);
105
LineCapMode get_begin_cap_mode() const;
106
107
void set_end_cap_mode(LineCapMode mode);
108
LineCapMode get_end_cap_mode() const;
109
110
void set_sharp_limit(float limit);
111
float get_sharp_limit() const;
112
113
void set_round_precision(int precision);
114
int get_round_precision() const;
115
116
void set_antialiased(bool p_antialiased);
117
bool get_antialiased() const;
118
119
protected:
120
void _notification(int p_what);
121
void _draw();
122
123
static void _bind_methods();
124
125
private:
126
void _gradient_changed();
127
void _curve_changed();
128
129
private:
130
Vector<Vector2> _points;
131
LineJointMode _joint_mode = LINE_JOINT_SHARP;
132
LineCapMode _begin_cap_mode = LINE_CAP_NONE;
133
LineCapMode _end_cap_mode = LINE_CAP_NONE;
134
bool _closed = false;
135
float _width = 10.0;
136
Ref<Curve> _curve;
137
Color _default_color = Color(1, 1, 1);
138
Ref<Gradient> _gradient;
139
Ref<Texture2D> _texture;
140
LineTextureMode _texture_mode = LINE_TEXTURE_NONE;
141
float _sharp_limit = 2.f;
142
int _round_precision = 8;
143
bool _antialiased = false;
144
};
145
146
// Needed so we can bind functions
147
VARIANT_ENUM_CAST(Line2D::LineJointMode)
148
VARIANT_ENUM_CAST(Line2D::LineCapMode)
149
VARIANT_ENUM_CAST(Line2D::LineTextureMode)
150
151