You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Improve 2D editor zoom logic
- Add 1-5 shortcuts to zoom between 100% and 1600% quickly (similar to GIMP). - When holding down Alt, go through integer zoom values if above 100% or fractional zoom values with integer denominators if below 100% (50%, ~33.3%, 25%, …).
This commit is contained in:
@@ -1149,8 +1149,9 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo
|
||||
view_offset.y += int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
||||
update_viewport();
|
||||
} else {
|
||||
zoom_widget->set_zoom_by_increments(-1);
|
||||
if (b->get_factor() != 1.f) {
|
||||
zoom_widget->set_zoom_by_increments(-1, Input::get_singleton()->is_key_pressed(KEY_ALT));
|
||||
if (!Math::is_equal_approx(b->get_factor(), 1.0f)) {
|
||||
// Handle high-precision (analog) scrolling.
|
||||
zoom_widget->set_zoom(zoom * ((zoom_widget->get_zoom() / zoom - 1.f) * b->get_factor() + 1.f));
|
||||
}
|
||||
_zoom_on_position(zoom_widget->get_zoom(), b->get_position());
|
||||
@@ -1164,8 +1165,9 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo
|
||||
view_offset.y -= int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
||||
update_viewport();
|
||||
} else {
|
||||
zoom_widget->set_zoom_by_increments(1);
|
||||
if (b->get_factor() != 1.f) {
|
||||
zoom_widget->set_zoom_by_increments(1, Input::get_singleton()->is_key_pressed(KEY_ALT));
|
||||
if (!Math::is_equal_approx(b->get_factor(), 1.0f)) {
|
||||
// Handle high-precision (analog) scrolling.
|
||||
zoom_widget->set_zoom(zoom * ((zoom_widget->get_zoom() / zoom - 1.f) * b->get_factor() + 1.f));
|
||||
}
|
||||
_zoom_on_position(zoom_widget->get_zoom(), b->get_position());
|
||||
@@ -1194,6 +1196,20 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo
|
||||
|
||||
Ref<InputEventKey> k = p_event;
|
||||
if (k.is_valid()) {
|
||||
if (k->is_pressed()) {
|
||||
if (ED_GET_SHORTCUT("canvas_item_editor/zoom_100_percent")->is_shortcut(p_event)) {
|
||||
_update_zoom(1.0 * MAX(1, EDSCALE));
|
||||
} else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_200_percent")->is_shortcut(p_event)) {
|
||||
_update_zoom(2.0 * MAX(1, EDSCALE));
|
||||
} else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_400_percent")->is_shortcut(p_event)) {
|
||||
_update_zoom(4.0 * MAX(1, EDSCALE));
|
||||
} else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_800_percent")->is_shortcut(p_event)) {
|
||||
_update_zoom(8.0 * MAX(1, EDSCALE));
|
||||
} else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_1600_percent")->is_shortcut(p_event)) {
|
||||
_update_zoom(16.0 * MAX(1, EDSCALE));
|
||||
}
|
||||
}
|
||||
|
||||
bool is_pan_key = pan_view_shortcut.is_valid() && pan_view_shortcut->is_shortcut(p_event);
|
||||
|
||||
if (is_pan_key && (EditorSettings::get_singleton()->get("editors/2d/simple_panning") || drag_type != DRAG_NONE)) {
|
||||
@@ -5610,6 +5626,16 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
|
||||
skeleton_menu->get_popup()->set_item_checked(skeleton_menu->get_popup()->get_item_index(SKELETON_SHOW_BONES), true);
|
||||
singleton = this;
|
||||
|
||||
// To ensure that scripts can parse the list of shortcuts correctly, we have to define
|
||||
// those shortcuts one by one.
|
||||
// Resetting zoom to 100% is a duplicate shortcut of `canvas_item_editor/reset_zoom`,
|
||||
// but it ensures both 1 and Ctrl + 0 can be used to reset zoom.
|
||||
ED_SHORTCUT("canvas_item_editor/zoom_100_percent", TTR("Zoom To 100%"), KEY_1);
|
||||
ED_SHORTCUT("canvas_item_editor/zoom_200_percent", TTR("Zoom To 200%"), KEY_2);
|
||||
ED_SHORTCUT("canvas_item_editor/zoom_400_percent", TTR("Zoom To 400%"), KEY_3);
|
||||
ED_SHORTCUT("canvas_item_editor/zoom_800_percent", TTR("Zoom To 800%"), KEY_4);
|
||||
ED_SHORTCUT("canvas_item_editor/zoom_1600_percent", TTR("Zoom To 1600%"), KEY_5);
|
||||
|
||||
set_process_unhandled_key_input(true);
|
||||
|
||||
// Update the menus' checkboxes
|
||||
|
||||
Reference in New Issue
Block a user