[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25897] trunk/blender: Multitouch trackpad 2 fingers gestures implementation

Mats Holmberg mats.holmberg at 2me.fi
Thu Jan 14 08:29:39 CET 2010


Thanks Damien for making multitouch work! Here's a couple of issues FYI.

I have an issue, where I feel zooming works inverted. In my opinion zooming out should be done by "pinching" and zooming in by "spreading" your fingers apart. That's the way it works on the iphone as an example. It also stops working often, so I need to lift my fingers from the touchpad and try again. All this combined with the incredible speed it zooms in, makes things quite unusable  for me =)

I'm using a 64-bit Blender build on a 15" MBP from late 2008 running osX 10.6.2.

Another (unrelated) issue has to do with osx spaces that I use all the time. For some reason Blender becomes unresponsive when returning to it from another osx spaces "screen". The buttons seem to work ok, but nothing happens in the 3d-window. At some point I got it working, but don't know what I did =) Now I usually restart Blender after returning to it.

-mats

On 11.1.2010, at 13.14, Damien Plisson wrote:

> Revision: 25897
>          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25897
> Author:   damien78
> Date:     2010-01-11 12:14:36 +0100 (Mon, 11 Jan 2010)
> 
> Log Message:
> -----------
> Multitouch trackpad 2 fingers gestures implementation
> 
> - 2 fingers scroll (MOUSEPAN / GHOST_kTrackpadEventScroll event) pans/scrolls the view
> - 2 fingers pinch (MOUSEZOOM / GHOST_kTrackpadEventMagnify event) zooms the view
> And in 3D view:
> - alt + 2 fingers scroll rotates the view
> - 2 fingers rotation (MOUSEROTATE / GHOST_kTrackpadEventRotate) orbits the view.
> 
> The implementation uses a new GHOST event type: GHOST_kEventTrackpad, that is then dispatched as Blender MOUSEPAN, MOUSEZOOM
> or MOUSEROTATE events.
> 
> This is currently fully implemented for OSX (GHOST Cocoa fires the new events), with auto-detection of the source peripheral, so that a regular mouse still sends MOUSEWHEEL events.
> 
> Modified Paths:
> --------------
>    trunk/blender/intern/ghost/GHOST_Types.h
>    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
>    trunk/blender/source/blender/editors/interface/view2d_ops.c
>    trunk/blender/source/blender/editors/space_image/image_ops.c
>    trunk/blender/source/blender/editors/space_image/space_image.c
>    trunk/blender/source/blender/editors/space_outliner/outliner.c
>    trunk/blender/source/blender/editors/space_text/space_text.c
>    trunk/blender/source/blender/editors/space_text/text_ops.c
>    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
>    trunk/blender/source/blender/editors/space_view3d/view3d_ops.c
>    trunk/blender/source/blender/makesrna/intern/rna_wm.c
>    trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
>    trunk/blender/source/blender/windowmanager/wm_event_types.h
> 
> Added Paths:
> -----------
>    trunk/blender/intern/ghost/intern/GHOST_EventTrackpad.h
> 
> Modified: trunk/blender/intern/ghost/GHOST_Types.h
> ===================================================================
> --- trunk/blender/intern/ghost/GHOST_Types.h	2010-01-11 11:11:21 UTC (rev 25896)
> +++ trunk/blender/intern/ghost/GHOST_Types.h	2010-01-11 11:14:36 UTC (rev 25897)
> @@ -151,6 +151,7 @@
> 	GHOST_kEventButtonDown,		/// Mouse button event
> 	GHOST_kEventButtonUp,		/// Mouse button event
> 	GHOST_kEventWheel,			/// Mouse wheel event
> +	GHOST_kEventTrackpad,		/// Trackpad event
> 
> 	GHOST_kEventNDOFMotion,		/// N degree of freedom device motion event
> 	GHOST_kEventNDOFButton,		/// N degree of freedom device button event
> @@ -373,7 +374,29 @@
> 	GHOST_TInt32 z;	
> } GHOST_TEventWheelData;
> 
> +typedef enum {
> +	GHOST_kTrackpadEventUnknown =0,
> +	GHOST_kTrackpadEventScroll,
> +	GHOST_kTrackpadEventRotate,
> +	GHOST_kTrackpadEventSwipe, /* Reserved, not used for now */
> +	GHOST_kTrackpadEventMagnify
> +} GHOST_TTrackpadEventSubTypes;
> +	
> 
> +typedef struct {
> +	/** The event subtype */
> +	GHOST_TTrackpadEventSubTypes subtype;
> +	/** The x-location of the trackpad event */
> +	GHOST_TInt32 x;
> +	/** The y-location of the trackpad event */
> +	GHOST_TInt32 y;
> +	/** The x-delta or value of the trackpad event */
> +	GHOST_TInt32 deltaX;
> +	/** The y-delta (currently only for scroll subtype) of the trackpad event */
> +	GHOST_TInt32 deltaY;
> +} GHOST_TEventTrackpadData;
> +
> +
> typedef enum {
> 	GHOST_kDragnDropTypeUnknown =0,
> 	GHOST_kDragnDropTypeFilenames, /*Array of strings representing file names (full path) */
> 
> Added: trunk/blender/intern/ghost/intern/GHOST_EventTrackpad.h
> ===================================================================
> --- trunk/blender/intern/ghost/intern/GHOST_EventTrackpad.h	                        (rev 0)
> +++ trunk/blender/intern/ghost/intern/GHOST_EventTrackpad.h	2010-01-11 11:14:36 UTC (rev 25897)
> @@ -0,0 +1,71 @@
> +/**
> + * $Id$
> + * ***** BEGIN GPL LICENSE BLOCK *****
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software Foundation,
> + * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
> + *
> + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
> + * All rights reserved.
> + *
> + * The Original Code is: all of this file.
> + *
> + * Contributor(s):  James Deery		11/2009
> + *					Damien Plisson	12/2009
> + *
> + * ***** END GPL LICENSE BLOCK *****
> + */
> +/**
> + * @file	GHOST_EventTrackpad.h
> + * Declaration of GHOST_EventTrackpad class.
> + */
> +
> +#ifndef _GHOST_EVENT_TRACKPAD_H_
> +#define _GHOST_EVENT_TRACKPAD_H_
> +
> +#include "GHOST_Event.h"
> +
> +/**
> + * Trackpad (scroll, magnify, rotate, ...) event.
> + */
> +class GHOST_EventTrackpad : public GHOST_Event
> +{
> +public:
> +	/**
> +	 * Constructor.
> +	 * @param msec		The time this event was generated.
> +	 * @param type		The type of this event.
> +	 * @param subtype	The subtype of the event.
> +	 * @param x			The x-delta of the pan event.
> +	 * @param y			The y-delta of the pan event.
> +	 */
> +	GHOST_EventTrackpad(GHOST_TUns64 msec, GHOST_IWindow* window, GHOST_TTrackpadEventSubTypes subtype, GHOST_TInt32 x, GHOST_TInt32 y, GHOST_TInt32 deltaX, GHOST_TInt32 deltaY)
> +		: GHOST_Event(msec, GHOST_kEventTrackpad, window)
> +	{
> +		m_trackpadEventData.subtype = subtype;
> +		m_trackpadEventData.x = x;
> +		m_trackpadEventData.y = y;
> +		m_trackpadEventData.deltaX = deltaX;
> +		m_trackpadEventData.deltaY = deltaY;
> +		m_data = &m_trackpadEventData;
> +	}
> +
> +protected:
> +	/** The mouse pan data */
> +	GHOST_TEventTrackpadData m_trackpadEventData;
> +};
> +
> +
> +#endif // _GHOST_EVENT_PAN_H_
> +
> 
> Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
> ===================================================================
> --- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2010-01-11 11:11:21 UTC (rev 25896)
> +++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2010-01-11 11:14:36 UTC (rev 25897)
> @@ -41,6 +41,7 @@
> #include "GHOST_EventCursor.h"
> #include "GHOST_EventWheel.h"
> #include "GHOST_EventNDOF.h"
> +#include "GHOST_EventTrackpad.h"
> #include "GHOST_EventDragnDrop.h"
> 
> #include "GHOST_TimerManager.h"
> @@ -376,7 +377,25 @@
> 
> #pragma mark defines for 10.6 api not documented in 10.5
> #ifndef MAC_OS_X_VERSION_10_6
> +enum {
> +	/* The following event types are available on some hardware on 10.5.2 and later */
> +	NSEventTypeGesture          = 29,
> +	NSEventTypeMagnify          = 30,
> +	NSEventTypeSwipe            = 31,
> +	NSEventTypeRotate           = 18,
> +	NSEventTypeBeginGesture     = 19,
> +	NSEventTypeEndGesture       = 20
> +};
> 
> + at interface NSEvent(GestureEvents)
> +/* This message is valid for events of type NSEventTypeMagnify, on 10.5.2 or later */
> +#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
> +- (float)magnification;       // change in magnification.
> +#else
> +- (CGFloat)magnification;       // change in magnification.
> +#endif
> + at end 
> +
> @interface NSEvent(SnowLeopardEvents)
> /* modifier keys currently down.  This returns the state of devices combined
>  with synthesized events at the moment, independent of which events
> @@ -596,7 +615,7 @@
> 		}
> 		
> 		[NSApp finishLaunching];
> -				
> +		
> 		[pool drain];
>     }
>     return success;
> @@ -846,7 +865,9 @@
> 				case NSScrollWheel:
> 				case NSOtherMouseDown:
> 				case NSOtherMouseUp:
> -				case NSOtherMouseDragged:				
> +				case NSOtherMouseDragged:
> +				case NSEventTypeMagnify:
> +				case NSEventTypeRotate:
> 					handleMouseEvent(event);
> 					break;
> 					
> @@ -855,11 +876,9 @@
> 					handleTabletEvent(event,[event type]);
> 					break;
> 					
> -					/* Trackpad features, will need OS X 10.6 for implementation
> +					/* Trackpad features, fired only from OS X 10.5.2
> 					 case NSEventTypeGesture:
> -					 case NSEventTypeMagnify:
> 					 case NSEventTypeSwipe:
> -					 case NSEventTypeRotate:
> 					 case NSEventTypeBeginGesture:
> 					 case NSEventTypeEndGesture:
> 					 break; */
> @@ -1316,16 +1335,53 @@
> 			
> 		case NSScrollWheel:
> 			{
> -				GHOST_TInt32 delta;
> -				
> -				double deltaF = [event deltaY];
> -				if (deltaF == 0.0) break; //discard trackpad delta=0 events
> -				
> -				delta = deltaF > 0.0 ? 1 : -1;
> -				pushEvent(new GHOST_EventWheel([event timestamp]*1000, window, delta));
> +				/* Send Wheel event if sent from the mouse, trackpad event otherwise */
> +				if ([event subtype] == NSMouseEventSubtype) {
> +					GHOST_TInt32 delta;
> +					
> +					double deltaF = [event deltaY];
> +					if (deltaF == 0.0) break; //discard trackpad delta=0 events
> +					
> +					delta = deltaF > 0.0 ? 1 : -1;
> +					pushEvent(new GHOST_EventWheel([event timestamp]*1000, window, delta));
> +				}
> +				else {
> +					NSPoint mousePos = [event locationInWindow];
> +					double dx = [event deltaX];
> +					double dy = -[event deltaY];
> +					
> +					const double deltaMax = 50.0;
> +					
> +					if ((dx == 0) && (dy == 0)) break;
> +					
> +					/* Quadratic acceleration */
> +					dx = dx*(fabs(dx)+0.5);
> +					if (dx<0.0) dx-=0.5; else dx+=0.5;
> +					if (dx< -deltaMax) dx= -deltaMax; else if (dx>deltaMax) dx=deltaMax;
> +					
> +					dy = dy*(fabs(dy)+0.5);
> +					if (dy<0.0) dy-=0.5; else dy+=0.5;
> +					if (dy< -deltaMax) dy= -deltaMax; else if (dy>deltaMax) dy=deltaMax;
> +
> +					pushEvent(new GHOST_EventTrackpad([event timestamp]*1000, window, GHOST_kTrackpadEventScroll, mousePos.x, mousePos.y, dx, dy));
> +				}
> 			}
> 			break;
> 			
> +		case NSEventTypeMagnify:
> +			{
> +				NSPoint mousePos = [event locationInWindow];
> +				pushEvent(new GHOST_EventTrackpad([event timestamp]*1000, window, GHOST_kTrackpadEventMagnify, mousePos.x, mousePos.y,
> +												  [event magnification]*250.0 + 0.1, 0));
> +			}
> +			break;
> +
> +		case NSEventTypeRotate:
> +			{
> +				NSPoint mousePos = [event locationInWindow];
> +				pushEvent(new GHOST_EventTrackpad([event timestamp]*1000, window, GHOST_kTrackpadEventRotate, mousePos.x, mousePos.y,
> +												  -[event rotation] * 5.0, 0));
> +			}
> 		default:
> 			return GHOST_kFailure;
> 			break;
> 
> Modified: trunk/blender/source/blender/editors/interface/view2d_ops.c
> ===================================================================
> --- trunk/blender/source/blender/editors/interface/view2d_ops.c	2010-01-11 11:11:21 UTC (rev 25896)
> +++ trunk/blender/source/blender/editors/interface/view2d_ops.c	2010-01-11 11:14:36 UTC (rev 25897)
> @@ -199,6 +199,16 @@
> 	/* set initial settings */
> 	vpd->startx= vpd->lastx= event->x;
> 	vpd->starty= vpd->lasty= event->y;
> +
> +	if (event->type == MOUSEPAN) {
> +		RNA_int_set(op->ptr, "deltax", event->prevx - event->x);
> +		RNA_int_set(op->ptr, "deltay", event->prevy - event->y);
> +		
> +		view_pan_apply(C, op);
> +		view_pan_exit(C, op);
> +		return OPERATOR_FINISHED;
> +	}
> +	
> 	RNA_int_set(op->ptr, "deltax", 0);
> 	RNA_int_set(op->ptr, "deltay", 0);
> 	
> @@ -789,6 +799,26 @@
> 	vzd= op->customdata;
> 	v2d= vzd->v2d;
> 	
> +	if (event->type == MOUSEZOOM) {
> +		float dx, dy, fac;
> +		
> +		vzd->lastx= event->prevx;
> +		vzd->lasty= event->prevy;
> +		
> +		/* As we have only 1D information (magnify value), feed both axes
> +		with magnify information that is stored in x axis */
> +		fac= 0.01f * (event->x - event->prevx);
> +		dx= fac * (v2d->cur.xmax - v2d->cur.xmin) / 10.0f;
> +		dy= fac * (v2d->cur.ymax - v2d->cur.ymin) / 10.0f;
> +
> +		RNA_float_set(op->ptr, "deltax", dx);
> +		RNA_float_set(op->ptr, "deltay", dy);
> +		
> +		view_zoomdrag_apply(C, op);
> +		view_zoomdrag_exit(C, op);
> +		return OPERATOR_FINISHED;
> +	}	
> +	
> 	/* set initial settings */
> 	vzd->lastx= event->x;
> 	vzd->lasty= event->y;
> @@ -1467,6 +1497,8 @@
> 	WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
> 	WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
> 	
> +	WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MOUSEPAN, 0, 0, 0);
> +	
> 	WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_right", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
> 	WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_left", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
> 	
> @@ -1489,6 +1521,7 @@
> 	
> 	/* zoom - drag */
> 	WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
> +	WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEZOOM, 0, 0, 0);
> 	
> 	/* borderzoom - drag */
> 
> @@ Diff output truncated at 10240 characters. @@
> 
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs



More information about the Bf-committers mailing list