Skip to content

Commit

Permalink
Cursor and Tracking Area
Browse files Browse the repository at this point in the history
  • Loading branch information
pppoe committed Aug 10, 2011
1 parent 47e88c3 commit b377a49
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 116 deletions.
6 changes: 6 additions & 0 deletions GetFrame.xcodeproj/project.pbxproj
Expand Up @@ -15,6 +15,7 @@
4654F93013F10E2800BE97F7 /* Main.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4654F92E13F10E2800BE97F7 /* Main.xib */; };
4654F93813F119D700BE97F7 /* GetFrameWinController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4654F93713F119D700BE97F7 /* GetFrameWinController.m */; };
4654F93A13F11A0300BE97F7 /* GetFrameWinController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4654F93913F11A0300BE97F7 /* GetFrameWinController.xib */; };
4654FD1513F267C900BE97F7 /* GetFrameImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4654FD1413F267C900BE97F7 /* GetFrameImageView.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -34,6 +35,8 @@
4654F93613F119D700BE97F7 /* GetFrameWinController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetFrameWinController.h; sourceTree = "<group>"; };
4654F93713F119D700BE97F7 /* GetFrameWinController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GetFrameWinController.m; sourceTree = "<group>"; };
4654F93913F11A0300BE97F7 /* GetFrameWinController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GetFrameWinController.xib; sourceTree = "<group>"; };
4654FD1313F267C900BE97F7 /* GetFrameImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetFrameImageView.h; sourceTree = "<group>"; };
4654FD1413F267C900BE97F7 /* GetFrameImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GetFrameImageView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -94,6 +97,8 @@
4654F93613F119D700BE97F7 /* GetFrameWinController.h */,
4654F93713F119D700BE97F7 /* GetFrameWinController.m */,
4654F93913F11A0300BE97F7 /* GetFrameWinController.xib */,
4654FD1313F267C900BE97F7 /* GetFrameImageView.h */,
4654FD1413F267C900BE97F7 /* GetFrameImageView.m */,
);
path = GetFrame;
sourceTree = "<group>";
Expand Down Expand Up @@ -177,6 +182,7 @@
4654F92713F10E2700BE97F7 /* main.m in Sources */,
4654F92D13F10E2700BE97F7 /* GetFrameAppDelegate.m in Sources */,
4654F93813F119D700BE97F7 /* GetFrameWinController.m in Sources */,
4654FD1513F267C900BE97F7 /* GetFrameImageView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 5 additions & 1 deletion GetFrame/GetFrameWinController.h
Expand Up @@ -14,10 +14,14 @@
IBOutlet NSImageView *_imageView;
IBOutlet NSScrollView *_scrollView;


IBOutlet NSTextField *_label;
IBOutlet NSTextField *_field;

//< For Zooming
NSSize _orgSize; //< Original Image Size
float _zoomFactor;

NSTrackingRectTag _curTrackingArea;
}

- (IBAction)openImage:(id)sender;
Expand Down
57 changes: 56 additions & 1 deletion GetFrame/GetFrameWinController.m
Expand Up @@ -63,6 +63,12 @@ - (void)windowDidLoad
_zoomFactor = 1.0f;

[_scrollView setDocumentView:_imageView];

_curTrackingArea = [_imageView addTrackingRect:[_imageView bounds]
owner:self
userData:nil
assumeInside:YES];

}

- (IBAction)openImage:(id)sender {
Expand Down Expand Up @@ -95,13 +101,61 @@ - (IBAction)zoomIn:(id)sender {
_zoomFactor = MIN(kMaxZoomFactor, 2 * _zoomFactor);

[self zoomView:_imageView withFactor:_zoomFactor];

[_imageView removeTrackingRect:_curTrackingArea];
[_imageView addTrackingRect:[_imageView bounds]
owner:self
userData:nil
assumeInside:YES];
}

- (IBAction)zoomOut:(id)sender {

_zoomFactor = MAX(kMinZoomFactor, _zoomFactor / 2.0f);

[self zoomView:_imageView withFactor:_zoomFactor];

[_imageView removeTrackingRect:_curTrackingArea];
[_imageView addTrackingRect:[_imageView bounds]
owner:self
userData:nil
assumeInside:YES];
}

/////////////////////////////////////////////////////////////////////
//< Events
/////////////////////////////////////////////////////////////////////
- (void)touchesBeganWithEvent:(NSEvent *)event {

}

- (void)touchesMovedWithEvent:(NSEvent *)event {

}

- (void)touchesEndedWithEvent:(NSEvent *)event {

}

- (void)mouseEntered:(NSEvent *)theEvent {
[[self window] setAcceptsMouseMovedEvents:YES];
[[NSCursor crosshairCursor] set];
}

- (void)mouseMoved:(NSEvent *)theEvent {
NSPoint pt = [theEvent locationInWindow];
NSLog(@"%f %f", pt.x, pt.y);
NSPoint newPt = [_imageView convertPointFromBase:pt];
NSLog(@"%f %f", newPt.x, newPt.y);
}

- (void)mouseDragged:(NSEvent *)theEvent {

}

- (void)mouseExited:(NSEvent *)theEvent {
[[self window] setAcceptsMouseMovedEvents:NO];
[[NSCursor arrowCursor] set];
}

@end
Expand All @@ -120,7 +174,8 @@ - (void)zoomView:(NSView *)view withFactor:(float)factor {

- (void)adjustFrameForNewImage
{

NSRect rect = [[_imageView image] alignmentRect];
NSLog(@"%f %f %f %f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
// NSSize size = [[_imageView image] size];
//
// //< Keep the Left and Bottom Padding
Expand Down

0 comments on commit b377a49

Please sign in to comment.