From 150ee44da031ecbd639b859828e472d1ea6988df Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Wed, 2 Dec 2009 16:39:38 -0800 Subject: [PATCH] Added background highlight to menu bar and fixed highligh turning off after stopping tracking in menu bar. Reviewed by me. --- AppKit/CPMenu/_CPMenuBarWindow.j | 11 +++++--- AppKit/CPMenuItem/_CPMenuItemMenuBarView.j | 26 ++++++++++-------- .../_CPMenuBarWindowBackgroundSelected.png | Bin 0 -> 151 bytes 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 AppKit/Resources/_CPMenuBarWindow/_CPMenuBarWindowBackgroundSelected.png diff --git a/AppKit/CPMenu/_CPMenuBarWindow.j b/AppKit/CPMenu/_CPMenuBarWindow.j index 786c7e149..b9d88f0bf 100644 --- a/AppKit/CPMenu/_CPMenuBarWindow.j +++ b/AppKit/CPMenu/_CPMenuBarWindow.j @@ -119,7 +119,7 @@ var _CPMenuBarWindowBackgroundColor = nil, if (!aColor) { if (!_CPMenuBarWindowBackgroundColor) - _CPMenuBarWindowBackgroundColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[_CPMenuBarWindow class]] pathForResource:@"_CPMenuBarWindow/_CPMenuBarWindowBackground.png"] size:CGSizeMake(1.0, 18.0)]]; + _CPMenuBarWindowBackgroundColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[_CPMenuBarWindow class]] pathForResource:@"_CPMenuBarWindow/_CPMenuBarWindowBackground.png"] size:CGSizeMake(1.0, 28.0)]]; [[self contentView] setBackgroundColor:_CPMenuBarWindowBackgroundColor]; } @@ -326,7 +326,10 @@ var _CPMenuBarWindowBackgroundColor = nil, beginTracking:anEvent menuContainer:self constraintRect:constraintRect - callback:nil]; + callback:function(aMenuContainer, aMenu) + { + [aMenu _highlightItemAtIndex:CPNotFound]; + }]; } - (CPFont)font @@ -366,13 +369,13 @@ var _CPMenuBarWindowBackgroundColor = nil, { [menuItemView setFrame:CGRectMake(x, 0.0, CGRectGetWidth(frame), MENUBAR_HEIGHT)]; - x += CGRectGetWidth([menuItemView frame]) + MENUBAR_MARGIN; + x += CGRectGetWidth([menuItemView frame]); } else { [menuItemView setFrame:CGRectMake(x - CGRectGetWidth(frame), 0.0, CGRectGetWidth(frame), MENUBAR_HEIGHT)]; - x = CGRectGetMinX([menuItemView frame]) - MENUBAR_MARGIN; + x = CGRectGetMinX([menuItemView frame]); } } diff --git a/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j b/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j index d860d272b..bf791b185 100644 --- a/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j +++ b/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j @@ -1,9 +1,9 @@ -var LEFT_MARGIN = 5.0, - RIGHT_MARGIN = 5.0, +var HORIZONTAL_MARGIN = 8.0, SUBMENU_INDICATOR_MARGIN = 5.0, VERTICAL_MARGIN = 4.0; -var SUBMENU_INDICATOR_COLOR = nil, +var SelectionColor = nil, + SUBMENU_INDICATOR_COLOR = nil, _CPMenuItemSelectionColor = nil, _CPMenuItemTextShadowColor = nil, @@ -26,15 +26,17 @@ var SUBMENU_INDICATOR_COLOR = nil, + (void)initialize { - if (self !== [_CPMenuItemStandardView class]) + if (self !== [_CPMenuItemMenuBarView class]) return; + var bundle = [CPBundle bundleForClass:self]; + + SelectionColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"_CPMenuBarWindow/_CPMenuBarWindowBackgroundSelected.png"] size:CGSizeMake(1.0, 28.0)]]; + SUBMENU_INDICATOR_COLOR = [CPColor grayColor]; _CPMenuItemSelectionColor = [CPColor colorWithCalibratedRed:95.0 / 255.0 green:131.0 / 255.0 blue:185.0 / 255.0 alpha:1.0]; - _CPMenuItemTextShadowColor = [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0] - - var bundle = [CPBundle bundleForClass:self]; + _CPMenuItemTextShadowColor = [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0]; _CPMenuItemDefaultStateImages[CPOffState] = nil; _CPMenuItemDefaultStateHighlightedImages[CPOffState] = nil; @@ -57,7 +59,7 @@ var SUBMENU_INDICATOR_COLOR = nil, if (self) { - _imageAndTextView = [[_CPImageAndTextView alloc] initWithFrame:CGRectMake(LEFT_MARGIN, 0.0, 0.0, 0.0)]; + _imageAndTextView = [[_CPImageAndTextView alloc] initWithFrame:CGRectMake(HORIZONTAL_MARGIN, 0.0, 0.0, 0.0)]; [_imageAndTextView setImagePosition:CPImageLeft]; [_imageAndTextView setTextShadowOffset:CGSizeMake(0.0, 1.0)]; @@ -95,7 +97,7 @@ var SUBMENU_INDICATOR_COLOR = nil, - (void)update { - var x = LEFT_MARGIN, + var x = HORIZONTAL_MARGIN, height = 0.0; [_imageAndTextView setFont:[_menuItem font] || _font]; @@ -123,7 +125,7 @@ var SUBMENU_INDICATOR_COLOR = nil, submenuViewFrame.origin.x = x + SUBMENU_INDICATOR_MARGIN; - x += CGRectGetWidth(submenuViewFrame); + x = CGRectGetMaxX(submenuViewFrame); height = MAX(height, CGRectGetHeight(submenuViewFrame)); } else @@ -140,7 +142,7 @@ var SUBMENU_INDICATOR_COLOR = nil, [_submenuIndicatorView setFrame:submenuViewFrame]; } - _minSize = CGSizeMake(x + RIGHT_MARGIN, height); + _minSize = CGSizeMake(x + HORIZONTAL_MARGIN, height); [self setAutoresizesSubviews:NO]; [self setFrameSize:_minSize]; @@ -155,7 +157,7 @@ var SUBMENU_INDICATOR_COLOR = nil, if (shouldHighlight) { - [self setBackgroundColor:_CPMenuItemSelectionColor]; + [self setBackgroundColor:SelectionColor]; [_imageAndTextView setTextColor:[CPColor whiteColor]]; [_imageAndTextView setTextShadowColor:_CPMenuItemTextShadowColor]; diff --git a/AppKit/Resources/_CPMenuBarWindow/_CPMenuBarWindowBackgroundSelected.png b/AppKit/Resources/_CPMenuBarWindow/_CPMenuBarWindowBackgroundSelected.png new file mode 100644 index 0000000000000000000000000000000000000000..92307f8b000f7130d02a0944a42a779dcc5e3091 GIT binary patch literal 151 zcmeAS@N?(olHy`uVBq!ia0vp^j6f{I!2~4r?VV-=DajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_d9MV6i}jv*Ddl4k7B625%5-G9cv|Nr@q{Gajfuk&)n9D%?8 y<$L;B|GRJa-+bkN`-KGKf6iZ|vsN*&NHA