Skip to content

Commit 68fadb9

Browse files
committed
Use Core Animation to fade out tooltips
This code was based on recent changes (db2c7982929a16da8abf9a0da20ac0b1ccccad01) made to OakToolTip in the main TextMate repository.
1 parent 813a177 commit 68fadb9

File tree

3 files changed

+14
-42
lines changed

3 files changed

+14
-42
lines changed

Commands/tooltip/TMDHTMLTips.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
{
1212
WebView* webView;
1313
WebPreferences* webPreferences;
14-
NSTimer* animationTimer;
15-
NSDate* animationStart;
1614

1715
NSDate* didOpenAtDate; // ignore mouse moves for the next second
1816
NSPoint mousePositionWhenOpened;

Commands/tooltip/TMDHTMLTips.mm

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@
1212
"$DIALOG" tooltip --html '<h1>‘foobar’</h1>'
1313
*/
1414

15-
static CGFloat slow_in_out (CGFloat t)
16-
{
17-
if(t < 1.0)
18-
t = 1.0 / (1.0 + exp((-t*12.0)+6.0));
19-
return std::min(t, 1.0);
20-
}
21-
2215
NSString* const TMDTooltipPreferencesIdentifier = @"TM Tooltip";
2316

2417
@interface TMDHTMLTip ()
2518
- (void)setContent:(NSString*)content transparent:(BOOL)transparent;
2619
- (void)runUntilUserActivity:(id)sender;
27-
- (void)stopAnimation:(id)sender;
2820
@end
2921

3022
@implementation TMDHTMLTip
@@ -200,45 +192,27 @@ - (void)runUntilUserActivity:(id)sender
200192
[keyWindow setAcceptsMouseMovedEvents:didAcceptMouseMovedEvents];
201193

202194

203-
[self orderOut:self];
195+
[self fadeOut:self];
204196
}
205197

206198
// =============
207199
// = Animation =
208200
// =============
209-
- (void)orderOut:(id)sender
201+
- (void)fadeOut:(id)sender
210202
{
211-
if(![self isVisible] || animationTimer)
212-
return;
203+
[NSAnimationContext beginGrouping];
213204

214-
[self stopAnimation:self];
215-
[self setValue:[NSDate date] forKey:@"animationStart"];
216-
[self setValue:[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(animationTick:) userInfo:nil repeats:YES] forKey:@"animationTimer"];
217-
}
205+
[NSAnimationContext currentContext].duration = 0.5;
206+
[NSAnimationContext currentContext].completionHandler = ^{
207+
[self orderOut:self];
208+
};
218209

219-
- (void)animationTick:(id)sender
220-
{
221-
CGFloat alpha = 0.97 * (1.0 - slow_in_out(-1.5 * [animationStart timeIntervalSinceNow]));
222-
if(alpha > 0.0)
223-
{
224-
[self setAlphaValue:alpha];
225-
}
226-
else
227-
{
228-
[super orderOut:self];
229-
[self stopAnimation:self];
230-
[self close];
231-
}
232-
}
210+
CABasicAnimation* anim = [CABasicAnimation animation];
211+
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
212+
self.animations = @{ @"alphaValue" : anim };
233213

234-
- (void)stopAnimation:(id)sender;
235-
{
236-
if(animationTimer)
237-
{
238-
[animationTimer invalidate];
239-
[self setValue:nil forKey:@"animationTimer"];
240-
[self setValue:nil forKey:@"animationStart"];
241-
[self setAlphaValue:0.97];
242-
}
214+
[self.animator setAlphaValue:0];
215+
216+
[NSAnimationContext endGrouping];
243217
}
244218
@end

plugin.target

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ PLIST_FLAGS += -d'EXECUTABLE_NAME=Dialog2' -d'PRODUCT_NAME=Dialog2'
88
BUNDLE_EXTENSION = tmplugin
99
LN_FLAGS += -bundle
1010

11-
FRAMEWORKS = Cocoa Carbon WebKit
11+
FRAMEWORKS = Cocoa Carbon WebKit Quartz

0 commit comments

Comments
 (0)