Permalink
Browse files

Able to Select an area and get the rect (not right)

  • Loading branch information...
1 parent b210779 commit ecf412ab1ddc4beab9357d7c7aa364cb5b69e335 @pppoe committed Aug 12, 2011
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 462F79E513F4DCB10093F62A /* GetFrameSelectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 462F79E413F4DCB10093F62A /* GetFrameSelectionView.m */; };
4654F91A13F10E2700BE97F7 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4654F91913F10E2700BE97F7 /* Cocoa.framework */; };
4654F92413F10E2700BE97F7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4654F92213F10E2700BE97F7 /* InfoPlist.strings */; };
4654F92713F10E2700BE97F7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4654F92613F10E2700BE97F7 /* main.m */; };
@@ -19,6 +20,9 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 462F79E213F4D0BD0093F62A /* GetFrameImageViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetFrameImageViewDelegate.h; sourceTree = "<group>"; };
+ 462F79E313F4DCB10093F62A /* GetFrameSelectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetFrameSelectionView.h; sourceTree = "<group>"; };
+ 462F79E413F4DCB10093F62A /* GetFrameSelectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GetFrameSelectionView.m; sourceTree = "<group>"; };
4654F91513F10E2700BE97F7 /* GetFrame.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GetFrame.app; sourceTree = BUILT_PRODUCTS_DIR; };
4654F91913F10E2700BE97F7 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
4654F91C13F10E2700BE97F7 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@@ -93,12 +97,15 @@
4654F92B13F10E2700BE97F7 /* GetFrameAppDelegate.h */,
4654F92C13F10E2700BE97F7 /* GetFrameAppDelegate.m */,
4654F92E13F10E2800BE97F7 /* Main.xib */,
- 4654F92013F10E2700BE97F7 /* Supporting Files */,
4654F93613F119D700BE97F7 /* GetFrameWinController.h */,
4654F93713F119D700BE97F7 /* GetFrameWinController.m */,
4654F93913F11A0300BE97F7 /* GetFrameWinController.xib */,
4654FD1313F267C900BE97F7 /* GetFrameImageView.h */,
4654FD1413F267C900BE97F7 /* GetFrameImageView.m */,
+ 4654F92013F10E2700BE97F7 /* Supporting Files */,
+ 462F79E213F4D0BD0093F62A /* GetFrameImageViewDelegate.h */,
+ 462F79E313F4DCB10093F62A /* GetFrameSelectionView.h */,
+ 462F79E413F4DCB10093F62A /* GetFrameSelectionView.m */,
);
path = GetFrame;
sourceTree = "<group>";
@@ -183,6 +190,7 @@
4654F92D13F10E2700BE97F7 /* GetFrameAppDelegate.m in Sources */,
4654F93813F119D700BE97F7 /* GetFrameWinController.m in Sources */,
4654FD1513F267C900BE97F7 /* GetFrameImageView.m in Sources */,
+ 462F79E513F4DCB10093F62A /* GetFrameSelectionView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
+@protocol GetFrameImageViewDelegate;
@interface GetFrameImageView : NSView {
@private
@@ -16,11 +17,14 @@
NSRect _imageRect;
NSPoint _originPoint;
+
+ id<GetFrameImageViewDelegate> _delegate;
}
@property (nonatomic, assign) NSPoint originPoint;
@property (nonatomic, readonly) NSRect imageRect;
@property (nonatomic, retain) NSImage *image;
+@property (nonatomic, assign) id<GetFrameImageViewDelegate> delegate;
- (NSPoint)pointFromBasePoint:(NSPoint)basePoint;
@@ -7,11 +7,13 @@
//
#import "GetFrameImageView.h"
+#import "GetFrameImageViewDelegate.h"
@implementation GetFrameImageView
@synthesize image = _image;
@synthesize imageRect = _imageRect;
@synthesize originPoint = _originPoint;
+@synthesize delegate = _delegate;
- (void)drawRect:(NSRect)dirtyRect {
@@ -36,6 +38,11 @@ - (void)drawRect:(NSRect)dirtyRect {
fraction:1.0f];
_originPoint = NSMakePoint(NSMinX(_imageRect), NSMaxY(_imageRect));
+
+ if ([self.delegate respondsToSelector:@selector(rectRenderFinishedInView:)])
+ {
+ [self.delegate rectRenderFinishedInView:self];
+ }
}
- (void)dealloc
@@ -0,0 +1,18 @@
+//
+// GetFrameImageViewDelegate.h
+// GetFrame
+//
+// Created by haoxiang on 8/12/11.
+// Copyright 2011 DEV. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class GetFrameImageView;
+
+@protocol GetFrameImageViewDelegate <NSObject>
+
+@optional
+- (void)rectRenderFinishedInView:(GetFrameImageView *)view;
+
+@end
@@ -0,0 +1,19 @@
+//
+// GetFrameSelectionView.h
+// GetFrame
+//
+// Created by haoxiang on 8/12/11.
+// Copyright 2011 DEV. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface GetFrameSelectionView : NSBox {
+@private
+ id target;
+ SEL selector;
+}
+
+- (void)setDragReleaseTarget:(id)theTarget andSelector:(SEL)theSelector;
+
+@end
@@ -0,0 +1,46 @@
+//
+// GetFrameSelectionView.m
+// GetFrame
+//
+// Created by haoxiang on 8/12/11.
+// Copyright 2011 DEV. All rights reserved.
+//
+
+#import "GetFrameSelectionView.h"
+
+
+@implementation GetFrameSelectionView
+
+- (id)initWithFrame:(NSRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ [self setBoxType:NSBoxCustom];
+ [self setFillColor:[[NSColor blueColor] colorWithAlphaComponent:0.6f]];
+ [self setBorderType:NSLineBorder];
+ [self setBorderColor:[NSColor blueColor]];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [super dealloc];
+}
+
+- (void)mouseDragged:(NSEvent *)theEvent {
+ NSPoint curPt = [self frame].origin;
+ [self setFrameOrigin:NSMakePoint(curPt.x + [theEvent deltaX],
+ curPt.y - [theEvent deltaY])];
+}
+
+- (void)mouseUp:(NSEvent *)theEvent {
+ [target performSelector:selector];
+}
+
+- (void)setDragReleaseTarget:(id)theTarget andSelector:(SEL)theSelector {
+ target = theTarget;
+ selector = theSelector;
+}
+
+@end
@@ -9,6 +9,13 @@
#import <Cocoa/Cocoa.h>
@class GetFrameImageView;
+@class GetFrameSelectionView;
+
+typedef enum {
+ EnumTrackingNone,
+ EnumTrackingPoint,
+ EnumTrackingSelection,
+} EnumTrackingMode;
@interface GetFrameWinController : NSWindowController {
@@ -19,11 +26,22 @@
IBOutlet NSTextField *_label;
IBOutlet NSTextField *_field;
+ GetFrameSelectionView *_selectionView;
+
//< For Zooming
NSSize _orgSize; //< Original Image Size
float _zoomFactor;
NSTrackingRectTag _curTrackingArea;
+
+ //< For Dragging and Selection
+ NSPoint _startBasePt;
+ EnumTrackingMode _trackingMode;
+ BOOL _acceptSelection;
+
+ //< Info
+ NSRect _curRect;
+ NSPoint _curPoint;
}
- (IBAction)openImage:(id)sender;
@@ -32,4 +50,8 @@
- (IBAction)zoomIn:(id)sender;
- (IBAction)zoomOut:(id)sender;
+@property (nonatomic, assign) NSRect curRect;
+@property (nonatomic, assign) NSPoint curPoint;
+@property (nonatomic, assign) EnumTrackingMode trackingMode;
+
@end
Oops, something went wrong.

0 comments on commit ecf412a

Please sign in to comment.