File: GBDebuggerButton.m

package info (click to toggle)
sameboy 1.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 10,528 kB
  • sloc: ansic: 29,948; objc: 22,249; asm: 1,424; pascal: 1,373; makefile: 1,065; xml: 111
file content (49 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#import "GBDebuggerButton.h"

@implementation GBDebuggerButton
{
    NSTrackingArea *_trackingArea;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    self.toolTip = self.title;
    self.imagePosition = NSImageOnly; // Newer versions of AppKit refuse to respect the value from the nib file
    return self;
}

- (void)mouseEntered:(NSEvent *)event
{
    if (@available(macOS 10.10, *)) {
        NSDictionary *attributes = @{
            NSForegroundColorAttributeName: [NSColor colorWithWhite:1.0 alpha:0.5],
            NSFontAttributeName: self.textField.font
        };
        self.textField.placeholderAttributedString =
            [[NSAttributedString alloc] initWithString:self.alternateTitle attributes:attributes];
    }
}

- (void)mouseExited:(NSEvent *)event
{
    if (@available(macOS 10.10, *)) {
        if ([self.textField.placeholderAttributedString.string isEqualToString:self.alternateTitle]) {
            self.textField.placeholderAttributedString = nil;
        }
    }
}

- (void)updateTrackingAreas
{
    [super updateTrackingAreas];
    if (_trackingArea) {
        [self removeTrackingArea:_trackingArea];
    }
    
    _trackingArea = [ [NSTrackingArea alloc] initWithRect:[self bounds]
                                                  options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways
                                                    owner:self
                                                 userInfo:nil];
    [self addTrackingArea:_trackingArea];
}
@end