// // DKTabView // DarkKit // // Created by Chad Weider on 5/2/08. // Copyright (c) 2008 Chad Weider // Some rights reserved: // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the // use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it // freely, subject to the following restrictions: // // 1. The origin of this software must not be misrepresented; you must not // claim that you wrote the original software. If you use this software in a // product, an acknowledgment in the product documentation would be appreciated // but is not required. // // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source distribution. // #import "DKTabView.h" #import "CTGradient.h" #import "NSBezierPath+PXRoundedRectangleAdditions.h" #import "NSTabView.h" @implementation DKTabView - (void)_drawThemeTab:(NSTabViewItem *)tabViewItem withState:(int)state inRect:(NSRect)rect { CTGradient *myGradient; if(state == NSSelectedTab) //Selected Tab myGradient = [CTGradient gradientWithBeginningColor:[NSColor colorWithCalibratedWhite:.4 alpha:1.0] endingColor:[NSColor colorWithCalibratedWhite:.2 alpha:1.0]]; else if(state == NSBackgroundTab) //Normal Tab myGradient = [CTGradient gradientWithBeginningColor:[NSColor colorWithCalibratedWhite:.3 alpha:1.0] endingColor:[NSColor colorWithCalibratedWhite:.0 alpha:1.0]]; else if(state == NSPressedTab) //Pressed Tab myGradient = [CTGradient gradientWithBeginningColor:[NSColor colorWithCalibratedWhite:.5 alpha:1.0] endingColor:[NSColor colorWithCalibratedWhite:.3 alpha:1.0]]; NSRect buttonRect; float buttonHeight; float buttonYShift; float buttonBoxHeight; float cornerRadius; float capInset; switch([self controlSize]) { case NSRegularControlSize: buttonYShift = 2; buttonBoxHeight = 25; buttonHeight = 20; cornerRadius = 4; capInset = 2; break; case NSSmallControlSize: buttonYShift = 2; buttonBoxHeight = 21; buttonHeight = 17; cornerRadius = 4; capInset = 2; break; case NSMiniControlSize: buttonYShift = 1; buttonBoxHeight = 17; buttonHeight = 14; cornerRadius = 3; capInset = 1; break; } if([self _hasHorizontalOrientation]) buttonRect = NSMakeRect(rect.origin.x+.5, floorf(NSMidY(rect)-(buttonBoxHeight)/2)+buttonYShift+.5, rect.size.width-1, buttonHeight); else buttonRect = NSMakeRect(floorf(NSMidX(rect)-(buttonBoxHeight)/2)+buttonYShift+.5, rect.origin.y+.5, buttonHeight, rect.size.height-1); NSBezierPath *bezelPath; //adjustments for ends OSCornerType corners = 0; if([self indexOfTabViewItem:tabViewItem] > 0 && [self indexOfTabViewItem:tabViewItem] < [self numberOfTabViewItems]) { if([self _hasHorizontalOrientation]) { buttonRect.origin.x -= 1; buttonRect.size.width += 1; } else { buttonRect.origin.y -= 1; buttonRect.size.height += 1; } } if([self indexOfTabViewItem:tabViewItem] == 0) { if([self _hasHorizontalOrientation]) //if Top { buttonRect.origin.x += capInset; buttonRect.size.width -= capInset; corners |= OSTopLeftCorner | OSBottomLeftCorner; } else //Left { buttonRect.origin.y += capInset; buttonRect.size.height -= capInset; corners |= OSBottomLeftCorner | OSBottomRightCorner; } } if([self indexOfTabViewItem:tabViewItem] == ([self numberOfTabViewItems] - 1)) { if([self _hasHorizontalOrientation]) //if Bottom { buttonRect.size.width -= capInset; corners |= OSTopRightCorner | OSBottomRightCorner; } else //Right { buttonRect.size.height -= capInset; corners |= OSTopLeftCorner | OSTopRightCorner; } } bezelPath = [NSBezierPath bezierPathWithRoundedRect:buttonRect cornerRadius:cornerRadius inCorners:corners]; float angle; if([self _hasHorizontalOrientation]) //if Top or Bottom Orientation angle = 90; else //Left or Right Orientation angle = -90+[self _tabOrientation]*90; [myGradient fillBezierPath:bezelPath angle:angle]; [bezelPath setLineWidth:1]; [[NSColor colorWithCalibratedWhite:1 alpha:1] set]; [bezelPath stroke]; } - (void)addTabViewItem:(NSTabViewItem *)tabViewItem { object_setClass(tabViewItem, [DKTabViewItem class]); [super addTabViewItem:tabViewItem]; } - (void)_drawBezelBorder:(id)fp8 inRect:(NSRect)rect { NSRect borderRect = [self bounds]; if([self _hasHorizontalOrientation]) { float xMargin = 7; float yMargin = 10; float buttonSizeAdjust = 0; switch([self controlSize]) { case NSRegularControlSize: buttonSizeAdjust = 6; break; case NSSmallControlSize: buttonSizeAdjust = 2; break; case NSMiniControlSize: buttonSizeAdjust = 0; break; } borderRect = NSInsetRect(borderRect, xMargin+.5, yMargin+.5); if([self tabViewType] == NSTopTabsBezelBorder) { borderRect.origin.y += buttonSizeAdjust; borderRect.size.height -= buttonSizeAdjust; } else { borderRect.origin.y += -6; borderRect.size.height -= buttonSizeAdjust-6; } } else { float xMargin = 7; float topMargin = 4; float bottomMargin = 10; float buttonSizeAdjust = 0; switch([self controlSize]) { case NSRegularControlSize: buttonSizeAdjust = 8; break; case NSSmallControlSize: buttonSizeAdjust = 5; break; case NSMiniControlSize: buttonSizeAdjust = 2; break; } borderRect = NSInsetRect(borderRect, xMargin+.5, .5); borderRect.origin.y += topMargin; borderRect.size.height -= topMargin + bottomMargin; if([self tabViewType] == NSLeftTabsBezelBorder) borderRect.origin.x += buttonSizeAdjust; borderRect.size.width -= buttonSizeAdjust; } NSBezierPath *borderPath = [NSBezierPath bezierPathWithRoundedRect:borderRect cornerRadius:4]; [[NSColor colorWithCalibratedWhite:.75 alpha:1] set]; [borderPath stroke]; } @end