-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
TPHotBorderView.m
137 lines (112 loc) · 2.48 KB
/
TPHotBorderView.m
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// TPHotBorderView.m
// teleport
//
// Created by JuL on 08/02/05.
// Copyright 2003-2005 abyssoft. All rights reserved.
//
#import "TPHotBorderView.h"
#import "TPPreferencesManager.h"
#import "TPHotBorder.h"
NSColor * _highlightColor = nil;
NSColor * _transparentColor = nil;
NSColor * _visibleColor = nil;
#define ANIMATION_TIME 2.0
@implementation TPHotBorderView
+ (void)initialize
{
if(self == [TPHotBorderView class]) {
_highlightColor = [NSColor redColor];
_visibleColor = [NSColor blueColor];
_transparentColor = nil;
}
}
- (NSColor*)normalColor
{
static NSColor * _normalColor = nil;
if(_normalColor == nil) {
if(DEBUG_HOTBORDER || [[TPPreferencesManager sharedPreferencesManager] boolForPref:@"visibleBorders"])
_normalColor = _visibleColor;
else
_normalColor = _transparentColor;
}
return _normalColor;
}
- (instancetype)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setColor:[self normalColor]];
_animationTimer = nil;
}
return self;
}
- (void)dealloc
{
if(_animationTimer) {
[_animationTimer invalidate];
}
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
return [(id)[self window] draggingEntered:sender];
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
[(id)[self window] draggingExited:sender];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
PRINT_ME;
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
PRINT_ME;
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
PRINT_ME;
}
- (void)fireAtLocation:(NSPoint)location
{
if(_animationTimer) {
[_animationTimer invalidate];
_animationTimer = nil;
}
NSDate * now = [[NSDate alloc] init];
_animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(_animationStep) userInfo:now repeats:YES];
}
- (void)_animationStep
{
NSDate * start = [_animationTimer userInfo];
NSTimeInterval elapsed = - [start timeIntervalSinceNow];
float progress = elapsed / ANIMATION_TIME;
if(progress >= 1.0) {
[self stopAnimation];
}
else {
[self setColor:[_highlightColor blendedColorWithFraction:progress ofColor:[self normalColor]]];
}
[self display];
}
- (void)setColor:(NSColor*)color
{
if(color != _color) {
_color = color;
}
}
- (void)stopAnimation
{
[_animationTimer invalidate];
_animationTimer = nil;
[self setColor:[self normalColor]];
[self window];
}
- (void)drawRect:(NSRect)rect
{
[_color set];
NSRectFill(rect);
}
@end