[Drawkit] Pan / Hand Tool?
Graham Cox
graham.cox at bigpond.com
Mon Aug 31 19:07:05 PDT 2009
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
More information about the Drawkit
mailing list