mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Remove all "infinite scroll" stuff to avoid changing mouse position (fixes #350)
Changing the mouse position isn't user-friendly in desktop apps, and has several problems in some platforms (Mac OS X). In this way we've changed the approach to handle the mouse position when it goes outside the ui::Editor viewport.
This commit is contained in:
parent
8e44e0fbab
commit
58b3e09d86
@ -31,7 +31,6 @@
|
||||
<vbox id="section_editor">
|
||||
<separator text="Editor" horizontal="true" />
|
||||
<check text="Zoom with Scroll Wheel" id="wheel_zoom" />
|
||||
<check text="Smooth auto-scroll" id="smooth" />
|
||||
<check text="Show scroll-bars in sprite editor" id="show_scrollbars" tooltip="Show scroll-bars in all sprite editors." />
|
||||
<hbox>
|
||||
<label text="Right-click:" />
|
||||
|
@ -71,9 +71,6 @@ public:
|
||||
pixelGridColorBox()->addChild(m_pixelGridColor);
|
||||
|
||||
// Others
|
||||
if (get_config_bool("Options", "MoveSmooth", true))
|
||||
smooth()->setSelected(true);
|
||||
|
||||
if (get_config_bool("Options", "AutoShowTimeline", true))
|
||||
autotimeline()->setSelected(true);
|
||||
|
||||
@ -144,7 +141,6 @@ public:
|
||||
m_docSettings->setGridColor(m_gridColor->getColor());
|
||||
m_docSettings->setPixelGridColor(m_pixelGridColor->getColor());
|
||||
|
||||
set_config_bool("Options", "MoveSmooth", smooth()->isSelected());
|
||||
set_config_bool("Options", "AutoShowTimeline", autotimeline()->isSelected());
|
||||
|
||||
m_settings->setShowSpriteEditorScrollbars(showScrollbars()->isSelected());
|
||||
|
@ -132,7 +132,7 @@ bool DrawingState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
editor->hideDrawingCursor();
|
||||
|
||||
// Infinite scroll
|
||||
gfx::Point mousePos = editor->controlInfiniteScroll(msg);
|
||||
gfx::Point mousePos = editor->autoScroll(msg);
|
||||
|
||||
// Hide the cursor again
|
||||
editor->hideDrawingCursor();
|
||||
|
@ -705,31 +705,24 @@ void Editor::flashCurrentLayer()
|
||||
#endif
|
||||
}
|
||||
|
||||
gfx::Point Editor::controlInfiniteScroll(MouseMessage* msg)
|
||||
gfx::Point Editor::autoScroll(MouseMessage* msg)
|
||||
{
|
||||
View* view = View::getView(this);
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
gfx::Point mousePos = msg->position();
|
||||
|
||||
gfx::Point delta = ui::get_delta_outside_box(vp, mousePos);
|
||||
if (delta != gfx::Point(0, 0)) {
|
||||
// Scrolling-by-steps (non-smooth), this is better for high
|
||||
// resolutions: scroll movement by big steps.
|
||||
if (!get_config_bool("Options", "MoveSmooth", true)) {
|
||||
gfx::Point newPos = mousePos;
|
||||
if (delta.x != 0) newPos.x = (mousePos.x-delta.x+(vp.x+vp.w/2))/2;
|
||||
if (delta.y != 0) newPos.y = (mousePos.y-delta.y+(vp.y+vp.h/2))/2;
|
||||
delta = mousePos - newPos;
|
||||
}
|
||||
|
||||
mousePos.x -= delta.x;
|
||||
mousePos.y -= delta.y;
|
||||
ui::set_mouse_position(mousePos);
|
||||
|
||||
if (!vp.contains(mousePos)) {
|
||||
gfx::Point scroll = view->getViewScroll();
|
||||
scroll += delta;
|
||||
scroll += (mousePos - m_oldPos);
|
||||
setEditorScroll(scroll.x, scroll.y, true);
|
||||
|
||||
m_oldPos = mousePos;
|
||||
mousePos = gfx::Point(
|
||||
MID(vp.x, mousePos.x, vp.x+vp.w-1),
|
||||
MID(vp.y, mousePos.y, vp.y+vp.h-1));
|
||||
}
|
||||
else
|
||||
m_oldPos = mousePos;
|
||||
|
||||
return mousePos;
|
||||
}
|
||||
|
@ -165,8 +165,8 @@ namespace app {
|
||||
|
||||
void updateStatusBar();
|
||||
|
||||
// Control scroll when cursor goes out of the editor.
|
||||
gfx::Point controlInfiniteScroll(ui::MouseMessage* msg);
|
||||
// Control scroll when cursor goes out of the editor viewport.
|
||||
gfx::Point autoScroll(ui::MouseMessage* msg);
|
||||
|
||||
tools::Tool* getCurrentEditorTool();
|
||||
tools::Ink* getCurrentEditorInk();
|
||||
|
@ -252,7 +252,7 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
// If there is a button pressed
|
||||
if (m_pixelsMovement->isDragging()) {
|
||||
// Infinite scroll
|
||||
gfx::Point mousePos = editor->controlInfiniteScroll(msg);
|
||||
gfx::Point mousePos = editor->autoScroll(msg);
|
||||
|
||||
// Get the position of the mouse in the sprite
|
||||
int x, y;
|
||||
|
@ -62,15 +62,11 @@ bool ScrollingState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
{
|
||||
View* view = View::getView(editor);
|
||||
gfx::Point scroll = view->getViewScroll();
|
||||
|
||||
gfx::Point newPos = msg->position();
|
||||
scroll -= newPos - m_oldPos;
|
||||
m_oldPos = newPos;
|
||||
|
||||
scroll += m_oldPos - newPos;
|
||||
editor->setEditorScroll(scroll.x, scroll.y, true);
|
||||
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
m_oldPos = ui::control_infinite_scroll(editor, vp, newPos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -445,10 +445,10 @@ bool Timeline::onProcessMessage(Message* msg)
|
||||
case STATE_SCROLLING: {
|
||||
gfx::Point absMousePos = static_cast<MouseMessage*>(msg)->position();
|
||||
setScroll(
|
||||
m_scroll_x + m_oldPos.x - absMousePos.x,
|
||||
m_scroll_y + m_oldPos.y - absMousePos.y);
|
||||
m_scroll_x - (absMousePos.x - m_oldPos.x),
|
||||
m_scroll_y - (absMousePos.y - m_oldPos.y));
|
||||
|
||||
m_oldPos = ui::control_infinite_scroll(this, getBounds(), absMousePos);
|
||||
m_oldPos = absMousePos;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -354,19 +354,6 @@ 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];
|
||||
@ -376,56 +363,6 @@ int jmouse_x(int antique) { return m_x[antique & 1]; }
|
||||
int jmouse_y(int antique) { return m_y[antique & 1]; }
|
||||
int jmouse_z(int antique) { return m_z[antique & 1]; }
|
||||
|
||||
gfx::Point get_delta_outside_box(const gfx::Rect& rect, const gfx::Point& mousePoint)
|
||||
{
|
||||
gfx::Point delta(0, 0);
|
||||
|
||||
if (mousePoint.x < rect.x)
|
||||
delta.x = mousePoint.x - rect.x;
|
||||
else if (mousePoint.x >= rect.x+rect.w)
|
||||
delta.x = mousePoint.x - (rect.x+rect.w);
|
||||
|
||||
if (mousePoint.y < rect.y)
|
||||
delta.y = mousePoint.y - rect.y;
|
||||
else if (mousePoint.y > rect.y+rect.h)
|
||||
delta.y = mousePoint.y - (rect.y+rect.h);
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
gfx::Point control_infinite_scroll(Widget* widget, const gfx::Rect& rect, const gfx::Point& mousePoint)
|
||||
{
|
||||
gfx::Point newPoint = mousePoint;
|
||||
gfx::Point delta = get_delta_outside_box(rect, newPoint);
|
||||
|
||||
if (delta.x < 0) {
|
||||
newPoint.x = rect.x+rect.w+delta.x;
|
||||
if (newPoint.x < rect.x)
|
||||
newPoint.x = rect.x;
|
||||
}
|
||||
else if (delta.x > 0) {
|
||||
newPoint.x = rect.x+delta.x;
|
||||
if (newPoint.x >= rect.x+rect.w)
|
||||
newPoint.x = rect.x+rect.w-1;
|
||||
}
|
||||
|
||||
if (delta.y < 0) {
|
||||
newPoint.y = rect.y+rect.h+delta.y;
|
||||
if (newPoint.y < rect.y)
|
||||
newPoint.y = rect.y;
|
||||
}
|
||||
else if (delta.y > 0) {
|
||||
newPoint.y = rect.y+delta.y;
|
||||
if (newPoint.y >= rect.y+rect.h)
|
||||
newPoint.y = rect.y+rect.h-1;
|
||||
}
|
||||
|
||||
if (mousePoint != newPoint)
|
||||
ui::set_mouse_position(newPoint);
|
||||
|
||||
return newPoint;
|
||||
}
|
||||
|
||||
static void update_mouse_position(const gfx::Point& pt)
|
||||
{
|
||||
m_x[0] = pt.x;
|
||||
|
@ -63,16 +63,12 @@ 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);
|
||||
int jmouse_y(int antique);
|
||||
int jmouse_z(int antique);
|
||||
|
||||
gfx::Point get_delta_outside_box(const gfx::Rect& rect, const gfx::Point& mousePoint);
|
||||
gfx::Point control_infinite_scroll(Widget* widget, const gfx::Rect& rect, const gfx::Point& mousePoint);
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
||||
|
@ -114,7 +114,7 @@ bool TextBox::onProcessMessage(Message* msg)
|
||||
scroll += m_oldPos - newPos;
|
||||
view->setViewScroll(scroll);
|
||||
|
||||
m_oldPos = ui::control_infinite_scroll(this, vp, newPos);
|
||||
m_oldPos = newPos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user