Project

General

Profile

Download (26.8 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 568d4698

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.main;
21

    
22
import android.app.Activity;
23
import android.content.SharedPreferences;
24
import android.util.DisplayMetrics;
25
import android.view.MotionEvent;
26

    
27
import org.distorted.library.main.QuatHelper;
28
import org.distorted.library.type.Static2D;
29
import org.distorted.library.type.Static4D;
30

    
31
import org.distorted.objectlib.helpers.BlockController;
32
import org.distorted.objectlib.helpers.MovesFinished;
33
import org.distorted.objectlib.helpers.ObjectLibInterface;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class ObjectControl
38
{
39
    public static final int NUM_SPEED_PROBES = 10;
40
    public static final int INVALID_POINTER_ID = -1;
41

    
42
    public static final int MODE_ROTATE  = 0;
43
    public static final int MODE_DRAG    = 1;
44
    public static final int MODE_REPLACE = 2;
45

    
46
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
47
    // given face by SWIPING_SENSITIVITY/2 degrees.
48
    public final static int SWIPING_SENSITIVITY  = 240;
49
    // Moving the finger by 0.3 of an inch will start a Rotation.
50
    public final static float ROTATION_SENSITIVITY = 0.3f;
51

    
52
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
53

    
54
    private final ObjectLibInterface mInterface;
55
    private final ObjectPreRender mPreRender;
56
    private Movement mMovement;
57
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
58
    private int mScreenWidth, mScreenHeight, mScreenMin;
59
    private float mMoveX, mMoveY;
60

    
61
    private float mRotAngle, mInitDistance;
62
    private float mStartRotX, mStartRotY;
63
    private float mAxisX, mAxisY;
64
    private float mRotationFactor;
65
    private int mLastCubitColor, mLastCubitFace, mLastCubit;
66
    private int mCurrentAxis, mCurrentRow;
67
    private float mCurrentAngle, mCurrRotSpeed;
68
    private final float[] mLastX;
69
    private final float[] mLastY;
70
    private final long[] mLastT;
71
    private int mFirstIndex, mLastIndex;
72
    private final int mDensity;
73

    
74
    private int mPointer1, mPointer2;
75
    private float mX1, mY1, mX2, mY2, mX, mY;
76
    private final boolean mIsAutomatic;
77

    
78
    private boolean mIsLocked, mRemLocked;
79

    
80
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
81
    private static final Static4D mTemp= new Static4D(0,0,0,1);
82

    
83
    private static boolean mForcedIconMode = false, mForcedCreateMesh = false;
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
87
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
88

    
89
    private void computeCurrentAxis(Static4D axis)
90
      {
91
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
92

    
93
      mAxisX =result.get0();
94
      mAxisY =result.get1();
95

    
96
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
97
      mAxisX /= len;
98
      mAxisY /= len;
99
      }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
    private void addSpeedProbe(float x, float y)
104
      {
105
      long currTime = System.currentTimeMillis();
106
      boolean theSame = mLastIndex==mFirstIndex;
107

    
108
      mLastIndex++;
109
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
110

    
111
      mLastT[mLastIndex] = currTime;
112
      mLastX[mLastIndex] = x;
113
      mLastY[mLastIndex] = y;
114

    
115
      if( mLastIndex==mFirstIndex)
116
        {
117
        mFirstIndex++;
118
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
119
        }
120

    
121
      if( theSame )
122
        {
123
        mLastT[mFirstIndex] = currTime;
124
        mLastX[mFirstIndex] = x;
125
        mLastY[mFirstIndex] = y;
126
        }
127
      }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
    private void computeCurrentSpeedInInchesPerSecond()
132
      {
133
      long firstTime = mLastT[mFirstIndex];
134
      long lastTime  = mLastT[mLastIndex];
135
      float fX = mLastX[mFirstIndex];
136
      float fY = mLastY[mFirstIndex];
137
      float lX = mLastX[mLastIndex];
138
      float lY = mLastY[mLastIndex];
139

    
140
      long timeDiff = lastTime-firstTime;
141

    
142
      mLastIndex = 0;
143
      mFirstIndex= 0;
144

    
145
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
146
      }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
151
      {
152
      float xDist = mScreenWidth*(xFrom-xTo);
153
      float yDist = mScreenHeight*(yFrom-yTo);
154
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
155

    
156
      return distInPixels/mDensity;
157
      }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
162
      {
163
      if( mode==MODE_DRAG )
164
        {
165
        mDragging           = true;
166
        mBeginningRotation  = false;
167
        mContinuingRotation = false;
168
        }
169
      else
170
        {
171
        TwistyObject object = mPreRender.getObject();
172
        CAMERA_POINT.set2( object==null ? 1.21f : object.getCameraDist() );
173

    
174
        Static4D touchPoint = new Static4D(x, y, 0, 0);
175
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
176
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
177

    
178
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
179
          {
180
          mDragging           = false;
181
          mContinuingRotation = false;
182

    
183
          if( mode==MODE_ROTATE )
184
            {
185
            mBeginningRotation= !mPreRender.isTouchBlocked();
186
            }
187
          else if( mode==MODE_REPLACE )
188
            {
189
            mBeginningRotation= false;
190

    
191
            if( down )
192
              {
193
              int color = mInterface.getCurrentColor();
194
              mLastCubitFace = mMovement.getTouchedFace();
195
              float[] point = mMovement.getTouchedPoint3D();
196
              mLastCubit = object.getCubit(point);
197
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
198
              mLastCubitColor = mInterface.cubitIsLocked(object.getObjectType(),mLastCubit);
199
              }
200
            }
201
          }
202
        else
203
          {
204
          mDragging           = (!mIsLocked || mIsAutomatic);
205
          mBeginningRotation  = false;
206
          mContinuingRotation = false;
207
          if( !mDragging ) mInterface.failedToDrag();
208
          }
209
        }
210
      }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
    private void drag(float x, float y)
215
      {
216
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
217
        {
218
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
219
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
220

    
221
        float angleNow = getAngle(x,y,x2,y2);
222
        float angleDiff = angleNow-mRotAngle;
223
        float sinA =-(float)Math.sin(angleDiff);
224
        float cosA = (float)Math.cos(angleDiff);
225

    
226
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
227
        mTemp.set(dragQuat);
228

    
229
        mRotAngle = angleNow;
230

    
231
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
232
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
233
        mInitDistance = distNow;
234
        TwistyObject object = mPreRender.getObject();
235
        if( object!=null ) object.setObjectRatio(distQuot);
236
        }
237
      else
238
        {
239
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
240
        mTemp.set(dragQuat);
241
        }
242

    
243
      mPreRender.setQuatOnNextRender();
244
      mX = x;
245
      mY = y;
246
      }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
    private void finishRotation()
251
      {
252
      computeCurrentSpeedInInchesPerSecond();
253
      TwistyObject object = mPreRender.getObject();
254
      int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
255
      mPreRender.finishRotation(angle);
256
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
257

    
258
      if( angle!=0 )
259
        {
260
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
261
        int realAngle = (angle*basicAngle)/360;
262
        mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
263
        }
264

    
265
      mContinuingRotation = false;
266
      mBeginningRotation  = false;
267
      mDragging           = true;
268
      }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

    
272
    private void continueRotation(float x, float y)
273
      {
274
      float dx = x-mStartRotX;
275
      float dy = y-mStartRotY;
276
      float alpha = dx*mAxisX + dy*mAxisY;
277
      float x2 = dx - alpha*mAxisX;
278
      float y2 = dy - alpha*mAxisY;
279

    
280
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
281

    
282
      // we have the length of 1D vector 'angle', now the direction:
283
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
284

    
285
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
286
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
287
      mPreRender.getObject().continueRotation(mCurrentAngle);
288

    
289
      addSpeedProbe(x2,y2);
290
      }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

    
294
    private void beginRotation(float x, float y)
295
      {
296
      mStartRotX = x;
297
      mStartRotY = y;
298

    
299
      TwistyObject object = mPreRender.getObject();
300
      int numLayers = object.getNumLayers();
301

    
302
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
303
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
304
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
305

    
306
      mCurrentAxis = (int)res.get0();
307
      mCurrentRow  = (int)res.get1();
308

    
309
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
310
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
311

    
312
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
313

    
314
      mInterface.onBeginRotation();
315

    
316
      addSpeedProbe(x,y);
317

    
318
      mBeginningRotation = false;
319
      mContinuingRotation= true;
320
      }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
    private float getAngle(float x1, float y1, float x2, float y2)
325
      {
326
      return (float) Math.atan2(y1-y2, x1-x2);
327
      }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
    private void prepareDown(MotionEvent event)
332
      {
333
      mPointer1 = event.getPointerId(0);
334
      mX1 = event.getX() - mMoveX;
335
      mY1 = event.getY() + mMoveY;
336
      mPointer2 = INVALID_POINTER_ID;
337
      }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
    private void prepareMove(MotionEvent event)
342
      {
343
      int index1 = event.findPointerIndex(mPointer1);
344

    
345
      if( index1>=0 )
346
        {
347
        mX1 = event.getX(index1) - mMoveX;
348
        mY1 = event.getY(index1) + mMoveY;
349
        }
350

    
351
      int index2 = event.findPointerIndex(mPointer2);
352

    
353
      if( index2>=0 )
354
        {
355
        mX2 = event.getX(index2) - mMoveX;
356
        mY2 = event.getY(index2) + mMoveY;
357
        }
358
      }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
    private void prepareUp(MotionEvent event)
363
      {
364
      mPointer1 = INVALID_POINTER_ID;
365
      mPointer2 = INVALID_POINTER_ID;
366
      }
367

    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

    
370
    private void prepareDown2(MotionEvent event)
371
      {
372
      int index = event.getActionIndex();
373

    
374
      if( mPointer1==INVALID_POINTER_ID )
375
        {
376
        mPointer1 = event.getPointerId(index);
377
        mX1 = event.getX(index) - mMoveX;
378
        mY1 = event.getY(index) + mMoveY;
379
        }
380
      else if( mPointer2==INVALID_POINTER_ID )
381
        {
382
        mPointer2 = event.getPointerId(index);
383
        mX2 = event.getX(index) - mMoveX;
384
        mY2 = event.getY(index) + mMoveY;
385
        }
386
      }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
    private void prepareUp2(MotionEvent event)
391
      {
392
      int index = event.getActionIndex();
393

    
394
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
395
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
396
      }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
401
      {
402
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
403
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
404

    
405
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
406
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
407

    
408
      if( mBeginningRotation )
409
        {
410
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
411
          {
412
          beginRotation(x,y);
413
          }
414
        }
415
      else if( mContinuingRotation )
416
        {
417
        continueRotation(x,y);
418
        }
419
      else if( mDragging )
420
        {
421
        drag(x,y);
422
        }
423
      else
424
        {
425
        setUpDragOrRotate(false,x,y,mode);
426
        }
427
      }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
    private void actionDown(float x, float y, int mode)
432
      {
433
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
434
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
435

    
436
      setUpDragOrRotate(true,mX,mY,mode);
437
      }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
    private void actionUp()
442
      {
443
      if( mContinuingRotation )
444
        {
445
        finishRotation();
446
        }
447

    
448
      if( mLastCubitColor>=0 )
449
        {
450
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
451
        mLastCubitColor = -1;
452
        }
453
      }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

    
457
    private void actionDown2(float x1, float y1, float x2, float y2)
458
      {
459
      mRotAngle = getAngle(x1,-y1, x2,-y2);
460
      mInitDistance = -1;
461

    
462
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
463
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
464

    
465
      if( mBeginningRotation )
466
        {
467
        mContinuingRotation = false;
468
        mBeginningRotation  = false;
469
        mDragging           = true;
470
        }
471
      else if( mContinuingRotation )
472
        {
473
        finishRotation();
474
        }
475
      }
476

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
480
      {
481
      if( p1isUp )
482
        {
483
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
484
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
485
        }
486
      if( p2isUp )
487
        {
488
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
489
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
490
        }
491
      }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494
// INTERNAL API (for AutomaticControl)
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496

    
497
    public ObjectPreRender getPreRender()
498
      {
499
      return mPreRender;
500
      }
501

    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

    
504
    public ObjectLibInterface getInterface()
505
      {
506
      return mInterface;
507
      }
508

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
    public static void setIconMode(boolean mode)
512
      {
513
      mForcedIconMode = mode;
514
      }
515

    
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

    
518
    public static void setForcedMesh(boolean mode)
519
      {
520
      mForcedCreateMesh = mode;
521
      }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524

    
525
    public static boolean isInIconMode()
526
      {
527
      return mForcedIconMode;
528
      }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531

    
532
    public static boolean isInCreateMesh()
533
      {
534
      return mForcedCreateMesh;
535
      }
536

    
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538
// PUBLIC API
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

    
541
    public ObjectControl(Activity act, ObjectLibInterface actioner)
542
      {
543
      mIsAutomatic = false;
544

    
545
      mLastCubitColor = -1;
546
      mCurrRotSpeed   = 0.0f;
547

    
548
      mLastX = new float[NUM_SPEED_PROBES];
549
      mLastY = new float[NUM_SPEED_PROBES];
550
      mLastT = new long[NUM_SPEED_PROBES];
551
      mFirstIndex =0;
552
      mLastIndex  =0;
553

    
554
      DisplayMetrics dm = new DisplayMetrics();
555
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
556

    
557
      mDensity = dm.densityDpi;
558

    
559
      mPreRender = new ObjectPreRender(act,this,actioner);
560
      mInterface = actioner;
561
      }
562

    
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564

    
565
    public void setScreenSize(int width, int height)
566
      {
567
      mScreenWidth = width;
568
      mScreenHeight= height;
569
      mScreenMin = Math.min(width, height);
570
      mPreRender.setScreenSize(width);
571
      }
572

    
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574

    
575
    public void setMove(int xmove, int ymove)
576
      {
577
      mMoveX = xmove;
578
      mMoveY = ymove;
579

    
580
      mPreRender.setMove(xmove,ymove);
581
      }
582

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584

    
585
    public void onPause()
586
      {
587
      BlockController.onPause();
588
      }
589

    
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591

    
592
    public void onResume()
593
      {
594
      mPointer1 = INVALID_POINTER_ID;
595
      mPointer2 = INVALID_POINTER_ID;
596

    
597
      unlock();
598

    
599
      BlockController.onResume();
600
      }
601

    
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603

    
604
    public void rotateNow(Static4D quat)
605
      {
606
      mTemp.set(quat);
607
      mQuat.set(mTemp);
608
      }
609

    
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611

    
612
    public void scaleNow(float scale)
613
      {
614
      mPreRender.getObject().setObjectRatioNow(scale);
615
      }
616

    
617
///////////////////////////////////////////////////////////////////////////////////////////////////
618

    
619
    public void setQuat()
620
      {
621
      mQuat.set(mTemp);
622
      }
623

    
624
///////////////////////////////////////////////////////////////////////////////////////////////////
625

    
626
    public Static4D getQuat()
627
      {
628
      return mQuat;
629
      }
630

    
631
///////////////////////////////////////////////////////////////////////////////////////////////////
632

    
633
    public void setMovement(Movement movement)
634
      {
635
      mMovement = movement;
636
      }
637

    
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639

    
640
    public void preRender()
641
      {
642
      mPreRender.preRender();
643
      }
644

    
645
///////////////////////////////////////////////////////////////////////////////////////////////////
646

    
647
    public void blockEverything(int place)
648
      {
649
      setLock(true);
650
      mPreRender.blockEverything(place);
651
      }
652

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654

    
655
    public void blockTouch(int place)
656
      {
657
      setLock(true);
658
      mPreRender.blockTouch(place);
659
      }
660

    
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662

    
663
    public void unblockEverything()
664
      {
665
      unsetLock();
666
      mPreRender.unblockEverything();
667
      }
668

    
669
///////////////////////////////////////////////////////////////////////////////////////////////////
670

    
671
    public void unblockTouch()
672
      {
673
      unsetLock();
674
      mPreRender.unblockTouch();
675
      }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678

    
679
    public void unblockUI()
680
      {
681
      mPreRender.unblockUI();
682
      }
683

    
684
///////////////////////////////////////////////////////////////////////////////////////////////////
685

    
686
    public boolean isTouchBlocked()
687
      {
688
      return mPreRender.isTouchBlocked();
689
      }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692

    
693
    public boolean isUINotBlocked()
694
      {
695
      return mPreRender.isUINotBlocked();
696
      }
697

    
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699

    
700
    public void initializeObject(int[][] moves)
701
      {
702
      mPreRender.initializeObject(moves);
703
      }
704

    
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706

    
707
    public void changeObject(ObjectType object)
708
      {
709
      mPreRender.changeObject(object);
710
      }
711

    
712
///////////////////////////////////////////////////////////////////////////////////////////////////
713

    
714
    public void recreateObject()
715
      {
716
      mPreRender.recreateObject();
717
      }
718

    
719
///////////////////////////////////////////////////////////////////////////////////////////////////
720

    
721
    public void scrambleObject(int num)
722
      {
723
      mPreRender.scrambleObject(num);
724
      }
725

    
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727

    
728
    public void solveObject()
729
      {
730
      mPreRender.solveObject();
731
      }
732

    
733
///////////////////////////////////////////////////////////////////////////////////////////////////
734

    
735
    public void solveOnly()
736
      {
737
      mPreRender.solveOnly();
738
      }
739

    
740
///////////////////////////////////////////////////////////////////////////////////////////////////
741

    
742
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
743
      {
744
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
745
      }
746

    
747
///////////////////////////////////////////////////////////////////////////////////////////////////
748

    
749
    public void resetAllTextureMaps()
750
      {
751
      mPreRender.resetAllTextureMaps();
752
      }
753

    
754
///////////////////////////////////////////////////////////////////////////////////////////////////
755

    
756
    public TwistyObject getObject()
757
      {
758
      return mPreRender.getObject();
759
      }
760

    
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762

    
763
    public void savePreferences(SharedPreferences.Editor editor)
764
      {
765
      mPreRender.savePreferences(editor);
766
      }
767

    
768
///////////////////////////////////////////////////////////////////////////////////////////////////
769

    
770
    public void restorePreferences(SharedPreferences preferences)
771
      {
772
      mPreRender.restorePreferences(preferences);
773
      }
774
///////////////////////////////////////////////////////////////////////////////////////////////////
775

    
776
    public boolean retLocked()
777
      {
778
      return mIsLocked;
779
      }
780

    
781
///////////////////////////////////////////////////////////////////////////////////////////////////
782

    
783
    public void toggleLock()
784
      {
785
      mIsLocked = !mIsLocked;
786
      }
787

    
788
///////////////////////////////////////////////////////////////////////////////////////////////////
789

    
790
    public void unlock()
791
      {
792
      mIsLocked = false;
793
      }
794

    
795
///////////////////////////////////////////////////////////////////////////////////////////////////
796

    
797
    public void setLock(boolean value)
798
      {
799
      mRemLocked = mIsLocked;
800
      mIsLocked = value;
801
      }
802

    
803
///////////////////////////////////////////////////////////////////////////////////////////////////
804

    
805
    public void unsetLock()
806
      {
807
      mIsLocked = mRemLocked;
808
      }
809

    
810
///////////////////////////////////////////////////////////////////////////////////////////////////
811

    
812
    public boolean onTouchEvent(MotionEvent event, int mode)
813
      {
814
      int action = event.getActionMasked();
815

    
816
      switch(action)
817
         {
818
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
819
                                               actionDown(mX1, mY1, mode);
820
                                               break;
821
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
822
                                               actionMove(mX1, mY1, mX2, mY2, mode);
823
                                               break;
824
         case MotionEvent.ACTION_UP          : prepareUp(event);
825
                                               actionUp();
826
                                               break;
827
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
828
                                               actionDown2(mX1, mY1, mX2, mY2);
829
                                               break;
830
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
831
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
832
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
833
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
834
                                               break;
835
         }
836

    
837
      return true;
838
      }
839
}
840

    
(7-7/15)