Created
August 2, 2014 17:00
-
-
Save insidegui/4bc3818e99233f9bf756 to your computer and use it in GitHub Desktop.
QTX Window with FOTWindow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_window.titleBarDrawingBlock = ^(BOOL drawsAsMainWindow, NSRect drawingRect, NSBezierPath *clippingPath){ | |
NSColor* fillColor = [NSColor colorWithCalibratedRed: 0.076 green: 0.073 blue: 0.076 alpha: 1]; | |
NSColor* strokeColor = [NSColor colorWithCalibratedRed: 0.289 green: 0.289 blue: 0.289 alpha: 1]; | |
NSColor* gradientColor = [NSColor colorWithCalibratedRed: 0.179 green: 0.179 blue: 0.179 alpha: 1]; | |
NSColor* shadowColor2 = [NSColor colorWithCalibratedRed: 0.719 green: 0.714 blue: 0.719 alpha: 1]; | |
NSGradient* gradient = [[NSGradient alloc] initWithColorsAndLocations: | |
strokeColor, 0.0, | |
gradientColor, 0.50, | |
fillColor, 0.51, nil]; | |
NSShadow* shadow = [[NSShadow alloc] init]; | |
[shadow setShadowColor: shadowColor2]; | |
[shadow setShadowOffset: NSMakeSize(0.1, -1.1)]; | |
[shadow setShadowBlurRadius: 0]; | |
CGFloat roundedRectangleCornerRadius = 4; | |
NSRect roundedRectangleRect = NSMakeRect(0, 0, NSWidth(_window.frame), 22.0); | |
NSRect roundedRectangleInnerRect = NSInsetRect(roundedRectangleRect, roundedRectangleCornerRadius, roundedRectangleCornerRadius); | |
NSBezierPath* roundedRectanglePath = [NSBezierPath bezierPath]; | |
[roundedRectanglePath moveToPoint: NSMakePoint(NSMinX(roundedRectangleRect), NSMinY(roundedRectangleRect))]; | |
[roundedRectanglePath lineToPoint: NSMakePoint(NSMaxX(roundedRectangleRect), NSMinY(roundedRectangleRect))]; | |
[roundedRectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(roundedRectangleInnerRect), NSMaxY(roundedRectangleInnerRect)) radius: roundedRectangleCornerRadius startAngle: 0 endAngle: 90]; | |
[roundedRectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(roundedRectangleInnerRect), NSMaxY(roundedRectangleInnerRect)) radius: roundedRectangleCornerRadius startAngle: 90 endAngle: 180]; | |
[roundedRectanglePath closePath]; | |
[gradient drawInBezierPath: roundedRectanglePath angle: -90]; | |
NSRect rectangleBorderRect = NSInsetRect([roundedRectanglePath bounds], -shadow.shadowBlurRadius, -shadow.shadowBlurRadius); | |
rectangleBorderRect = NSOffsetRect(rectangleBorderRect, -shadow.shadowOffset.width, -shadow.shadowOffset.height); | |
rectangleBorderRect = NSInsetRect(NSUnionRect(rectangleBorderRect, [roundedRectanglePath bounds]), -1, -1); | |
NSBezierPath* rectangleNegativePath = [NSBezierPath bezierPathWithRect: rectangleBorderRect]; | |
[rectangleNegativePath appendBezierPath: roundedRectanglePath]; | |
[rectangleNegativePath setWindingRule: NSEvenOddWindingRule]; | |
[NSGraphicsContext saveGraphicsState]; | |
{ | |
NSShadow* shadowWithOffset = [shadow copy]; | |
CGFloat xOffset = shadowWithOffset.shadowOffset.width + round(rectangleBorderRect.size.width); | |
CGFloat yOffset = shadowWithOffset.shadowOffset.height; | |
shadowWithOffset.shadowOffset = NSMakeSize(xOffset + copysign(0.1, xOffset), yOffset + copysign(0.1, yOffset)); | |
[shadowWithOffset set]; | |
[[NSColor grayColor] setFill]; | |
[roundedRectanglePath addClip]; | |
NSAffineTransform* transform = [NSAffineTransform transform]; | |
[transform translateXBy: -round(rectangleBorderRect.size.width) yBy: 0]; | |
[[transform transformBezierPath: rectangleNegativePath] fill]; | |
} | |
[NSGraphicsContext restoreGraphicsState]; | |
}; | |
_window.titleDrawingBlock = ^(BOOL drawsAsMainWindow, NSRect titleBarRect){ | |
NSColor* fillColor2 = [NSColor colorWithCalibratedRed: 1 green: 1 blue: 1 alpha: 1]; | |
NSColor* strokeColor2 = [NSColor colorWithCalibratedRed: 0 green: 0 blue: 0 alpha: 1]; | |
NSShadow* shadow2 = [[NSShadow alloc] init]; | |
[shadow2 setShadowColor: strokeColor2]; | |
[shadow2 setShadowOffset: NSMakeSize(1.1, 1.1)]; | |
[shadow2 setShadowBlurRadius: 0]; | |
NSString* textContent = self.window.title; | |
NSRect textRect; | |
if (_window.representedURL) { | |
textRect = NSMakeRect(20, -2, NSWidth(_window.frame)-20, NSHeight(_window.frame)); | |
} else { | |
textRect = NSMakeRect(0, -2, NSWidth(_window.frame), NSHeight(_window.frame)); | |
} | |
[NSGraphicsContext saveGraphicsState]; | |
[shadow2 set]; | |
NSMutableParagraphStyle* textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; | |
[textStyle setAlignment: NSCenterTextAlignment]; | |
NSDictionary* textFontAttributes = [NSDictionary dictionaryWithObjectsAndKeys: | |
[NSFont boldSystemFontOfSize: [NSFont systemFontSize]], NSFontAttributeName, | |
fillColor2, NSForegroundColorAttributeName, | |
textStyle, NSParagraphStyleAttributeName, nil]; | |
titleBarRect.origin.y -= 1; | |
[textContent drawInRect: titleBarRect withAttributes: textFontAttributes]; | |
[NSGraphicsContext restoreGraphicsState]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment