macOS: add trackpad smart zoom event support

This is done with two-finger double tap on trackpads, and is usually used to
zoom into an element under the cursor.

It can now be used for toggling local view in the 3D viewport.

Differential Revision: https://developer.blender.org/D6588
This commit is contained in:
Yevgeny Makarov 2020-01-28 11:29:38 +01:00 committed by Brecht Van Lommel
parent 92d606ba26
commit 773beec541
8 changed files with 31 additions and 2 deletions

View File

@ -436,7 +436,8 @@ typedef enum {
GHOST_kTrackpadEventScroll,
GHOST_kTrackpadEventRotate,
GHOST_kTrackpadEventSwipe, /* Reserved, not used for now */
GHOST_kTrackpadEventMagnify
GHOST_kTrackpadEventMagnify,
GHOST_kTrackpadEventSmartMagnify
} GHOST_TTrackpadEventSubTypes;
typedef struct {

View File

@ -1726,6 +1726,19 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
0));
} break;
case NSEventTypeSmartMagnify: {
NSPoint mousePos = [cocoawindow mouseLocationOutsideOfEventStream];
GHOST_TInt32 x, y;
window->clientToScreenIntern(mousePos.x, mousePos.y, x, y);
pushEvent(new GHOST_EventTrackpad([event timestamp] * 1000,
window,
GHOST_kTrackpadEventSmartMagnify,
x,
y,
0,
0));
} break;
case NSEventTypeRotate: {
NSPoint mousePos = [cocoawindow mouseLocationOutsideOfEventStream];
GHOST_TInt32 x, y;

View File

@ -154,6 +154,11 @@
systemCocoa->handleMouseEvent(event);
}
- (void)smartMagnifyWithEvent:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rotateWithEvent:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);

View File

@ -942,6 +942,7 @@ def km_view3d(params):
# Visibility.
("view3d.localview", {"type": 'NUMPAD_SLASH', "value": 'PRESS'}, None),
("view3d.localview", {"type": 'SLASH', "value": 'PRESS'}, None),
("view3d.localview", {"type": 'MOUSESMARTZOOM', "value": 'ANY'}, None),
("view3d.localview_remove_from", {"type": 'M', "value": 'PRESS'}, None),
# Navigation.
("view3d.rotate", {"type": 'MIDDLEMOUSE', "value": 'PRESS'}, None),

View File

@ -630,6 +630,7 @@ def km_view3d(params):
("wm.search_menu", {"type": 'TAB', "value": 'PRESS'}, None),
# Visibility.
("view3d.localview", {"type": 'I', "value": 'PRESS', "shift": True}, None),
("view3d.localview", {"type": 'MOUSESMARTZOOM', "value": 'ANY'}, None),
op_menu_pie("VIEW3D_MT_view_pie", {"type": 'V', "value": 'PRESS'}),
# Navigation.
("view3d.rotate", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, None),

View File

@ -90,6 +90,7 @@ static const EnumPropertyItem event_mouse_type_items[] = {
{MOUSEPAN, "TRACKPADPAN", 0, "Mouse/Trackpad Pan", ""},
{MOUSEZOOM, "TRACKPADZOOM", 0, "Mouse/Trackpad Zoom", ""},
{MOUSEROTATE, "MOUSEROTATE", 0, "Mouse/Trackpad Rotate", ""},
{MOUSESMARTZOOM, "MOUSESMARTZOOM", 0, "Mouse/Trackpad Smart Zoom", ""},
{0, "", 0, NULL, NULL},
{WHEELUPMOUSE, "WHEELUPMOUSE", 0, "Wheel Up", ""},
{WHEELDOWNMOUSE, "WHEELDOWNMOUSE", 0, "Wheel Down", ""},
@ -186,6 +187,7 @@ const EnumPropertyItem rna_enum_event_type_items[] = {
{MOUSEPAN, "TRACKPADPAN", 0, "Mouse/Trackpad Pan", "MsPan"},
{MOUSEZOOM, "TRACKPADZOOM", 0, "Mouse/Trackpad Zoom", "MsZoom"},
{MOUSEROTATE, "MOUSEROTATE", 0, "Mouse/Trackpad Rotate", "MsRot"},
{MOUSESMARTZOOM, "MOUSESMARTZOOM", 0, "Mouse/Trackpad Smart Zoom", "MsSmartZoom"},
{0, "", 0, NULL, NULL},
{WHEELUPMOUSE, "WHEELUPMOUSE", 0, "Wheel Up", "WhUp"},
{WHEELDOWNMOUSE, "WHEELDOWNMOUSE", 0, "Wheel Down", "WhDown"},

View File

@ -4292,6 +4292,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
pd->deltaX = -pd->deltaX;
pd->deltaY = -pd->deltaY;
break;
case GHOST_kTrackpadEventSmartMagnify:
event.type = MOUSESMARTZOOM;
break;
case GHOST_kTrackpadEventRotate:
event.type = MOUSEROTATE;
break;

View File

@ -63,6 +63,8 @@ enum {
MOUSEPAN = 0x000e,
MOUSEZOOM = 0x000f,
MOUSEROTATE = 0x0010,
MOUSESMARTZOOM = 0x0017,
/* defaults from ghost */
WHEELUPMOUSE = 0x000a,
WHEELDOWNMOUSE = 0x000b,
@ -359,7 +361,8 @@ enum {
(((event_type) >= LEFTCTRLKEY && (event_type) <= LEFTSHIFTKEY) || (event_type) == OSKEY)
/* test whether the event is a mouse button */
#define ISMOUSE(event_type) ((event_type) >= LEFTMOUSE && (event_type) <= BUTTON7MOUSE)
#define ISMOUSE(event_type) \
(((event_type) >= LEFTMOUSE && (event_type) <= BUTTON7MOUSE) || (event_type) == MOUSESMARTZOOM)
#define ISMOUSE_WHEEL(event_type) ((event_type) >= WHEELUPMOUSE && (event_type) <= WHEELOUTMOUSE)
#define ISMOUSE_GESTURE(event_type) ((event_type) >= MOUSEPAN && (event_type) <= MOUSEROTATE)