2020-09-07 18:30:31 +00:00
|
|
|
//
|
|
|
|
// EjectButton.m
|
|
|
|
// Ample
|
|
|
|
//
|
|
|
|
// Created by Kelvin Sherlock on 9/7/2020.
|
|
|
|
// Copyright © 2020 Kelvin Sherlock. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "EjectButton.h"
|
|
|
|
|
|
|
|
static NSImage *ejectImage = nil;
|
|
|
|
static NSImage *ejectHoverImage = nil;
|
|
|
|
|
|
|
|
@implementation EjectButton {
|
|
|
|
NSTrackingRectTag _tracking;
|
2020-09-07 19:01:36 +00:00
|
|
|
BOOL _mouse;
|
2020-09-07 18:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+(void)initialize {
|
|
|
|
// content tint only works with template images.
|
|
|
|
ejectImage = [NSImage imageNamed: @"eject-16x16"];
|
|
|
|
ejectHoverImage = [NSImage imageNamed: @"eject-hover-16x16"];
|
|
|
|
[ejectImage setTemplate: YES];
|
|
|
|
[ejectHoverImage setTemplate: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)awakeFromNib {
|
|
|
|
[super awakeFromNib];
|
|
|
|
[self setButtonType: NSButtonTypeMomentaryPushIn];
|
|
|
|
[self setImage: ejectImage];
|
|
|
|
[self setAlternateImage: ejectHoverImage];
|
2020-09-07 21:08:42 +00:00
|
|
|
// _tracking = [self addTrackingRect: [self bounds] owner: self userData: nil assumeInside: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)viewDidMoveToWindow {
|
|
|
|
if (!_tracking)
|
|
|
|
_tracking = [self addTrackingRect: [self bounds] owner: self userData: nil assumeInside: NO];
|
|
|
|
|
2020-09-07 18:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void)mouseEntered:(NSEvent *)event {
|
2020-09-07 19:01:36 +00:00
|
|
|
_mouse = YES;
|
2020-09-07 18:30:31 +00:00
|
|
|
if ([self isEnabled])
|
|
|
|
[self setImage: ejectHoverImage];
|
|
|
|
}
|
|
|
|
-(void)mouseExited:(NSEvent *)event {
|
2020-09-07 19:01:36 +00:00
|
|
|
_mouse = NO;
|
|
|
|
if ([self isEnabled])
|
|
|
|
[self setImage: ejectImage];
|
2020-09-07 18:30:31 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 19:01:36 +00:00
|
|
|
-(void)setEnabled:(BOOL)enabled {
|
|
|
|
[super setEnabled: enabled];
|
|
|
|
if (_mouse) {
|
|
|
|
[self setImage: enabled ? ejectHoverImage : ejectImage];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-07 18:30:31 +00:00
|
|
|
@end
|