Permalink
Browse files

Gradient box - You can now set fill to None in IB

  • Loading branch information...
bwalkin@99-204-55-68.pools.spcsdns.net
bwalkin@99-204-55-68.pools.spcsdns.net committed Jan 12, 2010
1 parent e824135 commit 4479822bea71f9e5e8033d3cb3499c475fde4cea
Showing with 327 additions and 184 deletions.
  1. +2 −2 BWGradientBox.h
  2. +10 −5 BWGradientBox.m
  3. +8 −0 BWGradientBoxInspector.h
  4. +64 −2 BWGradientBoxInspector.m
  5. +222 −174 BWGradientBoxInspector.xib
  6. +1 −1 BWGradientBoxIntegration.m
  7. +3 −0 NSView+BWAdditions.h
  8. +17 −0 NSView+BWAdditions.m
View
@@ -14,11 +14,11 @@
NSColor *topBorderColor, *bottomBorderColor;
float topInsetAlpha, bottomInsetAlpha;
- BOOL hasTopBorder, hasBottomBorder, hasGradient;
+ BOOL hasTopBorder, hasBottomBorder, hasGradient, hasFillColor;
}
@property (nonatomic, retain) NSColor *fillStartingColor, *fillEndingColor, *fillColor, *topBorderColor, *bottomBorderColor;
@property float topInsetAlpha, bottomInsetAlpha;
-@property BOOL hasTopBorder, hasBottomBorder, hasGradient;
+@property BOOL hasTopBorder, hasBottomBorder, hasGradient, hasFillColor;
@end
View
@@ -13,7 +13,7 @@ @implementation BWGradientBox
@synthesize fillStartingColor, fillEndingColor, fillColor, topBorderColor, bottomBorderColor;
@synthesize topInsetAlpha, bottomInsetAlpha;
-@synthesize hasTopBorder, hasBottomBorder, hasGradient;
+@synthesize hasTopBorder, hasBottomBorder, hasGradient, hasFillColor;
- (id)initWithCoder:(NSCoder *)decoder
{
@@ -28,7 +28,8 @@ - (id)initWithCoder:(NSCoder *)decoder
[self setHasTopBorder:[decoder decodeBoolForKey:@"BWGBHasTopBorder"]];
[self setHasBottomBorder:[decoder decodeBoolForKey:@"BWGBHasBottomBorder"]];
[self setHasGradient:[decoder decodeBoolForKey:@"BWGBHasGradient"]];
-
+ [self setHasFillColor:[decoder decodeBoolForKey:@"BWGBHasFillColor"]];
+
[self setTopInsetAlpha:[decoder decodeFloatForKey:@"BWGBTopInsetAlpha"]];
[self setBottomInsetAlpha:[decoder decodeFloatForKey:@"BWGBBottomInsetAlpha"]];
@@ -63,7 +64,8 @@ - (void)encodeWithCoder:(NSCoder *)coder
[coder encodeBool:[self hasTopBorder] forKey:@"BWGBHasTopBorder"];
[coder encodeBool:[self hasBottomBorder] forKey:@"BWGBHasBottomBorder"];
[coder encodeBool:[self hasGradient] forKey:@"BWGBHasGradient"];
-
+ [coder encodeBool:[self hasFillColor] forKey:@"BWGBHasFillColor"];
+
[coder encodeFloat:[self topInsetAlpha] forKey:@"BWGBTopInsetAlpha"];
[coder encodeFloat:[self bottomInsetAlpha] forKey:@"BWGBBottomInsetAlpha"];
}
@@ -78,8 +80,11 @@ - (void)drawRect:(NSRect)rect
}
else
{
- [fillColor set];
- NSRectFillUsingOperation(self.bounds, NSCompositeSourceOver);
+ if (hasFillColor)
+ {
+ [fillColor set];
+ NSRectFillUsingOperation(self.bounds, NSCompositeSourceOver);
+ }
}
if (hasTopBorder)
View
@@ -14,8 +14,16 @@
{
BWGradientBox *box;
int fillPopupSelection;
+
+ BWGradientWell *gradientWell;
+ NSColorWell *colorWell;
+ NSView *wellContainer;
+ float largeViewHeight, smallViewHeight;
}
+@property (nonatomic, retain) IBOutlet BWGradientWell *gradientWell;
+@property (nonatomic, retain) IBOutlet NSColorWell *colorWell;
+@property (nonatomic, retain) IBOutlet NSView *wellContainer;
@property int fillPopupSelection;
@end
View
@@ -7,10 +7,27 @@
//
#import "BWGradientBoxInspector.h"
+#import "NSEvent+BWAdditions.h"
+#import "NSView+BWAdditions.h"
+
+static float heightDelta = 33;
+static float animationDuration = 0.1;
+
+@interface BWGradientBoxInspector (BWGBIPrivate)
+- (void)updateWellVisibility;
+@end
@implementation BWGradientBoxInspector
-@synthesize fillPopupSelection;
+@synthesize fillPopupSelection, gradientWell, colorWell, wellContainer;
+
+- (void)awakeFromNib
+{
+ [super awakeFromNib];
+
+ largeViewHeight = [[self view] frame].size.height;
+ smallViewHeight = largeViewHeight - heightDelta;
+}
- (NSString *)viewNibName
{
@@ -22,12 +39,16 @@ - (void)refresh
[super refresh];
box = [[self inspectedObjects] objectAtIndex:0];
-
+ [self updateWellVisibility];
+
// Update the popup selections in case of an undo operation
if ([box hasGradient])
+ [self setFillPopupSelection:2];
+ else if ([box hasFillColor])
[self setFillPopupSelection:1];
else
[self setFillPopupSelection:0];
+
}
+ (BOOL)supportsMultipleObjectInspection
@@ -40,9 +61,50 @@ - (void)setFillPopupSelection:(int)anInt
fillPopupSelection = anInt;
if (fillPopupSelection == 0)
+ {
+ [box setHasGradient:NO];
+ [box setHasFillColor:NO];
+ }
+ else if (fillPopupSelection == 1)
+ {
[box setHasGradient:NO];
+ [box setHasFillColor:YES];
+ [gradientWell setHidden:YES];
+ [colorWell setHidden:NO];
+ [colorWell setEnabled:YES];
+ }
else
+ {
[box setHasGradient:YES];
+ [box setHasFillColor:NO];
+ [gradientWell setHidden:NO];
+ [colorWell setHidden:YES];
+ [colorWell setEnabled:NO];
+ }
+}
+
+- (void)updateWellVisibility
+{
+ BOOL willCollapse;
+ NSRect targetFrame = [[self view] frame];
+ float viewHeight = [[self view] frame].size.height;
+
+ if ((int)viewHeight == (int)largeViewHeight && ![box hasGradient] && ![box hasFillColor])
+ willCollapse = YES;
+ else if ((int)viewHeight == (int)smallViewHeight && ([box hasGradient] || [box hasFillColor]))
+ willCollapse = NO;
+ else
+ return;
+
+ targetFrame.size.height = willCollapse ? smallViewHeight : largeViewHeight;
+ float alpha = willCollapse ? 0 : 1;
+ float duration = [NSEvent bwShiftKeyIsDown] ? animationDuration * 10 : animationDuration;
+
+ [NSAnimationContext beginGrouping];
+ [[NSAnimationContext currentContext] setDuration:duration];
+ [[wellContainer bwAnimator] setAlphaValue:alpha];
+ [[[self view] bwAnimator] setFrame:targetFrame];
+ [NSAnimationContext endGrouping];
}
@end
Oops, something went wrong.

0 comments on commit 4479822

Please sign in to comment.