blob: 7963527000c1e509c4f5b33a3ba03db2ba4fe79a [file] [log] [blame]
Kateryna Kostiuk958cd072017-07-14 15:56:35 -04001/*
2 * Copyright (C) 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 "HoverButton.h"
21#import "NSColor+RingTheme.h"
22
23@implementation HoverButton
24
25-(void) awakeFromNib {
26 [super awakeFromNib];
27 if(!self.hoverColor) {
28 self.hoverColor = [NSColor ringBlue];
29 }
30 if(!self.mouseOutsideColor) {
31 self.mouseOutsideColor = [NSColor clearColor];
32 }
33 self.bgColor = self.mouseOutsideColor;
34}
35
36-(void)mouseEntered:(NSEvent *)theEvent {
37 self.bgColor = self.hoverColor;
38 [super setNeedsDisplay:YES];
39 [super mouseEntered:theEvent];
40}
41
42-(void)mouseExited:(NSEvent *)theEvent {
43 self.bgColor = self.mouseOutsideColor;
44 [super setNeedsDisplay:YES];
45 [super mouseExited:theEvent];
46}
47
48- (void)ensureTrackingArea {
49 if (trackingArea == nil) {
50 trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
51 options:NSTrackingInVisibleRect
52 | NSTrackingActiveAlways
53 | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
54 }
55}
56
57- (void)updateTrackingAreas {
58 [super updateTrackingAreas];
59 [self ensureTrackingArea];
60 if (![[self trackingAreas] containsObject:trackingArea]) {
61 [self addTrackingArea:trackingArea];
62 }
63}
64
65- (void)drawRect:(NSRect)dirtyRect
66{
67 [super drawRect:dirtyRect];
68}
69
70-(void)mouseDown:(NSEvent *)theEvent
71{
72 [super mouseDown:theEvent];
73 if(self.isEnabled) {
74 self.bgColor = self.mouseOutsideColor;
75 }
76}
77
78@end