Permalink
Browse files

Solid, more opaque background for gear icon.

On non-default backgrounds (likely with the previewImage), the existing background frequently led to the gear icon being invisible. Also, the gradient could end up looking quite ugly in some of these situations. Hence I replaced it by a solid circle to ensure the menu remains visible.
  • Loading branch information...
1 parent 3e0a746 commit 0dca4b4308981c3da5092af3ac83c4208b63929e @ssp ssp committed Oct 8, 2009
Showing with 24 additions and 26 deletions.
  1. +24 −26 Plugin/Plugin.m
View
@@ -718,16 +718,22 @@ - (void) _drawBadgeWithPressed: (BOOL) pressed
CGContextRef context = [ [ NSGraphicsContext currentContext ] graphicsPort ];
- CGContextSetAlpha( context, pressed ? 0.45 : 0.30 );
- CGContextBeginTransparencyLayer( context, nil );
+ CGFloat opacity = 0.45;
+ // Make Badge more opaque when we have a background image
+ if ( [self previewImage] != nil ) {
+ opacity = 0.8;
+ }
+
+ CGContextSetAlpha( context, pressed ? opacity : opacity - 0.15 );
+ CGContextBeginTransparencyLayer( context, nil );
// Draw everything at full size, centered on the origin.
NSPoint loc = { -strSize.width / 2, -strSize.height / 2 };
NSRect borderRect = NSMakeRect( loc.x - kFrameXInset, loc.y - kFrameYInset, w, h );
NSBezierPath* fillPath = bezierPathWithRoundedRectCornerRadius( borderRect, 4 );
- [ [ NSColor colorWithCalibratedWhite: 1.0 alpha: 0.45 ] set ];
+ [ [ NSColor colorWithCalibratedWhite: 1.0 alpha: opacity ] set ];
[ fillPath fill ];
NSBezierPath* darkBorderPath = bezierPathWithRoundedRectCornerRadius( borderRect, 4 );
@@ -736,7 +742,7 @@ - (void) _drawBadgeWithPressed: (BOOL) pressed
[ darkBorderPath stroke ];
NSBezierPath* lightBorderPath = bezierPathWithRoundedRectCornerRadius( NSInsetRect(borderRect, -2, -2), 6 );
- [ [ NSColor colorWithCalibratedWhite: 1.0 alpha: 0.45 ] set ];
+ [ [ NSColor colorWithCalibratedWhite: 1.0 alpha: opacity ] set ];
[ lightBorderPath setLineWidth: 2 ];
[ lightBorderPath stroke ];
@@ -769,30 +775,22 @@ - (void) _drawGearIcon
if( gearImage ) {
CGContextRef context = [ [ NSGraphicsContext currentContext ] graphicsPort ];
- CGContextSetAlpha( context, 0.25 );
+ CGContextSetAlpha( context, 0.65 );
CGContextBeginTransparencyLayer( context, nil );
- NSPoint gearImageCenter = NSMakePoint(NSMinX( bounds ) + ( margin + [gearImage size].width/2 ),
- NSMaxY( bounds ) - ( margin + [gearImage size].height/2 ));
-
- id gradient = [NSClassFromString(@"NSGradient") alloc];
- if (gradient != nil)
- {
- NSColor *startingColor = [NSColor colorWithDeviceWhite:1.0 alpha:1.0];
- NSColor *endingColor = [NSColor colorWithDeviceWhite:1.0 alpha:0.0];
-
- gradient = [gradient initWithStartingColor:startingColor endingColor:endingColor];
-
- // draw gradient behind gear so that it's visible even on dark backgrounds
- [gradient drawFromCenter:gearImageCenter
- radius:0.0
- toCenter:gearImageCenter
- radius:[gearImage size].height/2*1.5
- options:0];
-
- [gradient release];
- }
-
+ CGFloat padding = 3.0;
+ NSPoint gearImageCenter = NSMakePoint(NSMinX( bounds ) + ( padding + margin + [gearImage size].width/2 ),
+ NSMaxY( bounds ) - ( padding + margin + [gearImage size].height/2 ));
+
+ NSRect backgroundFrame = NSMakeRect(NSMinX(bounds) + margin,
+ NSMaxY(bounds) - margin - [gearImage size].height - 2.0 * padding,
+ [gearImage size].width + 2.0 * padding,
+ [gearImage size].height + 2.0 * padding );
+
+ NSBezierPath * circle = [NSBezierPath bezierPathWithOvalInRect:backgroundFrame];
+ [[NSColor whiteColor] set];
+ [circle fill];
+
// draw the gear image
[gearImage drawAtPoint:NSMakePoint(gearImageCenter.x - [gearImage size].width/2,
gearImageCenter.y - [gearImage size].height/2)

0 comments on commit 0dca4b4

Please sign in to comment.