2011-01-19 23:19:43 +03:00
|
|
|
//
|
|
|
|
// PSMTabDragWindowController.m
|
|
|
|
// PSMTabBarControl
|
|
|
|
//
|
|
|
|
// Created by Kent Sutherland on 6/18/07.
|
|
|
|
// Copyright 2007 Kent Sutherland. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "PSMTabDragWindowController.h"
|
|
|
|
#import "PSMTabDragWindow.h"
|
|
|
|
#import "PSMTabDragView.h"
|
|
|
|
|
|
|
|
@implementation PSMTabDragWindowController
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (id)initWithImage:(NSImage *)image styleMask:(NSUInteger)styleMask tearOffStyle:(PSMTabBarTearOffStyle)tearOffStyle {
|
2011-01-19 23:19:43 +03:00
|
|
|
PSMTabDragWindow *window = [PSMTabDragWindow dragWindowWithImage:image styleMask:styleMask];
|
2011-01-26 13:52:13 +03:00
|
|
|
if((self = [super initWithWindow:window])) {
|
2011-01-19 23:19:43 +03:00
|
|
|
_view = [[window dragView] retain];
|
|
|
|
_tearOffStyle = tearOffStyle;
|
2011-01-26 13:52:13 +03:00
|
|
|
|
|
|
|
if(tearOffStyle == PSMTabBarTearOffMiniwindow) {
|
2011-01-19 23:19:43 +03:00
|
|
|
[window setBackgroundColor:[NSColor clearColor]];
|
|
|
|
[window setHasShadow:YES];
|
|
|
|
}
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[window setAlphaValue:kPSMTabDragWindowAlpha];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)dealloc {
|
|
|
|
if(_timer) {
|
2011-01-19 23:19:43 +03:00
|
|
|
[_timer invalidate];
|
|
|
|
}
|
2011-01-26 13:52:13 +03:00
|
|
|
|
|
|
|
if(_animation) {
|
2011-01-19 23:19:43 +03:00
|
|
|
[_animation release];
|
|
|
|
}
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[_view release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (NSImage *)image {
|
2011-01-19 23:19:43 +03:00
|
|
|
return [_view image];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (NSImage *)alternateImage {
|
2011-01-19 23:19:43 +03:00
|
|
|
return [_view alternateImage];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)setAlternateImage:(NSImage *)image {
|
2011-01-19 23:19:43 +03:00
|
|
|
[_view setAlternateImage:image];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (BOOL)isAnimating {
|
2011-01-19 23:19:43 +03:00
|
|
|
return _animation != nil;
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)switchImages {
|
|
|
|
if(_tearOffStyle != PSMTabBarTearOffMiniwindow || ![_view alternateImage]) {
|
2011-01-19 23:19:43 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
CGFloat progress = 0;
|
|
|
|
_showingAlternate = !_showingAlternate;
|
2011-01-26 13:52:13 +03:00
|
|
|
|
|
|
|
if(_animation) {
|
2011-01-19 23:19:43 +03:00
|
|
|
//An animation already exists, get the current progress
|
|
|
|
progress = 1.0f - [_animation currentProgress];
|
|
|
|
[_animation stopAnimation];
|
|
|
|
[_animation release];
|
|
|
|
}
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
//begin animating
|
|
|
|
_animation = [[NSAnimation alloc] initWithDuration:0.25 animationCurve:NSAnimationEaseInOut];
|
|
|
|
[_animation setAnimationBlockingMode:NSAnimationNonblocking];
|
|
|
|
[_animation setCurrentProgress:progress];
|
|
|
|
[_animation startAnimation];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
_originalWindowFrame = [[self window] frame];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
|
|
|
if(_timer) {
|
2011-01-19 23:19:43 +03:00
|
|
|
[_timer invalidate];
|
|
|
|
}
|
|
|
|
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0f / 30.0f target:self selector:@selector(animateTimer:) userInfo:nil repeats:YES];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)animateTimer:(NSTimer *)timer {
|
2011-01-19 23:19:43 +03:00
|
|
|
NSRect frame = _originalWindowFrame;
|
2011-01-26 13:52:13 +03:00
|
|
|
NSImage *currentImage = _showingAlternate ?[_view alternateImage] :[_view image];
|
2011-01-19 23:19:43 +03:00
|
|
|
NSSize size = [currentImage size];
|
|
|
|
NSPoint mousePoint = [NSEvent mouseLocation];
|
|
|
|
CGFloat animationValue = [_animation currentValue];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
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);
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[_view setFadeValue:_showingAlternate ? 1.0f - animationValue : animationValue];
|
|
|
|
[[self window] setFrame:frame display:YES];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
|
|
|
if(![_animation isAnimating]) {
|
2011-01-19 23:19:43 +03:00
|
|
|
[_animation release], _animation = nil;
|
|
|
|
[timer invalidate];
|
|
|
|
_timer = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|