├── BBListView.h ├── BBListView.m ├── BBSubtleScroller.h ├── BBSubtleScroller.m └── README.md /BBListView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBListView.h 3 | // Hawler 4 | // 5 | // Created by Oliver Relph & Jean-Nicolas Jolivet on 21/03/2011. 6 | // Copyright 2011 BAMBAMBAM & Silver Cocoa. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "PXListView.h" 12 | 13 | 14 | @interface BBListView : PXListView { 15 | 16 | NSTrackingArea *trackingArea; 17 | 18 | @private 19 | 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /BBListView.m: -------------------------------------------------------------------------------- 1 | // 2 | // BBListView.m 3 | // Hawler 4 | // 5 | // Created by Oliver Relph & Jean-Nicolas Jolivet on 21/03/2011. 6 | // Copyright 2011 BAMBAMBAM & Silver Cocoa. All rights reserved. 7 | // 8 | 9 | #import "BBListView.h" 10 | 11 | 12 | @implementation BBListView 13 | 14 | - (id)init 15 | { 16 | self = [super init]; 17 | if (self) { 18 | // Initialization code here. 19 | } 20 | 21 | return self; 22 | } 23 | 24 | - (void)dealloc 25 | { 26 | [super dealloc]; 27 | } 28 | 29 | - (void)viewDidMoveToWindow 30 | { 31 | 32 | if (trackingArea == nil) { 33 | trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] 34 | options:NSTrackingMouseMoved+NSTrackingActiveInKeyWindow+NSTrackingMouseEnteredAndExited 35 | owner:self 36 | userInfo:nil]; 37 | [self addTrackingArea:trackingArea]; 38 | [self becomeFirstResponder]; 39 | } 40 | 41 | } 42 | 43 | #pragma mark - 44 | #pragma mark Drawing 45 | 46 | - (NSRect)contentViewRect 47 | { 48 | NSRect frame = [self frame]; 49 | NSSize frameSize = NSMakeSize(NSWidth(frame), NSHeight(frame)); 50 | NSSize availableSize = [[self class] contentSizeForFrameSize:frameSize 51 | hasHorizontalScroller:NO 52 | hasVerticalScroller:NO 53 | borderType:[self borderType]]; 54 | 55 | return NSMakeRect(0.0f, 0.0f, availableSize.width, availableSize.height); 56 | } 57 | 58 | - (void)tile 59 | { 60 | [super tile]; 61 | 62 | [self setAutohidesScrollers:NO]; 63 | 64 | [[self verticalScroller] removeFromSuperview]; 65 | [[self contentView] setFrame:[self bounds]]; 66 | [self addSubview:[self verticalScroller]]; 67 | 68 | [[self verticalScroller] setHidden:YES]; 69 | } 70 | #pragma mark - 71 | #pragma mark Animation 72 | 73 | - (void)showControls:(bool)show 74 | { 75 | CATransition *transition = [CATransition animation]; 76 | transition.duration = 0.5; 77 | transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 78 | 79 | transition.type = kCATransitionFade; 80 | 81 | [[[self verticalScroller] layer] addAnimation:transition forKey:nil]; 82 | 83 | [[self verticalScroller] setHidden:!show]; 84 | 85 | } 86 | 87 | 88 | #pragma mark - 89 | #pragma mark Mouse Tracking 90 | 91 | -(void)mouseEntered:(NSEvent *)theEvent 92 | { 93 | 94 | [self showControls:YES]; 95 | 96 | } 97 | 98 | -(void)mouseExited:(NSEvent *)theEvent 99 | { 100 | 101 | [self showControls:NO]; 102 | 103 | } 104 | 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /BBSubtleScroller.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBSubtleScroller.h 3 | // Hawler 4 | // 5 | // Created by Oliver Relph & Jean-Nicolas Jolivet on 21/03/2011. 6 | // Copyright 2011 BAMBAMBAM & Silver Cocoa. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface BBSubtleScroller : NSScroller { 13 | @private 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /BBSubtleScroller.m: -------------------------------------------------------------------------------- 1 | // 2 | // BBSubtleScroller.m 3 | // Hawler 4 | // 5 | // Created by Oliver Relph & Jean-Nicolas Jolivet on 21/03/2011. 6 | // Copyright 2011 BAMBAMBAM & Silver Cocoa. All rights reserved. 7 | // 8 | 9 | #import "BBSubtleScroller.h" 10 | 11 | 12 | @implementation BBSubtleScroller 13 | 14 | - (id)initWithCoder:(NSCoder *)aDecoder 15 | { 16 | 17 | self = [super initWithCoder:aDecoder]; 18 | if (self) { 19 | 20 | 21 | } 22 | 23 | return self; 24 | 25 | } 26 | 27 | + (CGFloat) scrollerWidth 28 | { 29 | return 5; 30 | } 31 | 32 | + (CGFloat) scrollerWidthForControlSize:(NSControlSize)controlSize 33 | { 34 | return 5; 35 | } 36 | 37 | - (void)drawRect:(NSRect)rect 38 | { 39 | [self drawKnob]; 40 | } 41 | 42 | - (void) drawBackground:(NSRect) rect 43 | { 44 | NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:0 yRadius:0]; 45 | [[NSColor clearColor] set]; 46 | [path fill]; 47 | } 48 | 49 | - (void)drawKnob 50 | { 51 | [self drawBackground:[self rectForPart:0]]; 52 | [self drawBackground:[self rectForPart:1]]; 53 | [self drawBackground:[self rectForPart:2]]; 54 | [self drawBackground:[self rectForPart:4]]; 55 | [self drawBackground:[self rectForPart:5]]; 56 | [self drawBackground:[self rectForPart:6]]; 57 | 58 | NSRect knobRect = [self rectForPart:NSScrollerKnob]; 59 | NSRect newRect = NSMakeRect((knobRect.size.width - [BBSubtleScroller scrollerWidth]) / 2, knobRect.origin.y, [BBSubtleScroller scrollerWidth], knobRect.size.height); 60 | NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:newRect xRadius:3 yRadius:3]; 61 | [[NSColor colorWithCalibratedWhite:255 alpha:1] set]; 62 | [path fill]; 63 | } 64 | 65 | @end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A custom NSScroller implementation specifically for PXListview 2 | --------------------------------------------------------------------------------