commit 3b8f5220b6c9d24a152c376315c167d753148805
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue May 17 12:43:35 2022 +0200

    Improve two things in the BandagedCreator:
    
    - when one minimizes the app and re-maximizes it, now the app remembers the state of the bandaged cube being created
    - when one minimizes the app while one of th cubits is marked, it no longer gets marked the second time on re-maximizaton (which was the reason why some cubits sometimes couldn't be unmarked).

diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java b/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
index 12cd318a..68e57ec6 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
@@ -279,25 +279,28 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
    @Override
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
       {
-      mWidth = width;
-      mHeight= height;
-      rescaleObject();
-
-      mScreen.detachAll();
-      int touched = mView.getTouched();
-
-      for(int i=0; i<mNumCubits; i++)
-        if( mCubits[i].isAttached() )
-          {
-          mCubits[i].scaleMove(mScaleValue);
-          if( touched==i ) mCubits[i].setMarked();
-          else             mCubits[i].setUnmarked();
-          DistortedNode node = mCubits[i].getNode();
-          mScreen.attach(node);
-          }
-
-      mView.setScreenSize(width,height);
-      mScreen.resize(width,height);
+      if( width!=mWidth || height!=mHeight )
+        {
+        mWidth = width;
+        mHeight= height;
+        rescaleObject();
+
+        mScreen.detachAll();
+        int touched = mView.getTouched();
+
+        for(int i=0; i<mNumCubits; i++)
+          if( mCubits[i].isAttached() )
+            {
+            mCubits[i].scaleMove(mScaleValue);
+            if( touched==i ) mCubits[i].setMarked();
+            else             mCubits[i].setUnmarked();
+            DistortedNode node = mCubits[i].getNode();
+            mScreen.attach(node);
+            }
+
+        mView.setScreenSize(width,height);
+        mScreen.resize(width,height);
+        }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -313,8 +316,18 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
       DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
       DistortedLibrary.setCull(true);
 
-      createCubits();
+      if( mCubits==null )
+        {
+        createCubits();
+        }
+      else
+        {
+        for(int i=0; i<mNumCubits; i++) mCubits[i].recreateBitmap();
+        }
+
       mCubitsCreated = true;
+      mWidth = 0;
+      mHeight= 0;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorView.java b/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
index cc208eb2..38d5c354 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
@@ -269,8 +269,13 @@ public class BandagedCreatorView extends GLSurfaceView
       if( mTouchedIndex2>=0 )
         {
         mRenderer.untouchCubit(mTouchedIndex1);
-        mRenderer.untouchCubit(mTouchedIndex2);
-        mRenderer.setConnecting(mTouchedIndex1,mTouchedIndex2);
+
+        if( mTouchedIndex2!=mTouchedIndex1 )
+          {
+          mRenderer.untouchCubit(mTouchedIndex2);
+          mRenderer.setConnecting(mTouchedIndex1,mTouchedIndex2);
+          }
+
         mTouchedIndex1 = -1;
         mTouchedIndex2 = -1;
         }
diff --git a/src/main/java/org/distorted/bandaged/BandagedCubit.java b/src/main/java/org/distorted/bandaged/BandagedCubit.java
index 00cb864a..d1ea9075 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCubit.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCubit.java
@@ -57,6 +57,7 @@ public class BandagedCubit
 
     private final DistortedNode mNode;
     private final DistortedEffects mEffects;
+    private final DistortedTexture mTexture;
     private final Static3D mMove;
     private final boolean mRoundCorners;
     private final int mX, mY, mZ;
@@ -181,9 +182,9 @@ public class BandagedCubit
       FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
       MeshBase mesh = factory.createMesh(mPosition,mX,mY,mZ,false,mRoundCorners);
 
-      DistortedTexture texture = new DistortedTexture();
+      mTexture = new DistortedTexture();
       if( mBitmap==null ) createBitmap();
-      texture.setTextureAlreadyInverted(mBitmap);
+      mTexture.setTextureAlreadyInverted(mBitmap);
 
       resetTextureMaps(mesh);
 
@@ -198,7 +199,7 @@ public class BandagedCubit
       mEffects.apply(quat2Effect);
       mEffects.apply(quat1Effect);
 
-      mNode = new DistortedNode(texture,mEffects,mesh);
+      mNode = new DistortedNode(mTexture,mEffects,mesh);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -245,6 +246,14 @@ public class BandagedCubit
       mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
       }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void recreateBitmap()
+      {
+      if( mBitmap==null ) createBitmap();
+      mTexture.setTextureAlreadyInverted(mBitmap);
+      }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     public void scaleMove(float scale)
@@ -256,16 +265,23 @@ public class BandagedCubit
 
     public void setMarked()
       {
-      FragmentEffectBrightness effect = new FragmentEffectBrightness(mAlpha);
-      mMarkedEffectID = effect.getID();
-      mEffects.apply(effect);
+      if( mMarkedEffectID<0 )
+        {
+        FragmentEffectBrightness effect = new FragmentEffectBrightness(mAlpha);
+        mMarkedEffectID = effect.getID();
+        mEffects.apply(effect);
+        }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     public void setUnmarked()
       {
-      if( mMarkedEffectID>=0 ) mEffects.abortById(mMarkedEffectID);
+      if( mMarkedEffectID>=0 )
+        {
+        mEffects.abortById(mMarkedEffectID);
+        mMarkedEffectID = -1;
+        }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
