diff --git a/src/app/ui/editor/drawing_state.cpp b/src/app/ui/editor/drawing_state.cpp index 58c7d4218..2307e1aa8 100644 --- a/src/app/ui/editor/drawing_state.cpp +++ b/src/app/ui/editor/drawing_state.cpp @@ -142,7 +142,7 @@ bool DrawingState::onMouseMove(Editor* editor, MouseMessage* msg) editor->hideDrawingCursor(); // Infinite scroll - gfx::Point mousePos = editor->autoScroll(msg, true); + gfx::Point mousePos = editor->autoScroll(msg, AutoScroll::MouseDir, true); // Hide the cursor again editor->hideDrawingCursor(); diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index eb6fe4eb2..bf67ef189 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -709,7 +709,7 @@ void Editor::flashCurrentLayer() #endif } -gfx::Point Editor::autoScroll(MouseMessage* msg, bool blit_valid_rgn) +gfx::Point Editor::autoScroll(MouseMessage* msg, AutoScroll dir, bool blit_valid_rgn) { View* view = View::getView(this); gfx::Rect vp = view->getViewportBounds(); @@ -717,19 +717,32 @@ gfx::Point Editor::autoScroll(MouseMessage* msg, bool blit_valid_rgn) if (!vp.contains(mousePos)) { gfx::Point delta = (mousePos - m_oldPos); + gfx::Point deltaScroll = delta; if (!((mousePos.x < vp.x && delta.x < 0) || - (mousePos.x >= vp.x+vp.w && delta.x > 0))) + (mousePos.x >= vp.x+vp.w && delta.x > 0))) { delta.x = 0; + } if (!((mousePos.y < vp.y && delta.y < 0) || - (mousePos.y >= vp.y+vp.h && delta.y > 0))) + (mousePos.y >= vp.y+vp.h && delta.y > 0))) { delta.y = 0; + } gfx::Point scroll = view->getViewScroll(); - scroll += delta; + if (dir == AutoScroll::MouseDir) { + scroll += delta; + } + else { + scroll -= deltaScroll; + } setEditorScroll(scroll.x, scroll.y, blit_valid_rgn); +#ifdef WIN32 + mousePos -= delta; + ui::set_mouse_position(mousePos); +#endif + m_oldPos = mousePos; mousePos = gfx::Point( MID(vp.x, mousePos.x, vp.x+vp.w-1), diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index 3a4d57276..0851cf84f 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -61,6 +61,11 @@ namespace app { class Tool; } + enum class AutoScroll { + MouseDir, + ScrollDir, + }; + class Editor : public ui::Widget, public DocumentSettingsObserver { public: @@ -166,7 +171,7 @@ namespace app { void updateStatusBar(); // Control scroll when cursor goes out of the editor viewport. - gfx::Point autoScroll(ui::MouseMessage* msg, bool blit_valid_rgn); + gfx::Point autoScroll(ui::MouseMessage* msg, AutoScroll dir, bool blit_valid_rgn); tools::Tool* getCurrentEditorTool(); tools::Ink* getCurrentEditorInk(); diff --git a/src/app/ui/editor/moving_pixels_state.cpp b/src/app/ui/editor/moving_pixels_state.cpp index 851b8a230..59009fb24 100644 --- a/src/app/ui/editor/moving_pixels_state.cpp +++ b/src/app/ui/editor/moving_pixels_state.cpp @@ -254,7 +254,7 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg) // If there is a button pressed if (m_pixelsMovement->isDragging()) { // Auto-scroll - gfx::Point mousePos = editor->autoScroll(msg, false); + gfx::Point mousePos = editor->autoScroll(msg, AutoScroll::MouseDir, false); // Get the position of the mouse in the sprite int x, y; diff --git a/src/app/ui/editor/scrolling_state.cpp b/src/app/ui/editor/scrolling_state.cpp index 840805ba4..51f40583d 100644 --- a/src/app/ui/editor/scrolling_state.cpp +++ b/src/app/ui/editor/scrolling_state.cpp @@ -63,6 +63,14 @@ bool ScrollingState::onMouseMove(Editor* editor, MouseMessage* msg) View* view = View::getView(editor); gfx::Point scroll = view->getViewScroll(); gfx::Point newPos = msg->position(); + +#ifdef WIN32 + if (newPos != editor->autoScroll(msg, AutoScroll::ScrollDir, true)) { + m_oldPos = newPos; + return true; + } +#endif + scroll -= newPos - m_oldPos; m_oldPos = newPos; diff --git a/src/ui/system.cpp b/src/ui/system.cpp index 24c6edebe..cfea56edf 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -366,6 +366,19 @@ gfx::Point get_mouse_position() return gfx::Point(jmouse_x(0), jmouse_y(0)); } +void set_mouse_position(const gfx::Point& newPos) +{ + moved = true; + + if (mouse_display) + mouse_display->setMousePosition(newPos); + + update_mouse_position(newPos); + + m_x[1] = m_x[0]; + m_y[1] = m_y[0]; +} + MouseButtons jmouse_b(int antique) { return (MouseButtons)m_b[antique & 1]; diff --git a/src/ui/system.h b/src/ui/system.h index 227dd6f0a..09dbdd9d7 100644 --- a/src/ui/system.h +++ b/src/ui/system.h @@ -54,6 +54,7 @@ namespace ui { void _internal_set_mouse_buttons(MouseButtons buttons); gfx::Point get_mouse_position(); + void set_mouse_position(const gfx::Point& newPos); MouseButtons jmouse_b(int antique); int jmouse_x(int antique);