diff options
Diffstat (limited to 'scene')
49 files changed, 665 insertions, 251 deletions
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index e994ebb5aa..1db9e4902a 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -229,6 +229,7 @@ public: // Used to resize/move/select the node virtual void _edit_set_rect(const Rect2 &p_rect){}; virtual Rect2 _edit_get_rect() const { return Rect2(-32, -32, 64, 64); }; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { return true; } Rect2 _edit_get_item_and_children_rect() const; virtual bool _edit_use_rect() const { return false; }; diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index eaa650b140..8c6b25f296 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -131,7 +131,7 @@ void CollisionPolygon2D::_notification(int p_what) { /*if (Engine::get_singleton()->is_editor_hint()) { //display above all else set_z_as_relative(false); - set_z(VS::CANVAS_ITEM_Z_MAX - 1); + set_z_index(VS::CANVAS_ITEM_Z_MAX - 1); }*/ } break; @@ -248,6 +248,11 @@ Rect2 CollisionPolygon2D::_edit_get_rect() const { return aabb; } +bool CollisionPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + return Geometry::is_point_in_polygon(p_point, Variant(polygon)); +} + String CollisionPolygon2D::get_configuration_warning() const { if (!Object::cast_to<CollisionObject2D>(get_parent())) { diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h index 4c8b55a9ee..fa7e5e1046 100644 --- a/scene/2d/collision_polygon_2d.h +++ b/scene/2d/collision_polygon_2d.h @@ -70,6 +70,7 @@ public: Vector<Point2> get_polygon() const; virtual Rect2 _edit_get_rect() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; virtual String get_configuration_warning() const; diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 1cadbe83d0..1956e23421 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -64,7 +64,7 @@ void CollisionShape2D::_notification(int p_what) { /*if (Engine::get_singleton()->is_editor_hint()) { //display above all else set_z_as_relative(false); - set_z(VS::CANVAS_ITEM_Z_MAX - 1); + set_z_index(VS::CANVAS_ITEM_Z_MAX - 1); }*/ } break; @@ -163,6 +163,14 @@ Rect2 CollisionShape2D::_edit_get_rect() const { return rect; } +bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + if (!shape.is_valid()) + return false; + + return shape->_edit_is_selected_on_click(p_point, p_tolerance); +} + String CollisionShape2D::get_configuration_warning() const { if (!Object::cast_to<CollisionObject2D>(get_parent())) { diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h index 833d9ae5cb..921066c5c8 100644 --- a/scene/2d/collision_shape_2d.h +++ b/scene/2d/collision_shape_2d.h @@ -52,6 +52,7 @@ protected: public: virtual Rect2 _edit_get_rect() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; void set_shape(const Ref<Shape2D> &p_shape); Ref<Shape2D> get_shape() const; diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index f108df140f..abc80216d4 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -48,6 +48,32 @@ Line2D::Line2D() : _round_precision = 8; } +Rect2 Line2D::_edit_get_rect() const { + + if (_points.size() == 0) + return Rect2(0, 0, 0, 0); + Vector2 d = Vector2(_width, _width); + Rect2 aabb = Rect2(_points[0] - d, 2 * d); + for (int i = 1; i < _points.size(); i++) { + aabb.expand_to(_points[i] - d); + aabb.expand_to(_points[i] + d); + } + return aabb; +} + +bool Line2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + const real_t d = _width / 2 + p_tolerance; + PoolVector<Vector2>::Read points = _points.read(); + for (int i = 0; i < _points.size() - 1; i++) { + Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, &points[i]); + if (p.distance_to(p_point) <= d) + return true; + } + + return false; +} + void Line2D::set_points(const PoolVector<Vector2> &p_points) { _points = p_points; update(); diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h index 123728ab39..54a4683dc7 100644 --- a/scene/2d/line_2d.h +++ b/scene/2d/line_2d.h @@ -57,6 +57,9 @@ public: Line2D(); + virtual Rect2 _edit_get_rect() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_points(const PoolVector<Vector2> &p_points); PoolVector<Vector2> get_points() const; diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index 9c297db52b..dde41dbf3f 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_polygon.cpp @@ -35,9 +35,50 @@ #include "thirdparty/misc/triangulator.h" +Rect2 NavigationPolygon::_edit_get_rect() const { + + if (rect_cache_dirty) { + item_rect = Rect2(); + bool first = true; + + for (int i = 0; i < outlines.size(); i++) { + const PoolVector<Vector2> &outline = outlines[i]; + const int outline_size = outline.size(); + if (outline_size < 3) + continue; + PoolVector<Vector2>::Read p = outline.read(); + for (int j = 0; j < outline_size; j++) { + if (first) { + item_rect = Rect2(p[j], Vector2(0, 0)); + first = false; + } else { + item_rect.expand_to(p[j]); + } + } + } + + rect_cache_dirty = false; + } + return item_rect; +} + +bool NavigationPolygon::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + for (int i = 0; i < outlines.size(); i++) { + const PoolVector<Vector2> &outline = outlines[i]; + const int outline_size = outline.size(); + if (outline_size < 3) + continue; + if (Geometry::is_point_in_polygon(p_point, Variant(outline))) + return true; + } + return false; +} + void NavigationPolygon::set_vertices(const PoolVector<Vector2> &p_vertices) { vertices = p_vertices; + rect_cache_dirty = true; } PoolVector<Vector2> NavigationPolygon::get_vertices() const { @@ -70,6 +111,7 @@ void NavigationPolygon::_set_outlines(const Array &p_array) { for (int i = 0; i < p_array.size(); i++) { outlines[i] = p_array[i]; } + rect_cache_dirty = true; } Array NavigationPolygon::_get_outlines() const { @@ -93,6 +135,7 @@ void NavigationPolygon::add_polygon(const Vector<int> &p_polygon) { void NavigationPolygon::add_outline_at_index(const PoolVector<Vector2> &p_outline, int p_index) { outlines.insert(p_index, p_outline); + rect_cache_dirty = true; } int NavigationPolygon::get_polygon_count() const { @@ -112,6 +155,7 @@ void NavigationPolygon::clear_polygons() { void NavigationPolygon::add_outline(const PoolVector<Vector2> &p_outline) { outlines.push_back(p_outline); + rect_cache_dirty = true; } int NavigationPolygon::get_outline_count() const { @@ -122,12 +166,14 @@ int NavigationPolygon::get_outline_count() const { void NavigationPolygon::set_outline(int p_idx, const PoolVector<Vector2> &p_outline) { ERR_FAIL_INDEX(p_idx, outlines.size()); outlines[p_idx] = p_outline; + rect_cache_dirty = true; } void NavigationPolygon::remove_outline(int p_idx) { ERR_FAIL_INDEX(p_idx, outlines.size()); outlines.remove(p_idx); + rect_cache_dirty = true; } PoolVector<Vector2> NavigationPolygon::get_outline(int p_idx) const { @@ -138,6 +184,7 @@ PoolVector<Vector2> NavigationPolygon::get_outline(int p_idx) const { void NavigationPolygon::clear_outlines() { outlines.clear(); + rect_cache_dirty = true; } void NavigationPolygon::make_polygons_from_outlines() { @@ -269,7 +316,8 @@ void NavigationPolygon::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "outlines", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_outlines", "_get_outlines"); } -NavigationPolygon::NavigationPolygon() { +NavigationPolygon::NavigationPolygon() : + rect_cache_dirty(true) { } void NavigationPolygonInstance::set_enabled(bool p_enabled) { @@ -311,6 +359,16 @@ bool NavigationPolygonInstance::is_enabled() const { ///////////////////////////// +Rect2 NavigationPolygonInstance::_edit_get_rect() const { + + return navpoly.is_valid() ? navpoly->_edit_get_rect() : Rect2(); +} + +bool NavigationPolygonInstance::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + return navpoly.is_valid() ? navpoly->_edit_is_selected_on_click(p_point, p_tolerance) : false; +} + void NavigationPolygonInstance::_notification(int p_what) { switch (p_what) { diff --git a/scene/2d/navigation_polygon.h b/scene/2d/navigation_polygon.h index febdcf2ca6..7b5220f92d 100644 --- a/scene/2d/navigation_polygon.h +++ b/scene/2d/navigation_polygon.h @@ -43,6 +43,9 @@ class NavigationPolygon : public Resource { Vector<Polygon> polygons; Vector<PoolVector<Vector2> > outlines; + mutable Rect2 item_rect; + mutable bool rect_cache_dirty; + protected: static void _bind_methods(); @@ -53,6 +56,9 @@ protected: Array _get_outlines() const; public: + Rect2 _edit_get_rect() const; + bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_vertices(const PoolVector<Vector2> &p_vertices); PoolVector<Vector2> get_vertices() const; @@ -93,6 +99,9 @@ protected: static void _bind_methods(); public: + virtual Rect2 _edit_get_rect() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_enabled(bool p_enabled); bool is_enabled() const; diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 2a305512af..e133f86ef7 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -329,13 +329,13 @@ void Node2D::set_global_transform(const Transform2D &p_transform) { set_transform(p_transform); } -void Node2D::set_z(int p_z) { +void Node2D::set_z_index(int p_z) { ERR_FAIL_COND(p_z < VS::CANVAS_ITEM_Z_MIN); ERR_FAIL_COND(p_z > VS::CANVAS_ITEM_Z_MAX); - z = p_z; - VS::get_singleton()->canvas_item_set_z(get_canvas_item(), z); - _change_notify("z"); + z_index = p_z; + VS::get_singleton()->canvas_item_set_z_index(get_canvas_item(), z_index); + _change_notify("z_index"); } void Node2D::set_z_as_relative(bool p_enabled) { @@ -351,9 +351,9 @@ bool Node2D::is_z_relative() const { return z_relative; } -int Node2D::get_z() const { +int Node2D::get_z_index() const { - return z; + return z_index; } Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const { @@ -427,8 +427,8 @@ void Node2D::_bind_methods() { ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Node2D::to_local); ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Node2D::to_global); - ClassDB::bind_method(D_METHOD("set_z", "z"), &Node2D::set_z); - ClassDB::bind_method(D_METHOD("get_z"), &Node2D::get_z); + ClassDB::bind_method(D_METHOD("set_z_index", "z_index"), &Node2D::set_z_index); + ClassDB::bind_method(D_METHOD("get_z_index"), &Node2D::get_z_index); ClassDB::bind_method(D_METHOD("set_z_as_relative", "enable"), &Node2D::set_z_as_relative); ClassDB::bind_method(D_METHOD("is_z_relative"), &Node2D::is_z_relative); @@ -448,8 +448,8 @@ void Node2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_scale", PROPERTY_HINT_NONE, "", 0), "set_global_scale", "get_global_scale"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform"); - ADD_GROUP("Z", ""); - ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "z", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z", "get_z"); + ADD_GROUP("Z Index", ""); + ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "z_index", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_index", "get_z_index"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative"); } @@ -458,6 +458,6 @@ Node2D::Node2D() { angle = 0; _scale = Vector2(1, 1); _xform_dirty = false; - z = 0; + z_index = 0; z_relative = true; } diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 7d2e5aa00c..321021a748 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -39,7 +39,7 @@ class Node2D : public CanvasItem { Point2 pos; float angle; Size2 _scale; - int z; + int z_index; bool z_relative; Transform2D _mat; @@ -96,8 +96,8 @@ public: void set_global_rotation_degrees(float p_degrees); void set_global_scale(const Size2 &p_scale); - void set_z(int p_z); - int get_z() const; + void set_z_index(int p_z); + int get_z_index() const; void look_at(const Vector2 &p_pos); float get_angle_to(const Vector2 &p_pos) const; diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 06bd55858c..d2a307a9ed 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -32,6 +32,51 @@ #include "engine.h" #include "scene/scene_string_names.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_scale.h" +#endif + +Rect2 Path2D::_edit_get_rect() const { + + if (curve->get_point_count() == 0) + return Rect2(0, 0, 0, 0); + + Rect2 aabb = Rect2(curve->get_point_position(0), Vector2(0, 0)); + + for (int i = 0; i < curve->get_point_count(); i++) { + + for (int j = 0; j <= 8; j++) { + + real_t frac = j / 8.0; + Vector2 p = curve->interpolate(i, frac); + aabb.expand_to(p); + } + } + + return aabb; +} + +bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + for (int i = 0; i < curve->get_point_count(); i++) { + Vector2 s[2]; + s[0] = curve->get_point_position(i); + + for (int j = 1; j <= 8; j++) { + real_t frac = j / 8.0; + s[1] = curve->interpolate(i, frac); + + Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, s); + if (p.distance_to(p_point) <= p_tolerance) + return true; + + s[0] = s[1]; + } + } + + return false; +} + void Path2D::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW && curve.is_valid()) { @@ -41,6 +86,13 @@ void Path2D::_notification(int p_what) { return; } +#if TOOLS_ENABLED + const float line_width = 2 * EDSCALE; +#else + const float line_width = 2; +#endif + const Color color = Color(0.5, 0.6, 1.0, 0.7); + for (int i = 0; i < curve->get_point_count(); i++) { Vector2 prev_p = curve->get_point_position(i); @@ -49,7 +101,7 @@ void Path2D::_notification(int p_what) { real_t frac = j / 8.0; Vector2 p = curve->interpolate(i, frac); - draw_line(prev_p, p, Color(0.5, 0.6, 1.0, 0.7), 2); + draw_line(prev_p, p, color, line_width); prev_p = p; } } diff --git a/scene/2d/path_2d.h b/scene/2d/path_2d.h index ebfa77d605..7f53821c7e 100644 --- a/scene/2d/path_2d.h +++ b/scene/2d/path_2d.h @@ -46,6 +46,9 @@ protected: static void _bind_methods(); public: + virtual Rect2 _edit_get_rect() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_curve(const Ref<Curve2D> &p_curve); Ref<Curve2D> get_curve() const; diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index a2f49d938b..f9951cdd08 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "polygon_2d.h" +#include "core/math/geometry.h" Rect2 Polygon2D::_edit_get_rect() const { @@ -42,13 +43,17 @@ Rect2 Polygon2D::_edit_get_rect() const { else item_rect.expand_to(pos); } - item_rect = item_rect.grow(20); rect_cache_dirty = false; } return item_rect; } +bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + return Geometry::is_point_in_polygon(p_point, Variant(polygon)); +} + void Polygon2D::_edit_set_pivot(const Point2 &p_pivot) { set_offset(p_pivot); diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h index a23e223e6e..5014cbc6e9 100644 --- a/scene/2d/polygon_2d.h +++ b/scene/2d/polygon_2d.h @@ -104,6 +104,7 @@ public: virtual bool _edit_use_pivot() const; virtual Rect2 _edit_get_rect() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; Polygon2D(); }; diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index c4a7e5aebd..68df95c042 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -47,6 +47,40 @@ bool Sprite::_edit_use_pivot() const { return true; } +void Sprite::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_clip) const { + + Size2 s; + r_filter_clip = false; + + if (region) { + + s = region_rect.size; + r_src_rect = region_rect; + r_filter_clip = region_filter_clip; + } else { + s = Size2(texture->get_size()); + s = s / Size2(hframes, vframes); + + r_src_rect.size = s; + r_src_rect.position.x += float(frame % hframes) * s.x; + r_src_rect.position.y += float(frame / hframes) * s.y; + } + + Point2 ofs = offset; + if (centered) + ofs -= s / 2; + if (Engine::get_singleton()->get_use_pixel_snap()) { + ofs = ofs.floor(); + } + + r_dst_rect = Rect2(ofs, s); + + if (hflip) + r_dst_rect.size.x = -r_dst_rect.size.x; + if (vflip) + r_dst_rect.size.y = -r_dst_rect.size.y; +} + void Sprite::_notification(int p_what) { switch (p_what) { @@ -63,38 +97,9 @@ void Sprite::_notification(int p_what) { break; */ - Size2 s; - Rect2 src_rect; - bool filter_clip = false; - - if (region) { - - s = region_rect.size; - src_rect = region_rect; - filter_clip = region_filter_clip; - } else { - s = Size2(texture->get_size()); - s = s / Size2(hframes, vframes); - - src_rect.size = s; - src_rect.position.x += float(frame % hframes) * s.x; - src_rect.position.y += float(frame / hframes) * s.y; - } - - Point2 ofs = offset; - if (centered) - ofs -= s / 2; - if (Engine::get_singleton()->get_use_pixel_snap()) { - ofs = ofs.floor(); - } - - Rect2 dst_rect(ofs, s); - - if (hflip) - dst_rect.size.x = -dst_rect.size.x; - if (vflip) - dst_rect.size.y = -dst_rect.size.y; - + Rect2 src_rect, dst_rect; + bool filter_clip; + _get_rects(src_rect, dst_rect, filter_clip); texture->draw_rect_region(ci, dst_rect, src_rect, Color(1, 1, 1), false, normal_map, filter_clip); } break; @@ -257,6 +262,30 @@ int Sprite::get_hframes() const { return hframes; } +bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + if (texture.is_null()) + return false; + + Rect2 src_rect, dst_rect; + bool filter_clip; + _get_rects(src_rect, dst_rect, filter_clip); + + if (!dst_rect.has_point(p_point)) + return false; + + Vector2 q = ((p_point - dst_rect.position) / dst_rect.size) * src_rect.size + src_rect.position; + + Ref<Image> image = texture->get_data(); + ERR_FAIL_COND_V(image.is_null(), false); + + image->lock(); + const Color c = image->get_pixel((int)q.x, (int)q.y); + image->unlock(); + + return c.a > 0.01; +} + Rect2 Sprite::_edit_get_rect() const { if (texture.is_null()) diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h index c437f6d404..7d9b2cf457 100644 --- a/scene/2d/sprite.h +++ b/scene/2d/sprite.h @@ -54,6 +54,8 @@ class Sprite : public Node2D { int vframes; int hframes; + void _get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_clip) const; + protected: void _notification(int p_what); @@ -65,6 +67,7 @@ public: virtual void _edit_set_pivot(const Point2 &p_pivot); virtual Point2 _edit_get_pivot() const; virtual bool _edit_use_pivot() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; virtual Rect2 _edit_get_rect() const; void set_texture(const Ref<Texture> &p_texture); diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 73fce4be75..8bd5676bc7 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -336,7 +336,7 @@ void TileMap::_update_dirty_quadrants() { debug_canvas_item = vs->canvas_item_create(); vs->canvas_item_set_parent(debug_canvas_item, canvas_item); vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item, false); - vs->canvas_item_set_z(debug_canvas_item, VS::CANVAS_ITEM_Z_MAX - 1); + vs->canvas_item_set_z_index(debug_canvas_item, VS::CANVAS_ITEM_Z_MAX - 1); q.canvas_items.push_back(debug_canvas_item); prev_debug_canvas_item = debug_canvas_item; } diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index ef60a2151d..aaa378bb68 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -160,14 +160,14 @@ void Skeleton::_notification(int p_what) { //if moved, just update transforms VisualServer *vs = VisualServer::get_singleton(); - Bone *bonesptr = &bones[0]; + const Bone *bonesptr = bones.ptr(); int len = bones.size(); Transform global_transform = get_global_transform(); Transform global_transform_inverse = global_transform.affine_inverse(); for (int i = 0; i < len; i++) { - Bone &b = bonesptr[i]; + const Bone &b = bonesptr[i]; vs->skeleton_bone_set_transform(skeleton, i, global_transform * (b.transform_final * global_transform_inverse)); } } break; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 8b5c85763a..a55c4a2cc5 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -555,30 +555,36 @@ bool Spatial::is_visible() const { return data.visible; } -void Spatial::rotate(const Vector3 &p_normal, float p_radians) { +void Spatial::rotate_object_local(const Vector3 &p_axis, float p_angle) { + Transform t = get_transform(); + t.basis.rotate_local(p_axis, p_angle); + set_transform(t); +} + +void Spatial::rotate(const Vector3 &p_axis, float p_angle) { Transform t = get_transform(); - t.basis.rotate_local(p_normal, p_radians); //use local rotation here, as it makes more sense here in tree hierarchy + t.basis.rotate(p_axis, p_angle); set_transform(t); } -void Spatial::rotate_x(float p_radians) { +void Spatial::rotate_x(float p_angle) { Transform t = get_transform(); - t.basis.rotate_local(Vector3(1, 0, 0), p_radians); + t.basis.rotate(Vector3(1, 0, 0), p_angle); set_transform(t); } -void Spatial::rotate_y(float p_radians) { +void Spatial::rotate_y(float p_angle) { Transform t = get_transform(); - t.basis.rotate_local(Vector3(0, 1, 0), p_radians); + t.basis.rotate(Vector3(0, 1, 0), p_angle); set_transform(t); } -void Spatial::rotate_z(float p_radians) { +void Spatial::rotate_z(float p_angle) { Transform t = get_transform(); - t.basis.rotate_local(Vector3(0, 0, 1), p_radians); + t.basis.rotate(Vector3(0, 0, 1), p_angle); set_transform(t); } @@ -589,19 +595,45 @@ void Spatial::translate(const Vector3 &p_offset) { set_transform(t); } +void Spatial::translate_object_local(const Vector3 &p_offset) { + Transform t = get_transform(); + + Transform s; + s.translate(p_offset); + set_transform(t * s); +} + void Spatial::scale(const Vector3 &p_ratio) { Transform t = get_transform(); t.basis.scale(p_ratio); set_transform(t); } -void Spatial::global_rotate(const Vector3 &p_normal, float p_radians) { - Basis rotation(p_normal, p_radians); +void Spatial::scale_object_local(const Vector3 &p_scale) { + Transform t = get_transform(); + t.basis.scale_local(p_scale); + set_transform(t); +} + +void Spatial::global_rotate(const Vector3 &p_axis, float p_angle) { + + Basis rotation(p_axis, p_angle); Transform t = get_global_transform(); t.basis = rotation * t.basis; set_global_transform(t); } + +void Spatial::global_scale(const Vector3 &p_scale) { + + Basis s; + s.set_scale(p_scale); + + Transform t = get_global_transform(); + t.basis = s * t.basis; + set_global_transform(t); +} + void Spatial::global_translate(const Vector3 &p_offset) { Transform t = get_global_transform(); t.origin += p_offset; @@ -620,7 +652,7 @@ void Spatial::set_identity() { set_transform(Transform()); } -void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up_normal) { +void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) { Transform lookat; lookat.origin = get_global_transform().origin; @@ -629,19 +661,19 @@ void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up_normal) { ERR_FAIL(); } - if (p_up_normal.cross(p_target - lookat.origin) == Vector3()) { + if (p_up.cross(p_target - lookat.origin) == Vector3()) { ERR_EXPLAIN("Up vector and direction between node origin and target are aligned, look_at() failed"); ERR_FAIL(); } - lookat = lookat.looking_at(p_target, p_up_normal); + lookat = lookat.looking_at(p_target, p_up); set_global_transform(lookat); } -void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up_normal) { +void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) { Transform lookat; lookat.origin = p_pos; - lookat = lookat.looking_at(p_target, p_up_normal); + lookat = lookat.looking_at(p_target, p_up); set_global_transform(lookat); } @@ -677,9 +709,9 @@ void Spatial::_bind_methods() { ClassDB::bind_method(D_METHOD("get_transform"), &Spatial::get_transform); ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Spatial::set_translation); ClassDB::bind_method(D_METHOD("get_translation"), &Spatial::get_translation); - ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Spatial::set_rotation); + ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Spatial::set_rotation); ClassDB::bind_method(D_METHOD("get_rotation"), &Spatial::get_rotation); - ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Spatial::set_rotation_degrees); + ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Spatial::set_rotation_degrees); ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Spatial::get_rotation_degrees); ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Spatial::set_scale); ClassDB::bind_method(D_METHOD("get_scale"), &Spatial::get_scale); @@ -711,22 +743,26 @@ void Spatial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Spatial::set_notify_transform); ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Spatial::is_transform_notification_enabled); - void rotate(const Vector3 &p_normal, float p_radians); - void rotate_x(float p_radians); - void rotate_y(float p_radians); - void rotate_z(float p_radians); + void rotate(const Vector3 &p_axis, float p_angle); + void rotate_x(float p_angle); + void rotate_y(float p_angle); + void rotate_z(float p_angle); void translate(const Vector3 &p_offset); void scale(const Vector3 &p_ratio); - void global_rotate(const Vector3 &p_normal, float p_radians); + void global_rotate(const Vector3 &p_axis, float p_angle); void global_translate(const Vector3 &p_offset); - ClassDB::bind_method(D_METHOD("rotate", "normal", "radians"), &Spatial::rotate); - ClassDB::bind_method(D_METHOD("global_rotate", "normal", "radians"), &Spatial::global_rotate); - ClassDB::bind_method(D_METHOD("rotate_x", "radians"), &Spatial::rotate_x); - ClassDB::bind_method(D_METHOD("rotate_y", "radians"), &Spatial::rotate_y); - ClassDB::bind_method(D_METHOD("rotate_z", "radians"), &Spatial::rotate_z); - ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate); + ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Spatial::rotate); + ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Spatial::global_rotate); + ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Spatial::global_scale); ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Spatial::global_translate); + ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Spatial::rotate_object_local); + ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Spatial::scale_object_local); + ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Spatial::translate_object_local); + ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Spatial::rotate_x); + ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Spatial::rotate_y); + ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Spatial::rotate_z); + ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate); ClassDB::bind_method(D_METHOD("orthonormalize"), &Spatial::orthonormalize); ClassDB::bind_method(D_METHOD("set_identity"), &Spatial::set_identity); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 5ebe2f5214..1c2e73d5ba 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -158,17 +158,23 @@ public: Transform get_relative_transform(const Node *p_parent) const; - void rotate(const Vector3 &p_normal, float p_radians); - void rotate_x(float p_radians); - void rotate_y(float p_radians); - void rotate_z(float p_radians); + void rotate(const Vector3 &p_axis, float p_angle); + void rotate_x(float p_angle); + void rotate_y(float p_angle); + void rotate_z(float p_angle); void translate(const Vector3 &p_offset); void scale(const Vector3 &p_ratio); - void global_rotate(const Vector3 &p_normal, float p_radians); + + void rotate_object_local(const Vector3 &p_axis, float p_angle); + void scale_object_local(const Vector3 &p_scale); + void translate_object_local(const Vector3 &p_offset); + + void global_rotate(const Vector3 &p_axis, float p_angle); + void global_scale(const Vector3 &p_scale); void global_translate(const Vector3 &p_offset); - void look_at(const Vector3 &p_target, const Vector3 &p_up_normal); - void look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up_normal); + void look_at(const Vector3 &p_target, const Vector3 &p_up); + void look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up); Vector3 to_local(Vector3 p_global) const; Vector3 to_global(Vector3 p_local) const; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 6463180d9e..bac95c6cca 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -547,12 +547,14 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, float p_delta, f if (!backwards && cd.pos <= len && next_pos == len /*&& playback.blend.empty()*/) { //playback finished - end_notify = true; + end_reached = true; + end_notify = cd.pos < len; // Notify only if not already at the end } if (backwards && cd.pos >= 0 && next_pos == 0 /*&& playback.blend.empty()*/) { //playback finished - end_notify = true; + end_reached = true; + end_notify = cd.pos > 0; // Notify only if not already at the beginning } } @@ -679,24 +681,26 @@ void AnimationPlayer::_animation_process(float p_delta) { if (playback.current.from) { + end_reached = false; end_notify = false; _animation_process2(p_delta); _animation_update_transforms(); - if (end_notify) { + if (end_reached) { if (queued.size()) { String old = playback.assigned; play(queued.front()->get()); String new_name = playback.assigned; queued.pop_front(); - end_notify = false; - emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name); + if (end_notify) + emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name); } else { //stop(); playing = false; _set_process(false); - end_notify = false; - emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned); + if (end_notify) + emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned); } + end_reached = false; } } else { @@ -954,7 +958,7 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float c.current.speed_scale = p_custom_scale; c.assigned = p_name; - if (!end_notify) + if (!end_reached) queued.clear(); _set_process(true); // always process when starting an animation playing = true; @@ -1348,6 +1352,7 @@ AnimationPlayer::AnimationPlayer() { cache_update_size = 0; cache_update_prop_size = 0; speed_scale = 1; + end_reached = false; end_notify = false; animation_process_mode = ANIMATION_PROCESS_IDLE; processing = false; diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 57c658e054..40a7252528 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -205,6 +205,7 @@ private: List<StringName> queued; + bool end_reached; bool end_notify; String autoplay; diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 2f30337cb8..1711fbffee 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -561,57 +561,50 @@ void Tween::_tween_process(float p_delta) { data.finish = true; } - switch (data.type) { - case INTER_PROPERTY: - case INTER_METHOD: { - Variant result = _run_equation(data); - emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result); - _apply_tween_value(data, result); - if (data.finish) - _apply_tween_value(data, data.final_val); - } break; - - case INTER_CALLBACK: - if (data.finish) { - if (data.call_deferred) { - - switch (data.args) { - case 0: - object->call_deferred(data.key[0]); - break; - case 1: - object->call_deferred(data.key[0], data.arg[0]); - break; - case 2: - object->call_deferred(data.key[0], data.arg[0], data.arg[1]); - break; - case 3: - object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2]); - break; - case 4: - object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3]); - break; - case 5: - object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); - break; - } - } else { - Variant::CallError error; - Variant *arg[5] = { - &data.arg[0], - &data.arg[1], - &data.arg[2], - &data.arg[3], - &data.arg[4], - }; - object->call(data.key[0], (const Variant **)arg, data.args, error); + if (data.type == INTER_CALLBACK) { + if (data.finish) { + if (data.call_deferred) { + + switch (data.args) { + case 0: + object->call_deferred(data.key[0]); + break; + case 1: + object->call_deferred(data.key[0], data.arg[0]); + break; + case 2: + object->call_deferred(data.key[0], data.arg[0], data.arg[1]); + break; + case 3: + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2]); + break; + case 4: + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3]); + break; + case 5: + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); + break; } + } else { + Variant::CallError error; + Variant *arg[5] = { + &data.arg[0], + &data.arg[1], + &data.arg[2], + &data.arg[3], + &data.arg[4], + }; + object->call(data.key[0], (const Variant **)arg, data.args, error); } - break; - default: {} + } + } else { + Variant result = _run_equation(data); + emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result); + _apply_tween_value(data, result); } if (data.finish) { + _apply_tween_value(data, data.final_val); emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false)); // not repeat mode, remove completed action if (!repeat) diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 95298f5a18..63478886c6 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -209,6 +209,7 @@ Color ColorPicker::get_pick_color() const { } void ColorPicker::add_preset(const Color &p_color) { + if (presets.find(p_color)) { presets.move_to_back(presets.find(p_color)); } else { diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index b1c862d1d1..5a4a0b2106 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -930,6 +930,9 @@ void ItemList::_notification(int p_what) { scroll_bar->hide(); } else { scroll_bar->show(); + + if (do_autoscroll_to_bottom) + scroll_bar->set_value(max); } break; } @@ -1313,6 +1316,11 @@ Size2 ItemList::get_minimum_size() const { return Size2(); } +void ItemList::set_autoscroll_to_bottom(const bool p_enable) { + + do_autoscroll_to_bottom = p_enable; +} + void ItemList::set_auto_height(bool p_enable) { auto_height = p_enable; @@ -1466,6 +1474,7 @@ ItemList::ItemList() { ensure_selected_visible = false; defer_select_single = -1; allow_rmb_select = false; + do_autoscroll_to_bottom = false; icon_scale = 1.0f; set_clip_contents(true); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index df751d8b9d..e56d5e5224 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -107,6 +107,8 @@ private: real_t icon_scale; + bool do_autoscroll_to_bottom; + Array _get_items() const; void _set_items(const Array &p_items); @@ -212,6 +214,8 @@ public: Size2 get_minimum_size() const; + void set_autoscroll_to_bottom(const bool p_enable); + VScrollBar *get_v_scroll() { return scroll_bar; } ItemList(); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 34abb1fbcc..dff7722a9e 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -368,6 +368,18 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { shift_selection_check_post(k->get_shift()); } break; + case KEY_UP: { + + shift_selection_check_pre(k->get_shift()); + set_cursor_position(0); + shift_selection_check_post(k->get_shift()); + } break; + case KEY_DOWN: { + + shift_selection_check_pre(k->get_shift()); + set_cursor_position(text.length()); + shift_selection_check_post(k->get_shift()); + } break; case KEY_DELETE: { if (!editable) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 4f2cfccd4a..bf048ea1b6 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -371,19 +371,20 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & cw = tab_size * font->get_char_size(' ').width; } - if (underline) { - Color uc = color; - uc.a *= 0.5; - int uy = y + lh - fh + ascent + 2; - float underline_width = 1.0; -#ifdef TOOLS_ENABLED - underline_width *= EDSCALE; -#endif - VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + pofs, uy), p_ofs + Point2(align_ofs + pofs + cw, uy), uc, underline_width); - } ofs += cw; } } + + if (underline) { + Color uc = color; + uc.a *= 0.5; + int uy = y + lh - fh + ascent + 2; + float underline_width = 1.0; +#ifdef TOOLS_ENABLED + underline_width *= EDSCALE; +#endif + VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width); + } } ADVANCE(fw); @@ -451,6 +452,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & table->columns[i].width = 0; } //compute minimum width for each cell + const int available_width = p_width - hseparation * (table->columns.size() - 1) - wofs; + for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) { ERR_CONTINUE(E->get()->type != ITEM_FRAME); //children should all be frames ItemFrame *frame = static_cast<ItemFrame *>(E->get()); @@ -461,7 +464,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & for (int i = 0; i < frame->lines.size(); i++) { - _process_line(frame, Point2(), ly, p_width, i, PROCESS_CACHE, cfont, Color()); + _process_line(frame, Point2(), ly, available_width, i, PROCESS_CACHE, cfont, Color()); table->columns[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].minimum_width); } idx++; @@ -470,11 +473,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & //compute available width and total ratio (for expanders) int total_ratio = 0; - int available_width = p_width - hseparation * (table->columns.size() - 1); + int remaining_width = available_width; table->total_width = hseparation; for (int i = 0; i < table->columns.size(); i++) { - available_width -= table->columns[i].min_width; + remaining_width -= table->columns[i].min_width; if (table->columns[i].expand) total_ratio += table->columns[i].expand_ratio; } @@ -484,7 +487,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & for (int i = 0; i < table->columns.size(); i++) { table->columns[i].width = table->columns[i].min_width; if (table->columns[i].expand) - table->columns[i].width += table->columns[i].expand_ratio * available_width / total_ratio; + table->columns[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio; table->total_width += table->columns[i].width + hseparation; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 46ad956b68..87043c65eb 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1498,7 +1498,7 @@ void TextEdit::_notification(int p_what) { if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->show_virtual_keyboard(get_text(), get_global_rect()); if (raised_from_completion) { - VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1); + VisualServer::get_singleton()->canvas_item_set_z_index(get_canvas_item(), 1); } } break; @@ -1512,7 +1512,7 @@ void TextEdit::_notification(int p_what) { if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->hide_virtual_keyboard(); if (raised_from_completion) { - VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 0); + VisualServer::get_singleton()->canvas_item_set_z_index(get_canvas_item(), 0); } } break; } @@ -1822,10 +1822,18 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (mb->is_pressed()) { if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) { - _scroll_up(3 * mb->get_factor()); + if (mb->get_shift()) { + h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor())); + } else { + _scroll_up(3 * mb->get_factor()); + } } if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) { - _scroll_down(3 * mb->get_factor()); + if (mb->get_shift()) { + h_scroll->set_value(h_scroll->get_value() + (100 * mb->get_factor())); + } else { + _scroll_down(3 * mb->get_factor()); + } } if (mb->get_button_index() == BUTTON_WHEEL_LEFT) { h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor())); @@ -2581,22 +2589,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (cc == 0 && cursor.line > 0) { cursor_set_line(cursor.line - 1); cursor_set_column(text[cursor.line].length()); - break; - } - - while (cc > 0) { - - bool ischar = _is_text_char(text[cursor.line][cc - 1]); + } else { + while (cc > 0) { + bool ischar = _is_text_char(text[cursor.line][cc - 1]); - if (prev_char && !ischar) - break; + if (prev_char && !ischar) + break; - prev_char = ischar; - cc--; + prev_char = ischar; + cc--; + } + cursor_set_column(cc); } - cursor_set_column(cc); - } else if (cursor.column == 0) { if (cursor.line > 0) { @@ -2645,21 +2650,18 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (cc == text[cursor.line].length() && cursor.line < text.size() - 1) { cursor_set_line(cursor.line + 1); cursor_set_column(0); - break; - } - - while (cc < text[cursor.line].length()) { - - bool ischar = _is_text_char(text[cursor.line][cc]); + } else { + while (cc < text[cursor.line].length()) { + bool ischar = _is_text_char(text[cursor.line][cc]); - if (prev_char && !ischar) - break; - prev_char = ischar; - cc++; + if (prev_char && !ischar) + break; + prev_char = ischar; + cc++; + } + cursor_set_column(cc); } - cursor_set_column(cc); - } else if (cursor.column == text[cursor.line].length()) { if (cursor.line < text.size() - 1) { @@ -2731,6 +2733,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { _scroll_lines_down(); break; } + + { #else if (k->get_command() && k->get_alt()) { _scroll_lines_down(); @@ -2739,9 +2743,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (k->get_command()) cursor_set_line(text.size() - 1, true, false); - else + else { #endif - cursor_set_line(cursor_get_line() + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1), true, false); + if (!is_last_visible_line(cursor.line)) { + cursor_set_line(cursor_get_line() + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1), true, false); + } else { + cursor_set_line(text.size() - 1); + cursor_set_column(get_line(cursor.line).length(), true); + } + } if (k->get_shift()) _post_shift_selection(); @@ -3137,6 +3147,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { void TextEdit::_scroll_up(real_t p_delta) { + if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta)) + scrolling = false; + if (scrolling) { target_v_scroll = (target_v_scroll - p_delta); } else { @@ -3147,8 +3160,12 @@ void TextEdit::_scroll_up(real_t p_delta) { if (target_v_scroll <= 0) { target_v_scroll = 0; } - scrolling = true; - set_physics_process(true); + if (Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) { + v_scroll->set_value(target_v_scroll); + } else { + scrolling = true; + set_physics_process(true); + } } else { v_scroll->set_value(target_v_scroll); } @@ -3156,6 +3173,9 @@ void TextEdit::_scroll_up(real_t p_delta) { void TextEdit::_scroll_down(real_t p_delta) { + if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(p_delta)) + scrolling = false; + if (scrolling) { target_v_scroll = (target_v_scroll + p_delta); } else { @@ -3172,8 +3192,13 @@ void TextEdit::_scroll_down(real_t p_delta) { if (target_v_scroll > max_v_scroll) { target_v_scroll = max_v_scroll; } - scrolling = true; - set_physics_process(true); + + if (Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) { + v_scroll->set_value(target_v_scroll); + } else { + scrolling = true; + set_physics_process(true); + } } else { v_scroll->set_value(target_v_scroll); } @@ -4590,6 +4615,24 @@ int TextEdit::num_lines_from(int p_line_from, int unhidden_amount) const { return num_total; } +bool TextEdit::is_last_visible_line(int p_line) const { + + ERR_FAIL_INDEX_V(p_line, text.size(), false); + + if (p_line == text.size() - 1) + return true; + + if (!is_hiding_enabled()) + return false; + + for (int i = p_line + 1; i < text.size(); i++) { + if (!is_line_hidden(i)) + return false; + } + + return true; +} + int TextEdit::get_indent_level(int p_line) const { ERR_FAIL_INDEX_V(p_line, text.size(), 0); @@ -5019,7 +5062,7 @@ void TextEdit::_confirm_completion() { void TextEdit::_cancel_code_hint() { - VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 0); + VisualServer::get_singleton()->canvas_item_set_z_index(get_canvas_item(), 0); raised_from_completion = false; completion_hint = ""; update(); @@ -5027,7 +5070,7 @@ void TextEdit::_cancel_code_hint() { void TextEdit::_cancel_completion() { - VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 0); + VisualServer::get_singleton()->canvas_item_set_z_index(get_canvas_item(), 0); raised_from_completion = false; if (!completion_active) return; @@ -5202,7 +5245,7 @@ void TextEdit::query_code_comple() { void TextEdit::set_code_hint(const String &p_hint) { - VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1); + VisualServer::get_singleton()->canvas_item_set_z_index(get_canvas_item(), 1); raised_from_completion = true; completion_hint = p_hint; completion_hint_offset = -0xFFFF; @@ -5211,7 +5254,7 @@ void TextEdit::set_code_hint(const String &p_hint) { void TextEdit::code_complete(const Vector<String> &p_strings, bool p_forced) { - VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1); + VisualServer::get_singleton()->canvas_item_set_z_index(get_canvas_item(), 1); raised_from_completion = true; completion_strings = p_strings; completion_active = true; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 320bb6d9fd..ccd7ba8278 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -433,6 +433,7 @@ public: void fold_all_lines(); void unhide_all_lines(); int num_lines_from(int p_line_from, int unhidden_amount) const; + bool is_last_visible_line(int p_line) const; bool can_fold(int p_line) const; bool is_folded(int p_line) const; void fold_line(int p_line); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 08f1bdff3d..b1a421c24f 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1423,17 +1423,33 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 #endif Point2i parent_pos = Point2i(parent_ofs - cache.arrow->get_width() / 2, p_pos.y + label_h / 2 + cache.arrow->get_height() / 2) - cache.offset + p_draw_ofs; - VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), parent_pos, cache.relationship_line_color, line_width); + + if (root_pos.y + line_width >= 0) { + VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), parent_pos, cache.relationship_line_color, line_width); + } + + if (htotal < 0) { + return -1; + } } - int child_h = draw_item(children_pos, p_draw_ofs, p_draw_size, c); + if (htotal >= 0) { + int child_h = draw_item(children_pos, p_draw_ofs, p_draw_size, c); - if (child_h < 0 && cache.draw_relationship_lines == 0) - return -1; // break, stop drawing, no need to anymore + if (child_h < 0) { + if (cache.draw_relationship_lines == 0) { + return -1; // break, stop drawing, no need to anymore + } else { + htotal = -1; + children_pos.y = cache.offset.y + p_draw_size.height; + } + } else { + htotal += child_h; + children_pos.y += child_h; + } + } - htotal += child_h; - children_pos.y += child_h; c = c->next; } } @@ -2352,8 +2368,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { last_keypress = 0; } } break; - - last_keypress = 0; } } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 07f93fa52b..632d912e43 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -2126,6 +2126,7 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("has_group", "name"), &SceneTree::has_group); ClassDB::bind_method(D_METHOD("set_auto_accept_quit", "enabled"), &SceneTree::set_auto_accept_quit); + ClassDB::bind_method(D_METHOD("set_quit_on_go_back", "enabled"), &SceneTree::set_quit_on_go_back); ClassDB::bind_method(D_METHOD("set_debug_collisions_hint", "enable"), &SceneTree::set_debug_collisions_hint); ClassDB::bind_method(D_METHOD("is_debugging_collisions_hint"), &SceneTree::is_debugging_collisions_hint); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 4036735807..998c790c94 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -220,31 +220,17 @@ void register_scene_types() { resource_loader_theme = memnew(ResourceFormatLoaderTheme); ResourceLoader::add_resource_format_loader(resource_loader_theme); - bool default_theme_hidpi = GLOBAL_DEF("gui/theme/use_hidpi", false); - ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/use_hidpi", PropertyInfo(Variant::BOOL, "gui/theme/use_hidpi", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)); - String theme_path = GLOBAL_DEF("gui/theme/custom", ""); - ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom", PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)); - String font_path = GLOBAL_DEF("gui/theme/custom_font", ""); - ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom_font", PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)); + resource_saver_text = memnew(ResourceFormatSaverText); + ResourceSaver::add_resource_format_saver(resource_saver_text, true); - bool has_theme = false; - if (theme_path != String()) { - Ref<Theme> theme = ResourceLoader::load(theme_path); - if (theme.is_valid()) { - Theme::set_default(theme); - has_theme = true; - } else { - ERR_PRINTS("Error loading custom theme '" + theme_path + "'"); - } - } + resource_loader_text = memnew(ResourceFormatLoaderText); + ResourceLoader::add_resource_format_loader(resource_loader_text, true); - if (!has_theme) { - Ref<Font> font; - if (font_path != String()) { - font = ResourceLoader::load(font_path); - } - make_default_theme(default_theme_hidpi, font); - } + resource_saver_shader = memnew(ResourceFormatSaverShader); + ResourceSaver::add_resource_format_saver(resource_saver_shader, true); + + resource_loader_shader = memnew(ResourceFormatLoaderShader); + ResourceLoader::add_resource_format_loader(resource_loader_shader, true); OS::get_singleton()->yield(); //may take time to init @@ -604,24 +590,42 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init - resource_saver_text = memnew(ResourceFormatSaverText); - ResourceSaver::add_resource_format_saver(resource_saver_text, true); - - resource_loader_text = memnew(ResourceFormatLoaderText); - ResourceLoader::add_resource_format_loader(resource_loader_text, true); - - resource_saver_shader = memnew(ResourceFormatSaverShader); - ResourceSaver::add_resource_format_saver(resource_saver_shader, true); - - resource_loader_shader = memnew(ResourceFormatLoaderShader); - ResourceLoader::add_resource_format_loader(resource_loader_shader, true); - for (int i = 0; i < 20; i++) { GLOBAL_DEF("layer_names/2d_render/layer_" + itos(i + 1), ""); GLOBAL_DEF("layer_names/2d_physics/layer_" + itos(i + 1), ""); GLOBAL_DEF("layer_names/3d_render/layer_" + itos(i + 1), ""); GLOBAL_DEF("layer_names/3d_physics/layer_" + itos(i + 1), ""); } + + bool default_theme_hidpi = GLOBAL_DEF("gui/theme/use_hidpi", false); + ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/use_hidpi", PropertyInfo(Variant::BOOL, "gui/theme/use_hidpi", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)); + String theme_path = GLOBAL_DEF("gui/theme/custom", ""); + ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom", PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)); + String font_path = GLOBAL_DEF("gui/theme/custom_font", ""); + ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom_font", PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)); + + Ref<Font> font; + if (font_path != String()) { + font = ResourceLoader::load(font_path); + if (!font.is_valid()) { + ERR_PRINTS("Error loading custom font '" + font_path + "'"); + } + } + + // Always make the default theme to avoid invalid default font/icon/style in the given theme + make_default_theme(default_theme_hidpi, font); + + if (theme_path != String()) { + Ref<Theme> theme = ResourceLoader::load(theme_path); + if (theme.is_valid()) { + Theme::set_default(theme); + if (font.is_valid()) { + Theme::set_default_font(font); + } + } else { + ERR_PRINTS("Error loading custom theme '" + theme_path + "'"); + } + } } void unregister_scene_types() { diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index 7b2dbf8e8c..2722ff7207 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -32,6 +32,25 @@ #include "servers/physics_2d_server.h" #include "servers/visual_server.h" +Vector<Vector2> CapsuleShape2D::_get_points() const { + + Vector<Vector2> points; + for (int i = 0; i < 24; i++) { + Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -get_height() * 0.5 : get_height() * 0.5); + + points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() + ofs); + if (i == 6 || i == 18) + points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() - ofs); + } + + return points; +} + +bool CapsuleShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + return Geometry::is_point_in_polygon(p_point, _get_points()); +} + void CapsuleShape2D::_update_shape() { Physics2DServer::get_singleton()->shape_set_data(get_rid(), Vector2(radius, height)); @@ -62,15 +81,7 @@ real_t CapsuleShape2D::get_height() const { void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) { - Vector<Vector2> points; - for (int i = 0; i < 24; i++) { - Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -get_height() * 0.5 : get_height() * 0.5); - - points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() + ofs); - if (i == 6 || i == 18) - points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() - ofs); - } - + Vector<Vector2> points = _get_points(); Vector<Color> col; col.push_back(p_color); VisualServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); diff --git a/scene/resources/capsule_shape_2d.h b/scene/resources/capsule_shape_2d.h index 7ce6a4ed63..784f2c02c8 100644 --- a/scene/resources/capsule_shape_2d.h +++ b/scene/resources/capsule_shape_2d.h @@ -39,11 +39,14 @@ class CapsuleShape2D : public Shape2D { real_t radius; void _update_shape(); + Vector<Vector2> _get_points() const; protected: static void _bind_methods(); public: + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_height(real_t p_height); real_t get_height() const; diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp index d9d0ddbe8f..669b1d8e7d 100644 --- a/scene/resources/circle_shape_2d.cpp +++ b/scene/resources/circle_shape_2d.cpp @@ -31,6 +31,12 @@ #include "servers/physics_2d_server.h" #include "servers/visual_server.h" + +bool CircleShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + return p_point.length() < get_radius() + p_tolerance; +} + void CircleShape2D::_update_shape() { Physics2DServer::get_singleton()->shape_set_data(get_rid(), radius); diff --git a/scene/resources/circle_shape_2d.h b/scene/resources/circle_shape_2d.h index f14f8f6776..3668521a55 100644 --- a/scene/resources/circle_shape_2d.h +++ b/scene/resources/circle_shape_2d.h @@ -42,6 +42,8 @@ protected: static void _bind_methods(); public: + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_radius(real_t p_radius); real_t get_radius() const; diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index 19985d4acf..69765796f6 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -32,6 +32,23 @@ #include "servers/physics_2d_server.h" #include "servers/visual_server.h" +bool ConcavePolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + PoolVector<Vector2> s = get_segments(); + int len = s.size(); + if (len == 0 || (len % 2) == 1) + return false; + + PoolVector<Vector2>::Read r = s.read(); + for (int i = 0; i < len; i += 2) { + Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, &r[i]); + if (p_point.distance_to(closest) < p_tolerance) + return true; + } + + return false; +} + void ConcavePolygonShape2D::set_segments(const PoolVector<Vector2> &p_segments) { Physics2DServer::get_singleton()->shape_set_data(get_rid(), p_segments); diff --git a/scene/resources/concave_polygon_shape_2d.h b/scene/resources/concave_polygon_shape_2d.h index 4a5defe72c..7ca14d4d66 100644 --- a/scene/resources/concave_polygon_shape_2d.h +++ b/scene/resources/concave_polygon_shape_2d.h @@ -39,6 +39,8 @@ protected: static void _bind_methods(); public: + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_segments(const PoolVector<Vector2> &p_segments); PoolVector<Vector2> get_segments() const; diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index 98ef2ca7c6..0402a70898 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -33,6 +33,11 @@ #include "servers/physics_2d_server.h" #include "servers/visual_server.h" +bool ConvexPolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + return Geometry::is_point_in_polygon(p_point, points); +} + void ConvexPolygonShape2D::_update_shape() { Physics2DServer::get_singleton()->shape_set_data(get_rid(), points); diff --git a/scene/resources/convex_polygon_shape_2d.h b/scene/resources/convex_polygon_shape_2d.h index f492b7651b..320cf94a5e 100644 --- a/scene/resources/convex_polygon_shape_2d.h +++ b/scene/resources/convex_polygon_shape_2d.h @@ -42,6 +42,8 @@ protected: static void _bind_methods(); public: + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_point_cloud(const Vector<Vector2> &p_points); void set_points(const Vector<Vector2> &p_points); Vector<Vector2> get_points() const; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index b18583dfb1..a4049e4461 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -880,7 +880,7 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) { Ref<StyleBox> default_style; Ref<Texture> default_icon; - Ref<BitmapFont> default_font; + Ref<Font> default_font; if (p_font.is_valid()) { default_font = p_font; } else if (p_hidpi) { @@ -888,7 +888,7 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) { } else { default_font = make_font2(_lodpi_font_height, _lodpi_font_ascent, _lodpi_font_charcount, &_lodpi_font_charrects[0][0], _lodpi_font_kerning_pair_count, &_lodpi_font_kerning_pairs[0][0], _lodpi_font_img_width, _lodpi_font_img_height, _lodpi_font_img_data); } - Ref<BitmapFont> large_font = default_font; + Ref<Font> large_font = default_font; fill_default_theme(t, default_font, large_font, default_icon, default_style, p_hidpi ? 2.0 : 1.0); Theme::set_default(t); diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 6216893667..b2c91f90eb 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -1218,7 +1218,7 @@ Environment::Environment() { ssao_radius2 = 0; ssao_intensity2 = 1; ssao_bias = 0.01; - ssao_direct_light_affect = false; + ssao_direct_light_affect = 0.0; ssao_blur = SSAO_BLUR_3x3; set_ssao_edge_sharpness(4); set_ssao_quality(SSAO_QUALITY_LOW); diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp index 4682ef5cb3..346599b25a 100644 --- a/scene/resources/segment_shape_2d.cpp +++ b/scene/resources/segment_shape_2d.cpp @@ -32,6 +32,13 @@ #include "servers/physics_2d_server.h" #include "servers/visual_server.h" +bool SegmentShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + Vector2 l[2] = { a, b }; + Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, l); + return p_point.distance_to(closest) < p_tolerance; +} + void SegmentShape2D::_update_shape() { Rect2 r; diff --git a/scene/resources/segment_shape_2d.h b/scene/resources/segment_shape_2d.h index 1285ae4f82..39a71f61d5 100644 --- a/scene/resources/segment_shape_2d.h +++ b/scene/resources/segment_shape_2d.h @@ -44,6 +44,8 @@ protected: static void _bind_methods(); public: + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_a(const Vector2 &p_a); void set_b(const Vector2 &p_b); diff --git a/scene/resources/shape_2d.h b/scene/resources/shape_2d.h index 5c2c24ed74..877a159aee 100644 --- a/scene/resources/shape_2d.h +++ b/scene/resources/shape_2d.h @@ -44,6 +44,8 @@ protected: Shape2D(const RID &p_rid); public: + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { return true; } + void set_custom_solver_bias(real_t p_bias); real_t get_custom_solver_bias() const; diff --git a/scene/resources/shape_line_2d.cpp b/scene/resources/shape_line_2d.cpp index c6cc3659f6..9548d35370 100644 --- a/scene/resources/shape_line_2d.cpp +++ b/scene/resources/shape_line_2d.cpp @@ -30,6 +30,21 @@ #include "shape_line_2d.h" #include "servers/physics_2d_server.h" #include "servers/visual_server.h" + +bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + + Vector2 point = get_d() * get_normal(); + Vector2 l[2][2] = { { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 }, { point, point + get_normal() * 30 } }; + + for (int i = 0; i < 2; i++) { + Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, l[i]); + if (p_point.distance_to(closest) < p_tolerance) + return true; + } + + return false; +} + void LineShape2D::_update_shape() { Array arr; diff --git a/scene/resources/shape_line_2d.h b/scene/resources/shape_line_2d.h index 747500b0ac..fe6f2d675e 100644 --- a/scene/resources/shape_line_2d.h +++ b/scene/resources/shape_line_2d.h @@ -44,6 +44,8 @@ protected: static void _bind_methods(); public: + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + void set_normal(const Vector2 &p_normal); void set_d(real_t p_d); |