| 2122 | } |
| 2123 | |
| 2124 | void RuntimeNodeSelect::_update_selection() { |
| 2125 | Window *root = SceneTree::get_singleton()->get_root(); |
| 2126 | |
| 2127 | RS::get_singleton()->canvas_item_clear(sbox_2d_ci); |
| 2128 | RS::get_singleton()->canvas_item_set_visible(sbox_2d_ci, selection_visible); |
| 2129 | |
| 2130 | for (LocalVector<ObjectID>::Iterator E = selected_ci_nodes.begin(); E != selected_ci_nodes.end(); ++E) { |
| 2131 | ObjectID id = *E; |
| 2132 | CanvasItem *ci = ObjectDB::get_instance<CanvasItem>(id); |
| 2133 | if (!ci) { |
| 2134 | selected_ci_nodes.erase(id); |
| 2135 | --E; |
| 2136 | continue; |
| 2137 | } |
| 2138 | |
| 2139 | if (!ci->is_inside_tree()) { |
| 2140 | continue; |
| 2141 | } |
| 2142 | |
| 2143 | Transform2D xform; |
| 2144 | // Cameras (overridden or not) don't affect `CanvasLayer`s. |
| 2145 | if (root->is_canvas_transform_override_enabled() && !(ci->get_canvas_layer_node() && !ci->get_canvas_layer_node()->is_following_viewport())) { |
| 2146 | xform = root->get_canvas_transform_override() * ci->get_global_transform(); |
| 2147 | } else { |
| 2148 | xform = ci->get_global_transform_with_canvas(); |
| 2149 | } |
| 2150 | |
| 2151 | // Fallback. |
| 2152 | Rect2 rect = Rect2(Vector2(), Vector2(10, 10)); |
| 2153 | |
| 2154 | if (ci->_edit_use_rect()) { |
| 2155 | rect = ci->_edit_get_rect(); |
| 2156 | } else { |
| 2157 | #ifndef PHYSICS_2D_DISABLED |
| 2158 | CollisionShape2D *collision_shape = Object::cast_to<CollisionShape2D>(ci); |
| 2159 | if (collision_shape) { |
| 2160 | Ref<Shape2D> shape = collision_shape->get_shape(); |
| 2161 | if (shape.is_valid()) { |
| 2162 | rect = shape->get_rect(); |
| 2163 | } |
| 2164 | } |
| 2165 | #endif // PHYSICS_2D_DISABLED |
| 2166 | } |
| 2167 | |
| 2168 | const Vector2 endpoints[4] = { |
| 2169 | xform.xform(rect.position), |
| 2170 | xform.xform(rect.position + Point2(rect.size.x, 0)), |
| 2171 | xform.xform(rect.position + rect.size), |
| 2172 | xform.xform(rect.position + Point2(0, rect.size.y)) |
| 2173 | }; |
| 2174 | |
| 2175 | const Color selection_color_2d = Color(1, 0.6, 0.4, 0.7); |
| 2176 | for (int i = 0; i < 4; i++) { |
| 2177 | RS::get_singleton()->canvas_item_add_line(sbox_2d_ci, endpoints[i], endpoints[(i + 1) % 4], selection_color_2d, 2); |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | #ifndef _3D_DISABLED |
nothing calls this directly
no test coverage detected