diff options
Diffstat (limited to 'frontends/cocoa/PSMTabBarControl/PSMTabDragWindowController.m')
-rw-r--r-- | frontends/cocoa/PSMTabBarControl/PSMTabDragWindowController.m | 149 |
1 files changed, 78 insertions, 71 deletions
diff --git a/frontends/cocoa/PSMTabBarControl/PSMTabDragWindowController.m b/frontends/cocoa/PSMTabBarControl/PSMTabDragWindowController.m index 59e52deb7..78b0fcb2c 100644 --- a/frontends/cocoa/PSMTabBarControl/PSMTabDragWindowController.m +++ b/frontends/cocoa/PSMTabBarControl/PSMTabDragWindowController.m @@ -12,91 +12,98 @@ @implementation PSMTabDragWindowController -- (id)initWithImage:(NSImage *)image styleMask:(NSUInteger)styleMask tearOffStyle:(PSMTabBarTearOffStyle)tearOffStyle { - PSMTabDragWindow *window = [PSMTabDragWindow dragWindowWithImage:image styleMask:styleMask]; - if((self = [super initWithWindow:window])) { - _view = [window dragView] ; - _tearOffStyle = tearOffStyle; - - if(tearOffStyle == PSMTabBarTearOffMiniwindow) { - [window setBackgroundColor:[NSColor clearColor]]; - [window setHasShadow:YES]; - } - - [window setAlphaValue:kPSMTabDragWindowAlpha]; - } - return self; +- (id)initWithImage:(NSImage *)image styleMask:(NSUInteger)styleMask tearOffStyle:(PSMTabBarTearOffStyle)tearOffStyle +{ + PSMTabDragWindow *window = [PSMTabDragWindow dragWindowWithImage:image styleMask:styleMask]; + if ((self = [super initWithWindow:window])) { + _view = [window dragView]; + _tearOffStyle = tearOffStyle; + + if (tearOffStyle == PSMTabBarTearOffMiniwindow) { + [window setBackgroundColor:[NSColor clearColor]]; + [window setHasShadow:YES]; + } + + [window setAlphaValue:kPSMTabDragWindowAlpha]; + } + return self; } -- (void)dealloc { - [_timer invalidate]; - +- (void)dealloc +{ + [_timer invalidate]; } -- (NSImage *)image { - return [_view image]; +- (NSImage *)image +{ + return [_view image]; } -- (NSImage *)alternateImage { - return [_view alternateImage]; +- (NSImage *)alternateImage +{ + return [_view alternateImage]; } -- (void)setAlternateImage:(NSImage *)image { - [_view setAlternateImage:image]; +- (void)setAlternateImage:(NSImage *)image +{ + [_view setAlternateImage:image]; } -- (BOOL)isAnimating { - return _animation != nil; +- (BOOL)isAnimating +{ + return _animation != nil; } -- (void)switchImages { - if(_tearOffStyle != PSMTabBarTearOffMiniwindow || ![_view alternateImage]) { - return; - } - - CGFloat progress = 0; - _showingAlternate = !_showingAlternate; - - if(_animation) { - //An animation already exists, get the current progress - progress = 1.0f - [_animation currentProgress]; - [_animation stopAnimation]; - } - - //begin animating - _animation = [[NSAnimation alloc] initWithDuration:0.25 animationCurve:NSAnimationEaseInOut]; - [_animation setAnimationBlockingMode:NSAnimationNonblocking]; - [_animation setCurrentProgress:progress]; - [_animation startAnimation]; - - _originalWindowFrame = [[self window] frame]; - - if(_timer) { - [_timer invalidate]; - } - _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f / 30.0f target:self selector:@selector(animateTimer:) userInfo:nil repeats:YES]; +- (void)switchImages +{ + if (_tearOffStyle != PSMTabBarTearOffMiniwindow || ![_view alternateImage]) { + return; + } + + CGFloat progress = 0; + _showingAlternate = !_showingAlternate; + + if (_animation) { + //An animation already exists, get the current progress + progress = 1.0f - [_animation currentProgress]; + [_animation stopAnimation]; + } + + //begin animating + _animation = [[NSAnimation alloc] initWithDuration:0.25 animationCurve:NSAnimationEaseInOut]; + [_animation setAnimationBlockingMode:NSAnimationNonblocking]; + [_animation setCurrentProgress:progress]; + [_animation startAnimation]; + + _originalWindowFrame = [[self window] frame]; + + if (_timer) { + [_timer invalidate]; + } + _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f / 30.0f target:self selector:@selector(animateTimer:) userInfo:nil repeats:YES]; } -- (void)animateTimer:(NSTimer *)timer { - NSRect frame = _originalWindowFrame; - NSImage *currentImage = _showingAlternate ?[_view alternateImage] :[_view image]; - NSSize size = [currentImage size]; - NSPoint mousePoint = [NSEvent mouseLocation]; - CGFloat animationValue = [_animation currentValue]; - - frame.size.width = _originalWindowFrame.size.width + (size.width - _originalWindowFrame.size.width) * animationValue; - frame.size.height = _originalWindowFrame.size.height + (size.height - _originalWindowFrame.size.height) * animationValue; - frame.origin.x = mousePoint.x - (frame.size.width / 2); - frame.origin.y = mousePoint.y - (frame.size.height / 2); - - [_view setFadeValue:_showingAlternate ? 1.0f - animationValue : animationValue]; - [[self window] setFrame:frame display:YES]; - - if(![_animation isAnimating]) { - _animation = nil; - [timer invalidate]; - _timer = nil; - } +- (void)animateTimer:(NSTimer *)timer +{ + NSRect frame = _originalWindowFrame; + NSImage *currentImage = _showingAlternate ? [_view alternateImage] : [_view image]; + NSSize size = [currentImage size]; + NSPoint mousePoint = [NSEvent mouseLocation]; + CGFloat animationValue = [_animation currentValue]; + + frame.size.width = _originalWindowFrame.size.width + (size.width - _originalWindowFrame.size.width) * animationValue; + frame.size.height = _originalWindowFrame.size.height + (size.height - _originalWindowFrame.size.height) * animationValue; + frame.origin.x = mousePoint.x - (frame.size.width / 2); + frame.origin.y = mousePoint.y - (frame.size.height / 2); + + [_view setFadeValue:_showingAlternate ? 1.0f - animationValue : animationValue]; + [[self window] setFrame:frame display:YES]; + + if (![_animation isAnimating]) { + _animation = nil; + [timer invalidate]; + _timer = nil; + } } @end |