NSWindow glossy buttons

This commit is contained in:
Riccardo Canalicchio 2013-12-21 15:18:13 +01:00
parent d0d076ece4
commit 25f131ed4f
7 changed files with 257 additions and 1 deletions

View File

@ -12,7 +12,11 @@ Rik_OBJC_FILES = \
Rik.m\
Rik+Drawings.m\
Rik+Button.m\
Rik+WindowDecoration.m
Rik+WindowDecoration.m\
GSStandardDecorationView+Rik.m\
NSWindow+Rik.m\
RikWindowButton.m\
RikWindowButtonCell.m
ADDITIONAL_TOOL_LIBS = -lopal
$(BUNDLE_NAME)_RESOURCE_FILES = \

View File

@ -0,0 +1,40 @@
#import <GNUstepGUI/GSWindowDecorationView.h>
#import <GNUstepGUI/GSTheme.h>
#define TITLEBAR_BUTTON_SIZE 15
#define TITLEBAR_PADDING_LEFT 10.5
#define TITLEBAR_PADDING_RIGHT 10.5
#define TITLEBAR_PADDING_TOP 5.5
@interface GSStandardWindowDecorationView(RikTheme)
@end
@implementation GSStandardWindowDecorationView(RikTheme)
- (void) updateRects
{
GSTheme *theme = [GSTheme theme];
if (hasTitleBar)
{
CGFloat titleHeight = [theme titlebarHeight];
titleBarRect = NSMakeRect(0.0, [self bounds].size.height - titleHeight,
[self bounds].size.width, titleHeight);
}
if (hasResizeBar)
{
resizeBarRect = NSMakeRect(0.0, 0.0, [self bounds].size.width, [theme resizebarHeight]);
}
if (hasCloseButton)
{
closeButtonRect = NSMakeRect(
[self bounds].size.width - TITLEBAR_BUTTON_SIZE - TITLEBAR_PADDING_RIGHT, [self bounds].size.height - TITLEBAR_BUTTON_SIZE - TITLEBAR_PADDING_TOP, TITLEBAR_BUTTON_SIZE, TITLEBAR_BUTTON_SIZE);
[closeButton setFrame: closeButtonRect];
}
if (hasMiniaturizeButton)
{
miniaturizeButtonRect = NSMakeRect(
TITLEBAR_PADDING_LEFT, [self bounds].size.height - TITLEBAR_BUTTON_SIZE - TITLEBAR_PADDING_TOP, TITLEBAR_BUTTON_SIZE, TITLEBAR_BUTTON_SIZE);
[miniaturizeButton setFrame: miniaturizeButtonRect];
}
}
@end

60
NSWindow+Rik.m Normal file
View File

@ -0,0 +1,60 @@
#import <AppKit/NSWindow.h>
#include "RikWindowButton.h"
@interface NSWindow(RikTheme)
@end
@implementation NSWindow(RikTheme)
+ (NSButton *) standardWindowButton: (NSWindowButton)button
forStyleMask: (NSUInteger) mask
{
NSButton *newButton;
switch (button)
{
case NSWindowCloseButton:
newButton = [[RikWindowButton alloc] init];
[(RikWindowButton*)newButton setBaseColor: [NSColor colorWithCalibratedRed: 0.698 green: 0.427 blue: 1.00 alpha: 1]];
[newButton setImage: [NSImage imageNamed: @"common_Close"]];
[newButton setAlternateImage: [NSImage imageNamed: @"common_CloseH"]];
[newButton setAction: @selector(performClose:)];
break;
case NSWindowMiniaturizeButton:
newButton = [[RikWindowButton alloc] init];
[newButton setBaseColor: [NSColor colorWithCalibratedRed: 0.9 green: 0.7 blue: 0.3 alpha: 1]];
[newButton setImage: [NSImage imageNamed: @"common_Miniaturize"]];
[newButton setAlternateImage: [NSImage imageNamed: @"common_MiniaturizeH"]];
[newButton setAction: @selector(miniaturize:)];
break;
case NSWindowZoomButton:
// FIXME
newButton = [[RikWindowButton alloc] init];
[newButton setBaseColor: [NSColor colorWithCalibratedRed: 0.322 green: 0.778 blue: 0.244 alpha: 1]];
[newButton setAction: @selector(zoom:)];
break;
case NSWindowToolbarButton:
// FIXME
newButton = [[NSButton alloc] init];
[newButton setAction: @selector(toggleToolbarShown:)];
break;
case NSWindowDocumentIconButton:
default:
newButton = [[NSButton alloc] init];
// FIXME
break;
}
[newButton setRefusesFirstResponder: YES];
[newButton setButtonType: NSMomentaryChangeButton];
[newButton setImagePosition: NSImageOnly];
[newButton setBordered: YES];
[newButton setTag: button];
return AUTORELEASE(newButton);
}
@end

14
RikWindowButton.h Normal file
View File

@ -0,0 +1,14 @@
#import <AppKit/NSButton.h>
@interface RikWindowButton : NSButton
{
}
- (void) setBaseColor: (NSColor*)c;
+ (void) initialize;;
@end

23
RikWindowButton.m Normal file
View File

@ -0,0 +1,23 @@
#import "RikWindowButton.h"
#import "RikWindowButtonCell.h"
@implementation RikWindowButton
+ (void) initialize
{
if (self == [RikWindowButton class])
{
[self setVersion: 1];
[self setCellClass: [RikWindowButtonCell class]];
}
}
- (void) setBaseColor: (NSColor*)c
{
[_cell setBaseColor: c];
}
- (BOOL) isFlipped
{
return NO;
}
@end

12
RikWindowButtonCell.h Normal file
View File

@ -0,0 +1,12 @@
#import <AppKit/NSButtonCell.h>
@interface RikWindowButtonCell : NSButtonCell
{
NSColor * baseColor;
}
- (void) drawBallWithRect: (NSRect)frame;
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView;
@property (retain) NSColor * baseColor;
@end

103
RikWindowButtonCell.m Normal file
View File

@ -0,0 +1,103 @@
#include <AppKit/AppKit.h>
#include "RikWindowButtonCell.h"
@implementation RikWindowButtonCell
@synthesize baseColor;
- (void) drawBallWithRect: (NSRect)frame{
frame = NSInsetRect(frame, 0.5, 0.5);
NSColor * bc = baseColor;
float luminosity = 0.5;
if(_cell.is_highlighted)
{
bc = [baseColor shadowWithLevel: 0.2];
luminosity = 0.3;
}
NSColor* gradientDownColor1 = [bc highlightWithLevel: luminosity];
NSColor* gradientDownColor2 = [bc colorWithAlphaComponent: 0];
NSColor* shadowColor1 = [bc shadowWithLevel: 0.5];
NSColor* shadowColor2 = [bc shadowWithLevel: 0.8];
NSColor* gradientStrokeColor2 = [shadowColor1 highlightWithLevel: luminosity];
NSColor* gradientUpColor1 = [bc highlightWithLevel: luminosity+0.2];
NSColor* gradientUpColor2 = [gradientUpColor1 colorWithAlphaComponent: 0.5];
NSColor* gradientUpColor3 = [gradientUpColor1 colorWithAlphaComponent: 0];
NSColor* light1 = [NSColor whiteColor];
NSColor* light2 = [light1 colorWithAlphaComponent:0];
//// Gradient Declarations
NSGradient* gradientUp = [[NSGradient alloc] initWithColorsAndLocations:
gradientUpColor1, 0.1,
gradientUpColor2, 0.3,
gradientUpColor3, 1.0, nil];
NSGradient* gradientDown = [[NSGradient alloc] initWithColorsAndLocations:
gradientDownColor1, 0.0,
gradientDownColor2, 1.0, nil];
NSGradient* baseGradient = [[NSGradient alloc] initWithColorsAndLocations:
bc, 0.0,
shadowColor1, 0.80, nil];
NSGradient* gradientStroke = [[NSGradient alloc] initWithColorsAndLocations:
light1, 0.2,
light2, 1.0, nil];
NSGradient* gradientStroke2 = [[NSGradient alloc] initWithColorsAndLocations:
shadowColor2, 0.47,
gradientStrokeColor2, 1.0, nil];
//paintcode stuff...
NSRect baseCircleGradientStrokeRect = frame;
NSRect baseCircleGradientStrokeRect2 = NSInsetRect(baseCircleGradientStrokeRect, 0.5, 0.5);
frame = NSInsetRect(frame, 1, 1);
NSRect baseCircleRect = NSMakeRect(NSMinX(frame) + floor(NSWidth(frame) * 0.06667 + 0.5), NSMinY(frame) + floor(NSHeight(frame) * 0.06667 + 0.5), floor(NSWidth(frame) * 0.93333 + 0.5) - floor(NSWidth(frame) * 0.06667 + 0.5), floor(NSHeight(frame) * 0.93333 + 0.5) - floor(NSHeight(frame) * 0.06667 + 0.5));
NSRect basecircle2Rect = NSMakeRect(NSMinX(frame) + floor(NSWidth(frame) * 0.06667 + 0.5), NSMinY(frame) + floor(NSHeight(frame) * 0.06667 + 0.5), floor(NSWidth(frame) * 0.93333 + 0.5) - floor(NSWidth(frame) * 0.06667 + 0.5), floor(NSHeight(frame) * 0.93333 + 0.5) - floor(NSHeight(frame) * 0.06667 + 0.5));
//// BaseCircleGradientStroke Drawing
NSBezierPath* baseCircleGradientStrokePath = [NSBezierPath bezierPathWithOvalInRect: baseCircleGradientStrokeRect];
[gradientStroke drawInBezierPath: baseCircleGradientStrokePath angle: 90];
NSBezierPath* baseCircleGradientStrokePath2 = [NSBezierPath bezierPathWithOvalInRect: baseCircleGradientStrokeRect2];
[gradientStroke2 drawInBezierPath: baseCircleGradientStrokePath2 angle: -90];
//// BaseCircle Drawing
NSBezierPath* baseCirclePath = [NSBezierPath bezierPathWithOvalInRect: baseCircleRect];
CGFloat baseCircleResizeRatio = MIN(NSWidth(baseCircleRect) / 13, NSHeight(baseCircleRect) / 13);
[NSGraphicsContext saveGraphicsState];
[baseCirclePath addClip];
[baseGradient drawFromCenter: NSMakePoint(NSMidX(baseCircleRect) + 0 * baseCircleResizeRatio, NSMidY(baseCircleRect) + 0 * baseCircleResizeRatio) radius: 2.85 * baseCircleResizeRatio
toCenter: NSMakePoint(NSMidX(baseCircleRect) + 0 * baseCircleResizeRatio, NSMidY(baseCircleRect) + 0 * baseCircleResizeRatio) radius: 7.32 * baseCircleResizeRatio
options: NSGradientDrawsBeforeStartingLocation | NSGradientDrawsAfterEndingLocation];
[NSGraphicsContext restoreGraphicsState];
//// basecircle2 Drawing
NSBezierPath* basecircle2Path = [NSBezierPath bezierPathWithOvalInRect: basecircle2Rect];
CGFloat basecircle2ResizeRatio = MIN(NSWidth(basecircle2Rect) / 13, NSHeight(basecircle2Rect) / 13);
[NSGraphicsContext saveGraphicsState];
[basecircle2Path addClip];
[gradientDown drawFromCenter: NSMakePoint(NSMidX(basecircle2Rect) + -0.98 * basecircle2ResizeRatio, NSMidY(basecircle2Rect) + -6.5 * basecircle2ResizeRatio) radius: 1.54 * basecircle2ResizeRatio
toCenter: NSMakePoint(NSMidX(basecircle2Rect) + -1.86 * basecircle2ResizeRatio, NSMidY(basecircle2Rect) + -8.73 * basecircle2ResizeRatio) radius: 8.65 * basecircle2ResizeRatio
options: NSGradientDrawsBeforeStartingLocation | NSGradientDrawsAfterEndingLocation];
[NSGraphicsContext restoreGraphicsState];
//// halfcircle Drawing
NSBezierPath* halfcirclePath = [NSBezierPath bezierPath];
[halfcirclePath moveToPoint: NSMakePoint(NSMinX(frame) + 0.93316 * NSWidth(frame), NSMinY(frame) + 0.46157 * NSHeight(frame))];
[halfcirclePath curveToPoint: NSMakePoint(NSMinX(frame) + 0.78652 * NSWidth(frame), NSMinY(frame) + 0.81548 * NSHeight(frame)) controlPoint1: NSMakePoint(NSMinX(frame) + 0.93316 * NSWidth(frame), NSMinY(frame) + 0.46157 * NSHeight(frame)) controlPoint2: NSMakePoint(NSMinX(frame) + 0.94476 * NSWidth(frame), NSMinY(frame) + 0.66376 * NSHeight(frame))];
[halfcirclePath curveToPoint: NSMakePoint(NSMinX(frame) + 0.21348 * NSWidth(frame), NSMinY(frame) + 0.81548 * NSHeight(frame)) controlPoint1: NSMakePoint(NSMinX(frame) + 0.62828 * NSWidth(frame), NSMinY(frame) + 0.96721 * NSHeight(frame)) controlPoint2: NSMakePoint(NSMinX(frame) + 0.37172 * NSWidth(frame), NSMinY(frame) + 0.96721 * NSHeight(frame))];
[halfcirclePath curveToPoint: NSMakePoint(NSMinX(frame) + 0.06684 * NSWidth(frame), NSMinY(frame) + 0.46157 * NSHeight(frame)) controlPoint1: NSMakePoint(NSMinX(frame) + 0.05524 * NSWidth(frame), NSMinY(frame) + 0.66376 * NSHeight(frame)) controlPoint2: NSMakePoint(NSMinX(frame) + 0.06684 * NSWidth(frame), NSMinY(frame) + 0.46157 * NSHeight(frame))];
[halfcirclePath lineToPoint: NSMakePoint(NSMinX(frame) + 0.93316 * NSWidth(frame), NSMinY(frame) + 0.46157 * NSHeight(frame))];
[halfcirclePath closePath];
[halfcirclePath setLineCapStyle: NSRoundLineCapStyle];
[halfcirclePath setLineJoinStyle: NSRoundLineJoinStyle];
[gradientUp drawInBezierPath: halfcirclePath angle: -90];
}
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
if (NSIsEmptyRect(cellFrame))
return;
if(baseColor != nil)
[self drawBallWithRect: cellFrame];
[self drawInteriorWithFrame: cellFrame inView: controlView];
}
@end