Project

General

Profile

« Previous | Next » 

Revision 99a80c08

Added by Leszek Koltunski almost 2 years ago

Minor.

View differences:

src/main/java/org/distorted/examples/TableOfContents.java
88 88

  
89 89
  private enum Application
90 90
    {
91
    FLATBLUR2         (R.drawable.icon_example_flatblur        , R.string.example_flatblur         , R.string.example_flatblur_subtitle         , FlatBlur2Activity.class ),
92

  
91 93
    MONALISA          (R.drawable.icon_example_monalisa        , R.string.example_monalisa        , R.string.example_monalisa_subtitle        ,         MonaLisaActivity.class),
92 94
    SINK              (R.drawable.icon_example_sink            , R.string.example_sink            , R.string.example_sink_subtitle            ,             SinkActivity.class),
93 95
    BEAN              (R.drawable.icon_example_bean            , R.string.example_bean            , R.string.example_bean_subtitle            ,             BeanActivity.class),
......
130 132
    SINGLEMESH        (R.drawable.icon_example_singlemesh      , R.string.example_singlemesh           , R.string.example_singlemesh_subtitle           ,            SingleMeshActivity.class),
131 133
    MESHFILE          (R.drawable.icon_example_meshfile        , R.string.example_meshfile           , R.string.example_meshfile_subtitle           ,            MeshFileActivity.class),
132 134
    FLATBLUR          (R.drawable.icon_example_flatblur        , R.string.example_flatblur         , R.string.example_flatblur_subtitle         , FlatBlurActivity.class ),
133
    FLATBLUR2         (R.drawable.icon_example_flatblur        , R.string.example_flatblur         , R.string.example_flatblur_subtitle         , FlatBlur2Activity.class ),
134 135

  
135 136
    ;
136 137

  
src/main/java/org/distorted/examples/flatblur2/DataGeneric.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.examples.flatblur2;
11

  
12
///////////////////////////////////////////////////////////////////////////////////////////////////
13

  
14
public abstract class DataGeneric
15
{
16

  
17

  
18
}
src/main/java/org/distorted/examples/flatblur2/DataStars.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.examples.flatblur2;
11

  
12
///////////////////////////////////////////////////////////////////////////////////////////////////
13

  
14
import android.content.res.Resources;
15

  
16
public class DataStars extends DataGeneric
17
{
18
  private final int mTotStars, mNewStars;
19
  private final Resources mRes;
20

  
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

  
23
  public DataStars(int totStars, int newStars, Resources res)
24
    {
25
    mTotStars = totStars;
26
    mNewStars = newStars;
27
    mRes = res;
28
    }
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
  int getTotal()
33
    {
34
    return mTotStars;
35
    }
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
  int getNew()
40
    {
41
    return mNewStars;
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
  Resources getResources()
47
    {
48
    return mRes;
49
    }
50
}
src/main/java/org/distorted/examples/flatblur2/FlatBlur2Activity.java
71 71

  
72 72
///////////////////////////////////////////////////////////////////////////////////////////////////
73 73

  
74
    public void crash(View view)
74
    public void button1(View view)
75 75
      {
76 76
      FlatBlur2SurfaceView v = findViewById(R.id.flatblur2SurfaceView);
77 77
      FlatBlur2Renderer renderer = v.getRenderer();
78
      renderer.crash();
78
      renderer.button1();
79
      }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
    public void button2(View view)
84
      {
85
      FlatBlur2SurfaceView v = findViewById(R.id.flatblur2SurfaceView);
86
      FlatBlur2Renderer renderer = v.getRenderer();
87
      renderer.button2();
79 88
      }
80 89
}
src/main/java/org/distorted/examples/flatblur2/FlatBlur2Renderer.java
19 19

  
20 20
package org.distorted.examples.flatblur2;
21 21

  
22
import android.content.res.Resources;
22 23
import android.opengl.GLSurfaceView;
23 24

  
25
import org.distorted.library.effect.EffectQuality;
26
import org.distorted.library.effect.EffectType;
27
import org.distorted.library.effect.MatrixEffectRotate;
28
import org.distorted.library.effect.MatrixEffectScale;
24 29
import org.distorted.library.effect.PostprocessEffectGlow;
25
import org.distorted.library.effect.VertexEffectScale;
26 30
import org.distorted.library.main.DistortedEffects;
27 31
import org.distorted.library.main.DistortedLibrary;
28 32
import org.distorted.library.main.DistortedNode;
29 33
import org.distorted.library.main.DistortedScreen;
30 34
import org.distorted.library.main.DistortedTexture;
35
import org.distorted.library.mesh.MeshCubes;
31 36
import org.distorted.library.mesh.MeshQuad;
37

  
38
import org.distorted.library.message.EffectListener;
39
import org.distorted.library.type.Dynamic2D;
40
import org.distorted.library.type.Dynamic4D;
41
import org.distorted.library.type.Static1D;
32 42
import org.distorted.library.type.Static2D;
43
import org.distorted.library.type.Static3D;
33 44
import org.distorted.library.type.Static4D;
34 45

  
35 46
import javax.microedition.khronos.egl.EGLConfig;
......
37 48

  
38 49
///////////////////////////////////////////////////////////////////////////////////////////////////
39 50

  
40
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
51
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener, ListenerOverlay, EffectListener
41 52
{
42 53
    private final GLSurfaceView mView;
43 54
    private final DistortedScreen mScreen;
44
    private final DistortedNode mNode;
55
    private Static3D mScale1, mScale2;
56
    private DistortedNode mNode;
45 57

  
46 58
///////////////////////////////////////////////////////////////////////////////////////////////////
47 59

  
......
49 61
      {
50 62
      mView = v;
51 63
      mScreen = new DistortedScreen();
52

  
53
      DistortedTexture texture1 = new DistortedTexture();
54
      texture1.setColorARGB(0xffff0000);
55
      MeshQuad mesh1 = new MeshQuad();
56
      DistortedEffects effects1 = new DistortedEffects();
57
      VertexEffectScale mainScale= new VertexEffectScale(200);
58
      effects1.apply(mainScale);
59
      mNode = new DistortedNode(texture1,effects1,mesh1);
60
      mScreen.attach(mNode);
61

  
62
      DistortedTexture texture2 = new DistortedTexture();
63
      texture2.setColorARGB(0xffff0000);
64
      MeshQuad mesh2 = new MeshQuad();
65
      DistortedEffects effects2 = new DistortedEffects();
66
      DistortedNode node2 = new DistortedNode(texture2,effects2,mesh2);
67
      mScreen.attach(node2);
68 64
      }
69 65

  
70 66
///////////////////////////////////////////////////////////////////////////////////////////////////
......
78 74

  
79 75
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
80 76
      {
77
      float s = width*0.05f;
78
      mScale1.set(width,width,0);
79
      mScale2.set(s,s,s);
81 80
      mScreen.resize(width,height);
82 81
      }
83 82

  
......
85 84
    
86 85
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
87 86
      {
88
      VertexEffectScale.enable();
89
      PostprocessEffectGlow.enable();
87
      DistortedTexture surface1 = new DistortedTexture();
88
      surface1.setColorARGB(0xffff0000);
89
      MeshQuad mesh1 = new MeshQuad();
90
      DistortedEffects effects1 = new DistortedEffects();
91

  
92
      mScale1 = new Static3D(1,1,1);
93
      MatrixEffectScale scale1 = new MatrixEffectScale(mScale1);
94
      effects1.apply(scale1);
95
      mNode = new DistortedNode(surface1,effects1,mesh1);
96
      mScreen.attach(mNode);
97

  
98
      DistortedTexture surface2 = new DistortedTexture();
99
      surface2.setColorARGB(0xff0000ff);
100
      MeshCubes mesh2 = new MeshCubes(2,2,2);
101
      DistortedEffects effects2 = new DistortedEffects();
102

  
103
      mScale2 = new Static3D(1,1,1);
104
      MatrixEffectScale scale2 = new MatrixEffectScale(mScale2);
105
      effects2.apply(scale2);
106
      Static1D angle = new Static1D(30);
107
      float SQ3 = (float)Math.sqrt(3);
108
      Static3D axis = new Static3D(SQ3/3,SQ3/3,SQ3/3);
109
      Static3D center = new Static3D(0,0,0);
110
      MatrixEffectRotate rot = new MatrixEffectRotate(angle,axis,center);
111
      effects2.apply(rot);
112
      DistortedNode node2 = new DistortedNode(surface2,effects2,mesh2);
113
      mNode.attach(node2);
114

  
115
      OverlayStars.enableEffects();
90 116
      DistortedLibrary.onSurfaceCreated( mView.getContext(), this);
91 117
      }
92 118

  
......
99 125

  
100 126
///////////////////////////////////////////////////////////////////////////////////////////////////
101 127

  
102
    public void crash()
128
    public void button1()
103 129
      {
104
      Static2D haloRadius = new Static2D(15,50);
105
      Static4D color      = new Static4D(1,1,1,1);
106
      PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
130
      OverlayStars stars = new OverlayStars();
131
      Resources res = mView.getResources();
132
      DataStars data  = new DataStars(10,5,res);
133
      stars.startOverlay(mScreen,this,data);
134
      }
135

  
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

  
138
    public void button2()
139
      {
140
      PostprocessEffectGlow glow = constructGlow();
107 141
      DistortedEffects effects = mNode.getEffects();
108 142
      effects.apply(glow);
109 143
      }
144

  
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

  
147
   private PostprocessEffectGlow constructGlow()
148
      {
149
      final int DUR_GLO = 3000;
150
      Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,0.5f);
151
      Static2D point20 = new Static2D( 0, 0);
152
      Static2D point21 = new Static2D(15,50);
153
      Dynamic4D color = new Dynamic4D(DUR_GLO, 0.5f);
154
      Static4D point40 = new Static4D(1,1,1,0.0f);
155
      Static4D point41 = new Static4D(1,1,1,0.8f);
156

  
157
      haloRadius.add(point20);
158
      haloRadius.add(point21);
159
      haloRadius.add(point20);
160
      color.add(point40);
161
      color.add(point41);
162
      color.add(point40);
163

  
164
      PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
165
      glow.setQuality(EffectQuality.MEDIUM);
166
      glow.notifyWhenFinished(this);
167
      return glow;
168
      }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
    public void overlayFinished(long id)
173
      {
174

  
175
      }
176

  
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

  
179
    public void effectFinished(long id)
180
      {
181
      DistortedEffects effects = mNode.getEffects();
182
      effects.abortByType(EffectType.POSTPROCESS);
183
      }
110 184
}
src/main/java/org/distorted/examples/flatblur2/ListenerOverlay.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.examples.flatblur2;
11

  
12
///////////////////////////////////////////////////////////////////////////////////////////////////
13

  
14
public interface ListenerOverlay
15
{
16
  void overlayFinished(long id);
17
}
src/main/java/org/distorted/examples/flatblur2/OverlayGeneric.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.examples.flatblur2;
11

  
12
import org.distorted.library.main.DistortedScreen;
13

  
14
import java.lang.reflect.Method;
15

  
16
///////////////////////////////////////////////////////////////////////////////////////////////////
17

  
18
public abstract class OverlayGeneric
19
{
20
   private enum Overlays
21
      {
22
      STARS ( OverlayStars.class )
23
      ;
24

  
25
      private final Class<? extends OverlayGeneric> mClass;
26

  
27
      Overlays(Class<? extends OverlayGeneric> clazz)
28
         {
29
         mClass = clazz;
30
         }
31
      }
32

  
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

  
35
   public static void enableEffects()
36
     {
37
     Method method;
38

  
39
     for(Overlays overlay: Overlays.values() )
40
        {
41
        try
42
          {
43
          method = overlay.mClass.getDeclaredMethod("enableEffects");
44
          }
45
        catch(NoSuchMethodException ex)
46
          {
47
          android.util.Log.e("OverlayGeneric", overlay.mClass.getSimpleName()+": exception getting method: "+ex.getMessage());
48
          method = null;
49
          }
50

  
51
        try
52
          {
53
          if( method!=null ) method.invoke(null);
54
          }
55
        catch(Exception ex)
56
          {
57
          android.util.Log.e("OverlayGeneric", overlay.mClass.getSimpleName()+": exception invoking method: "+ex.getMessage());
58
          }
59
        }
60
      }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
   public abstract long startOverlay(DistortedScreen screen, ListenerOverlay listener, DataGeneric data);
65
}
src/main/java/org/distorted/examples/flatblur2/OverlayStars.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.examples.flatblur2;
11

  
12
import android.content.res.Resources;
13
import android.graphics.Bitmap;
14
import android.graphics.BitmapFactory;
15
import android.graphics.Canvas;
16
import android.graphics.Paint;
17

  
18
import org.distorted.examples.R;
19
import org.distorted.library.effect.EffectQuality;
20
import org.distorted.library.effect.FragmentEffectAlpha;
21
import org.distorted.library.effect.MatrixEffectMove;
22
import org.distorted.library.effect.MatrixEffectScale;
23
import org.distorted.library.effect.PostprocessEffectGlow;
24
import org.distorted.library.effect.VertexEffectMove;
25
import org.distorted.library.effect.VertexEffectScale;
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedNode;
28
import org.distorted.library.main.DistortedScreen;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.main.InternalOutputSurface;
31
import org.distorted.library.mesh.MeshJoined;
32
import org.distorted.library.mesh.MeshQuad;
33
import org.distorted.library.message.EffectListener;
34
import org.distorted.library.type.Dynamic;
35
import org.distorted.library.type.Dynamic1D;
36
import org.distorted.library.type.Dynamic2D;
37
import org.distorted.library.type.Dynamic3D;
38
import org.distorted.library.type.Dynamic4D;
39
import org.distorted.library.type.Static1D;
40
import org.distorted.library.type.Static2D;
41
import org.distorted.library.type.Static3D;
42
import org.distorted.library.type.Static4D;
43

  
44
import java.util.Random;
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
public class OverlayStars extends OverlayGeneric implements EffectListener
49
{
50
   private static final int DUR_APP =  3500;
51
   private static final int DUR_MOV = 17500;
52
   private static final int DUR_GLO =  2600;
53

  
54
   private ListenerOverlay mListener;
55
   private DistortedNode mNodeFalling, mNodeCentral;
56
   private DistortedScreen mScreen;
57
   private DistortedTexture mTexture;
58
   private Bitmap mCountBitmap, mStarBitmap;
59
   private Canvas mCountCanvas;
60
   private Paint mPaint;
61
   private int mBmpW, mBmpH;
62
   private float mWidth, mHeight;
63
   private Random mRandom;
64
   private long mMoveID, mGlow1ID, mGlow2ID, mAlphaID;
65
   private int mTotalStars, mNewStars;
66
   private FragmentEffectAlpha mAlpha;
67
   private Dynamic1D mAlphaStrength;
68
   private boolean mIncrease;
69
   private float mTextHeight;
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
   private Dynamic3D createRandomMove(boolean increase)
74
      {
75
      Dynamic3D move = new Dynamic3D();
76
      move.setMode(Dynamic.MODE_PATH);
77
      move.setDuration(DUR_MOV);
78
      move.setCount(0.5f);
79

  
80
      float widthS = (mRandom.nextFloat()-0.5f)*mWidth*1.10f;
81
      float widthM = widthS + (mRandom.nextFloat()-0.5f)*mWidth*0.2f;
82
      float heighS = mRandom.nextFloat()*mHeight*0.2f;
83
      float heighM = (mRandom.nextFloat()-0.5f)*mHeight*0.2f;
84

  
85
      Static3D pointS = new Static3D(widthS,mHeight*0.55f+heighS,0);
86
      Static3D pointM = new Static3D(widthM,mHeight*0.25f+heighM,0);
87
      Static3D pointE = new Static3D(0,0,0);
88
      Static3D pointF = new Static3D(0,0,-10000);
89

  
90
      if( increase )
91
         {
92
         move.add(pointS);
93
         move.add(pointM);
94
         move.add(pointE);
95
         move.add(pointF);
96
         }
97
      else
98
         {
99
         move.add(pointF);
100
         move.add(pointE);
101
         move.add(pointM);
102
         move.add(pointS);
103
         }
104

  
105
      return move;
106
      }
107

  
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
   private void createAlphaEffect(boolean appear)
111
      {
112
      if( mAlpha==null )
113
         {
114
         mAlphaStrength = new Dynamic1D();
115
         mAlphaStrength.setMode(Dynamic.MODE_PATH);
116
         mAlphaStrength.setDuration(DUR_APP);
117
         mAlphaStrength.setCount(0.5f);
118
         equipAlpha(mAlphaStrength,appear);
119
         mAlpha = new FragmentEffectAlpha(mAlphaStrength);
120
         }
121
      else
122
         {
123
         mAlphaStrength.resetToBeginning();
124
         equipAlpha(mAlphaStrength,appear);
125
         }
126
      }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
   private void equipAlpha(Dynamic1D alpha, boolean appear)
131
      {
132
      Static1D point0 = new Static1D(0.0f);
133
      Static1D point1 = new Static1D(1.0f);
134

  
135
      alpha.removeAll();
136

  
137
      if( appear )
138
        {
139
        alpha.add(point0);
140
        alpha.add(point1);
141
        }
142
      else
143
        {
144
        alpha.add(point1);
145
        alpha.add(point0);
146
        }
147
      }
148

  
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

  
151
   private float computeQuotientAndTextHeight(int total)
152
      {
153
      if( total>=10000 )
154
         {
155
         mTextHeight = 0.610f;
156
         return 0.16f;
157
         }
158
      if( total>= 1000 )
159
         {
160
         mTextHeight = 0.625f;
161
         return 0.20f;
162
         }
163
      if( total>=  100 )
164
         {
165
         mTextHeight = 0.640f;
166
         return 0.26f;
167
         }
168

  
169
      mTextHeight = 0.655f;
170
      return 0.28f;
171
      }
172

  
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

  
175
   private void createBitmap(Resources res, int total)
176
      {
177
      mStarBitmap = BitmapFactory.decodeResource(res, R.raw.yellow_star);
178
      mBmpW = mStarBitmap.getWidth();
179
      mBmpH = mStarBitmap.getHeight();
180
      mCountBitmap = Bitmap.createBitmap(mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
181
      mCountCanvas = new Canvas(mCountBitmap);
182

  
183
      float quotient = computeQuotientAndTextHeight(total);
184

  
185
      mPaint = new Paint();
186
      mPaint.setColor(0xff000000);
187
      mPaint.setTextSize(mBmpH*quotient);
188
      mPaint.setAntiAlias(true);
189
      mPaint.setTextAlign(Paint.Align.CENTER);
190
      }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
   private DistortedNode createNodeFalling(boolean increase)
195
      {
196
      DistortedTexture texture = new DistortedTexture();
197
      texture.setTexture(mStarBitmap);
198

  
199
      MeshQuad[] mesh = new MeshQuad[mNewStars];
200

  
201
      for(int i=0; i<mNewStars; i++)
202
         {
203
         mesh[i] = new MeshQuad();
204
         mesh[i].setEffectAssociation(0,1,i+1);
205
         }
206

  
207
      MeshJoined wholeMesh = new MeshJoined(mesh);
208

  
209
      DistortedEffects effects = new DistortedEffects();
210
      VertexEffectScale scaleE = new VertexEffectScale(mWidth*0.15f);
211
      scaleE.setMeshAssociation(1,-1);
212
      effects.apply(scaleE);
213

  
214
      for(int i=0; i<mNewStars; i++)
215
        {
216
        Dynamic3D moveP = createRandomMove(increase);
217
        VertexEffectMove moveE= new VertexEffectMove(moveP);
218
        moveE.setMeshAssociation(0,i+1);
219
        effects.apply(moveE);
220

  
221
        if( i==0 )
222
           {
223
           mMoveID = moveE.getID();
224
           moveE.notifyWhenFinished(this);
225
           }
226
        }
227

  
228
      return new DistortedNode(texture,effects,wholeMesh);
229
      }
230

  
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

  
233
   private DistortedNode createNodeCentral(int numStars)
234
      {
235
      mTexture = new DistortedTexture();
236
      renderStars(numStars);
237

  
238
      MeshQuad mesh = new MeshQuad();
239

  
240
      DistortedEffects effects = new DistortedEffects();
241
      float scaleM  = mWidth*0.40f;
242
      Static3D moveM= new Static3D(0,0,1);
243
      MatrixEffectMove move  = new MatrixEffectMove(moveM);
244
      MatrixEffectScale scale= new MatrixEffectScale(scaleM);
245
      effects.apply(move);
246
      effects.apply(scale);
247
      createAlphaEffect(true);
248
      effects.apply(mAlpha);
249

  
250
      return new DistortedNode(mTexture,effects,mesh);
251
      }
252

  
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

  
255
   private void renderStars(int numStars)
256
      {
257
      String txt = ""+numStars;
258
      mCountBitmap.eraseColor(0x00000000);
259
      mCountCanvas.drawBitmap(mStarBitmap,0,0,null);
260
      mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*mTextHeight,mPaint);
261
      mTexture.setTexture(mCountBitmap);
262
      }
263

  
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

  
266
   public long startOverlay(DistortedScreen screen, ListenerOverlay listener, DataGeneric data)
267
      {
268
      mRandom = new Random();
269
      mScreen = screen;
270
      mListener= listener;
271
      DataStars stars = (DataStars)data;
272
      mTotalStars = stars.getTotal();
273
      mNewStars   = stars.getNew();
274
      Resources res = stars.getResources();
275
      mWidth = mScreen.getWidth();
276
      mHeight= mScreen.getHeight();
277
      mIncrease = mNewStars>0;
278
      if( !mIncrease ) mNewStars = -mNewStars;
279

  
280
      createBitmap(res, mTotalStars);
281
      mNodeFalling = createNodeFalling(mIncrease);
282
      mNodeFalling.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
283
      mScreen.attach(mNodeFalling);
284
      mNodeCentral = createNodeCentral(mTotalStars);
285
      mNodeCentral.glDepthMask(false);
286
      mScreen.attach(mNodeCentral);
287

  
288
      return 0;
289
      }
290

  
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

  
293
   private PostprocessEffectGlow constructGlow(boolean firstPhase)
294
      {
295
      Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,0.5f);
296
      Static2D point20 = new Static2D( 0, 0);
297
      Static2D point21 = new Static2D(15,50);
298
      Dynamic4D color = new Dynamic4D(DUR_GLO, 0.5f);
299
      Static4D point40 = new Static4D(1,1,1,0.0f);
300
      Static4D point41 = new Static4D(1,1,1,0.8f);
301

  
302
      if( firstPhase )
303
         {
304
         haloRadius.add(point20);
305
         haloRadius.add(point21);
306
         color.add(point40);
307
         color.add(point41);
308
         }
309
      else
310
         {
311
         haloRadius.add(point21);
312
         haloRadius.add(point20);
313
         color.add(point41);
314
         color.add(point40);
315
         }
316

  
317
      PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
318
      glow.setQuality(EffectQuality.MEDIUM);
319
      glow.notifyWhenFinished(this);
320

  
321
      return glow;
322
      }
323

  
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

  
326
   public void effectFinished(long id)
327
      {
328
      if( id==mMoveID )
329
         {
330
         PostprocessEffectGlow glow = constructGlow(true);
331
         mGlow1ID = glow.getID();
332
         DistortedEffects effects = mNodeCentral.getEffects();
333
         effects.apply(glow);
334
         }
335
      if( id==mGlow1ID )
336
         {
337
         renderStars(mTotalStars+(mIncrease ? mNewStars : -mNewStars));
338
         PostprocessEffectGlow glow = constructGlow(false);
339
         mGlow2ID = glow.getID();
340
         DistortedEffects effects = mNodeCentral.getEffects();
341
         effects.abortById(mGlow1ID);
342
         effects.apply(glow);
343
         }
344
      if( id==mGlow2ID )
345
         {
346
         DistortedEffects effects = mNodeCentral.getEffects();
347
         effects.abortById(mGlow2ID);
348
         createAlphaEffect(false);
349
         mAlphaID = mAlpha.getID();
350
         mAlpha.notifyWhenFinished(this);
351
         effects.apply(mAlpha);
352
         }
353
      if( id==mAlphaID )
354
         {
355
         mScreen.detach(mNodeCentral);
356
         mNodeCentral.markForDeletion();
357
         mNodeCentral=null;
358
         mScreen.detach(mNodeFalling);
359
         mNodeFalling.markForDeletion();
360
         mNodeFalling=null;
361
         mListener.overlayFinished(id);
362
         }
363
      }
364

  
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

  
367
  @SuppressWarnings("unused")
368
  public static void enableEffects()
369
     {
370
     FragmentEffectAlpha.enable();
371
     VertexEffectMove.enable();
372
     VertexEffectScale.enable();
373
     PostprocessEffectGlow.enable();
374
     }
375
}
src/main/res/layout/flatblur2layout.xml
10 10
        android:layout_height="0dp"
11 11
        android:layout_weight="1" />
12 12

  
13
    <LinearLayout
14
        android:orientation="horizontal"
15
        android:layout_width="match_parent"
16
        android:layout_height="wrap_content"
17
        android:gravity="center">
18

  
19
        <Button
20
                android:id="@+id/flatblurButton1"
21
                android:layout_width="0dp"
22
                android:layout_height="match_parent"
23
                android:layout_weight="1"
24
                android:onClick="button1"
25
                android:checked="false"/>
13 26
        <Button
14
                android:id="@+id/flatblur2Button2"
15
                android:text="CRASH"
16
                android:layout_width="match_parent"
17
                android:layout_height="100dp"
18
                android:onClick="crash"
27
                android:id="@+id/flatblurButton2"
28
                android:layout_width="0dp"
29
                android:layout_height="match_parent"
30
                android:layout_weight="1"
31
                android:onClick="button2"
19 32
                android:checked="false"/>
20 33

  
34
    </LinearLayout>
35

  
21 36
</LinearLayout>

Also available in: Unified diff