Project

General

Profile

« Previous | Next » 

Revision 8d5a8e06

Added by Leszek Koltunski about 5 years ago

Simplify the way applications can get notifications when an effect finishes.

Now, instead of the 'DistortedEffects.(de)registerForNotifications()' 2 APIs, we call a single 'Effect.notifyWhenFinished()'.

View differences:

src/main/java/org/distorted/examples/listener/ListenerRenderer.java
41 41
import org.distorted.library.type.Static3D;
42 42
import org.distorted.library.type.Static4D;
43 43
import org.distorted.library.message.EffectListener;
44
import org.distorted.library.message.EffectMessage;
45 44

  
46 45
import android.graphics.Bitmap;
47 46
import android.graphics.BitmapFactory;
......
68 67
      {
69 68
      mView = v;
70 69
      mEffects = new DistortedEffects();
71
      mEffects.registerForMessages(this);
72 70
      mScreen = new DistortedScreen();
73 71
      mRnd = new Random(0);
74 72

  
......
92 90
      dDistort.add(new Static3D(0,0,     0));
93 91
      dDistort.add(new Static3D(0,0,height));
94 92

  
95
      return mEffects.apply( new VertexEffectDistort(dDistort, new Static3D(pointx,pointy,0), new Static4D(0,0,0,radius)) );
93
      VertexEffectDistort distort = new VertexEffectDistort(dDistort, new Static3D(pointx,pointy,0), new Static4D(0,0,0,radius));
94
      distort.notifyWhenFinished(this);
95

  
96
      return mEffects.apply(distort);
96 97
      }
97 98
   
98 99
///////////////////////////////////////////////////////////////////////////////////////////////////
99
// the library sending messages to us. This is running on a library 'MessageSender' thread.
100 100

  
101
   public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
101
   public void effectFinished(final long effectID)
102 102
     {
103
     switch(em)
104
        {
105
        case EFFECT_FINISHED: mEffects.abortById(effectID);
106

  
107
                              if( !addNewBubble() )
108
                                {
109
                                android.util.Log.e("Listener", "failed to add new bubble - this should never happen!");
110
                                }
111
                              break;
112
        }
103
     mEffects.abortById(effectID);
104

  
105
     if( !addNewBubble() )
106
       {
107
       android.util.Log.e("Listener", "failed to add new bubble - this should never happen!");
108
       }
113 109
     }
114 110
   
115 111
///////////////////////////////////////////////////////////////////////////////////////////////////
......
128 124
       int w = (height*bmpWidth)/bmpHeight;
129 125
       float factor = (float)height/bmpHeight;
130 126

  
131
       mMove.set((width-w)/2,0,0);
127
       mMove.set((width-w)*0.5f,0,0);
132 128
       mScale.set(factor,factor,factor);
133 129
       }
134 130
     else
......
136 132
       int h = (width*bmpHeight)/bmpWidth;
137 133
       float factor = (float)width/bmpWidth;
138 134

  
139
       mMove.set(0,(height-h)/2,0);
135
       mMove.set(0,(height-h)*0.5f,0);
140 136
       mScale.set(factor,factor,factor);
141 137
       }
142 138
      

Also available in: Unified diff