Permalink
Browse files

Add a stub outline view implementation (disabled)

  • Loading branch information...
1 parent 8801b55 commit 1424bd8b16ce655c72a8e1d2966507d734eca985 @p2 committed Feb 25, 2013
View
6 growth-charts-helper.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ EE0069DF16DBEFD3008EB91D /* CHOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = EE0069DE16DBEFD3008EB91D /* CHOutlineView.m */; };
EE9408A616860CDA001FC955 /* CHClickableView.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9408A516860CDA001FC955 /* CHClickableView.m */; };
EEAECBFE16815E2F00E8ABE1 /* CHRectToStringTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = EEAECBFD16815E2F00E8ABE1 /* CHRectToStringTransformer.m */; };
EEAECC1716816B7800E8ABE1 /* CHFloatToStringTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = EEAECC1616816B7800E8ABE1 /* CHFloatToStringTransformer.m */; };
@@ -36,6 +37,8 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ EE0069DD16DBEFD3008EB91D /* CHOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHOutlineView.h; sourceTree = "<group>"; };
+ EE0069DE16DBEFD3008EB91D /* CHOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHOutlineView.m; sourceTree = "<group>"; };
EE9408A416860CDA001FC955 /* CHClickableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHClickableView.h; sourceTree = "<group>"; };
EE9408A516860CDA001FC955 /* CHClickableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHClickableView.m; sourceTree = "<group>"; };
EEAECBFC16815E2F00E8ABE1 /* CHRectToStringTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHRectToStringTransformer.h; sourceTree = "<group>"; };
@@ -206,6 +209,8 @@
EEEB2DE41681075A004DC719 /* CHDropView.m */,
EE9408A416860CDA001FC955 /* CHClickableView.h */,
EE9408A516860CDA001FC955 /* CHClickableView.m */,
+ EE0069DD16DBEFD3008EB91D /* CHOutlineView.h */,
+ EE0069DE16DBEFD3008EB91D /* CHOutlineView.m */,
EEEB2DDA1680FFC7004DC719 /* CHEnumToNumberTransformer.h */,
EEEB2DDB1680FFC7004DC719 /* CHEnumToNumberTransformer.m */,
EEAECC1516816B7800E8ABE1 /* CHFloatToStringTransformer.h */,
@@ -303,6 +308,7 @@
EEAECC1A16816C4500E8ABE1 /* CHDecimalNumberToStringTransformer.m in Sources */,
EEEFDEB11682737B005C4D17 /* CHResizableChartAreaView.m in Sources */,
EE9408A616860CDA001FC955 /* CHClickableView.m in Sources */,
+ EE0069DF16DBEFD3008EB91D /* CHOutlineView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
134 growth-charts-helper/CHChartAreaView.m
@@ -24,12 +24,15 @@
#import "CHChartArea.h"
#import "CHChartPDFView.h"
#import "CHResizableChartAreaView.h" // our subclass
+#import "CHOutlineView.h"
@interface CHChartAreaView () {
CGRect inParentRect;
}
+@property (nonatomic, weak) CHOutlineView *outlineView;
+
@end
@@ -203,9 +206,21 @@ - (void)didRemoveArea:(CHChartArea *)area
}
+
+#pragma mark - First Responder
- (void)didBecomeFirstResponder
{
[_pageView didBecomeFirstResponder:self];
+ [self addOutline];
+}
+
+- (void)didResignFirstResponder
+{
+ if (_outlineView) {
+ [_outlineView removeFromSuperview];
+ [_outlineView.superview setNeedsDisplayInRect:_outlineView.frame];
+ self.outlineView = nil;
+ }
}
@@ -268,25 +283,6 @@ - (CGRect)framingBox
}
/**
- * A rect in our own coordinate system containing our outline, our bounds if we don't have one.
- * @return The rect covering our outline, an empty rect if we don't have an outline
- */
-- (CGRect)outlineBox
-{
-/* if (_outline) {
- CGSize mySize = [self bounds].size;
- CGRect scaledOutline = CGPathGetBoundingBox(_outline);
- scaledOutline.origin.x *= mySize.width;
- scaledOutline.origin.y *= mySize.height;
- scaledOutline.size.width *= mySize.width;
- scaledOutline.size.height *= mySize.height;
-
- return scaledOutline;
- } // */
- return self.bounds;
-}
-
-/**
* The rect in our own coordinate system that describes our content rect.
*
* By default just returns the bounds, but subclasses can override this to return a different rectangle (e.g. text boxes).
@@ -351,45 +347,14 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(NSEvent *)event
-#pragma mark - Drawing
-- (void)drawRect:(NSRect)dirtyRect
-{
- [NSGraphicsContext saveGraphicsState];
-
- if (self.active) {
- [[NSColor colorWithDeviceRed:0.f green:1.f blue:0.f alpha:0.5f] setFill];
- }
- else {
- [[NSColor colorWithDeviceRed:0.f green:0.f blue:1.f alpha:0.25f] setFill];
- }
-
- [NSBezierPath fillRect:self.bounds];
- [NSGraphicsContext restoreGraphicsState];
-
- // the outline path
- if (self.active && self.outline) {
- [NSGraphicsContext saveGraphicsState];
-
- // transform to current size
- NSRect bnds = self.bounds;
- NSAffineTransform *transform = [NSAffineTransform transform];
- [transform scaleXBy:bnds.size.width yBy:bnds.size.height];
- NSBezierPath *outlinePath = [_outline copy];
- [outlinePath transformUsingAffineTransform:transform];
-
- [outlinePath setClip];
- [[NSColor colorWithDeviceRed:1.f green:0.f blue:0.f alpha:0.5f] setFill];
- [NSBezierPath fillRect:bnds];
-
- [NSGraphicsContext restoreGraphicsState];
- }
-}
-
+#pragma mark - Outline
- (NSBezierPath *)outline
{
if (!_outline) {
if ([self.area.outlinePoints count] > 0) {
NSBezierPath *path = nil;
+
+ // create the path
for (NSValue *pointValue in self.area.outlinePoints) {
if (!path) {
path = [NSBezierPath new];
@@ -401,12 +366,73 @@ - (NSBezierPath *)outline
}
[path closePath];
- self.outline = path;
+
+ // flip it (it's upside down now)
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ [transform scaleXBy:1.f yBy:-1.f];
+ [transform translateXBy:0.f yBy:-1.f];
+
+ self.outline = [transform transformBezierPath:path];
}
}
return _outline;
}
+- (void)addOutline
+{
+ return;
+ if (!_outlineView) {
+ CGRect outline = [self outlineBox];
+ if (!CGRectIsEmpty(outline)) {
+ CHOutlineView *slayer = [[CHOutlineView alloc] initWithFrame:outline];
+ slayer.outline = _outline;
+ slayer.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
+
+ [self addSubview:slayer];
+ self.outlineView = slayer;
+ }
+ }
+}
+
+/**
+ * A rect in our own coordinate system containing our outline, our bounds if we don't have one.
+ * @return The rect covering our outline, an empty rect if we don't have an outline
+ */
+- (CGRect)outlineBox
+{
+ if (self.outline) {
+ CGSize mySize = [self bounds].size;
+ CGRect scaledOutline = [_outline bounds];
+ scaledOutline.origin.x *= mySize.width;
+ scaledOutline.origin.y *= mySize.height;
+ scaledOutline.size.width *= mySize.width;
+ scaledOutline.size.height *= mySize.height;
+
+ return scaledOutline;
+ }
+
+ return CGRectZero;
+}
+
+
+
+#pragma mark - Drawing
+//- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
+- (void)drawRect:(NSRect)dirtyRect
+{
+ [NSGraphicsContext saveGraphicsState];
+
+ if (self.active) {
+ [[NSColor colorWithDeviceRed:0.f green:1.f blue:0.f alpha:0.5f] setFill];
+ }
+ else {
+ [[NSColor colorWithDeviceRed:0.f green:0.f blue:1.f alpha:0.25f] setFill];
+ }
+
+ [NSBezierPath fillRect:self.bounds];
+ [NSGraphicsContext restoreGraphicsState];
+}
+
#pragma mark - Class Registration
View
1 growth-charts-helper/CHClickableView.h
@@ -18,6 +18,7 @@
- (BOOL)makeFirstResponder;
- (void)didBecomeFirstResponder;
+- (void)didResignFirstResponder;
@end
View
13 growth-charts-helper/CHClickableView.m
@@ -59,6 +59,19 @@ - (void)didBecomeFirstResponder
{
}
+- (BOOL)resignFirstResponder
+{
+ BOOL didResign = [super resignFirstResponder];
+ if (didResign) {
+ [self didResignFirstResponder];
+ }
+ return didResign;
+}
+
+- (void)didResignFirstResponder
+{
+}
+
#pragma mark - Mouse Handling
View
16 growth-charts-helper/CHOutlineView.h
@@ -0,0 +1,16 @@
+//
+// CHOutlineLayer.h
+// growth-charts-helper
+//
+// Created by Pascal Pfiffner on 2/25/13.
+// Copyright (c) 2013 CHIP. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface CHOutlineView : NSView
+
+@property (nonatomic, strong) NSBezierPath *outline;
+
+@end
View
42 growth-charts-helper/CHOutlineView.m
@@ -0,0 +1,42 @@
+//
+// CHOutlineLayer.m
+// growth-charts-helper
+//
+// Created by Pascal Pfiffner on 2/25/13.
+// Copyright (c) 2013 CHIP. All rights reserved.
+//
+
+#import "CHOutlineView.h"
+
+
+@implementation CHOutlineView
+
+
+
+#pragma mark - Drawing
+- (void)drawRect:(NSRect)dirtyRect
+{
+ if (_outline) {
+ [NSGraphicsContext saveGraphicsState];
+
+ // we need to fit entirely into our bounds
+ NSRect bnds = self.bounds;
+ NSRect rect = [_outline bounds];
+
+ // transform to current size
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ [transform scaleXBy:(bnds.size.width / rect.size.width) yBy:(bnds.size.height / rect.size.height)];
+ [transform translateXBy:-rect.origin.x yBy:-rect.origin.y];
+ NSBezierPath *outlinePath = [_outline copy];
+ [outlinePath transformUsingAffineTransform:transform];
+
+ // fill
+ [[[NSColor orangeColor] colorWithAlphaComponent:0.5f] setFill];
+ [outlinePath fill];
+
+ [NSGraphicsContext restoreGraphicsState];
+ }
+}
+
+
+@end
View
8 growth-charts-helper/en.lproj/CHDocument.xib
@@ -249,7 +249,7 @@
<int key="NSCellFlags2">272630784</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="653464429"/>
- <string key="NSPlaceholderString">e.g. World Health Organization</string>
+ <string key="NSPlaceholderString">World Health Organization</string>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="763037372"/>
<bool key="NSDrawsBackground">YES</bool>
@@ -272,7 +272,7 @@
<int key="NSCellFlags2">272630784</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="653464429"/>
- <string key="NSPlaceholderString">e.g. WHO</string>
+ <string key="NSPlaceholderString">WHO</string>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="1038006853"/>
<bool key="NSDrawsBackground">YES</bool>
@@ -440,7 +440,7 @@
<int key="NSCellFlags2">272630784</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="653464429"/>
- <string key="NSPlaceholderString">e.g. Boys 0 - 24 Months</string>
+ <string key="NSPlaceholderString">Boys 0 - 24 months</string>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="457686569"/>
<bool key="NSDrawsBackground">YES</bool>
@@ -1638,7 +1638,7 @@
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="586073561"/>
</object>
- <string key="NSScreenRect">{{0, 0}, {1440, 900}}</string>
+ <string key="NSScreenRect">{{0, 0}, {1920, 1058}}</string>
<string key="NSMinSize">{800, 622}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<int key="NSWindowAnimationBehavior">3</int>

0 comments on commit 1424bd8

Please sign in to comment.