Bring back infinite scroll in sprite editor

This commit is contained in:
David Capello 2014-09-09 21:51:47 -03:00
parent c37958a7f3
commit bdd64b2c34
7 changed files with 47 additions and 7 deletions

View File

@ -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();

View File

@ -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),

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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];

View File

@ -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);