summaryrefslogtreecommitdiff
path: root/scene/2d/line_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/line_2d.cpp')
-rw-r--r--scene/2d/line_2d.cpp125
1 files changed, 87 insertions, 38 deletions
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 73692e0535..af3ed671aa 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -38,15 +38,16 @@ VARIANT_ENUM_CAST(Line2D::LineJointMode)
VARIANT_ENUM_CAST(Line2D::LineCapMode)
VARIANT_ENUM_CAST(Line2D::LineTextureMode)
-Line2D::Line2D() :
- Node2D() {
+Line2D::Line2D() {
_joint_mode = LINE_JOINT_SHARP;
_begin_cap_mode = LINE_CAP_NONE;
_end_cap_mode = LINE_CAP_NONE;
_width = 10;
_default_color = Color(0.4, 0.5, 1);
+ _texture_mode = LINE_TEXTURE_NONE;
_sharp_limit = 2.f;
_round_precision = 8;
+ _antialiased = false;
}
Rect2 Line2D::_edit_get_rect() const {
@@ -84,10 +85,10 @@ void Line2D::set_points(const PoolVector<Vector2> &p_points) {
update();
}
-void Line2D::set_width(float width) {
- if (width < 0.0)
- width = 0.0;
- _width = width;
+void Line2D::set_width(float p_width) {
+ if (p_width < 0.0)
+ p_width = 0.0;
+ _width = p_width;
update();
}
@@ -95,16 +96,37 @@ float Line2D::get_width() const {
return _width;
}
+void Line2D::set_curve(const Ref<Curve> &p_curve) {
+ // Cleanup previous connection if any
+ if (_curve.is_valid()) {
+ _curve->disconnect(CoreStringNames::get_singleton()->changed, this, "_curve_changed");
+ }
+
+ _curve = p_curve;
+
+ // Connect to the curve so the line will update when it is changed
+ if (_curve.is_valid()) {
+ _curve->connect(CoreStringNames::get_singleton()->changed, this, "_curve_changed");
+ }
+
+ update();
+}
+
+Ref<Curve> Line2D::get_curve() const {
+ return _curve;
+}
+
PoolVector<Vector2> Line2D::get_points() const {
return _points;
}
-void Line2D::set_point_position(int i, Vector2 pos) {
- _points.set(i, pos);
+void Line2D::set_point_position(int i, Vector2 p_pos) {
+ _points.set(i, p_pos);
update();
}
Vector2 Line2D::get_point_position(int i) const {
+ ERR_FAIL_INDEX_V(i, _points.size(), Vector2());
return _points.get(i);
}
@@ -120,8 +142,12 @@ void Line2D::clear_points() {
}
}
-void Line2D::add_point(Vector2 pos) {
- _points.append(pos);
+void Line2D::add_point(Vector2 p_pos, int p_atpos) {
+ if (p_atpos < 0 || _points.size() < p_atpos) {
+ _points.append(p_pos);
+ } else {
+ _points.insert(p_atpos, p_pos);
+ }
update();
}
@@ -130,8 +156,8 @@ void Line2D::remove_point(int i) {
update();
}
-void Line2D::set_default_color(Color color) {
- _default_color = color;
+void Line2D::set_default_color(Color p_color) {
+ _default_color = p_color;
update();
}
@@ -139,18 +165,18 @@ Color Line2D::get_default_color() const {
return _default_color;
}
-void Line2D::set_gradient(const Ref<Gradient> &gradient) {
+void Line2D::set_gradient(const Ref<Gradient> &p_gradient) {
// Cleanup previous connection if any
if (_gradient.is_valid()) {
- (**_gradient).disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
+ _gradient->disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
- _gradient = gradient;
+ _gradient = p_gradient;
// Connect to the gradient so the line will update when the ColorRamp is changed
if (_gradient.is_valid()) {
- (**_gradient).connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
+ _gradient->connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
update();
@@ -160,8 +186,8 @@ Ref<Gradient> Line2D::get_gradient() const {
return _gradient;
}
-void Line2D::set_texture(const Ref<Texture> &texture) {
- _texture = texture;
+void Line2D::set_texture(const Ref<Texture> &p_texture) {
+ _texture = p_texture;
update();
}
@@ -169,8 +195,8 @@ Ref<Texture> Line2D::get_texture() const {
return _texture;
}
-void Line2D::set_texture_mode(const LineTextureMode mode) {
- _texture_mode = mode;
+void Line2D::set_texture_mode(const LineTextureMode p_mode) {
+ _texture_mode = p_mode;
update();
}
@@ -178,8 +204,8 @@ Line2D::LineTextureMode Line2D::get_texture_mode() const {
return _texture_mode;
}
-void Line2D::set_joint_mode(LineJointMode mode) {
- _joint_mode = mode;
+void Line2D::set_joint_mode(LineJointMode p_mode) {
+ _joint_mode = p_mode;
update();
}
@@ -187,8 +213,8 @@ Line2D::LineJointMode Line2D::get_joint_mode() const {
return _joint_mode;
}
-void Line2D::set_begin_cap_mode(LineCapMode mode) {
- _begin_cap_mode = mode;
+void Line2D::set_begin_cap_mode(LineCapMode p_mode) {
+ _begin_cap_mode = p_mode;
update();
}
@@ -196,8 +222,8 @@ Line2D::LineCapMode Line2D::get_begin_cap_mode() const {
return _begin_cap_mode;
}
-void Line2D::set_end_cap_mode(LineCapMode mode) {
- _end_cap_mode = mode;
+void Line2D::set_end_cap_mode(LineCapMode p_mode) {
+ _end_cap_mode = p_mode;
update();
}
@@ -213,10 +239,10 @@ void Line2D::_notification(int p_what) {
}
}
-void Line2D::set_sharp_limit(float limit) {
- if (limit < 0.f)
- limit = 0.f;
- _sharp_limit = limit;
+void Line2D::set_sharp_limit(float p_limit) {
+ if (p_limit < 0.f)
+ p_limit = 0.f;
+ _sharp_limit = p_limit;
update();
}
@@ -224,10 +250,10 @@ float Line2D::get_sharp_limit() const {
return _sharp_limit;
}
-void Line2D::set_round_precision(int precision) {
- if (precision < 1)
- precision = 1;
- _round_precision = precision;
+void Line2D::set_round_precision(int p_precision) {
+ if (p_precision < 1)
+ p_precision = 1;
+ _round_precision = p_precision;
update();
}
@@ -235,6 +261,15 @@ int Line2D::get_round_precision() const {
return _round_precision;
}
+void Line2D::set_antialiased(bool p_antialiased) {
+ _antialiased = p_antialiased;
+ update();
+}
+
+bool Line2D::get_antialiased() const {
+ return _antialiased;
+}
+
void Line2D::_draw() {
if (_points.size() <= 1 || _width == 0.f)
return;
@@ -263,10 +298,11 @@ void Line2D::_draw() {
lb.round_precision = _round_precision;
lb.sharp_limit = _sharp_limit;
lb.width = _width;
+ lb.curve = *_curve;
RID texture_rid;
if (_texture.is_valid()) {
- texture_rid = (**_texture).get_rid();
+ texture_rid = _texture->get_rid();
lb.tile_aspect = _texture->get_size().aspect();
}
@@ -279,8 +315,8 @@ void Line2D::_draw() {
lb.vertices,
lb.colors,
lb.uvs, Vector<int>(), Vector<float>(),
-
- texture_rid);
+ texture_rid, -1, RID(),
+ _antialiased);
// DEBUG
// Draw wireframe
@@ -307,6 +343,10 @@ void Line2D::_gradient_changed() {
update();
}
+void Line2D::_curve_changed() {
+ update();
+}
+
// static
void Line2D::_bind_methods() {
@@ -318,7 +358,7 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point_count"), &Line2D::get_point_count);
- ClassDB::bind_method(D_METHOD("add_point", "position"), &Line2D::add_point);
+ ClassDB::bind_method(D_METHOD("add_point", "position", "at_position"), &Line2D::add_point, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("remove_point", "i"), &Line2D::remove_point);
ClassDB::bind_method(D_METHOD("clear_points"), &Line2D::clear_points);
@@ -326,6 +366,9 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_width", "width"), &Line2D::set_width);
ClassDB::bind_method(D_METHOD("get_width"), &Line2D::get_width);
+ ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Line2D::set_curve);
+ ClassDB::bind_method(D_METHOD("get_curve"), &Line2D::get_curve);
+
ClassDB::bind_method(D_METHOD("set_default_color", "color"), &Line2D::set_default_color);
ClassDB::bind_method(D_METHOD("get_default_color"), &Line2D::get_default_color);
@@ -353,8 +396,12 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_round_precision", "precision"), &Line2D::set_round_precision);
ClassDB::bind_method(D_METHOD("get_round_precision"), &Line2D::get_round_precision);
+ ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &Line2D::set_antialiased);
+ ClassDB::bind_method(D_METHOD("get_antialiased"), &Line2D::get_antialiased);
+
ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "default_color"), "set_default_color", "get_default_color");
ADD_GROUP("Fill", "");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_gradient", "get_gradient");
@@ -367,6 +414,7 @@ void Line2D::_bind_methods() {
ADD_GROUP("Border", "");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "sharp_limit"), "set_sharp_limit", "get_sharp_limit");
ADD_PROPERTY(PropertyInfo(Variant::INT, "round_precision"), "set_round_precision", "get_round_precision");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased");
BIND_ENUM_CONSTANT(LINE_JOINT_SHARP);
BIND_ENUM_CONSTANT(LINE_JOINT_BEVEL);
@@ -381,4 +429,5 @@ void Line2D::_bind_methods() {
BIND_ENUM_CONSTANT(LINE_TEXTURE_STRETCH);
ClassDB::bind_method(D_METHOD("_gradient_changed"), &Line2D::_gradient_changed);
+ ClassDB::bind_method(D_METHOD("_curve_changed"), &Line2D::_curve_changed);
}