aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/BWToolkitFramework.framework/BWGradientBox.m
diff options
context:
space:
mode:
authoravenjamin <avenjamin@gmail.com>2009-06-24 15:46:27 +0000
committeravenjamin <avenjamin@gmail.com>2009-06-24 15:46:27 +0000
commit5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40 (patch)
treef0eaf423f2c13f2091fe9cfceaa2e0a6f2169723 /Frameworks/BWToolkitFramework.framework/BWGradientBox.m
parent37bd86b2879c107ebb026954693540979cf25e2a (diff)
downloadsequelpro-5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40.tar.gz
sequelpro-5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40.tar.bz2
sequelpro-5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40.zip
- Changed the way the BWToolkit framework was included to allow modifications to be made easily.
- Fixed show/hide info pane toggle button image states to now show correctly
Diffstat (limited to 'Frameworks/BWToolkitFramework.framework/BWGradientBox.m')
-rw-r--r--Frameworks/BWToolkitFramework.framework/BWGradientBox.m179
1 files changed, 179 insertions, 0 deletions
diff --git a/Frameworks/BWToolkitFramework.framework/BWGradientBox.m b/Frameworks/BWToolkitFramework.framework/BWGradientBox.m
new file mode 100644
index 00000000..14aa19eb
--- /dev/null
+++ b/Frameworks/BWToolkitFramework.framework/BWGradientBox.m
@@ -0,0 +1,179 @@
+//
+// BWGradientBox.m
+// BWToolkit
+//
+// Created by Brandon Walkin (www.brandonwalkin.com)
+// All code is provided under the New BSD license.
+//
+
+#import "BWGradientBox.h"
+#import "NSColor+BWAdditions.h"
+
+@implementation BWGradientBox
+
+@synthesize fillStartingColor, fillEndingColor, fillColor, topBorderColor, bottomBorderColor;
+@synthesize topInsetAlpha, bottomInsetAlpha;
+@synthesize hasTopBorder, hasBottomBorder, hasGradient;
+
+- (id)initWithCoder:(NSCoder *)decoder
+{
+ if ((self = [super initWithCoder:decoder]) != nil)
+ {
+ [self setFillStartingColor:[decoder decodeObjectForKey:@"BWGBFillStartingColor"]];
+ [self setFillEndingColor:[decoder decodeObjectForKey:@"BWGBFillEndingColor"]];
+ [self setFillColor:[decoder decodeObjectForKey:@"BWGBFillColor"]];
+ [self setTopBorderColor:[decoder decodeObjectForKey:@"BWGBTopBorderColor"]];
+ [self setBottomBorderColor:[decoder decodeObjectForKey:@"BWGBBottomBorderColor"]];
+
+ [self setHasTopBorder:[decoder decodeBoolForKey:@"BWGBHasTopBorder"]];
+ [self setHasBottomBorder:[decoder decodeBoolForKey:@"BWGBHasBottomBorder"]];
+ [self setHasGradient:[decoder decodeBoolForKey:@"BWGBHasGradient"]];
+
+ [self setTopInsetAlpha:[decoder decodeFloatForKey:@"BWGBTopInsetAlpha"]];
+ [self setBottomInsetAlpha:[decoder decodeFloatForKey:@"BWGBBottomInsetAlpha"]];
+
+ if (self.fillStartingColor == nil)
+ self.fillStartingColor = [NSColor whiteColor];
+
+ if (self.fillEndingColor == nil)
+ self.fillEndingColor = [NSColor grayColor];
+
+ if (self.fillColor == nil)
+ self.fillColor = [NSColor grayColor];
+
+ if (self.topBorderColor == nil)
+ self.topBorderColor = [NSColor blackColor];
+
+ if (self.bottomBorderColor == nil)
+ self.bottomBorderColor = [NSColor blackColor];
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+ [super encodeWithCoder:coder];
+
+ [coder encodeObject:[self fillStartingColor] forKey:@"BWGBFillStartingColor"];
+ [coder encodeObject:[self fillEndingColor] forKey:@"BWGBFillEndingColor"];
+ [coder encodeObject:[self fillColor] forKey:@"BWGBFillColor"];
+ [coder encodeObject:[self topBorderColor] forKey:@"BWGBTopBorderColor"];
+ [coder encodeObject:[self bottomBorderColor] forKey:@"BWGBBottomBorderColor"];
+
+ [coder encodeBool:[self hasTopBorder] forKey:@"BWGBHasTopBorder"];
+ [coder encodeBool:[self hasBottomBorder] forKey:@"BWGBHasBottomBorder"];
+ [coder encodeBool:[self hasGradient] forKey:@"BWGBHasGradient"];
+
+ [coder encodeFloat:[self topInsetAlpha] forKey:@"BWGBTopInsetAlpha"];
+ [coder encodeFloat:[self bottomInsetAlpha] forKey:@"BWGBBottomInsetAlpha"];
+}
+
+- (void)drawRect:(NSRect)rect
+{
+ if (hasGradient)
+ {
+ NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:fillStartingColor endingColor:fillEndingColor];
+ [gradient drawInRect:self.bounds angle:90];
+ [gradient release];
+ }
+ else
+ {
+ [fillColor set];
+ NSRectFillUsingOperation(self.bounds, NSCompositeSourceOver);
+ }
+
+ if (hasTopBorder)
+ {
+ [topBorderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:self.bounds inView:self horizontal:YES flip:NO];
+ [[[NSColor whiteColor] colorWithAlphaComponent:topInsetAlpha] drawPixelThickLineAtPosition:1 withInset:0 inRect:self.bounds inView:self horizontal:YES flip:NO];
+ }
+ else
+ {
+ [[[NSColor whiteColor] colorWithAlphaComponent:topInsetAlpha] drawPixelThickLineAtPosition:0 withInset:0 inRect:self.bounds inView:self horizontal:YES flip:NO];
+ }
+
+
+ if (hasBottomBorder)
+ {
+ [bottomBorderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:self.bounds inView:self horizontal:YES flip:YES];
+ [[[NSColor whiteColor] colorWithAlphaComponent:bottomInsetAlpha] drawPixelThickLineAtPosition:1 withInset:0 inRect:self.bounds inView:self horizontal:YES flip:YES];
+ }
+ else
+ {
+ [[[NSColor whiteColor] colorWithAlphaComponent:bottomInsetAlpha] drawPixelThickLineAtPosition:0 withInset:0 inRect:self.bounds inView:self horizontal:YES flip:YES];
+ }
+
+}
+
+- (BOOL)isFlipped
+{
+ return YES;
+}
+
+- (void)setFillColor:(NSColor *)color
+{
+ if (fillColor != color)
+ {
+ [fillColor release];
+ fillColor = [color retain];
+
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (void)setFillStartingColor:(NSColor *)color
+{
+ if (fillStartingColor != color)
+ {
+ [fillStartingColor release];
+ fillStartingColor = [color retain];
+
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (void)setFillEndingColor:(NSColor *)color
+{
+ if (fillEndingColor != color)
+ {
+ [fillEndingColor release];
+ fillEndingColor = [color retain];
+
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (void)setTopBorderColor:(NSColor *)color
+{
+ if (topBorderColor != color)
+ {
+ [topBorderColor release];
+ topBorderColor = [color retain];
+
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (void)setBottomBorderColor:(NSColor *)color
+{
+ if (bottomBorderColor != color)
+ {
+ [bottomBorderColor release];
+ bottomBorderColor = [color retain];
+
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (void)dealloc
+{
+ [fillColor release];
+ [fillStartingColor release];
+ [fillEndingColor release];
+ [topBorderColor release];
+ [bottomBorderColor release];
+
+ [super dealloc];
+}
+
+@end