Permalink
Browse files

Zoom in/Out

  • Loading branch information...
pppoe committed Aug 10, 2011
1 parent edd34fa commit 47e88c33862872f39a6074687e24e897158dd7fc
@@ -12,7 +12,7 @@
4654F92713F10E2700BE97F7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4654F92613F10E2700BE97F7 /* main.m */; };
4654F92A13F10E2700BE97F7 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 4654F92813F10E2700BE97F7 /* Credits.rtf */; };
4654F92D13F10E2700BE97F7 /* GetFrameAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4654F92C13F10E2700BE97F7 /* GetFrameAppDelegate.m */; };
- 4654F93013F10E2800BE97F7 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4654F92E13F10E2800BE97F7 /* MainMenu.xib */; };
+ 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 */; };
/* End PBXBuildFile section */
@@ -30,7 +30,7 @@
4654F92913F10E2700BE97F7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; };
4654F92B13F10E2700BE97F7 /* GetFrameAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GetFrameAppDelegate.h; sourceTree = "<group>"; };
4654F92C13F10E2700BE97F7 /* GetFrameAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GetFrameAppDelegate.m; sourceTree = "<group>"; };
- 4654F92F13F10E2800BE97F7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
+ 4654F92F13F10E2800BE97F7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/Main.xib; sourceTree = "<group>"; };
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>"; };
@@ -89,7 +89,7 @@
children = (
4654F92B13F10E2700BE97F7 /* GetFrameAppDelegate.h */,
4654F92C13F10E2700BE97F7 /* GetFrameAppDelegate.m */,
- 4654F92E13F10E2800BE97F7 /* MainMenu.xib */,
+ 4654F92E13F10E2800BE97F7 /* Main.xib */,
4654F92013F10E2700BE97F7 /* Supporting Files */,
4654F93613F119D700BE97F7 /* GetFrameWinController.h */,
4654F93713F119D700BE97F7 /* GetFrameWinController.m */,
@@ -162,7 +162,7 @@
files = (
4654F92413F10E2700BE97F7 /* InfoPlist.strings in Resources */,
4654F92A13F10E2700BE97F7 /* Credits.rtf in Resources */,
- 4654F93013F10E2800BE97F7 /* MainMenu.xib in Resources */,
+ 4654F93013F10E2800BE97F7 /* Main.xib in Resources */,
4654F93A13F11A0300BE97F7 /* GetFrameWinController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -199,12 +199,12 @@
name = Credits.rtf;
sourceTree = "<group>";
};
- 4654F92E13F10E2800BE97F7 /* MainMenu.xib */ = {
+ 4654F92E13F10E2800BE97F7 /* Main.xib */ = {
isa = PBXVariantGroup;
children = (
4654F92F13F10E2800BE97F7 /* en */,
);
- name = MainMenu.xib;
+ name = Main.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
@@ -291,6 +291,7 @@
4654F93513F10E2800BE97F7 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
@@ -25,7 +25,7 @@
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
- <string>MainMenu</string>
+ <string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
@@ -9,10 +9,21 @@
#import <Cocoa/Cocoa.h>
@interface GetFrameWinController : NSWindowController {
+
@private
IBOutlet NSImageView *_imageView;
+ IBOutlet NSScrollView *_scrollView;
+
+
+ //< For Zooming
+ NSSize _orgSize; //< Original Image Size
+ float _zoomFactor;
}
- (IBAction)openImage:(id)sender;
+- (IBAction)modeGetFrame:(id)sender;
+- (IBAction)zoomIn:(id)sender;
+- (IBAction)zoomOut:(id)sender;
+
@end
@@ -8,6 +8,32 @@
#import "GetFrameWinController.h"
+/////////////////////////////////////////////////////////////////////
+//< Constants
+/////////////////////////////////////////////////////////////////////
+#define kMinWinWidth (400)
+#define kMinWinHeight (400)
+
+#define kMaxWinWidth (800)
+#define kMaxWinHeight (800)
+
+#define kImagePadding (5)
+
+#define kMaxImageWidth (5000)
+#define kMaxImageHeight (5000)
+
+#define kMinImageWidth (16)
+#define kMinImageHeight (16)
+
+#define kMinZoomFactor (1.0f)
+#define kMaxZoomFactor (8.0f)
+
+@interface GetFrameWinController (Private)
+
+- (void)adjustFrameForNewImage;
+- (void)zoomView:(NSView *)view withFactor:(float)factor;
+
+@end
@implementation GetFrameWinController
@@ -29,6 +55,14 @@ - (void)dealloc
- (void)windowDidLoad
{
[super windowDidLoad];
+
+ [[self window] setMinSize:NSMakeSize(kMinWinWidth, kMinWinHeight)];
+ [[self window] setMaxSize:NSMakeSize(kMaxWinWidth, kMaxWinHeight)];
+
+ _orgSize = [_imageView frame].size;
+ _zoomFactor = 1.0f;
+
+ [_scrollView setDocumentView:_imageView];
}
- (IBAction)openImage:(id)sender {
@@ -46,8 +80,75 @@ - (IBAction)openImage:(id)sender {
{
[_imageView setImage:image];
[image release];
+
+ [self adjustFrameForNewImage];
}
}
}
+- (IBAction)modeGetFrame:(id)sender {
+
+}
+
+- (IBAction)zoomIn:(id)sender {
+
+ _zoomFactor = MIN(kMaxZoomFactor, 2 * _zoomFactor);
+
+ [self zoomView:_imageView withFactor:_zoomFactor];
+}
+
+- (IBAction)zoomOut:(id)sender {
+
+ _zoomFactor = MAX(kMinZoomFactor, _zoomFactor / 2.0f);
+
+ [self zoomView:_imageView withFactor:_zoomFactor];
+}
+
+@end
+
+@implementation GetFrameWinController (Private)
+
+- (void)zoomView:(NSView *)view withFactor:(float)factor {
+ NSSize s = [view frame].size;
+ NSPoint org = [view frame].origin;
+ NSPoint ctrPt = NSMakePoint(org.x + s.width/2.0f, org.y + s.height/2.0f);
+ NSSize newSize = NSMakeSize(_orgSize.width * factor, _orgSize.height * factor);
+ [[view animator] setFrame:NSMakeRect(ctrPt.x - newSize.width/2.0f,
+ ctrPt.y - newSize.height/2.0f,
+ newSize.width, newSize.height)];
+}
+
+- (void)adjustFrameForNewImage
+{
+
+// NSSize size = [[_imageView image] size];
+//
+// //< Keep the Left and Bottom Padding
+// float leftPadding = _imageView.frame.origin.x;
+// float bottomPadding = _imageView.frame.origin.y;
+//
+// //< Keep the Center Point
+// NSSize winSize = NSMakeSize(MIN(MAX((size.width + 2 * kImagePadding + 2 * leftPadding), kMinWinWidth), kMaxWinWidth),
+// MIN(MAX((size.height + 2 * kImagePadding + 2 * bottomPadding), kMinWinHeight), kMaxWinHeight));
+// NSRect oldWinFrame = [[self window] frame];
+// NSPoint ctrPoint = NSMakePoint(oldWinFrame.origin.x + oldWinFrame.size.width/2.0f,
+// oldWinFrame.origin.y + oldWinFrame.size.height/2.0f);
+//
+// NSRect winFrame = NSMakeRect(ctrPoint.x - winSize.width/2.0f,
+// ctrPoint.y - winSize.height/2.0f,
+// winSize.width, winSize.height);
+// [[self window] setFrame:winFrame
+// display:NO
+// animate:YES];
+//
+// NSRect rect = NSMakeRect((winSize.width - (size.width + 2*kImagePadding))/2.0f,
+// (winSize.height - (size.height + 2*kImagePadding))/2.0f,
+// (size.width + 2*kImagePadding),
+// (size.height + 2*kImagePadding));
+// [_imageView setFrame:rect];
+//
+// [[self window] setMinSize:NSMakeSize(winFrame.size.width, winFrame.size.height)];
+
+}
+
@end
Oops, something went wrong.

0 comments on commit 47e88c3

Please sign in to comment.