[Drawkit] Pan / Hand Tool?
Allan Daly
allandaly at me.com
Tue Sep 1 07:59:26 PDT 2009
As always, thanks for your very helpful reply.
In my work (building system design) I do lots of CAD and I find that
a very useful UI element is to use the scroll wheel to zoom in and out
and to use the scroll wheel button (third button) in the way you
describe below -- to 'flip' to the pan tool temporarily, then revert
to the originally selected tool. In this way all of your navigation in/
out/pan is all on a single button and it makes moving around 'inside'
another command easy and intuitive. Perhaps give this a try when you
get around to implementing that flip code. (This is the way AutoDesk
AutoCAD works.)
-Allan
On Aug 31, 2009, at 7:07 PM, Graham Cox wrote:
> Hi Allan,
>
> Right now the pan tool is not part of DK, but it is an extremely
> simple tool. It'll probably end up in DK, especially as I want to
> implement a way to 'flip' to the pan tool when the spacebar is
> pressed while using other tools, though that's harder to do than it
> looks from the user's POV.
>
> Anyway, the current implementation is as follows:
>
> #import <GCDrawKit/DKDrawingTool.h>
>
>
> @interface DKOPanTool : DKDrawingTool
> {
> NSPoint mAnchor;
> NSPoint mViewOrigin;
> BOOL mDragging;
> }
>
> @end
>
> // -------------------
>
>
> #import "DKOPanTool.h"
> #import <GCDrawKit/DKDrawingView.h>
> #import <GCDrawKit/DKLayer.h>
>
> @implementation DKOPanTool
>
>
> - (int) mouseDownAtPoint:(NSPoint) p targetObject:
> (DKDrawableObject*) obj layer:(DKLayer*) layer event:(NSEvent*)
> event delegate:(id) aDel
> {
> #pragma unused(obj, p, aDel)
>
> mDragging = YES;
> mAnchor = [event locationInWindow];
> DKDrawingView* zv = (DKDrawingView*)[layer currentView];
>
> float scale = [zv scale];
>
> NSClipView* clippy = (NSClipView*)[zv superview];
> mViewOrigin = [clippy documentVisibleRect].origin;
>
> mViewOrigin.x *= scale;
> mViewOrigin.y *= scale;
>
> //NSLog(@"will begin pan at point: %@, clip view origin = %@",
> NSStringFromPoint( p ), NSStringFromPoint( mViewOrigin ));
>
> [[NSCursor closedHandCursor] set];
>
> return 0;
> }
>
>
> - (void) mouseDraggedToPoint:(NSPoint) p partCode:(int) pc layer:
> (DKLayer*) layer event:(NSEvent*) event delegate:(id) aDel
> {
> #pragma unused(pc, p, aDel)
>
> DKDrawingView* zv = (DKDrawingView*)[layer currentView];
> NSPoint newOrigin = NSMakePoint( mViewOrigin.x - ([event
> locationInWindow].x - mAnchor.x), mViewOrigin.y + ([event
> locationInWindow].y - mAnchor.y));
>
> // take into account the zoom factor of the view
>
> float scale = [zv scale];
>
> newOrigin.x /= scale;
> newOrigin.y /= scale;
>
> [zv scrollPoint:newOrigin];
> }
>
>
> - (BOOL) mouseUpAtPoint:(NSPoint) p partCode:(int) pc layer:
> (DKLayer*) layer event:(NSEvent*) event delegate:(id) aDel;
> {
> #pragma unused( p, pc, layer, event, aDel )
>
> [[NSCursor openHandCursor] set];
>
> mDragging = NO;
> return NO;
> }
>
>
> - (NSCursor*) cursor
> {
> if( mDragging )
> return [NSCursor closedHandCursor];
> else
> return [NSCursor openHandCursor];
> }
>
>
>
> @end
>
>
>
>
> On 01/09/2009, at 11:54 AM, Allan Daly wrote:
>
>> Hi Graham,
>>
>> I've got my copy of Ortelius up and running. What fun. Nice job and
>> congrats.
>>
>> I see that you have a "hand" tool implemented in there that pans
>> around the screen when you're zoomed in. This is something I have
>> been thinking about doing in my app and I wonder if this is a
>> standard tool now in DK (didn't see it when I looked around) or if
>> not if I could please ask you to please send along a few notes on
>> the best route to implement that.
>>
>> Thanks.
>>
>> -Allan
>
> _______________________________________________
> Drawkit mailing list
> Drawkit at lists.apptree.net
> http://lists.apptree.net/listinfo.cgi/drawkit-apptree.net
More information about the Drawkit
mailing list