Changeset 2916

Show
Ignore:
Timestamp:
05/27/05 20:17:47 (4 years ago)
Author:
morris
Message:

Allow scrolling image view by dragging image

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHImageView.h

    r2909 r2916  
    3535        NSString                                        *_label; 
    3636        NSMutableDictionary                     *_labelAttributes; 
     37         
     38        BOOL                                            _dragging; 
    3739} 
    3840 
  • Footagehead/trunk/FHImageView.m

    r2909 r2916  
    7070        [NSColor blackColor],           NSForegroundColorAttributeName, 
    7171        NULL]; 
     72         
     73} 
     74 
     75 
     76 
     77- (void)viewDidMoveToSuperview { 
     78        NSView          *view; 
     79         
     80        view = [self superview]; 
     81         
     82        if([view isKindOfClass:[NSClipView class]]) { 
     83                [view setPostsFrameChangedNotifications:YES]; 
     84                 
     85                [[NSNotificationCenter defaultCenter] addObserver:self 
     86                                                                                                 selector:@selector(viewFrameDidChange:) 
     87                                                                                                         name:NSViewFrameDidChangeNotification 
     88                                                                                                   object:view]; 
     89        } 
    7290} 
    7391 
     
    82100 
    83101        [super dealloc]; 
     102} 
     103 
     104 
     105 
     106#pragma mark - 
     107 
     108- (void)viewFrameDidChange:(NSNotification *)notification { 
     109        NSClipView              *clipView; 
     110        NSRect                  frame, visibleRect; 
     111         
     112        clipView        = [notification object]; 
     113        frame           = [[clipView documentView] frame]; 
     114        visibleRect     = [clipView documentVisibleRect]; 
     115         
     116        if(frame.size.width > visibleRect.size.width || frame.size.height > visibleRect.size.height) 
     117                [clipView setDocumentCursor:[NSCursor openHandCursor]]; 
     118        else 
     119                [clipView setDocumentCursor:[NSCursor arrowCursor]]; 
    84120} 
    85121 
     
    207243 
    208244- (void)mouseDown:(NSEvent *)event { 
    209         [[FHController controller] zoom:self]; 
     245        _dragging = NO; 
     246
     247 
     248 
     249 
     250- (void)mouseUp:(NSEvent *)event { 
     251        if(!_dragging) 
     252                [[FHController controller] zoom:self]; 
     253
     254 
     255 
     256 
     257- (void)mouseDragged:(NSEvent *)event { 
     258        NSPoint         point, originalPoint; 
     259        NSRect          originalRect; 
     260        float           x, y; 
     261         
     262        _dragging = YES; 
     263 
     264        originalPoint   = [event locationInWindow]; 
     265        originalRect    = [self visibleRect]; 
     266         
     267        [[NSCursor closedHandCursor] push]; 
     268         
     269        do { 
     270                event = [[self window] nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask]; 
     271                 
     272                if([event type] == NSLeftMouseDragged) { 
     273                        point   = [event locationInWindow]; 
     274                        x               = originalPoint.x - point.x; 
     275                        y               = originalPoint.y - point.y; 
     276                         
     277                        [self scrollRectToVisible:NSOffsetRect(originalRect, x, y)]; 
     278                } 
     279        } while([event type] != NSLeftMouseUp); 
     280         
     281        [NSCursor pop]; 
    210282} 
    211283