Mercurial > projects > dstep
diff dstep/appkit/NSAnimation.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | |
children | b9de51448c6b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/appkit/NSAnimation.d Sun Jan 03 22:06:11 2010 +0100 @@ -0,0 +1,369 @@ +/** + * Copyright: Copyright (c) 2009 Jacob Carlborg. + * Authors: Jacob Carlborg + * Version: Initial created: Sep 24, 2009 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module dstep.appkit.NSAnimation; + +import dstep.appkit.AppKitDefines; +import dstep.appkit.NSGraphicsContext; +import dstep.foundation.NSArray; +import dstep.foundation.NSCoder; +import dstep.foundation.NSDictionary; +import dstep.foundation.NSObjCRuntime; +import dstep.foundation.NSObject; +import dstep.foundation.NSString; +import dstep.foundation.NSTimer; +import dstep.foundation.NSString; +import dstep.foundation.NSZone; +import dstep.objc.bridge.Bridge; +import dstep.objc.objc; + +import bindings = dstep.appkit.NSAnimation_bindings; + +alias NSUInteger NSAnimationCurve; +alias NSUInteger NSAnimationBlockingMode; +alias float NSAnimationProgress; + +private +{ + NSString NSAnimationProgressMarkNotification_; + NSString NSAnimationProgressMark_; + NSString NSViewAnimationTargetKey_; + NSString NSViewAnimationStartFrameKey_; + NSString NSViewAnimationEndFrameKey_; + NSString NSViewAnimationEffectKey_; + NSString NSViewAnimationFadeInEffect_; + NSString NSViewAnimationFadeOutEffect_; + NSString NSAnimationTriggerOrderIn_; + NSString NSAnimationTriggerOrderOut_; +} + +NSString NSAnimationProgressMarkNotification () +{ + if (NSAnimationProgressMarkNotification_) + return NSAnimationProgressMarkNotification_; + + return NSAnimationProgressMarkNotification_ = new NSString(bindings.NSAnimationProgressMarkNotification); +} + +NSString NSAnimationProgressMark () +{ + if (NSAnimationProgressMark_) + return NSAnimationProgressMark_; + + return NSAnimationProgressMark_ = new NSString(bindings.NSAnimationProgressMark); +} + +NSString NSViewAnimationTargetKey () +{ + if (NSViewAnimationTargetKey_) + return NSViewAnimationTargetKey_; + + return NSViewAnimationTargetKey_ = new NSString(bindings.NSViewAnimationTargetKey); +} + +NSString NSViewAnimationStartFrameKey () +{ + if (NSViewAnimationStartFrameKey_) + return NSViewAnimationStartFrameKey_; + + return NSViewAnimationStartFrameKey_ = new NSString(bindings.NSViewAnimationStartFrameKey); +} + +NSString NSViewAnimationEndFrameKey () +{ + if (NSViewAnimationEndFrameKey_) + return NSViewAnimationEndFrameKey_; + + return NSViewAnimationEndFrameKey_ = new NSString(bindings.NSViewAnimationEndFrameKey); +} + +NSString NSViewAnimationEffectKey () +{ + if (NSViewAnimationEffectKey_) + return NSViewAnimationEffectKey_; + + return NSViewAnimationEffectKey_ = new NSString(bindings.NSViewAnimationEffectKey); +} + +NSString NSViewAnimationFadeInEffect () +{ + if (NSViewAnimationFadeInEffect_) + return NSViewAnimationFadeInEffect_; + + return NSViewAnimationFadeInEffect_ = new NSString(bindings.NSViewAnimationFadeInEffect); +} + +NSString NSViewAnimationFadeOutEffect () +{ + if (NSViewAnimationFadeOutEffect_) + return NSViewAnimationFadeOutEffect_; + + return NSViewAnimationFadeOutEffect_ = new NSString(bindings.NSViewAnimationFadeOutEffect); +} + +NSString NSAnimationTriggerOrderIn () +{ + if (NSAnimationTriggerOrderIn_) + return NSAnimationTriggerOrderIn_; + + return NSAnimationTriggerOrderIn_ = new NSString(bindings.NSAnimationTriggerOrderIn); +} + +NSString NSAnimationTriggerOrderOut () +{ + if (NSAnimationTriggerOrderOut_) + return NSAnimationTriggerOrderOut_; + + return NSAnimationTriggerOrderOut_ = new NSString(bindings.NSAnimationTriggerOrderOut); +} + +enum +{ + NSAnimationEaseInOut, + NSAnimationEaseIn, + NSAnimationEaseOut, + NSAnimationLinear +} + +enum +{ + NSAnimationBlocking, + NSAnimationNonblocking, + NSAnimationNonblockingThreaded +} + +class NSAnimation : NSObject, INSCopying, INSCoding +{ + mixin (ObjcWrap); + + this (NSCoder aDecoder) + { + super(typeof(this).alloc.initWithCoder(aDecoder).objcObject); + } + + void encodeWithCoder (NSCoder aCoder) + { + return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); + } + + typeof(this) initWithCoder (NSCoder aDecoder) + { + return invokeObjcSelf!(typeof(this), "initWithCoder:", NSCoder)(aDecoder); + } + + typeof(this) copyWithZone (NSZone* zone) + { + return invokeObjcSelf!(typeof(this), "copyWithZone:", NSZone*)(zone); + } + + NSAnimation initWithDuration (double duration, uint animationCurve) + { + id result = invokeObjcSelf!(id, "initWithDuration:animationCurve:", double, uint)(duration, animationCurve); + return result is this.objcObject ? this : (result !is null ? new NSAnimation(result) : null); + } + + this (double duration, uint animationCurve) + { + super(NSAnimation.alloc.initWithDuration(duration, animationCurve).objcObject); + } + + void startAnimation () + { + return invokeObjcSelf!(void, "startAnimation"); + } + + void stopAnimation () + { + return invokeObjcSelf!(void, "stopAnimation"); + } + + bool isAnimating () + { + return invokeObjcSelf!(bool, "isAnimating"); + } + + float currentProgress () + { + return invokeObjcSelf!(float, "currentProgress"); + } + + void setCurrentProgress (float progress) + { + return invokeObjcSelf!(void, "setCurrentProgress:", float)(progress); + } + + void setDuration (double duration) + { + return invokeObjcSelf!(void, "setDuration:", double)(duration); + } + + double duration () + { + return invokeObjcSelf!(double, "duration"); + } + + uint animationBlockingMode () + { + return invokeObjcSelf!(uint, "animationBlockingMode"); + } + + void setAnimationBlockingMode (uint animationBlockingMode) + { + return invokeObjcSelf!(void, "setAnimationBlockingMode:", uint)(animationBlockingMode); + } + + void setFrameRate (float framesPerSecond) + { + return invokeObjcSelf!(void, "setFrameRate:", float)(framesPerSecond); + } + + float frameRate () + { + return invokeObjcSelf!(float, "frameRate"); + } + + void setAnimationCurve (uint curve) + { + return invokeObjcSelf!(void, "setAnimationCurve:", uint)(curve); + } + + uint animationCurve () + { + return invokeObjcSelf!(uint, "animationCurve"); + } + + float currentValue () + { + return invokeObjcSelf!(float, "currentValue"); + } + + void setDelegate (Object delegate_) + { + return invokeObjcSelf!(void, "setDelegate:", Object)(delegate_); + } + + Object delegate_ () + { + return invokeObjcSelf!(Object, "delegate"); + } + + NSArray progressMarks () + { + return invokeObjcSelf!(NSArray, "progressMarks"); + } + + void setProgressMarks (NSArray progressMarks) + { + return invokeObjcSelf!(void, "setProgressMarks:", NSArray)(progressMarks); + } + + void addProgressMark (float progressMark) + { + return invokeObjcSelf!(void, "addProgressMark:", float)(progressMark); + } + + void removeProgressMark (float progressMark) + { + return invokeObjcSelf!(void, "removeProgressMark:", float)(progressMark); + } + + void startWhenAnimation (NSAnimation animation, float startProgress) + { + return invokeObjcSelf!(void, "startWhenAnimation:reachesProgress:", NSAnimation, float)(animation, startProgress); + } + + void stopWhenAnimation (NSAnimation animation, float stopProgress) + { + return invokeObjcSelf!(void, "stopWhenAnimation:reachesProgress:", NSAnimation, float)(animation, stopProgress); + } + + void clearStartAnimation () + { + return invokeObjcSelf!(void, "clearStartAnimation"); + } + + void clearStopAnimation () + { + return invokeObjcSelf!(void, "clearStopAnimation"); + } + + NSArray runLoopModesForAnimating () + { + return invokeObjcSelf!(NSArray, "runLoopModesForAnimating"); + } + +} + +class NSViewAnimation : NSAnimation +{ + mixin (ObjcWrap); + + NSViewAnimation initWithViewAnimations (NSArray viewAnimations) + { + id result = invokeObjcSelf!(id, "initWithViewAnimations:", NSArray)(viewAnimations); + return result is this.objcObject ? this : (result !is null ? new NSViewAnimation(result) : null); + } + + this (NSArray viewAnimations) + { + super(NSViewAnimation.alloc.initWithViewAnimations(viewAnimations).objcObject); + } + + NSArray viewAnimations () + { + return invokeObjcSelf!(NSArray, "viewAnimations"); + } + + void setViewAnimations (NSArray viewAnimations) + { + return invokeObjcSelf!(void, "setViewAnimations:", NSArray)(viewAnimations); + } +} + +interface INSAnimatablePropertyContainer +{ + Object animator (); + NSDictionary animations (); + void setAnimations (NSDictionary dict); + Object animationForKey (NSString key); + static Object defaultAnimationForKey (NSString key); +} + +const TNSAnimationDelegate = ` + + bool animationShouldStart (NSAnimation animation) + { + return invokeObjcSelf!(bool, "animationShouldStart:", NSAnimation)(animation); + } + + void animationDidStop (NSAnimation animation) + { + return invokeObjcSelf!(void, "animationDidStop:", NSAnimation)(animation); + } + + void animationDidEnd (NSAnimation animation) + { + return invokeObjcSelf!(void, "animationDidEnd:", NSAnimation)(animation); + } + + float animation (NSAnimation animation, float progress) + { + return invokeObjcSelf!(float, "animation:valueForProgress:", NSAnimation, float)(animation, progress); + } + + void animation (NSAnimation animation, float progress) + { + return invokeObjcSelf!(void, "animation:didReachProgressMark:", NSAnimation, float)(animation, progress); + } + + //mixin ObjcBindMethod!(animationShouldStart, "animationShouldStart:"); + //mixin ObjcBindMethod!(animationDidStop, "animationDidStop:"); + //mixin ObjcBindMethod!(animationDidEnd, "animationDidEnd:"); + //mixin ObjcBindMethod!(animation, "animation:valueForProgress:"); + //mixin ObjcBindMethod!(animation, "animation:didReachProgressMark:"); + +`; +