From 332accd330b679f8ccb0ed0c8916439a39347711 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Wed, 10 Mar 2010 18:33:34 +0000 Subject: [Author: dmaclach] Change over animation so it will work with other event types than just mouse downs. R=thomasvl DELTA=33 (16 added, 1 deleted, 16 changed) --- AppKit/GTMNSAnimation+Duration.m | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'AppKit/GTMNSAnimation+Duration.m') diff --git a/AppKit/GTMNSAnimation+Duration.m b/AppKit/GTMNSAnimation+Duration.m index 884cd32..c47772b 100644 --- a/AppKit/GTMNSAnimation+Duration.m +++ b/AppKit/GTMNSAnimation+Duration.m @@ -6,9 +6,9 @@ // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -18,13 +18,16 @@ #import "GTMNSAnimation+Duration.h" -NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration) { +const NSUInteger kGTMLeftMouseDownAndKeyDownMask + = NSLeftMouseDownMask | NSKeyDownMask; + +NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration, + NSUInteger eventMask) { NSEvent *event = [NSApp currentEvent]; - if ([event type] == NSLeftMouseUp) { + if (eventMask & NSEventMaskFromType([event type])) { NSUInteger modifiers = [event modifierFlags]; if (!(modifiers & (NSAlternateKeyMask | - NSCommandKeyMask | - NSFunctionKeyMask))) { + NSCommandKeyMask))) { if (modifiers & NSShiftKeyMask) { duration *= 5.0; } @@ -39,14 +42,18 @@ NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration) { @implementation NSAnimation (GTMNSAnimationDurationAdditions) -- (id)gtm_initWithDuration:(NSTimeInterval)duration +- (id)gtm_initWithDuration:(NSTimeInterval)duration + eventMask:(NSUInteger)eventMask animationCurve:(NSAnimationCurve)animationCurve { - return [self initWithDuration:GTMModifyDurationBasedOnCurrentState(duration) + return [self initWithDuration:GTMModifyDurationBasedOnCurrentState(duration, + eventMask) animationCurve:animationCurve]; } -- (void)gtm_setDuration:(NSTimeInterval)duration { - [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)]; +- (void)gtm_setDuration:(NSTimeInterval)duration + eventMask:(NSUInteger)eventMask { + [self setDuration:GTMModifyDurationBasedOnCurrentState(duration, + eventMask)]; } @end @@ -55,16 +62,20 @@ NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration) { @implementation NSAnimationContext (GTMNSAnimationDurationAdditions) -- (void)gtm_setDuration:(NSTimeInterval)duration { - [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)]; +- (void)gtm_setDuration:(NSTimeInterval)duration + eventMask:(NSUInteger)eventMask { + [self setDuration:GTMModifyDurationBasedOnCurrentState(duration, + eventMask)]; } @end @implementation CAAnimation (GTMCAAnimationDurationAdditions) -- (void)gtm_setDuration:(CFTimeInterval)duration { - [self setDuration:GTMModifyDurationBasedOnCurrentState(duration)]; +- (void)gtm_setDuration:(CFTimeInterval)duration + eventMask:(NSUInteger)eventMask { + [self setDuration:GTMModifyDurationBasedOnCurrentState(duration, + eventMask)]; } @end -- cgit v1.2.3