// Created by Abhishek Banthia on 11/4/15. // Copyright (c) 2015 Abhishek Banthia All rights reserved. // // Copyright (c) 2015, Abhishek Banthia // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation and/or // other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import "BackgroundView.h" #define FILL_OPACITY 0.9f #define STROKE_OPACITY 1.0f #define LINE_THICKNESS 1.0f #define CORNER_RADIUS 6.0f #define SEARCH_INSET 10.0f #import "ApplicationDelegate.h" #import "PanelController.h" #pragma mark - @implementation BackgroundView @synthesize arrowX = _arrowX; #pragma mark - - (void)drawRect:(NSRect)dirtyRect { NSRect contentRect = NSInsetRect([self bounds], LINE_THICKNESS, LINE_THICKNESS); NSBezierPath *path = [NSBezierPath bezierPath]; [path moveToPoint:NSMakePoint(_arrowX, NSMaxY(contentRect))]; [path lineToPoint:NSMakePoint(_arrowX + ARROW_WIDTH / 2, NSMaxY(contentRect) - ARROW_HEIGHT)]; [path lineToPoint:NSMakePoint(NSMaxX(contentRect) - CORNER_RADIUS, NSMaxY(contentRect) - ARROW_HEIGHT)]; NSPoint topRightCorner = NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT); [path curveToPoint:NSMakePoint(NSMaxX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT - CORNER_RADIUS) controlPoint1:topRightCorner controlPoint2:topRightCorner]; [path lineToPoint:NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect) + CORNER_RADIUS)]; NSPoint bottomRightCorner = NSMakePoint(NSMaxX(contentRect), NSMinY(contentRect)); [path curveToPoint:NSMakePoint(NSMaxX(contentRect) - CORNER_RADIUS, NSMinY(contentRect)) controlPoint1:bottomRightCorner controlPoint2:bottomRightCorner]; [path lineToPoint:NSMakePoint(NSMinX(contentRect) + CORNER_RADIUS, NSMinY(contentRect))]; [path curveToPoint:NSMakePoint(NSMinX(contentRect), NSMinY(contentRect) + CORNER_RADIUS) controlPoint1:contentRect.origin controlPoint2:contentRect.origin]; [path lineToPoint:NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT - CORNER_RADIUS)]; NSPoint topLeftCorner = NSMakePoint(NSMinX(contentRect), NSMaxY(contentRect) - ARROW_HEIGHT); [path curveToPoint:NSMakePoint(NSMinX(contentRect) + CORNER_RADIUS, NSMaxY(contentRect) - ARROW_HEIGHT) controlPoint1:topLeftCorner controlPoint2:topLeftCorner]; [path lineToPoint:NSMakePoint(_arrowX - ARROW_WIDTH / 2, NSMaxY(contentRect) - ARROW_HEIGHT)]; [path closePath]; [[NSColor colorWithDeviceWhite:1 alpha:FILL_OPACITY] setFill]; [path fill]; [NSGraphicsContext saveGraphicsState]; NSBezierPath *clip = [NSBezierPath bezierPathWithRect:[self bounds]]; [clip appendBezierPath:path]; [clip addClip]; [path setLineWidth:LINE_THICKNESS * 2]; [[NSColor whiteColor] setStroke]; [path stroke]; [NSGraphicsContext restoreGraphicsState]; } -(void)mouseEntered:(NSEvent *)theEvent { [super mouseEntered:theEvent]; ApplicationDelegate *delegate = (ApplicationDelegate*)[NSApplication sharedApplication].delegate; PanelController *controller = delegate.panelController; [controller showOptions:YES]; } -(void)mouseExited:(NSEvent *)theEvent { [super mouseExited:theEvent]; ApplicationDelegate *delegate = (ApplicationDelegate*) [NSApplication sharedApplication].delegate; PanelController *controller = delegate.panelController; [controller showOptions:NO]; } -(void)updateTrackingAreas { if(self.trackingArea != nil) { [self removeTrackingArea:self.trackingArea]; } int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways); self.trackingArea = [ [NSTrackingArea alloc] initWithRect:[self bounds] options:opts owner:self userInfo:nil]; [self addTrackingArea:self.trackingArea]; } #pragma mark - #pragma mark Public accessors - (void)setArrowX:(NSInteger)value { _arrowX = value; [self setNeedsDisplay:YES]; } @end