summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-04-30 11:02:47 +0200
committerGitHub <noreply@github.com>2019-04-30 11:02:47 +0200
commit6e1b8b07b93e30ac09175cfcc7001d3aba5685cf (patch)
treec475c128cfd32488cd2c64560fe8bb03b9d59ef1 /scene/2d
parentac0369e9ff15c575a5ba242203e51b5ee4e7254f (diff)
parent714953b3ac697f0925c740581880cb71e2f94777 (diff)
Merge pull request #27805 from Kanabenki/line2d-add-point-idx
Add optional position argument for add_point in Line2D
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/line_2d.cpp10
-rw-r--r--scene/2d/line_2d.h2
2 files changed, 8 insertions, 4 deletions
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 73692e0535..ba06b3ebff 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -120,8 +120,12 @@ void Line2D::clear_points() {
}
}
-void Line2D::add_point(Vector2 pos) {
- _points.append(pos);
+void Line2D::add_point(Vector2 pos, int atpos) {
+ if (atpos < 0 || _points.size() < atpos) {
+ _points.append(pos);
+ } else {
+ _points.insert(atpos, pos);
+ }
update();
}
@@ -318,7 +322,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);
diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h
index 32befab2d3..8a6f7b2dc5 100644
--- a/scene/2d/line_2d.h
+++ b/scene/2d/line_2d.h
@@ -72,7 +72,7 @@ public:
void clear_points();
- void add_point(Vector2 pos);
+ void add_point(Vector2 pos, int atpos = -1);
void remove_point(int i);
void set_width(float width);