diff options
Diffstat (limited to 'frontends/cocoa/BlackScroller.m')
-rw-r--r-- | frontends/cocoa/BlackScroller.m | 178 |
1 files changed, 90 insertions, 88 deletions
diff --git a/frontends/cocoa/BlackScroller.m b/frontends/cocoa/BlackScroller.m index 025e3a955..df15e916f 100644 --- a/frontends/cocoa/BlackScroller.m +++ b/frontends/cocoa/BlackScroller.m @@ -25,130 +25,132 @@ @implementation BlackScroller -- (void) setFrame: (NSRect)frameRect +- (void)setFrame:(NSRect)frameRect { - [super setFrame: frameRect]; - if (tag != 0) [self removeTrackingRect: tag]; - tag = [self addTrackingRect: [self bounds] owner: self userData: NULL assumeInside: NO]; + [super setFrame:frameRect]; + if (tag != 0) + [self removeTrackingRect:tag]; + tag = [self addTrackingRect:[self bounds] owner:self userData:NULL assumeInside:NO]; } -- (void) drawRect: (NSRect)dirtyRect +- (void)drawRect:(NSRect)dirtyRect { - [[NSColor clearColor] set]; - [NSBezierPath fillRect: dirtyRect]; + [[NSColor clearColor] set]; + [NSBezierPath fillRect:dirtyRect]; - if (drawTrack) [self drawKnobSlotInRect: [self rectForPart: NSScrollerKnobSlot] - highlight: NO]; - [self drawKnob]; + if (drawTrack) + [self drawKnobSlotInRect:[self rectForPart:NSScrollerKnobSlot] + highlight:NO]; + [self drawKnob]; } -- (void) drawKnobSlotInRect: (NSRect)slotRect highlight: (BOOL)flag +- (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag { - slotRect = NSInsetRect( slotRect, 2, 2 ); - slotRect = [self.window convertRectToScreen: slotRect]; - slotRect.origin.x = floor( slotRect.origin.x ) + 0.5; - slotRect.origin.y = floor( slotRect.origin.y ) + 0.5; - slotRect.size.width = floor( slotRect.size.width ); - slotRect.size.height = floor( slotRect.size.height ); - slotRect = [self.window convertRectFromScreen: slotRect]; - - NSGradient *gradient = [[NSGradient alloc] initWithColorsAndLocations: - [NSColor clearColor], 0.0, - [NSColor clearColor], 0.4, - [NSColor whiteColor], 1.0, - nil]; - [[NSColor whiteColor] set]; - const float radius = 0.5 * ([self isHorizontal] ? NSHeight( slotRect ) : NSWidth( slotRect )); - NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: slotRect - xRadius: radius - yRadius: radius]; - [gradient drawInBezierPath: path angle: [self isHorizontal] ? 90 : 0]; - - [path stroke]; + slotRect = NSInsetRect(slotRect, 2, 2); + slotRect = [self.window convertRectToScreen:slotRect]; + slotRect.origin.x = floor(slotRect.origin.x) + 0.5; + slotRect.origin.y = floor(slotRect.origin.y) + 0.5; + slotRect.size.width = floor(slotRect.size.width); + slotRect.size.height = floor(slotRect.size.height); + slotRect = [self.window convertRectFromScreen:slotRect]; + + NSGradient *gradient = [[NSGradient alloc] initWithColorsAndLocations: + [NSColor clearColor], 0.0, + [NSColor clearColor], 0.4, + [NSColor whiteColor], 1.0, + nil]; + [[NSColor whiteColor] set]; + const float radius = 0.5 * ([self isHorizontal] ? NSHeight(slotRect) : NSWidth(slotRect)); + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:slotRect + xRadius:radius + yRadius:radius]; + [gradient drawInBezierPath:path angle:[self isHorizontal] ? 90 : 0]; + + [path stroke]; } - -- (NSUsableScrollerParts) usableParts +- (NSUsableScrollerParts)usableParts { - return NSScrollerKnob | NSScrollerKnobSlot; + return NSScrollerKnob | NSScrollerKnobSlot; } -- (void) drawKnob +- (void)drawKnob { - NSRect rect = NSInsetRect( [self rectForPart: NSScrollerKnob], 2, 2 ); - - rect = [self.window convertRectToScreen: rect]; - rect.origin.x = floor( rect.origin.x ) + 0.5; - rect.origin.y = floor( rect.origin.y ) + 0.5; - rect.size.width = floor( rect.size.width ); - rect.size.height = floor( rect.size.height ); - rect = [self.window convertRectFromScreen: rect]; - - [[NSColor colorWithDeviceWhite: 1.0 alpha: drawTrack ? 1.0 : 0.6] set]; - - const float radius = 0.5 * ([self isHorizontal] ? NSHeight( rect ) : NSWidth( rect )); - NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: rect - xRadius: radius - yRadius: radius]; - [path fill]; - [path stroke]; + NSRect rect = NSInsetRect([self rectForPart:NSScrollerKnob], 2, 2); + + rect = [self.window convertRectToScreen:rect]; + rect.origin.x = floor(rect.origin.x) + 0.5; + rect.origin.y = floor(rect.origin.y) + 0.5; + rect.size.width = floor(rect.size.width); + rect.size.height = floor(rect.size.height); + rect = [self.window convertRectFromScreen:rect]; + + [[NSColor colorWithDeviceWhite:1.0 alpha:drawTrack ? 1.0 : 0.6] set]; + + const float radius = 0.5 * ([self isHorizontal] ? NSHeight(rect) : NSWidth(rect)); + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect + xRadius:radius + yRadius:radius]; + [path fill]; + [path stroke]; } -- (NSRect) rectForPart: (NSScrollerPart)partCode +- (NSRect)rectForPart:(NSScrollerPart)partCode { - const bool horizontal = [self isHorizontal]; - - NSRect rect = horizontal ? NSInsetRect( [self bounds], 4, 0 ) : NSInsetRect( [self bounds], 0, 4 ); + const bool horizontal = [self isHorizontal]; - switch (partCode) { - case NSScrollerKnobSlot: - return rect; + NSRect rect = horizontal ? NSInsetRect([self bounds], 4, 0) : NSInsetRect([self bounds], 0, 4); - case NSScrollerKnob: { - const CGFloat len = horizontal ? NSWidth( rect ) : NSHeight( rect ); - CGFloat knobLen = [self knobProportion] * len; - const CGFloat minKnobLen = horizontal ? NSHeight( rect ) : NSWidth( rect ); - if (knobLen < minKnobLen) knobLen = minKnobLen; + switch (partCode) { + case NSScrollerKnobSlot: + return rect; - const CGFloat start = [self doubleValue] * (len - knobLen); + case NSScrollerKnob: { + const CGFloat len = horizontal ? NSWidth(rect) : NSHeight(rect); + CGFloat knobLen = [self knobProportion] * len; + const CGFloat minKnobLen = horizontal ? NSHeight(rect) : NSWidth(rect); + if (knobLen < minKnobLen) + knobLen = minKnobLen; - if (horizontal) { - rect.origin.x += start; - rect.size.width = knobLen; - } else { - rect.origin.y += start; - rect.size.height = knobLen; - } + const CGFloat start = [self doubleValue] * (len - knobLen); - return rect; + if (horizontal) { + rect.origin.x += start; + rect.size.width = knobLen; + } else { + rect.origin.y += start; + rect.size.height = knobLen; } - default: - return [super rectForPart: partCode]; - } + return rect; + } + + default: + return [super rectForPart:partCode]; + } } -- (BOOL) isOpaque +- (BOOL)isOpaque { - return NO; + return NO; } -- (BOOL) isHorizontal +- (BOOL)isHorizontal { - NSRect bounds = [self bounds]; - return NSWidth( bounds ) > NSHeight( bounds ); + NSRect bounds = [self bounds]; + return NSWidth(bounds) > NSHeight(bounds); } -- (void) mouseEntered: (NSEvent *)theEvent +- (void)mouseEntered:(NSEvent *)theEvent { - drawTrack = YES; - [self setNeedsDisplay: YES]; + drawTrack = YES; + [self setNeedsDisplay:YES]; } -- (void) mouseExited: (NSEvent *)theEvent +- (void)mouseExited:(NSEvent *)theEvent { - drawTrack = NO; - [self setNeedsDisplay: YES]; + drawTrack = NO; + [self setNeedsDisplay:YES]; } @end |