From 15b383886e9be1568c7dfd2970dd8c0887c3e8f2 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 5 Apr 2009 16:00:42 -0700 Subject: [PATCH] Adding support for shadows in the title bar. --- AppKit/CPMenu.j | 44 +++++++++++++++++++++++++++++++++++++++++++- AppKit/CPMenuItem.j | 21 ++++++++++++++++++++- AppKit/CPToolbar.j | 18 ++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/AppKit/CPMenu.j b/AppKit/CPMenu.j index 08a6b9bf4..58933dfa8 100644 --- a/AppKit/CPMenu.j +++ b/AppKit/CPMenu.j @@ -98,6 +98,8 @@ var _CPMenuBarVisible = NO, [_CPMenuBarSharedWindow setColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarBackgroundColor"]]; [_CPMenuBarSharedWindow setTextColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTextColor"]]; [_CPMenuBarSharedWindow setTitleColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTitleColor"]]; + [_CPMenuBarSharedWindow setTextShadowColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTextShadowColor"]]; + [_CPMenuBarSharedWindow setTitleShadowColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTitleShadowColor"]]; [_CPMenuBarSharedWindow orderFront:self]; } @@ -140,7 +142,9 @@ var _CPMenuBarVisible = NO, _CPMenuBarAttributes = [attributes copy]; var textColor = [attributes objectForKey:@"CPMenuBarTextColor"], - titleColor = [attributes objectForKey:@"CPMenuBarTitleColor"]; + titleColor = [attributes objectForKey:@"CPMenuBarTitleColor"], + textShadowColor = [attributes objectForKey:@"CPMenuBarTextShadowColor"], + titleShadowColor = [attributes objectForKey:@"CPMenuBarTitleShadowColor"]; if (!textColor && titleColor) [_CPMenuBarAttributes setObject:titleColor forKey:@"CPMenuBarTextColor"]; @@ -154,11 +158,25 @@ var _CPMenuBarVisible = NO, [_CPMenuBarAttributes setObject:[CPColor blackColor] forKey:@"CPMenuBarTitleColor"]; } + if (!textShadowColor && titleShadowColor) + [_CPMenuBarAttributes setObject:titleShadowColor forKey:@"CPMenuBarTextShadowColor"]; + + else if (textShadowColor && !titleShadowColor) + [_CPMenuBarAttributes setObject:textShadowColor forKey:@"CPMenuBarTitleShadowColor"]; + + else if (!textShadowColor && !titleShadowColor) + { + [_CPMenuBarAttributes setObject:[CPColor colorWithWhite:1.0 alpha:0.8] forKey:@"CPMenuBarTextShadowColor"]; + [_CPMenuBarAttributes setObject:[CPColor colorWithWhite:1.0 alpha:0.8] forKey:@"CPMenuBarTitleShadowColor"]; + } + if (_CPMenuBarSharedWindow) { [_CPMenuBarSharedWindow setColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarBackgroundColor"]]; [_CPMenuBarSharedWindow setTextColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTextColor"]]; [_CPMenuBarSharedWindow setTitleColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTitleColor"]]; + [_CPMenubarSharedWindow setTextShadowColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTextShadowColor"]]; + [_CPMenubarSharedWindow setTitleShadowColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTitleShadowColor"]]; } } @@ -1380,6 +1398,9 @@ var _CPMenuBarWindowBackgroundColor = nil, CPColor _textColor; CPColor _titleColor; + + CPColor _textShadowColor; + CPColor _titleShadowColor; } + (void)initialize @@ -1419,6 +1440,7 @@ var _CPMenuBarWindowBackgroundColor = nil, [_titleField setFont:[CPFont boldSystemFontOfSize:12.0]]; [_titleField setAlignment:CPCenterTextAlignment]; + [_titleField setTextShadowOffset:CGSizeMake(0, 1)]; [contentView addSubview:_titleField]; } @@ -1491,6 +1513,26 @@ var _CPMenuBarWindowBackgroundColor = nil, [_titleField setTextColor:aColor ? aColor : [CPColor blackColor]]; } +- (void)setTextShadowColor:(CPColor)aColor +{ + if (_textShadowColor == aColor) + return; + + _textShadowColor = aColor; + + [_menuItemViews makeObjectsPerformSelector:@selector(setTextShadowColor:) withObject:_textShadowColor]; +} + +- (void)setTitleShadowColor:(CPColor)aColor +{ + if (_titleShadowColor == aColor) + return; + + _titleShadowColor = aColor; + + [_titleField setTextShadowColor:aColor ? aColor : [CPColor whiteColor]]; +} + - (void)setMenu:(CPMenu)aMenu { if (_menu == aMenu) diff --git a/AppKit/CPMenuItem.j b/AppKit/CPMenuItem.j index d339f88c2..6b4913504 100644 --- a/AppKit/CPMenuItem.j +++ b/AppKit/CPMenuItem.j @@ -870,6 +870,7 @@ var _CPMenuItemSelectionColor = nil, CPFont _font; CPColor _textColor; + CPColor _textShadowColor; CGSize _minSize; BOOL _isDirty; @@ -1034,6 +1035,8 @@ var _CPMenuItemSelectionColor = nil, [_imageAndTextView setImage:[_menuItem image]]; [_imageAndTextView setText:[_menuItem title]]; [_imageAndTextView setTextColor:[self textColor]]; + [_imageAndTextView setTextShadowColor:[self textShadowColor]]; + [_imageAndTextView setTextShadowOffset:CGSizeMake(0, 1)]; [_imageAndTextView setFrameOrigin:CGPointMake(x, VERTICAL_MARGIN)]; [_imageAndTextView sizeToFit]; @@ -1108,7 +1111,7 @@ var _CPMenuItemSelectionColor = nil, [self setBackgroundColor:nil]; [_imageAndTextView setTextColor:[self textColor]]; - [_imageAndTextView setTextShadowColor:nil]; + [_imageAndTextView setTextShadowColor:[self textShadowColor]]; } var state = [_menuItem state]; @@ -1185,6 +1188,22 @@ var _CPMenuItemSelectionColor = nil, return [_menuItem isEnabled] ? (_textColor ? _textColor : [CPColor colorWithCalibratedRed:70.0 / 255.0 green:69.0 / 255.0 blue:69.0 / 255.0 alpha:1.0]) : [CPColor darkGrayColor]; } +- (void)setTextShadowColor:(CPColor)aColor +{ + if (_textShadowColor == aColor) + return; + + _textShadowColor = aColor; + + [_imageAndTextView setTextShadowColor:[self textShadowColor]]; + //[_submenuView setColor:[self textColor]]; +} + +- (CPColor)textShadowColor +{ + return [_menuItem isEnabled] ? (_textShadowColor ? _textShadowColor : [CPColor colorWithWhite:1.0 alpha:0.8]) : [CPColor colorWithWhite:0.8 alpha:0.8]; +} + @end @implementation _CPMenuItemArrowView : CPView diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j index 4727dc2f5..6ca1939ff 100644 --- a/AppKit/CPToolbar.j +++ b/AppKit/CPToolbar.j @@ -448,6 +448,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth) CPPopUpButton _additionalItemsButton; CPColor _labelColor; + CPColor _labelShadowColor; float _minWidth; } @@ -473,6 +474,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth) _minWidth = 0; _labelColor = [CPColor blackColor]; + _labelShadowColor = [CPColor colorWithWhite:1.0 alpha:0.75]; _additionalItemsButton = [[CPPopUpButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 15.0) pullsDown:YES]; [_additionalItemsButton setBordered:NO]; @@ -510,6 +512,20 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth) [[self labelForItem:items[count]] setTextColor:_labelColor]; } +- (void)setLabelShadowColor:(CPColor)aColor +{ + if (_labelShadowColor === aColor) + return; + + _labelShadowColor = aColor; + + var items = [_toolbar items], + count = [items count]; + + while (count--) + [[self labelForItem:items[count]] setTextShadowColor:_labelShadowColor]; +} + // This *should* be roughly O(3N) = O(N) - (void)resizeSubviewsWithOldSize:(CGSize)aSize { @@ -785,6 +801,8 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth) [label setStringValue:[item label]]; [label setFont:[CPFont systemFontOfSize:11.0]]; [label setTextColor:_labelColor]; + [label setTextShadowColor:_labelShadowColor]; + [label setTextShadowOffset:CGSizeMake(0, 1)]; [label sizeToFit]; [label setTarget:[item target]];