From ddc599486919250a6bee2f53094d8d91ebce2f8a Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Mon, 28 Nov 2011 12:05:43 +0100 Subject: [PATCH] tooltips are now themable. --- AppKit/CPWindow/_CPToolTipWindowView.j | 47 +++++++++++++------------ AppKit/Themes/Aristo/ThemeDescriptors.j | 18 ++++++++++ AppKit/_CPToolTip.j | 2 +- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/AppKit/CPWindow/_CPToolTipWindowView.j b/AppKit/CPWindow/_CPToolTipWindowView.j index 19bbc01d0..1bc63ae62 100644 --- a/AppKit/CPWindow/_CPToolTipWindowView.j +++ b/AppKit/CPWindow/_CPToolTipWindowView.j @@ -27,15 +27,31 @@ { BOOL _mouseDownPressed @accessors(getter=isMouseDownPressed, setter=setMouseDownPressed:); unsigned _gravity @accessors(property=gravity); - - CPColor _backgroundColor; - CPColor _strokeColor; } #pragma mark - #pragma mark Class methods ++ (CPString)defaultThemeClass +{ + return @"tooltip"; +} + ++ (id)themeAttributes +{ + return [CPDictionary dictionaryWithObjects:[[CPColor colorWithHexString:@"E3E3E3"], + [CPColor colorWithHexString:@"FFFFCA"], + 2.0, + 1.0, + [CPColor blackColor]] + forKeys:[@"stroke-color", + @"background-color", + @"border-radius", + @"stroke-width", + @"color"]]; +} + /*! compute the contentView frame from a given window frame @param aFrameRect the window frame */ @@ -67,21 +83,6 @@ } -#pragma mark - -#pragma mark Initialization - -- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask -{ - if (self = [super initWithFrame:aFrame styleMask:aStyleMask]) - { - _strokeColor = [CPColor colorWithHexString:@"E3E3E3"]; - _backgroundColor = [CPColor colorWithHexString:@"FFFFCA"]; - } - - return self; -} - - #pragma mark - #pragma mark drawing @@ -90,11 +91,13 @@ [super drawRect:aRect]; var context = [[CPGraphicsContext currentContext] graphicsPort], - radius = 2, - strokeWidth = 1; + radius = [self currentValueForThemeAttribute:@"border-radius"], + strokeWidth = [self currentValueForThemeAttribute:@"stroke-width"], + strokeColor = [self currentValueForThemeAttribute:@"stroke-color"], + bgColor = [self currentValueForThemeAttribute:@"background-color"]; - CGContextSetStrokeColor(context, _strokeColor); - CGContextSetFillColor(context, _backgroundColor); + CGContextSetStrokeColor(context, strokeColor); + CGContextSetFillColor(context, bgColor); CGContextSetLineWidth(context, strokeWidth); CGContextBeginPath(context); diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index 02f7c26db..d4166a9c5 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -1766,6 +1766,24 @@ var themedButtonValues = nil, return ruleEditor; } ++ (_CPToolTipWindowView)themedTooltip +{ + var toolTipView = [[_CPToolTipWindowView alloc] initWithFrame:CPRectMakeZero() styleMask:_CPToolTipWindowMask], + + themeValues = + [ + [@"stroke-color", [CPColor colorWithHexString:@"E3E3E3"]], + [@"stroke-width", 1.0], + [@"border-radius", 2.0], + [@"background-color", [CPColor colorWithHexString:@"FFFFCA"]], + [@"color", [CPColor blackColor]] + ]; + + [self registerThemeValues:themeValues forView:toolTipView]; + + return toolTipView; +} + @end @implementation AristoHUDThemeDescriptor : BKThemeDescriptor diff --git a/AppKit/_CPToolTip.j b/AppKit/_CPToolTip.j index 7dfe5363e..cc4591a16 100644 --- a/AppKit/_CPToolTip.j +++ b/AppKit/_CPToolTip.j @@ -134,7 +134,7 @@ var _CPToolTipHeight = 24.0, [_content setFrameOrigin:CPPointMake(0.0, 0.0)]; [_content setFrameSize:textFrameSize]; [_content setTextShadowOffset:CGSizeMake(0.0, 1.0)]; - [_content setTextColor:[CPColor blackColor]]; + [_content setTextColor:[[[CPTheme defaultTheme] attributeWithName:@"color" forClass:_CPToolTipWindowView] value]]; [[self contentView] addSubview:_content];