Skip to content

Commit

Permalink
Importing NicePlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
qin committed Feb 13, 2005
0 parents commit 2833eca
Show file tree
Hide file tree
Showing 189 changed files with 21,095 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Classes/FadeOut.h
@@ -0,0 +1,26 @@
//
// FadeOut.h
// NicePlayer
//
// Created by Robert Chin on 2/11/05.
// Copyright 2005 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>


@interface FadeOut : NSObject {
NSMutableSet *windowList;
NSTimer *faderTimer;
}

+(id)fadeOut;
-(id)init;
-(void)initialFadeForObjects:(id)anArray;
-(void)doInitialFadeForObjects:(id)aTimer;
-(void)addWindow:(id)anObject;
-(void)destroyAndCreateTimer;
-(void)updateAlphaValues;
-(void)testForRemoval;

@end
114 changes: 114 additions & 0 deletions Classes/FadeOut.m
@@ -0,0 +1,114 @@
//
// FadeOut.m
// NicePlayer
//
// Created by Robert Chin on 2/11/05.
// Copyright 2005 __MyCompanyName__. All rights reserved.
//

#import "FadeOut.h"
#import "Preferences.h"

#define INITIAL_FADE_DURATION 5.0
#define ALPHA_VALUE_DELTA 0.04
#define TIMER_INTERVAL 0.01

static id fadeOutInstance = nil;

@implementation FadeOut

+(id)fadeOut
{
if(!fadeOutInstance)
fadeOutInstance = [FadeOut new];
return fadeOutInstance;
}

-(id)init
{
if(self = [super init]){
windowList = [[NSMutableSet set] retain];
faderTimer = nil;
}
return self;
}

-(void)initialFadeForObjects:(id)anArray
{
if([[Preferences mainPrefs] showInitialOverlays]){
[NSTimer scheduledTimerWithTimeInterval:INITIAL_FADE_DURATION
target:self
selector:@selector(doInitialFadeForObjects:)
userInfo:anArray
repeats:NO];
} else {
id anObject, e = [anArray objectEnumerator];
while(anObject = [e nextObject]){
[anObject setAlphaValue:0.0];
}
}
}

-(void)doInitialFadeForObjects:(NSTimer *)aTimer
{
if([[Preferences mainPrefs] fadeOverlays]){
[windowList addObjectsFromArray:[aTimer userInfo]];
[self destroyAndCreateTimer];
} else {
id anObject, e = [[aTimer userInfo] objectEnumerator];
while(anObject = [e nextObject]){
[anObject setAlphaValue:0.0];
}
}
}

-(void)addWindow:(id)anObject
{
if([[Preferences mainPrefs] fadeOverlays]){
[windowList addObject:anObject];
[self destroyAndCreateTimer];
} else
[anObject setAlphaValue:0.0];
}

-(void)destroyAndCreateTimer
{
if(([windowList count] > 0) && (faderTimer == nil)){
faderTimer = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL
target:self
selector:@selector(updateAlphaValues)
userInfo:nil
repeats:YES];
}
if(([windowList count] == 0) && (faderTimer != nil)){
[faderTimer invalidate];
faderTimer = nil;
}
}

-(void)updateAlphaValues
{
id anObject, e = [windowList objectEnumerator];
while(anObject = [e nextObject]){
float newValue = [anObject alphaValue] - ALPHA_VALUE_DELTA;
newValue = (newValue < 0.0) ? 0.0 : newValue;
[anObject setAlphaValue:newValue];
}
[self testForRemoval];
[self destroyAndCreateTimer];
}

-(void)testForRemoval
{
id newSet = [[NSMutableSet set] retain];
id anObject, e = [windowList objectEnumerator];
while(anObject = [e nextObject]){
if([anObject alphaValue] > 0.0)
[newSet addObject:anObject];
}

[windowList release];
windowList = newSet;
}

@end
13 changes: 13 additions & 0 deletions Classes/MainWindowProxy.h
@@ -0,0 +1,13 @@
/**
* MainWindowProxy.h
* NicePlayer
*/

#import <Cocoa/Cocoa.h>


@interface MainWindowProxy : NSObject {

}

@end
24 changes: 24 additions & 0 deletions Classes/MainWindowProxy.m
@@ -0,0 +1,24 @@
/**
* MainWindowProxy.h
* NicePlayer
*/

#import "MainWindowProxy.h"


@implementation MainWindowProxy

- (void)forwardInvocation:(NSInvocation *)invocation
{
id friend = [[NSApp delegate] documentForWindow:[NSApp mainWindow]];
if ([friend respondsToSelector:[invocation selector]])
[invocation invokeWithTarget:friend];
else
[self doesNotRecognizeSelector:[invocation selector]];
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector{

return [NSWindow instanceMethodSignatureForSelector:aSelector];
}
@end
17 changes: 17 additions & 0 deletions Classes/NPApplication.h
@@ -0,0 +1,17 @@
//
// NPApplication.h
// NicePlayer
//
// Created by Robert Chin on 11/1/04.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "NiceController.h"

@interface NPApplication : NSApplication {
NSTimer *inactiveTimer;
NSPoint lastPoint;
}

@end
171 changes: 171 additions & 0 deletions Classes/NPApplication.m
@@ -0,0 +1,171 @@
/**
* NPApplication.m
* NicePlayer
*
* The application subclass that allows for us to detect mouse movement when the application
* is not in focus, allowing us to show and hide movie controls even when other apps are
* active.
*/

#import "NPApplication.h"

@implementation NPApplication

- (void)finishLaunching
{
[super finishLaunching];
lastPoint = [NSEvent mouseLocation];
inactiveTimer = nil;

[NSApp checkForUpdates:nil];

[self setDelegate:self];
}

/**
* This method tests to see if the mouse has moved to a different location. If so, inject the event into
* our applications loop in order to determine of the mouse is in a place where the controls should appear
* for the movie controller or title bar.
*/
-(void)testCursorMovement
{
if(!NSEqualPoints(lastPoint, [NSEvent mouseLocation])){
lastPoint = [NSEvent mouseLocation];
NSEvent *newEvent = [NSEvent mouseEventWithType:NSMouseMoved
location:lastPoint
modifierFlags:0
timestamp:0
windowNumber:0
context:nil
eventNumber:0
clickCount:0
pressure:1.0];
[self sendEvent:newEvent];
}
}

/* Ripped from http://www.cocoabuilder.com/archive/message/cocoa/2004/9/1/116398 */

- (void)sendEvent:(NSEvent *)anEvent
{
// catch first right mouse click, activate app
// and hand the event on to the window for further processing
BOOL done = NO;
NSPoint locationInWindow;
NSWindow *theWindow;
NSView *theView = nil;
if (![self isActive]) {
//NSLog(@"a: event type: %i", [anEvent type]);
// we do NOT get an NSRightMouseDown event
if(([anEvent type] == NSRightMouseUp) || ([anEvent type] == NSMouseMoved)){
// there seems to be no window assigned with this event at the moment;
// but just in case ...
if (theWindow = [anEvent window]) {
theView = [[theWindow contentView] hitTest:[anEvent
locationInWindow]];
locationInWindow = [anEvent locationInWindow];
} else {
// find window
NSEnumerator *enumerator = [[self orderedWindows] objectEnumerator];
while (theWindow = [enumerator nextObject]) {
locationInWindow = [theWindow mouseLocationOutsideOfEventStream];
NSView *contentView = [theWindow contentView];
theView = [contentView hitTest:locationInWindow];
if (theView) {
// we found our view
//NSLog(@"hit view of class: %@", NSStringFromClass([theView class]));
break;
}
}
}
if (theView) {
// create new event with useful window, location and event values
unsigned int flags = [anEvent modifierFlags];
NSTimeInterval timestamp = [anEvent timestamp];
int windowNumber = [theWindow windowNumber];
NSGraphicsContext *context = [anEvent context];
// original event is not a mouse down event so the following values are missing
int eventNumber = 0; // [anEvent eventNumber]
int clickCount = 0; // [anEvent clickCount]
float pressure = 1.0; // [anEvent pressure]
NSEvent *newEvent = [NSEvent mouseEventWithType:[anEvent type]
location:locationInWindow
modifierFlags:flags
timestamp:timestamp
windowNumber:windowNumber
context:context
eventNumber:eventNumber
clickCount:clickCount
pressure:pressure];
if ([theView acceptsFirstMouse:newEvent]) {
// activate app and send event to the window
//[self activateIgnoringOtherApps:YES];
[theWindow sendEvent:newEvent];
done = YES;
}
}
}
}

if (!done) {
// we did not catch this one
[super sendEvent:anEvent];
}
}

-(void)deactivateTimer
{
if(inactiveTimer){
[inactiveTimer invalidate];
inactiveTimer = nil;
}
}

-(void)activateTimer
{
if(!inactiveTimer){
inactiveTimer = [NSTimer scheduledTimerWithTimeInterval:0.01
target:self
selector:@selector(testCursorMovement)
userInfo:nil
repeats:YES];
}
}

#pragma mark -
#pragma mark Delegate Methods

-(void)applicationDidBecomeActive:(NSNotification *)aNotification
{
[self deactivateTimer];
}

-(void)applicationDidResignActive:(NSNotification *)aNotification
{
if(![self isHidden])
[self activateTimer];
}

-(void)applicationDidHide:(NSNotification *)aNotification
{
[self deactivateTimer];
}

-(void)applicationDidUnhide:(NSNotification *)aNotification
{
if(![self isActive])
[self activateTimer];
}

-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
if(![self isActive])
[self activateTimer];
}

-(void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
{
[[NiceController controller] openFiles:filenames];
}

@end

0 comments on commit 2833eca

Please sign in to comment.