From 35094617f6fddcef1cedf62f583b5bc11f102e5b Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 1 Aug 2012 23:56:56 +0000 Subject: [PATCH] update views git-svn-id: svn://qnap.local/TwoTerm/branches/frameless@2463 5590a31f-7b70-45f8-8c82-aa3a8e5f4507 --- Views/CurveView.m | 1 + Views/TitleBarView.h | 8 +++-- Views/TitleBarView.m | 73 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 66 insertions(+), 16 deletions(-) diff --git a/Views/CurveView.m b/Views/CurveView.m index 991f7f9..63af99a 100644 --- a/Views/CurveView.m +++ b/Views/CurveView.m @@ -102,5 +102,6 @@ -(void)dealloc { [_color release]; + [super dealloc]; } @end diff --git a/Views/TitleBarView.h b/Views/TitleBarView.h index 8bc2bfe..2435eba 100644 --- a/Views/TitleBarView.h +++ b/Views/TitleBarView.h @@ -10,17 +10,21 @@ @interface TitleBarView : NSView { - NSColor *_color; + NSColor *_backgroundColor; NSTextField *_label; NSImage *_rightImage; NSImage *_leftImage; NSImage *_centerImage; + + BOOL _dark; } -@property (nonatomic, retain) NSColor *color; +@property (nonatomic, retain) NSColor *backgroundColor; @property (nonatomic, retain) IBOutlet NSTextField *label; @property (nonatomic, retain) NSString *title; +-(void)updateTitle; + -(void)fadeIn; -(void)fadeOut; @end diff --git a/Views/TitleBarView.m b/Views/TitleBarView.m index 38204b5..17436a1 100644 --- a/Views/TitleBarView.m +++ b/Views/TitleBarView.m @@ -12,7 +12,7 @@ @implementation TitleBarView @synthesize label = _label; -@synthesize color = _color; +@synthesize backgroundColor = _backgroundColor; -(id)initWithFrame:(NSRect)frameRect { @@ -40,29 +40,74 @@ -(void)dealloc { + [_backgroundColor release]; [_leftImage release]; [_rightImage release]; [_centerImage release]; [_label release]; + + [super dealloc]; +} + +-(void)setBackgroundColor:(NSColor *)backgroundColor +{ + + NSColor *tmp; + + if (_backgroundColor == backgroundColor) return; + + [_backgroundColor release]; + _backgroundColor = [backgroundColor retain]; + + + _dark = YES; + + tmp = [_backgroundColor colorUsingColorSpaceName: NSCalibratedWhiteColorSpace]; + if (tmp) + { + if ([tmp whiteComponent] > 0.5) _dark = NO; + } + + [self updateTitle]; } -(void)setTitle:(NSString *)title +{ + [_label setStringValue: title]; + [self updateTitle]; +} + +-(NSString *)title +{ + return [_label stringValue]; +} + + +-(void)updateTitle { NSAttributedString *as; NSDictionary *attr; NSShadow *shadow; NSMutableParagraphStyle *ps; - if (!title) + + NSString *title; + + + title = [_label stringValue]; + + + if (![title length]) { - [_label setStringValue: @""]; return; } - + + [_label setTextColor: _dark ? [NSColor whiteColor] : [NSColor blackColor]]; + shadow = [NSShadow new]; [shadow setShadowBlurRadius: 1.0]; - [shadow setShadowColor: [NSColor blackColor]]; - [shadow setShadowOffset: NSMakeSize(0.0, 1.0)]; + [shadow setShadowColor: _dark ? [NSColor blackColor] : [NSColor whiteColor]]; + [shadow setShadowOffset: _dark ? NSMakeSize(0.0, 1.0) : NSMakeSize(0.0, -1.0)]; ps = [NSMutableParagraphStyle new]; [ps setAlignment: NSCenterTextAlignment]; @@ -75,16 +120,13 @@ as = [[NSAttributedString alloc] initWithString: title attributes: attr]; [_label setAttributedStringValue: as]; - + [as release]; - [shadow release]; + [shadow release]; + } --(NSString *)title -{ - return [_label stringValue]; -} -(BOOL)isFlipped @@ -96,6 +138,7 @@ -(void)drawRect:(NSRect)dirtyRect { NSRect bounds; + NSRect rect; bounds = [self bounds]; @@ -107,10 +150,12 @@ [path addClip]; - [_color setFill]; + [_backgroundColor setFill]; NSRectFill(dirtyRect); - NSDrawThreePartImage(NSMakeRect(0, 0, bounds.size.width, 24.0),_leftImage, _centerImage, _rightImage, NO, NSCompositeSourceOver, 1.0, YES); + rect = NSMakeRect(0, 0, bounds.size.width, 24.0); + rect = NSInsetRect(rect, 1, 0); + NSDrawThreePartImage(rect, _leftImage, _centerImage, _rightImage, NO, NSCompositeSourceOver, 1.0, YES); }