Merge pull request #27805 from Kanabenki/line2d-add-point-idx
Add optional position argument for add_point in Line2D
This commit is contained in:
commit
6e1b8b07b9
3 changed files with 11 additions and 4 deletions
|
@ -14,8 +14,11 @@
|
|||
</return>
|
||||
<argument index="0" name="position" type="Vector2">
|
||||
</argument>
|
||||
<argument index="1" name="at_position" type="int" default="-1">
|
||||
</argument>
|
||||
<description>
|
||||
Add a point at the [code]position[/code]. Appends the point at the end of the line.
|
||||
If [code]at_position[/code] is given, the point is inserted before the point number [code]at_position[/code], moving that point (and every point after) after the inserted point. If [code]at_position[/code] is not given, or is an illegal value ([code]at_position < 0[/code] or [code]at_position >= [method get_point_count][/code]), the point will be appended at the end of the point list.
|
||||
</description>
|
||||
</method>
|
||||
<method name="clear_points">
|
||||
|
|
|
@ -120,8 +120,12 @@ void Line2D::clear_points() {
|
|||
}
|
||||
}
|
||||
|
||||
void Line2D::add_point(Vector2 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue