Kateryna Kostiuk | 58276bc | 2017-06-07 08:50:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015-2017 Savoir-faire Linux Inc. |
| 3 | * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | |
| 20 | #import "MessageBubbleView.h" |
| 21 | #import <CoreGraphics/CoreGraphics.h> |
| 22 | #import <QuartzCore/QuartzCore.h> |
| 23 | #import "NSColor+RingTheme.h" |
| 24 | |
| 25 | @implementation MessageBubbleView |
| 26 | |
| 27 | - (void)drawRect:(NSRect)dirtyRect { |
| 28 | [super drawRect:dirtyRect]; |
| 29 | CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; |
| 30 | CGContextSetRGBFillColor(context, 1, 1, 1, 1); |
| 31 | CGFloat radius = 6; |
| 32 | CGFloat minx = CGRectGetMinX(dirtyRect), midx = CGRectGetMidX(dirtyRect), maxx = CGRectGetMaxX(dirtyRect); |
| 33 | CGFloat miny = CGRectGetMinY(dirtyRect), midy = CGRectGetMidY(dirtyRect), maxy = CGRectGetMaxY(dirtyRect); |
| 34 | |
| 35 | CGMutablePathRef outlinePath = CGPathCreateMutable(); |
| 36 | |
| 37 | if (self.pointerDirection == LEFT) |
| 38 | { |
| 39 | minx += 6; |
| 40 | CGPathMoveToPoint(outlinePath, nil, midx, miny); |
| 41 | CGPathAddArcToPoint(outlinePath, nil, maxx, miny, maxx, midy, radius); |
| 42 | CGPathAddArcToPoint(outlinePath, nil, maxx, maxy, midx, maxy, radius); |
| 43 | CGPathAddArcToPoint(outlinePath, nil, minx, maxy, minx, midy, radius); |
| 44 | if(self.needPointer) { |
| 45 | CGPathAddLineToPoint(outlinePath, nil, minx, maxy - 20); |
| 46 | CGPathAddLineToPoint(outlinePath, nil, minx - 6, maxy - 15); |
| 47 | CGPathAddLineToPoint(outlinePath, nil, minx, maxy - 10); |
| 48 | } |
| 49 | |
| 50 | CGPathAddArcToPoint(outlinePath, nil, minx, miny, midx, miny, radius); |
| 51 | CGPathCloseSubpath(outlinePath); |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | maxx-=6; |
| 56 | CGPathMoveToPoint(outlinePath, nil, midx, miny); |
| 57 | CGPathAddArcToPoint(outlinePath, nil, minx, miny, minx, midy, radius); |
| 58 | CGPathAddArcToPoint(outlinePath, nil, minx, maxy, midx, maxy, radius); |
| 59 | CGPathAddArcToPoint(outlinePath, nil, maxx, maxy, maxx, midy, radius); |
| 60 | if(self.needPointer) { |
| 61 | CGPathAddLineToPoint(outlinePath, nil, maxx, maxy - 20); |
| 62 | CGPathAddLineToPoint(outlinePath, nil, maxx + 6, maxy - 15); |
| 63 | CGPathAddLineToPoint(outlinePath, nil, maxx, maxy - 10); |
| 64 | } |
| 65 | CGPathAddArcToPoint(outlinePath, nil, maxx, miny, midx, miny, radius); |
| 66 | CGPathCloseSubpath(outlinePath); |
| 67 | } |
Kateryna Kostiuk | 58276bc | 2017-06-07 08:50:48 -0400 | [diff] [blame] | 68 | CGContextAddPath(context, outlinePath); |
| 69 | CGContextFillPath(context); |
| 70 | |
| 71 | CGContextAddPath(context, outlinePath); |
| 72 | CGContextClip(context); |
| 73 | if(self.bgColor) { |
| 74 | CGContextSetFillColorWithColor(context, self.bgColor.CGColor); |
| 75 | CGContextStrokePath(context); |
| 76 | NSRectFill(dirtyRect); |
| 77 | } |
| 78 | } |
| 79 | @end |