/src/org/mt4j/util/animation/ani/AniAdapter.java

http://mt4j.googlecode.com/ · Java · 125 lines · 74 code · 37 blank · 14 comment · 2 complexity · 9b2caa888d40a754f1680fa5ff2667f3 MD5 · raw file

  1. package org.mt4j.util.animation.ani;
  2. import org.mt4j.util.animation.AnimationEvent;
  3. import org.mt4j.util.animation.AnimationManager;
  4. import de.looksgood.ani.Ani;
  5. public class AniAdapter extends Ani {
  6. private AniAnimation correspondingAnimation;
  7. private Object animationTarget;
  8. private float currentStepDelta;
  9. static{
  10. Ani.noAutostart();
  11. }
  12. // public AdaptedAni(Adapter theTarget, float from, float to, float theDuration, float theDelay,
  13. // String theFieldName, String theEasing,
  14. // String theCallback) {
  15. // super(theTarget, theDuration, theDelay, "x", to, theEasing,
  16. // theCallback);
  17. //
  18. // this.setBegin(from);
  19. // this.correspondingAnimation = theTarget;
  20. // }
  21. public AniAdapter(AniAnimation theTarget, float from, float to, float theDuration, float theDelay, String theFieldName, String theEasing, Object animationTarget) {
  22. super(theTarget, theDuration, theDelay, theFieldName, to, theEasing);
  23. this.setBegin(from);
  24. this.currentStepDelta = 0;
  25. this.correspondingAnimation = theTarget;
  26. this.animationTarget = animationTarget;
  27. }
  28. @Override
  29. public void seek(float theValue) {
  30. if (theValue == 0.0f){
  31. this.currentStepDelta = 0.0f;
  32. this.position = getBegin(); //FIXME TEST to fix bug with currentStepDelta
  33. }
  34. super.seek(theValue);
  35. }
  36. @Override
  37. protected void dispatchOnStart() {
  38. super.dispatchOnStart();
  39. correspondingAnimation.fireAnimationEvent(new AnimationEvent(this, AnimationEvent.ANIMATION_STARTED, correspondingAnimation, animationTarget));
  40. }
  41. @Override
  42. protected void updatePosition() {
  43. float lastPosition = this.getPosition();
  44. super.updatePosition();
  45. this.currentStepDelta = this.getPosition() - lastPosition;
  46. // if (this.currentStepDelta == -1.0f){
  47. // System.out.println();
  48. // }
  49. correspondingAnimation.fireAnimationEvent(new AnimationEvent(this, AnimationEvent.ANIMATION_UPDATED, correspondingAnimation, animationTarget));
  50. }
  51. @Override
  52. protected void dispatchOnEnd() {
  53. this.currentStepDelta = 0.0f; //Else we get the same delta as from the last step twice!
  54. super.dispatchOnEnd();
  55. correspondingAnimation.fireAnimationEvent(new AnimationEvent(this, AnimationEvent.ANIMATION_ENDED, correspondingAnimation, animationTarget));
  56. }
  57. @Override
  58. public void start() {
  59. // this.currentStepDelta = 0;
  60. AnimationManager.getInstance().registerAnimation(correspondingAnimation);
  61. super.start();
  62. }
  63. @Override
  64. public void end() {
  65. AnimationManager.getInstance().unregisterAnimation(correspondingAnimation);
  66. super.end();
  67. // this.currentStepDelta = 0;
  68. }
  69. public float getCurrentStepDelta(){
  70. return this.currentStepDelta;
  71. }
  72. @Override
  73. public void repeat(int theRepeatCount) {
  74. super.repeat(theRepeatCount);
  75. }
  76. @Override
  77. public void setCallback(String theCallback) {
  78. super.setCallback(theCallback);
  79. }
  80. @Override
  81. public void setDelay(float theDurationDelay) {
  82. super.setDelay(theDurationDelay);
  83. }
  84. @Override
  85. public void setDuration(float theDurationEasing) {
  86. super.setDuration(theDurationEasing);
  87. }
  88. }