diff options
author | Kevin Barnes | 2008-01-16 21:53:09 +0000 |
---|---|---|
committer | Kevin Barnes | 2008-01-16 21:53:09 +0000 |
commit | b5cec6ded9c0a74a5e0fd701f0636cf2d2d31973 (patch) | |
tree | d7823fde99c9f200339fb6c7e63a1b7c6051d516 | |
parent | 0838701ca4cc696010a9256770a1e6012bcf417a (diff) | |
download | eclipse.platform.swt-b5cec6ded9c0a74a5e0fd701f0636cf2d2d31973.tar.gz eclipse.platform.swt-b5cec6ded9c0a74a5e0fd701f0636cf2d2d31973.tar.xz eclipse.platform.swt-b5cec6ded9c0a74a5e0fd701f0636cf2d2d31973.zip |
*** empty log message ***
9 files changed, 234 insertions, 38 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/Animation.java b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/Animation.java index 25b1a77d92..346189381a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/Animation.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/Animation.java @@ -37,36 +37,54 @@ public class Animation { OS.class_addMethod(cls, OS.sel_tag, proc2, "@:"); OS.class_addMethod(cls, OS.sel_setTag_1, proc3, "@:i"); OS.objc_registerClassPair(cls); + + className = "SWTAnimationView"; + cls = OS.objc_allocateClassPair(OS.class_SWTAnimationViewBase, className, 0); + OS.class_addMethod(cls, OS.sel_animationUpdated_1, proc3, "@:^NSNumber"); + + OS.objc_registerClassPair(cls); } - static int animationDelegateProc(int delegate, int sel) { + static int animationDelegateProc(int id, int sel) { if (sel == OS.sel_tag) { int[] tag = new int[1]; - OS.object_getInstanceVariable(delegate, "tag", tag); + OS.object_getInstanceVariable(id, "tag", tag); return tag[0]; } return 0; } - static int animationDelegateProc(int delegate, int sel, int arg0) { + static int animationDelegateProc(int id, int sel, int arg0) { if (sel == OS.sel_setTag_1) { - OS.object_setInstanceVariable(delegate, "tag", arg0); + OS.object_setInstanceVariable(id, "tag", arg0); return 0; } - int jniRef = OS.objc_msgSend(delegate, OS.sel_tag); + int jniRef = OS.objc_msgSend(id, OS.sel_tag); if (jniRef == 0 || jniRef == -1) return 0; - Animation animation = (Animation)OS.JNIGetObject(jniRef); + Object object = OS.JNIGetObject(jniRef); + if (!(object instanceof Animation)) return 0; + Animation animation = (Animation) object; if (animation == null) return 0; - if (sel == OS.sel_animationDidStart_1) animation.animationDidStart(arg0); + if (sel == OS.sel_animationUpdated_1) { + NSNumber number = new NSNumber(arg0); + animation.animationUpdated(number.floatValue()); + } + if (sel == OS.sel_animationDidStart_1) { + animation.animationDidStart(arg0); + } return 0; } - static int animationDelegateProc(int delegate, int sel, int arg0, int arg1) { - int jniRef = OS.objc_msgSend(delegate, OS.sel_tag); + static int animationDelegateProc(int id, int sel, int arg0, int arg1) { + int jniRef = OS.objc_msgSend(id, OS.sel_tag); if (jniRef == 0 || jniRef == -1) return 0; - Animation animation = (Animation)OS.JNIGetObject(jniRef); + Object object = OS.JNIGetObject(jniRef); + if (!(object instanceof Animation)) return 0; + Animation animation = (Animation) object; if (animation == null) return 0; - if (sel == OS.sel_animationDidStop_1finished_1) animation.animationDidStop(arg0, arg1); + if (sel == OS.sel_animationDidStop_1finished_1) { + animation.animationDidStop(arg0, arg1); + } return 0; } @@ -76,6 +94,9 @@ public class Animation { void animationDidStop(int animation, int finished) { } + void animationUpdated(float progress) { + } + void create () { if (delegate == null) { jniRef = OS.NewGlobalRef(this); @@ -163,9 +184,6 @@ public class Animation { public void stop() { checkAnimation(); } - - public void setDelegate(SWTCAAnimationDelegate delegate) { - } //FIXME: don't know how to do this //remove API. diff --git a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/CompositeAnimation.java b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/CompositeAnimation.java index 2f6801ac5a..385cb6ba35 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/CompositeAnimation.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/CompositeAnimation.java @@ -65,5 +65,12 @@ public class CompositeAnimation extends Animation { a.start(widget); } } + + public void stop() { + for (int i = 0; i < childCount; i++) { + Animation a = animations[i]; + a.stop(); + } + } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/PropertyAnimation.java b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/PropertyAnimation.java index 13eb4d18fc..9772762a6e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/PropertyAnimation.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/PropertyAnimation.java @@ -12,7 +12,7 @@ public class PropertyAnimation extends Animation { String property; Object target; Method method; -// int animatorHandle, customAnimation; + SWTAnimationViewBase animationView; //FIXME??? don't know how to do custom interpolation with Cocoa IInterpolator interpolator; @@ -21,28 +21,36 @@ public class PropertyAnimation extends Animation { boolean started; int completed; + Class paramType; + void animationDidStart(int id) { - System.out.println("did start"); started = true; } void animationDidStop(int id, int finished) { - System.out.println("stopped"); if (finished > 0) completed++; if (parent != null && isFinished()) parent.childFinished(this); } + void animationUpdated(float progress) { + System.out.println("val = " + progress); + } + void create() { super.create(); if (target == null || property == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (animations == null) { - createAnimations(); + if (animations != null) { for (int i = 0; i < animations.length; i++) { - animations[i].setDelegate(delegate); + if (animations[i] != null) animations[i].release(); } + animations = null; + } + createAnimations(); + for (int i = 0; i < animations.length; i++) { + animations[i].setDelegate(delegate); } setTimingFunction(); - updateFromToValues(); + updateFromValue(); } void createAnimations() { @@ -65,6 +73,34 @@ public class PropertyAnimation extends Animation { animations[0].retain(); dict.setValue(animations[0], keyPath); } + if (animations == null) { + animations = new CABasicAnimation[1]; + NSString keyPath = createNSString("animationValue"); + animations[0] = new CABasicAnimation(CABasicAnimation.animationWithKeyPath(keyPath).id); + animations[0].retain(); + dict.setValue(animations[0], keyPath); + + animationView = (SWTAnimationView) new SWTAnimationView().alloc().init(); + animationView.setTag(jniRef); + animationView.setAnimationValue(0.0f); + ((Control)target).view.addSubview_(animationView); + + //use reflection + String mName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); + Class clazz = target.getClass(); + Method[] methods = clazz.getMethods(); + for (int i = 0; i < methods.length; i++) { + Method m = methods[i]; + if (m.getName().equals(mName)) { + Class[] parameterTypes = m.getParameterTypes(); + if (parameterTypes.length == 1) { + method = m; + break; + } + } + } + paramType = method.getParameterTypes()[0]; + } int id = targetHandle(); if (id != 0) OS.objc_msgSend(id, OS.sel_setAnimations_1, dict.id); } @@ -125,14 +161,7 @@ public class PropertyAnimation extends Animation { } animations = null; } - - public void setDelegate(SWTCAAnimationDelegate delegate) { - for (int i = 0; i < animations.length; i++) { - CAAnimation animation = animations[i]; - animation.setDelegate(delegate); - } - } - + public void setDuration(long duration) { checkAnimation(); this.duration = duration; @@ -176,8 +205,9 @@ public class PropertyAnimation extends Animation { public void start(Widget widget) { super.start(widget); completed = 0; + started = false; int id = targetHandle(); - NSAnimationContext.beginGrouping(); +// NSAnimationContext.beginGrouping(); NSAnimationContext context = NSAnimationContext.currentContext(); context.setDuration(duration/1000f); int animator = OS.objc_msgSend(id, OS.sel_animator); @@ -193,10 +223,28 @@ public class PropertyAnimation extends Animation { if ("alpha".equalsIgnoreCase(property)) { int alpha = ((Integer)to).intValue(); float viewAlpha = (alpha & 0xFF) / (float) 0xFF; -// NSValue val = NSNumber.numberWithFloat(viewAlpha); OS.objc_msgSend(animator, OS.sel_setAlphaValue_1, viewAlpha); } - NSAnimationContext.endGrouping(); + if (animationView != null) { + OS.objc_msgSend(animator, OS.sel_setAnimationValue_1, 1.0f); + } +// NSAnimationContext.endGrouping(); + } + + public void stop() { + int id = targetHandle(); + NSAnimationContext context = NSAnimationContext.currentContext(); + context.setDuration(0.0001f); + int animator = OS.objc_msgSend(id, OS.sel_animator); + if ("bounds".equalsIgnoreCase(property)) { + NSRect nsRect = new NSRect(); + OS.objc_msgSend_stret(nsRect, id, OS.sel_frame); + OS.objc_msgSend(animator, OS.sel_setFrame_1, nsRect); + } + if ("alpha".equalsIgnoreCase(property)) { + int viewAlpha = OS.objc_msgSend(id, OS.sel_alphaValue); + OS.objc_msgSend(animator, OS.sel_setAlphaValue_1, viewAlpha); + } } int targetHandle() { @@ -208,9 +256,10 @@ public class PropertyAnimation extends Animation { if (target instanceof Control) { Control control = (Control) target; result = control.view.id; + } + if (animationView != null) { + result = animationView.id; } - //TODO - //return fake view?? /* * FIXME @@ -225,13 +274,13 @@ public class PropertyAnimation extends Animation { * alpha value, and we don't get some of the performance * benefits of CAAnimation. */ -// ((Control) target).view.setWantsLayer(true); + ((Control) target).view.setWantsLayer(true); // ((Control) target).view.superview().setWantsLayer(true); return result; } - void updateFromToValues() { + void updateFromValue() { if (property.equalsIgnoreCase("bounds")) { if (!(from instanceof Rectangle && to instanceof Rectangle)) SWT.error(SWT.ERROR_INVALID_ARGUMENT); Rectangle rect = (Rectangle) from; @@ -253,5 +302,9 @@ public class PropertyAnimation extends Animation { NSValue val = NSNumber.numberWithFloat(viewAlpha); animations[0].setFromValue(val); } + if (animationView != null) { + NSValue val = NSNumber.numberWithInt(0); + animations[0].setFromValue(val); + } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/SequenceAnimation.java b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/SequenceAnimation.java index 8affe0e90f..fb065a293a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/SequenceAnimation.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Animation2/cocoa/org/eclipse/swt/animation/SequenceAnimation.java @@ -5,9 +5,12 @@ import org.eclipse.swt.widgets.*; public class SequenceAnimation extends CompositeAnimation { - int current = 0; + int current; + boolean stopped; public void start(Widget widget) { + current = 0; + stopped = false; this.widget = widget; for (int i = 0; i < childCount; i++) { Animation a = animations[i]; @@ -17,7 +20,13 @@ public class SequenceAnimation extends CompositeAnimation { } public void childFinished(Animation child) { + if (stopped) return; current++; if (current < childCount) animations[current].start(widget); } + + public void stop() { + stopped = true; + if (current < childCount) animations[current].stop(); + } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c index 1c94d8a746..000e5425c1 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c @@ -364,4 +364,41 @@ JNIEXPORT SWT_PTR JNICALL OS_NATIVE(drawRect_1CALLBACK) drawRect_1CALLBACK = func; return (SWT_PTR)drawRect; } -#endif
\ No newline at end of file +#endif + + +@interface SWTAnimationViewBase : NSView { +} +jint jniRef; +float animationValue; +-(void)setTag:(jint)tag; +-(jint)tag; +-(void)setAnimationValue:(float)val; +-(float)animationValue; +-(void)animationUpdated:(NSNumber*)num; +@end + +@implementation SWTAnimationViewBase +-(id)initWithFrame:(NSRect)frame { + return [super initWithFrame:frame]; +} +-(void)drawRect:(NSRect)rect { + [super drawRect:rect]; +} +-(void)setTag:(jint)tag { + jniRef = tag; +} +-(jint)tag { + return jniRef; +} +-(void)setAnimationValue:(float)val { + animationValue = val; + [self animationUpdated:[NSNumber numberWithFloat:val]]; +} +-(float)animationValue { + return animationValue; +} +-(void)animationUpdated:(NSNumber*)num { + printf ("new val = %f\n", [num floatValue]); +} +@end diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index 98b20705e1..76b0a12f8b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -443,6 +443,7 @@ public static final int class_NSCalendar = objc_getClass("NSCalendar"); public static final int class_NSTokenField = objc_getClass("NSTokenField"); public static final int class_NSCollectionView = objc_getClass("NSCollectionView"); public static final int class_NSColorList = objc_getClass("NSColorList"); +public static final int class_SWTAnimationViewBase = objc_getClass("SWTAnimationViewBase"); /** Selectors */ public static final int sel_inputClientEnabled_1 = sel_registerName("inputClientEnabled:"); @@ -6833,6 +6834,9 @@ public static final int sel_byValue = sel_registerName("byValue"); public static final int sel_setByValue_1 = sel_registerName("setByValue:"); public static final int sel_timingFunction = sel_registerName("timingFunction"); public static final int sel_setTimingFunction_1 = sel_registerName("setTimingFunction:"); +public static final int sel_animationValue = sel_registerName("animationValue"); +public static final int sel_setAnimationValue_1 = sel_registerName("setAnimationValue:"); +public static final int sel_animationUpdated_1 = sel_registerName("animationUpdated:"); /** Constants */ public static final int NSAWTEventType = 16; diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTAnimationView.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTAnimationView.java new file mode 100644 index 0000000000..e017b47fa1 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTAnimationView.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.internal.cocoa; + +public class SWTAnimationView extends SWTAnimationViewBase { +// void animationUpdated(NSNumber val) { +// System.out.println(val.floatValue()); +// } +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTAnimationViewBase.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTAnimationViewBase.java new file mode 100644 index 0000000000..14a5ba7217 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTAnimationViewBase.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.internal.cocoa; + +public class SWTAnimationViewBase extends NSView { + + public SWTAnimationViewBase() { + super(0); + } + + public SWTAnimationViewBase(int id) { + super(id); + } + + public int tag() { + return OS.objc_msgSend(id, OS.sel_tag); + } + + public void setTag(int tag) { + OS.objc_msgSend(id, OS.sel_setTag_1, tag); + } + + public float animationValue() { + return OS.objc_msgSend(id, OS.sel_animationValue); + } + + public void setAnimationValue(float val) { + OS.objc_msgSend(id, OS.sel_setAnimationValue_1, val); + } + + void animationUpdated(NSNumber val) { + } +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTCAAnimationDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTCAAnimationDelegate.java index b2f998bd39..266d017143 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTCAAnimationDelegate.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTCAAnimationDelegate.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.swt.internal.cocoa; public class SWTCAAnimationDelegate extends NSObject { |