From 2c0642d1f1b10ea597c74480d28db8fead61f392 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 19 Apr 2014 20:43:23 -0300 Subject: [PATCH] It's better if mouse wheel doesn't center the scroll on zoom-in/out --- src/app/ui/editor/editor.cpp | 16 ++++++++++++++-- src/app/ui/editor/editor.h | 8 +++++++- src/app/ui/editor/keys.cpp | 3 ++- src/app/ui/editor/standby_state.cpp | 4 +++- src/app/ui/editor/zooming_state.cpp | 3 ++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 2fa7a760b..b4f51c6e7 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1120,14 +1120,26 @@ bool Editor::isInsideSelection() m_document->getMask()->containsPoint(x, y); } -void Editor::setZoomAndCenterInMouse(int zoom, int mouse_x, int mouse_y) +void Editor::setZoomAndCenterInMouse(int zoom, int mouse_x, int mouse_y, ZoomBehavior zoomBehavior) { View* view = View::getView(this); Rect vp = view->getViewportBounds(); int x, y; - bool centerMouse = get_config_bool("Editor", "CenterMouseInZoom", true); + bool centerMouse; int mx, my; + switch (zoomBehavior) { + case kCofiguredZoomBehavior: + centerMouse = get_config_bool("Editor", "CenterMouseInZoom", true); + break; + case kCenterOnZoom: + centerMouse = true; + break; + case kDontCenterOnZoom: + centerMouse = false; + break; + } + hideDrawingCursor(); screenToEditor(mouse_x, mouse_y, &x, &y); diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index 241516a28..eea121132 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -70,6 +70,12 @@ namespace app { kDefaultEditorFlags = kShowGridFlag | kShowMaskFlag, }; + enum ZoomBehavior { + kCofiguredZoomBehavior, + kCenterOnZoom, + kDontCenterOnZoom, + }; + Editor(Document* document, EditorFlags flags = kDefaultEditorFlags); ~Editor(); @@ -157,7 +163,7 @@ namespace app { // Returns true if the cursor is inside the active mask/selection. bool isInsideSelection(); - void setZoomAndCenterInMouse(int zoom, int mouse_x, int mouse_y); + void setZoomAndCenterInMouse(int zoom, int mouse_x, int mouse_y, ZoomBehavior zoomBehavior); bool processKeysToSetZoom(ui::KeyMessage* msg); diff --git a/src/app/ui/editor/keys.cpp b/src/app/ui/editor/keys.cpp index c37e65fef..be2e83e82 100644 --- a/src/app/ui/editor/keys.cpp +++ b/src/app/ui/editor/keys.cpp @@ -62,7 +62,8 @@ bool Editor::processKeysToSetZoom(KeyMessage* msg) // Change zoom if (zoom >= 0) { - setZoomAndCenterInMouse(zoom, jmouse_x(0), jmouse_y(0)); + setZoomAndCenterInMouse(zoom, jmouse_x(0), jmouse_y(0), + Editor::kCofiguredZoomBehavior); return true; } } diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index 4fb27361b..97e1155df 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -356,7 +356,9 @@ bool StandbyState::onMouseWheel(Editor* editor, MouseMessage* msg) MouseMessage* mouseMsg = static_cast(msg); int zoom = MID(MIN_ZOOM, editor->getZoom()-dz, MAX_ZOOM); if (editor->getZoom() != zoom) - editor->setZoomAndCenterInMouse(zoom, mouseMsg->position().x, mouseMsg->position().y); + editor->setZoomAndCenterInMouse(zoom, + mouseMsg->position().x, mouseMsg->position().y, + Editor::kDontCenterOnZoom); break; } diff --git a/src/app/ui/editor/zooming_state.cpp b/src/app/ui/editor/zooming_state.cpp index 53868335d..74c0d0e54 100644 --- a/src/app/ui/editor/zooming_state.cpp +++ b/src/app/ui/editor/zooming_state.cpp @@ -60,7 +60,8 @@ bool ZoomingState::onMouseUp(Editor* editor, MouseMessage* msg) else if (msg->right() && zoom > 0) --zoom; - editor->setZoomAndCenterInMouse(zoom, msg->position().x, msg->position().y); + editor->setZoomAndCenterInMouse(zoom, msg->position().x, msg->position().y, + Editor::kCofiguredZoomBehavior); editor->backToPreviousState(); editor->releaseMouse();