Add new option to zoom sliding two fingers on OS X trackpad

It was requested here:
http://steamcommunity.com/app/431730/discussions/2/357286663677659387/
This commit is contained in:
David Capello 2016-05-27 13:15:13 -03:00
parent 21661a2a5d
commit af2c2838e0
4 changed files with 38 additions and 10 deletions

View File

@ -97,6 +97,7 @@
</section>
<section id="editor" text="Editor">
<option id="zoom_with_wheel" type="bool" default="true" migrate="Options.ZoomWithMouseWheel" />
<option id="zoom_with_slide" type="bool" default="false" />
<option id="zoom_from_center_with_wheel" type="bool" default="false" />
<option id="zoom_from_center_with_keys" type="bool" default="false" />
<option id="show_scrollbars" type="bool" default="true" migrate="Options.ShowScrollbars" />

View File

@ -59,6 +59,7 @@
<vbox id="section_editor">
<separator text="Editor" horizontal="true" />
<check text="Zoom with scroll wheel" id="wheel_zoom" />
<check text="Zoom sliding two fingers up or down" id="slide_zoom" />
<check text="Zoom from center with scroll wheel" id="zoom_from_center_with_wheel" />
<check text="Zoom from center with keys" id="zoom_from_center_with_keys" />
<check text="Show scroll-bars in sprite editor" id="show_scrollbars" tooltip="Show scroll-bars in all sprite editors." />

View File

@ -153,6 +153,13 @@ public:
// Zoom with Scroll Wheel
wheelZoom()->setSelected(m_pref.editor.zoomWithWheel());
// Zoom sliding two fingers
#if __APPLE__
slideZoom()->setSelected(m_pref.editor.zoomWithSlide());
#else
slideZoom()->setVisible(false);
#endif
// Checked background size
checkedBgSize()->addItem("16x16");
checkedBgSize()->addItem("8x8");
@ -214,6 +221,9 @@ public:
m_pref.editor.zoomFromCenterWithKeys(zoomFromCenterWithKeys()->isSelected());
m_pref.editor.showScrollbars(showScrollbars()->isSelected());
m_pref.editor.zoomWithWheel(wheelZoom()->isSelected());
#if __APPLE__
m_pref.editor.zoomWithSlide(slideZoom()->isSelected());
#endif
m_pref.editor.rightClickMode(static_cast<app::gen::RightClickMode>(rightClickBehavior()->getSelectedItemIndex()));
m_pref.editor.cursorColor(m_cursorColor->getColor());
m_pref.editor.brushPreview(static_cast<app::gen::BrushPreview>(brushPreview()->getSelectedItemIndex()));

View File

@ -36,7 +36,8 @@ enum WHEEL_ACTION { WHEEL_NONE,
bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
{
double dz = msg->wheelDelta().x + msg->wheelDelta().y;
gfx::Point delta = msg->wheelDelta();
double dz = delta.x + delta.y;
WHEEL_ACTION wheelAction = WHEEL_NONE;
bool scrollBigSteps = false;
@ -50,21 +51,40 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
// Normal behavior: mouse wheel zooms If the message is from a
// precise wheel i.e. a trackpad/touch-like device, we scroll by
// default.
else if (Preferences::instance().editor.zoomWithWheel() &&
!msg->preciseWheel()) {
else if (Preferences::instance().editor.zoomWithWheel() && !msg->preciseWheel()) {
if (msg->ctrlPressed())
wheelAction = WHEEL_FRAME;
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
else if (delta.x != 0 || msg->shiftPressed())
wheelAction = WHEEL_HSCROLL;
else
wheelAction = WHEEL_ZOOM;
}
// Zoom sliding two fingers
else if (Preferences::instance().editor.zoomWithSlide() && msg->preciseWheel()) {
if (msg->ctrlPressed())
wheelAction = WHEEL_FRAME;
else if (std::abs(delta.x) > std::abs(delta.y)) {
delta.y = 0;
dz = delta.x;
wheelAction = WHEEL_HSCROLL;
}
else if (msg->shiftPressed()) {
delta.x = 0;
dz = delta.y;
wheelAction = WHEEL_VSCROLL;
}
else {
delta.x = 0;
dz = delta.y;
wheelAction = WHEEL_ZOOM;
}
}
// For laptops, it's convenient to that Ctrl+wheel zoom (because
// it's the "pinch" gesture).
else {
if (msg->ctrlPressed())
wheelAction = WHEEL_ZOOM;
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
else if (delta.x != 0 || msg->shiftPressed())
wheelAction = WHEEL_HSCROLL;
else
wheelAction = WHEEL_VSCROLL;
@ -131,12 +151,8 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
case WHEEL_VSCROLL: {
View* view = View::getView(editor);
gfx::Point scroll = view->viewScroll();
gfx::Point delta(0, 0);
if (msg->preciseWheel()) {
delta = msg->wheelDelta();
}
else {
if (!msg->preciseWheel()) {
gfx::Rect vp = view->viewportBounds();
if (wheelAction == WHEEL_HSCROLL) {