commit 473611ee7d023bd389d834e57a4f146d48a0264f
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun Apr 5 19:42:02 2020 +0100

    Progress with the 3x3x3 Solver.

diff --git a/src/main/java/org/distorted/main/RubikPostRender.java b/src/main/java/org/distorted/main/RubikPostRender.java
index b8cdc884..f96370f5 100644
--- a/src/main/java/org/distorted/main/RubikPostRender.java
+++ b/src/main/java/org/distorted/main/RubikPostRender.java
@@ -451,7 +451,7 @@ public class RubikPostRender implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void setTextureMap(int cubit, int face, int newColor)
+  void setTextureMap(int cubit, int face, int newColor)
     {
     mSetTextureMap = true;
 
diff --git a/src/main/java/org/distorted/main/RubikSurfaceView.java b/src/main/java/org/distorted/main/RubikSurfaceView.java
index 18d6509c..b9247679 100644
--- a/src/main/java/org/distorted/main/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/main/RubikSurfaceView.java
@@ -32,12 +32,17 @@ import org.distorted.library.type.Static4D;
 import org.distorted.objects.RubikObject;
 import org.distorted.objects.RubikObjectMovement;
 import org.distorted.states.RubikState;
+import org.distorted.states.RubikStateSolver;
 import org.distorted.states.RubikStateSolving;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 public class RubikSurfaceView extends GLSurfaceView
 {
+    public static final int MODE_ROTATE  = 0;
+    public static final int MODE_DRAG    = 1;
+    public static final int MODE_REPLACE = 2;
+
     // Moving the finger from the middle of the vertical screen to the right edge will rotate a
     // given face by SWIPING_SENSITIVITY/2 degrees.
     private final static int SWIPING_SENSITIVITY  = 240;
@@ -170,7 +175,9 @@ public class RubikSurfaceView extends GLSurfaceView
 
     private void setUpDragOrRotate(float x, float y)
       {
-      if( !RubikState.canRotate() )
+      int mode = RubikState.getMode();
+
+      if( mode==MODE_DRAG )
         {
         mDragging           = true;
         mBeginningRotation  = false;
@@ -185,8 +192,21 @@ public class RubikSurfaceView extends GLSurfaceView
         if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint1,rotatedCamera) )
           {
           mDragging           = false;
-          mBeginningRotation  = mPostRender.canRotate();
           mContinuingRotation = false;
+
+          if( mode==MODE_ROTATE )
+            {
+            mBeginningRotation= mPostRender.canRotate();
+            }
+          else if( mode==MODE_REPLACE )
+            {
+            mBeginningRotation= false;
+            RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass();
+            int cubit = mMovement.getTouchedCubit();
+            int face  = mMovement.getTouchedFace();
+            int color = solver.getCurrentColor();
+            mPostRender.setTextureMap( cubit, face, color );
+            }
           }
         else
           {
diff --git a/src/main/java/org/distorted/objects/RubikObjectMovement.java b/src/main/java/org/distorted/objects/RubikObjectMovement.java
index 50cece29..59e19234 100644
--- a/src/main/java/org/distorted/objects/RubikObjectMovement.java
+++ b/src/main/java/org/distorted/objects/RubikObjectMovement.java
@@ -283,4 +283,19 @@ public abstract class RubikObjectMovement
 
     return new Static2D(rotIndex,offset);
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int getTouchedFace()
+    {
+    return mLastTouchedAxis*mNumFacesPerAxis + mLastTouchedLR;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
+
+  public int getTouchedCubit()
+    {
+    return 0;
+    }
   }
diff --git a/src/main/java/org/distorted/states/RubikState.java b/src/main/java/org/distorted/states/RubikState.java
index 63919442..47651158 100644
--- a/src/main/java/org/distorted/states/RubikState.java
+++ b/src/main/java/org/distorted/states/RubikState.java
@@ -21,22 +21,23 @@ package org.distorted.states;
 
 import android.content.SharedPreferences;
 import org.distorted.main.RubikActivity;
+import static org.distorted.main.RubikSurfaceView.*;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 public enum RubikState
   {
-  MAIN ( null , false, new RubikStateMain()      ),
-  PLAY ( MAIN , true , new RubikStatePlay()      ),
-  SOLV ( PLAY , true , new RubikStateSolving()   ),
-  PATT ( MAIN , false, new RubikStatePattern()   ),
-  SVER ( MAIN , false, new RubikStateSolver()    ),
-  SOLU ( SVER , false, new RubikStateSolution()  ),
+  MAIN ( null , MODE_DRAG   , new RubikStateMain()     ),
+  PLAY ( MAIN , MODE_ROTATE , new RubikStatePlay()     ),
+  SOLV ( PLAY , MODE_ROTATE , new RubikStateSolving()  ),
+  PATT ( MAIN , MODE_DRAG   , new RubikStatePattern()  ),
+  SVER ( MAIN , MODE_REPLACE, new RubikStateSolver()   ),
+  SOLU ( SVER , MODE_DRAG   , new RubikStateSolution() ),
   ;
 
   public static final int LENGTH = values().length;
   private final RubikState mBack;
-  private boolean mCanRotate;
+  private int mMode;
   private final RubikStateAbstract mClass;
   private static final RubikState[] sizes;
 
@@ -70,9 +71,9 @@ public enum RubikState
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public static boolean canRotate()
+  public static int getMode()
     {
-    return mCurrState.mCanRotate;
+    return mCurrState.mMode;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -122,11 +123,11 @@ public enum RubikState
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  RubikState(RubikState back, boolean canRotate, RubikStateAbstract clazz)
+  RubikState(RubikState back, int mode, RubikStateAbstract clazz)
     {
-    mBack      = back;
-    mCanRotate = canRotate;
-    mClass     = clazz;
+    mBack = back;
+    mMode = mode;
+    mClass= clazz;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/states/RubikStateSolver.java b/src/main/java/org/distorted/states/RubikStateSolver.java
index 0c21dbed..41aa2536 100644
--- a/src/main/java/org/distorted/states/RubikStateSolver.java
+++ b/src/main/java/org/distorted/states/RubikStateSolver.java
@@ -24,6 +24,9 @@ import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
+import android.support.v4.content.ContextCompat;
 import android.util.DisplayMetrics;
 import android.view.View;
 import android.widget.Button;
@@ -32,7 +35,7 @@ import android.widget.LinearLayout;
 
 import org.distorted.main.R;
 import org.distorted.main.RubikActivity;
-import org.distorted.objects.RubikObject;
+import org.distorted.main.RubikPostRender;
 import org.distorted.objects.RubikObjectList;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -123,8 +126,8 @@ public class RubikStateSolver extends RubikStateAbstract
 
   void leaveState(RubikActivity act)
     {
-    RubikObject object = act.getObject();
-    object.resetAllTextureMaps();
+    RubikPostRender post = act.getPostRender();
+    post.resetAllTextureMaps();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -134,6 +137,8 @@ public class RubikStateSolver extends RubikStateAbstract
     mSolving = false;
 
     act.changeObject(RubikObjectList.CUBE,3,null);
+    RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
+    play.setObjectAndSize(RubikObjectList.CUBE,3);
 
     DisplayMetrics metrics = act.getResources().getDisplayMetrics();
     final float scale = metrics.density;
@@ -145,6 +150,8 @@ public class RubikStateSolver extends RubikStateAbstract
     if( mBitmap     ==null ) setupBitmaps(scale);
     if( mColorButton==null ) setupColorButtons(act,scale);
 
+    markButton(act);
+
     for(ImageButton button: mColorButton) layoutTop.addView(button);
 
     // BOT ////////////////////////////
@@ -222,7 +229,8 @@ public class RubikStateSolver extends RubikStateAbstract
         @Override
         public void onClick(View view)
           {
-          android.util.Log.e("solver", "button "+FACE_COLORS[ii]+" clicked");
+          mCurrentColor = ii;
+          markButton(act);
           }
         });
       }
@@ -276,6 +284,25 @@ public class RubikStateSolver extends RubikStateAbstract
       });
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void markButton(RubikActivity act)
+    {
+    for(int b=0; b<NUM_FACES; b++)
+      {
+      Drawable d = mColorButton[b].getBackground();
+
+      if( b==mCurrentColor )
+        {
+        d.setColorFilter(ContextCompat.getColor(act,R.color.red), PorterDuff.Mode.MULTIPLY);
+        }
+      else
+        {
+        d.clearColorFilter();
+        }
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void savePreferences(SharedPreferences.Editor editor)
@@ -293,4 +320,11 @@ public class RubikStateSolver extends RubikStateAbstract
     {
     mCurrentColor = preferences.getInt("stateSolver_color", 0);
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int getCurrentColor()
+    {
+    return mCurrentColor;
+    }
   }
