commit ec4987d4feb8325591dd3050d226322cf6139437
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Dec 19 14:58:32 2022 +0100

    'Stars' animation: support totalStars up to 5 digits long, i.e. up to 99999.

diff --git a/src/main/java/org/distorted/overlays/OverlayStars.java b/src/main/java/org/distorted/overlays/OverlayStars.java
index 71c542fa..fc39d8b4 100644
--- a/src/main/java/org/distorted/overlays/OverlayStars.java
+++ b/src/main/java/org/distorted/overlays/OverlayStars.java
@@ -34,7 +34,6 @@ import org.distorted.library.type.Dynamic;
 import org.distorted.library.type.Dynamic1D;
 import org.distorted.library.type.Dynamic2D;
 import org.distorted.library.type.Dynamic3D;
-import org.distorted.library.type.Dynamic4D;
 import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static2D;
 import org.distorted.library.type.Static3D;
@@ -47,12 +46,9 @@ import java.util.Random;
 
 public class OverlayStars extends OverlayGeneric implements EffectListener
 {
-   private static final int DUR_APP =  1000;
-   private static final int DUR_MOV =  4000;
-   private static final int DUR_GLO =  2000;
-
-   private static final int[] colors = new int[] {0,0,1,  1,0,1,  1,0,0,  1,1,0,  0,1,0,  1,1,1}; // blue, pink, red, yellow, green, white
-   private static final int INDEX = 5;
+   private static final int DUR_APP =  1500;
+   private static final int DUR_MOV =  3500;
+   private static final int DUR_GLO =   600;
 
    private ListenerOverlay mListener;
    private DistortedNode mNodeFalling, mNodeCentral;
@@ -64,11 +60,12 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
    private int mBmpW, mBmpH;
    private float mWidth, mHeight;
    private Random mRandom;
-   private long mMoveID, mGlowID, mAlphaID;
+   private long mMoveID, mGlow1ID, mGlow2ID, mAlphaID;
    private int mTotalStars, mNewStars;
    private FragmentEffectAlpha mAlpha;
    private Dynamic1D mAlphaStrength;
    private boolean mIncrease;
+   private float mTextHeight;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -150,16 +147,43 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   private void createBitmap(Resources res)
+   private float computeQuotientAndTextHeight(int total)
+      {
+      if( total>=10000 )
+         {
+         mTextHeight = 0.610f;
+         return 0.16f;
+         }
+      if( total>= 1000 )
+         {
+         mTextHeight = 0.625f;
+         return 0.20f;
+         }
+      if( total>=  100 )
+         {
+         mTextHeight = 0.640f;
+         return 0.26f;
+         }
+
+      mTextHeight = 0.655f;
+      return 0.28f;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   private void createBitmap(Resources res, int total)
       {
       mStarBitmap = BitmapFactory.decodeResource(res, R.drawable.star);
       mBmpW = mStarBitmap.getWidth();
       mBmpH = mStarBitmap.getHeight();
       mCountBitmap = Bitmap.createBitmap(mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
       mCountCanvas = new Canvas(mCountBitmap);
+
+      float quotient = computeQuotientAndTextHeight(total);
+
       mPaint = new Paint();
       mPaint.setColor(0xff000000);
-      mPaint.setTextSize(mBmpH*0.28f);
+      mPaint.setTextSize(mBmpH*quotient);
       mPaint.setAntiAlias(true);
       mPaint.setTextAlign(Paint.Align.CENTER);
       }
@@ -232,7 +256,7 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
       String txt = ""+numStars;
       mCountBitmap.eraseColor(0x00000000);
       mCountCanvas.drawBitmap(mStarBitmap,0,0,null);
-      mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*0.64f,mPaint);
+      mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*mTextHeight,mPaint);
       mTexture.setTexture(mCountBitmap);
       }
 
@@ -244,7 +268,7 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
       mScreen = screen;
       mListener= listener;
       DataStars stars = (DataStars)data;
-      mTotalStars = stars.getTotal();
+      mTotalStars = 7;//stars.getTotal();
       mNewStars   = stars.getNew();
       Resources res = stars.getResources();
       mWidth = mScreen.getWidth();
@@ -252,49 +276,73 @@ public class OverlayStars extends OverlayGeneric implements EffectListener
       mIncrease = mNewStars>0;
       if( !mIncrease ) mNewStars = -mNewStars;
 
-      createBitmap(res);
+      createBitmap(res, mTotalStars);
       mNodeFalling = createNodeFalling(mIncrease);
       mNodeFalling.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
       mScreen.attach(mNodeFalling);
       mNodeCentral = createNodeCentral(mTotalStars);
       mNodeCentral.glDepthMask(false);
-      mNodeCentral.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
       mScreen.attach(mNodeCentral);
 
       return 0;
       }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   private PostprocessEffectGlow constructGlow(boolean firstPhase)
+      {
+      Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,0.5f);
+      Static2D point0 = new Static2D( 0, 0);
+      Static2D point1 = new Static2D(15,50);
+
+      if( firstPhase )
+         {
+         haloRadius.add(point0);
+         haloRadius.add(point1);
+         }
+      else
+         {
+         haloRadius.add(point1);
+         haloRadius.add(point0);
+         }
+
+      Static4D color = new Static4D(1,1,1,0.5f);
+
+      PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
+      glow.setQuality(EffectQuality.MEDIUM);
+      glow.notifyWhenFinished(this);
+
+      return glow;
+      }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
    public void effectFinished(long id)
       {
       if( id==mMoveID )
          {
-         Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,1.0f);
-         haloRadius.add(new Static2D( 0, 0));
-         haloRadius.add(new Static2D(15,50));
-         haloRadius.add(new Static2D( 0, 0));
-
-         Dynamic4D color= new Dynamic4D(DUR_GLO,1.0f);
-         Static4D P1    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f);
-         Static4D P2    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f);
-         color.add(P1);
-         color.add(P2);
-         color.add(P1);
-
-         PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
-         glow.setQuality(EffectQuality.MEDIUM);
-         mGlowID = glow.getID();
-         glow.notifyWhenFinished(this);
+         PostprocessEffectGlow glow = constructGlow(true);
+         mGlow1ID = glow.getID();
          DistortedEffects effects = mNodeCentral.getEffects();
          effects.apply(glow);
+         }
+      if( id==mGlow1ID )
+         {
          renderStars(mTotalStars+(mIncrease ? mNewStars : -mNewStars));
+         PostprocessEffectGlow glow = constructGlow(false);
+         mGlow2ID = glow.getID();
+         DistortedEffects effects = mNodeCentral.getEffects();
+         effects.abortById(mGlow1ID);
+         effects.apply(glow);
          }
-      if( id==mGlowID )
+      if( id==mGlow2ID )
          {
+         DistortedEffects effects = mNodeCentral.getEffects();
+         effects.abortById(mGlow2ID);
          createAlphaEffect(false);
          mAlphaID = mAlpha.getID();
          mAlpha.notifyWhenFinished(this);
+         effects.apply(mAlpha);
          }
       if( id==mAlphaID )
          {
