| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
#include "scene/resources/gradient.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 DEBUG_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 |
|
| 146 |
VARIANT_ENUM_CAST(Line2D::LineJointMode) |
| 147 |
VARIANT_ENUM_CAST(Line2D::LineCapMode) |
| 148 |
VARIANT_ENUM_CAST(Line2D::LineTextureMode) |