Skip to content
Permalink
Browse files

Update tab view drawing to match the style used by 10.12's automatic …

…tabs and remove unused tab styles.

Issues still to address:

	- Add tab button does not darken when moused over
	- The tab overflow button is being clipped and the image is not high res
  • Loading branch information
stuconnolly committed Mar 26, 2017
1 parent 2aad505 commit 044789b21056562bacd81fa6aafd76c091f00d69
@@ -24,11 +24,11 @@
- (nullable NSImage *)rolloverImage;

// tracking rect for mouse events
- (void)rolloverFrameDidChange:(nonnull NSNotification *)inNotification;
- (void)rolloverFrameDidChange:(nonnull NSNotification *)notification;
- (void)addTrackingRect;
- (void)removeTrackingRect;

- (void)mouseEntered:(nullable NSEvent *)theEvent;
- (void)mouseExited:(nullable NSEvent *)theEvent;
- (void)mouseEntered:(nullable NSEvent *)event;
- (void)mouseExited:(nullable NSEvent *)event;

@end
@@ -20,6 +20,7 @@ - (void)awakeFromNib
selector:@selector(rolloverFrameDidChange:)
name:NSViewFrameDidChangeNotification
object:self];

[self setPostsFrameChangedNotifications:YES];
[self resetCursorRects];

@@ -28,17 +29,6 @@ - (void)awakeFromNib
_usualImage = nil;
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];

[self removeTrackingRect];
[_rolloverImage release];
[_usualImage release];

[super dealloc];
}

// the regular image
- (void)setUsualImage:(NSImage *)newImage
{
@@ -66,7 +56,7 @@ - (NSImage *)rolloverImage
return _rolloverImage;
}

//Remove old tracking rects when we change superviews
// Remove old tracking rects when we change superviews
- (void)viewWillMoveToSuperview:(NSView *)newSuperview
{
[self removeTrackingRect];
@@ -95,7 +85,7 @@ - (void)viewDidMoveToWindow
[self resetCursorRects];
}

- (void)rolloverFrameDidChange:(NSNotification *)inNotification
- (void)rolloverFrameDidChange:(NSNotification *)notification
{
[self resetCursorRects];
}
@@ -104,40 +94,46 @@ - (void)addTrackingRect
{
// assign a tracking rect to watch for mouse enter/exit
NSRect trackRect = [self bounds];
NSPoint localPoint = [self convertPoint:[[self window] convertScreenToBase:[NSEvent mouseLocation]]
fromView:nil];
BOOL mouseInside = NSPointInRect(localPoint, trackRect);
NSPoint localPoint = [self convertPoint:[[self window] convertScreenToBase:[NSEvent mouseLocation]] fromView:nil];

BOOL mouseInside = NSPointInRect(localPoint, trackRect);

_myTrackingRectTag = [self addTrackingRect:trackRect owner:self userData:nil assumeInside:mouseInside];
if (mouseInside)

if (mouseInside) {
[self mouseEntered:nil];
else
}
else {
[self mouseExited:nil];
}
}

- (void)removeTrackingRect
{
if (_myTrackingRectTag != -1) {
[self removeTrackingRect:_myTrackingRectTag];
}

_myTrackingRectTag = -1;
}

// override for rollover effect
- (void)mouseEntered:(nullable NSEvent *)theEvent
- (void)mouseEntered:(nullable NSEvent *)event
{
// set rollover image
[self setImage:_rolloverImage];

[super mouseEntered:theEvent];
[super mouseEntered:event];
}

- (void)mouseExited:(nullable NSEvent *)theEvent
- (void)mouseExited:(nullable NSEvent *)event
{
// restore usual image
[self setImage:_usualImage];

[super mouseExited:theEvent];
[self setHighlighted:NO];

[super mouseExited:event];
}

- (void)resetCursorRects
@@ -162,26 +158,42 @@ - (void)setBounds:(NSRect)rect
#pragma mark -
#pragma mark Archiving

- (void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder:aCoder];
if ([aCoder allowsKeyedCoding]) {
[aCoder encodeObject:_rolloverImage forKey:@"rolloverImage"];
[aCoder encodeObject:_usualImage forKey:@"usualImage"];
[aCoder encodeInteger:_myTrackingRectTag forKey:@"myTrackingRectTag"];
- (void)encodeWithCoder:(NSCoder *)coder
{
[super encodeWithCoder:coder];

if ([coder allowsKeyedCoding]) {
[coder encodeObject:_rolloverImage forKey:@"rolloverImage"];
[coder encodeObject:_usualImage forKey:@"usualImage"];
[coder encodeInteger:_myTrackingRectTag forKey:@"myTrackingRectTag"];
}
}

- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
if ([aDecoder allowsKeyedCoding]) {
_rolloverImage = [[aDecoder decodeObjectForKey:@"rolloverImage"] retain];
_usualImage = [[aDecoder decodeObjectForKey:@"usualImage"] retain];
_myTrackingRectTag = [aDecoder decodeIntegerForKey:@"myTrackingRectTag"];
- (id)initWithCoder:(NSCoder *)decoder
{
if ((self = [super initWithCoder:decoder])) {
if ([decoder allowsKeyedCoding]) {
_rolloverImage = [[decoder decodeObjectForKey:@"rolloverImage"] retain];
_usualImage = [[decoder decodeObjectForKey:@"usualImage"] retain];
_myTrackingRectTag = [decoder decodeIntegerForKey:@"myTrackingRectTag"];
}
}

return self;
}

#pragma mark -

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];

[self removeTrackingRect];

[_rolloverImage release];
[_usualImage release];

[super dealloc];
}

@end
@@ -432,8 +432,11 @@ - (NSImage *)dragImage
[image lockFocusFlipped:YES];
#endif
[self setFrame:tabDrawFrame];
[(id <PSMTabStyle>)[(PSMTabBarControl *)_customControlView style] drawTabCell:self];

[(id <PSMTabStyle>)[(PSMTabBarControl *)_customControlView style] drawTabCellForDragImage:self];

[self setFrame:oldFrame];

[image unlockFocus];

// Add the indicator if appropriate
@@ -15,13 +15,16 @@
#define PSMTabDragDidEndNotification @"PSMTabDragDidEndNotification"
#define PSMTabDragDidBeginNotification @"PSMTabDragDidBeginNotification"

#define kPSMTabBarControlHeight 34
#define kPSMTabBarControlHeight 25
#define kPSMTabBarControlDefaultHeightCollapsed 0 // can be changed with a property

// internal cell border
#define MARGIN_X 6
#define MARGIN_Y 5
#define MARGIN_Y 6

// padding between objects
#define kPSMTabBarCellPadding 4

// fixed size objects
#define kPSMMinimumTitleWidth 30
#define kPSMTabBarIndicatorWidth 16.0f
@@ -48,13 +51,13 @@ typedef enum {
} PSMTabBarTearOffStyle;

enum {
PSMTab_SelectedMask = 1 << 1,
PSMTab_LeftIsSelectedMask = 1 << 2,
PSMTab_RightIsSelectedMask = 1 << 3,
PSMTab_SelectedMask = 1 << 1,
PSMTab_LeftIsSelectedMask = 1 << 2,
PSMTab_RightIsSelectedMask = 1 << 3,
PSMTab_PositionLeftMask = 1 << 4,
PSMTab_PositionMiddleMask = 1 << 5,
PSMTab_PositionRightMask = 1 << 6,
PSMTab_PositionSingleMask = 1 << 7
PSMTab_PositionMiddleMask = 1 << 5,
PSMTab_PositionRightMask = 1 << 6,
PSMTab_PositionSingleMask = 1 << 7
};

@interface PSMTabBarControl : NSControl {
@@ -11,11 +11,6 @@
#import "PSMOverflowPopUpButton.h"
#import "PSMRolloverButton.h"
#import "PSMTabStyle.h"
#import "PSMMetalTabStyle.h"
#import "PSMAquaTabStyle.h"
#import "PSMUnifiedTabStyle.h"
#import "PSMCardTabStyle.h"
#import "PSMAdiumTabStyle.h"
#import "PSMSequelProTabStyle.h"
#import "PSMTabDragAssistant.h"
#import "PSMTabBarController.h"
@@ -161,6 +156,7 @@ - (void)initAddedProperties
// new tab button
NSRect addTabButtonRect = NSMakeRect([self frame].size.width - [style rightMarginForTabBarControl] + 1, 3.0f, 16.0f, 16.0f);
_addTabButton = [[PSMRolloverButton alloc] initWithFrame:addTabButtonRect];

if (_addTabButton) {
NSImage *newButtonImage = [style addTabButtonImage];
if (newButtonImage) {
@@ -369,31 +365,16 @@ - (void)setStyle:(id <PSMTabStyle>)newStyle
- (void)setStyleNamed:(NSString *)name
{
id <PSMTabStyle> newStyle;

/* if ([name isEqualToString:@"Aqua"]) {
newStyle = [[PSMAquaTabStyle alloc] init];
} else if ([name isEqualToString:@"Unified"]) {
newStyle = [[PSMUnifiedTabStyle alloc] init];
} else if ([name isEqualToString:@"Adium"]) {
newStyle = [[PSMAdiumTabStyle alloc] init];
} else if ([name isEqualToString:@"Card"]) {
newStyle = [[PSMCardTabStyle alloc] init];
} else if ([name isEqualToString:@"Metal"]) {
newStyle = [[PSMMetalTabStyle alloc] init];

} else */
if ([name isEqualToString:@"SequelPro"]) {
newStyle = [[PSMSequelProTabStyle alloc] init];

} else {
}
else {
newStyle = [[PSMSequelProTabStyle alloc] init];
}

[self setStyle:newStyle];

[newStyle release];
}

@@ -214,7 +214,7 @@ - (void)layoutCells
_addButtonRect.size = [[_control addTabButton] frame].size;
if ([_control orientation] == PSMTabBarHorizontalOrientation) {
_addButtonRect.origin.y = MARGIN_Y;
_addButtonRect.origin.x += [[cellWidths valueForKeyPath:@"@sum.floatValue"] floatValue] + MARGIN_X;
_addButtonRect.origin.x += [[cellWidths valueForKeyPath:@"@sum.floatValue"] floatValue] + MARGIN_X;
} else {
_addButtonRect.origin.x = 0;
_addButtonRect.origin.y = [[cellWidths lastObject] floatValue];
@@ -34,7 +34,9 @@ - (void)drawRect:(NSRect)rect {
srcRect.size = [_image size];

[_image drawInRect:[self bounds] fromRect:srcRect operation:NSCompositeSourceOver fraction:primaryAlpha];

srcRect.size = [_alternateImage size];

[_alternateImage drawInRect:[self bounds] fromRect:srcRect operation:NSCompositeSourceOver fraction:alternateAlpha];
}

@@ -7,8 +7,10 @@
//

/*
Protocol to be observed by all style delegate objects. These objects handle the drawing responsibilities for PSMTabBarCell; once the control has been assigned a style, the background and cells draw consistent with that style. Design pattern and implementation by David Smith, Seth Willits, and Chris Forsythe, all touch up and errors by John P. :-)
*/
* Protocol to be observed by all style delegate objects.
* These objects handle the drawing responsibilities for PSMTabBarCell; once the control has been assigned a style, the background and cells draw consistent with that style.
* Design pattern and implementation by David Smith, Seth Willits, and Chris Forsythe, all touch up and errors by John P. :-)
*/

#import "PSMTabBarCell.h"
#import "PSMTabBarControl.h"
@@ -45,6 +47,7 @@ Protocol to be observed by all style delegate objects. These objects handle the

// drawing
- (void)drawTabCell:(PSMTabBarCell *)cell;
- (void)drawTabCellForDragImage:(PSMTabBarCell *)cell;
- (void)drawBackgroundInRect:(NSRect)rect;
- (void)drawTabBar:(PSMTabBarControl *)bar inRect:(NSRect)rect;

This file was deleted.

0 comments on commit 044789b

Please sign in to comment.
You can’t perform that action at this time.