diff options
Diffstat (limited to 'editor/plugins/canvas_item_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index dc5acce823..85846d7bc6 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -60,11 +60,6 @@ #include "scene/resources/packed_scene.h" #include "scene/resources/style_box_texture.h" -// Min and Max are power of two in order to play nicely with successive increment. -// That way, we can naturally reach a 100% zoom from boundaries. -constexpr real_t MIN_ZOOM = 1. / 128; -constexpr real_t MAX_ZOOM = 128; - #define RULER_WIDTH (15 * EDSCALE) constexpr real_t SCALE_HANDLE_DISTANCE = 25; constexpr real_t MOVE_HANDLE_DISTANCE = 25; @@ -2279,6 +2274,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { NodePath root_path = get_tree()->get_edited_scene_root()->get_path(); StringName root_name = root_path.get_name(root_path.get_name_count() - 1); + int icon_max_width = EditorNode::get_singleton()->get_editor_theme()->get_constant(SNAME("class_icon_size"), EditorStringName(Editor)); for (int i = 0; i < selection_results.size(); i++) { CanvasItem *item = selection_results[i].item; @@ -2310,6 +2306,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { } selection_menu->add_item((String)item->get_name() + suffix); selection_menu->set_item_icon(i, icon); + selection_menu->set_item_icon_max_width(i, icon_max_width); selection_menu->set_item_metadata(i, node_path); selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path); } @@ -3656,6 +3653,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans void CanvasItemEditor::_draw_hover() { List<Rect2> previous_rects; + Vector2 icon_size = Vector2(1, 1) * get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)); for (int i = 0; i < hovering_results.size(); i++) { Ref<Texture2D> node_icon = hovering_results[i].icon; @@ -3664,9 +3662,9 @@ void CanvasItemEditor::_draw_hover() { Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); Size2 node_name_size = font->get_string_size(node_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); - Size2 item_size = Size2(node_icon->get_size().x + 4 + node_name_size.x, MAX(node_icon->get_size().y, node_name_size.y - 3)); + Size2 item_size = Size2(icon_size.x + 4 + node_name_size.x, MAX(icon_size.y, node_name_size.y - 3)); - Point2 pos = transform.xform(hovering_results[i].position) - Point2(0, item_size.y) + (Point2(node_icon->get_size().x, -node_icon->get_size().y) / 4); + Point2 pos = transform.xform(hovering_results[i].position) - Point2(0, item_size.y) + (Point2(icon_size.x, -icon_size.y) / 4); // Rectify the position to avoid overlapping items for (const Rect2 &E : previous_rects) { if (E.intersects(Rect2(pos, item_size))) { @@ -3677,10 +3675,10 @@ void CanvasItemEditor::_draw_hover() { previous_rects.push_back(Rect2(pos, item_size)); // Draw icon - viewport->draw_texture(node_icon, pos, Color(1.0, 1.0, 1.0, 0.5)); + viewport->draw_texture_rect(node_icon, Rect2(pos, icon_size), false, Color(1.0, 1.0, 1.0, 0.5)); // Draw name - viewport->draw_string(font, pos + Point2(node_icon->get_size().x + 4, item_size.y - 3), node_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5)); + viewport->draw_string(font, pos + Point2(icon_size.x + 4, item_size.y - 3), node_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5)); } } @@ -4115,10 +4113,9 @@ void CanvasItemEditor::_update_scroll(real_t) { } void CanvasItemEditor::_zoom_on_position(real_t p_zoom, Point2 p_position) { - p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM); + p_zoom = CLAMP(p_zoom, zoom_widget->get_min_zoom(), zoom_widget->get_max_zoom()); if (p_zoom == zoom) { - zoom_widget->set_zoom(p_zoom); return; } @@ -4128,12 +4125,12 @@ void CanvasItemEditor::_zoom_on_position(real_t p_zoom, Point2 p_position) { view_offset += p_position / prev_zoom - p_position / zoom; // We want to align in-scene pixels to screen pixels, this prevents blurry rendering - // in small details (texts, lines). + // of small details (texts, lines). // This correction adds a jitter movement when zooming, so we correct only when the // zoom factor is an integer. (in the other cases, all pixels won't be aligned anyway) const real_t closest_zoom_factor = Math::round(zoom); if (Math::is_zero_approx(zoom - closest_zoom_factor)) { - // make sure scene pixel at view_offset is aligned on a screen pixel + // Make sure scene pixel at view_offset is aligned on a screen pixel. Vector2 view_offset_int = view_offset.floor(); Vector2 view_offset_frac = view_offset - view_offset_int; view_offset = view_offset_int + (view_offset_frac * closest_zoom_factor).round() / closest_zoom_factor; @@ -5147,9 +5144,9 @@ CanvasItemEditor::CanvasItemEditor() { button_center_view->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback).bind(VIEW_CENTER_TO_SELECTION)); zoom_widget = memnew(EditorZoomWidget); - controls_hb->add_child(zoom_widget); zoom_widget->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT, Control::PRESET_MODE_MINSIZE, 2 * EDSCALE); zoom_widget->set_shortcut_context(this); + controls_hb->add_child(zoom_widget); zoom_widget->connect("zoom_changed", callable_mp(this, &CanvasItemEditor::_update_zoom)); panner.instantiate(); @@ -5505,6 +5502,7 @@ CanvasItemEditor::CanvasItemEditor() { selection_menu = memnew(PopupMenu); add_child(selection_menu); selection_menu->set_min_size(Vector2(100, 0)); + selection_menu->set_auto_translate(false); selection_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_selection_result_pressed)); selection_menu->connect("popup_hide", callable_mp(this, &CanvasItemEditor::_selection_menu_hide), CONNECT_DEFERRED); |