Skip to content

Commit

Permalink
Update tab view drawing to match the style used by 10.12's automatic …
Browse files Browse the repository at this point in the history
…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 044789b
Show file tree
Hide file tree
Showing 23 changed files with 299 additions and 4,065 deletions.
6 changes: 3 additions & 3 deletions Frameworks/PSMTabBar/PSMRolloverButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
82 changes: 47 additions & 35 deletions Frameworks/PSMTabBar/PSMRolloverButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ - (void)awakeFromNib
selector:@selector(rolloverFrameDidChange:)
name:NSViewFrameDidChangeNotification
object:self];

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

Expand All @@ -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
{
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -95,7 +85,7 @@ - (void)viewDidMoveToWindow
[self resetCursorRects];
}

- (void)rolloverFrameDidChange:(NSNotification *)inNotification
- (void)rolloverFrameDidChange:(NSNotification *)notification
{
[self resetCursorRects];
}
Expand All @@ -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
Expand All @@ -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
5 changes: 4 additions & 1 deletion Frameworks/PSMTabBar/PSMTabBarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions Frameworks/PSMTabBar/PSMTabBarControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
27 changes: 4 additions & 23 deletions Frameworks/PSMTabBar/PSMTabBarControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
}

Expand Down
2 changes: 1 addition & 1 deletion Frameworks/PSMTabBar/PSMTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions Frameworks/PSMTabBar/PSMTabDragView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
7 changes: 5 additions & 2 deletions Frameworks/PSMTabBar/PSMTabStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down
39 changes: 0 additions & 39 deletions Frameworks/PSMTabBar/Styles/PSMAdiumTabStyle.h

This file was deleted.

Loading

0 comments on commit 044789b

Please sign in to comment.