Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ b9956428

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 java.lang.ref.WeakReference;
23

    
24
import android.content.SharedPreferences;
25
import android.util.DisplayMetrics;
26
import android.view.MotionEvent;
27

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

    
32
import org.distorted.objectlib.helpers.MovesFinished;
33
import org.distorted.objectlib.helpers.ObjectStateActioner;
34
import org.distorted.objectlib.helpers.TwistyActivity;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

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

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

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

    
55
    private final WeakReference<TwistyActivity> mAct;
56
    private final ObjectStateActioner mActioner;
57
    private final ObjectPreRender mPreRender;
58
    private Movement mMovement;
59
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
60
    private int mScreenWidth, mScreenHeight, mScreenMin;
61

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

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

    
79
    private boolean mIsLocked, mRemLocked;
80

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

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

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

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

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

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

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

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

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

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

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

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

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

    
139
      long timeDiff = lastTime-firstTime;
140

    
141
      mLastIndex = 0;
142
      mFirstIndex= 0;
143

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

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

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

    
155
      return distInPixels/mDensity;
156
      }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

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

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

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

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

    
190
            if( down )
191
              {
192
              int color = mActioner.getCurrentColor();
193
              mLastCubitFace = mMovement.getTouchedFace();
194
              float[] point = mMovement.getTouchedPoint3D();
195
              mLastCubit = object.getCubit(point);
196
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
197
              mLastCubitColor = mActioner.cubitIsLocked(object.getObjectType(),mLastCubit);
198
              }
199
            }
200
          }
201
        else
202
          {
203
          final TwistyActivity act = mAct.get();
204
          mDragging           = (!mIsLocked || mIsAutomatic);
205
          mBeginningRotation  = false;
206
          mContinuingRotation = false;
207
          if( !mDragging ) mActioner.failedToDrag(act);
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
        TwistyActivity act = mAct.get();
261

    
262
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
263
        int realAngle = (angle*basicAngle)/360;
264

    
265
        mActioner.onFinishRotation(act,mCurrentAxis,mCurrentRow,realAngle);
266
        }
267

    
268
      mContinuingRotation = false;
269
      mBeginningRotation  = false;
270
      mDragging           = true;
271
      }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

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

    
283
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
284

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

    
288
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
289
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
290
      mPreRender.getObject().continueRotation(mCurrentAngle);
291

    
292
      addSpeedProbe(x2,y2);
293
      }
294

    
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

    
297
    private void beginRotation(float x, float y)
298
      {
299
      mStartRotX = x;
300
      mStartRotY = y;
301

    
302
      TwistyObject object = mPreRender.getObject();
303
      int numLayers = object.getNumLayers();
304

    
305
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
306
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
307
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
308

    
309
      mCurrentAxis = (int)res.get0();
310
      mCurrentRow  = (int)res.get1();
311

    
312
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
313
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
314

    
315
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
316

    
317
      TwistyActivity act = mAct.get();
318
      mActioner.onBeginRotation(act);
319

    
320
      addSpeedProbe(x,y);
321

    
322
      mBeginningRotation = false;
323
      mContinuingRotation= true;
324
      }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
    private float getAngle(float x1, float y1, float x2, float y2)
329
      {
330
      return (float) Math.atan2(y1-y2, x1-x2);
331
      }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
    private void prepareDown(MotionEvent event)
336
      {
337
      mPointer1 = event.getPointerId(0);
338
      mX1 = event.getX();
339
      mY1 = event.getY();
340
      mPointer2 = INVALID_POINTER_ID;
341
      }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

    
345
    private void prepareMove(MotionEvent event)
346
      {
347
      int index1 = event.findPointerIndex(mPointer1);
348

    
349
      if( index1>=0 )
350
        {
351
        mX1 = event.getX(index1);
352
        mY1 = event.getY(index1);
353
        }
354

    
355
      int index2 = event.findPointerIndex(mPointer2);
356

    
357
      if( index2>=0 )
358
        {
359
        mX2 = event.getX(index2);
360
        mY2 = event.getY(index2);
361
        }
362
      }
363

    
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365

    
366
    private void prepareUp(MotionEvent event)
367
      {
368
      mPointer1 = INVALID_POINTER_ID;
369
      mPointer2 = INVALID_POINTER_ID;
370
      }
371

    
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

    
374
    private void prepareDown2(MotionEvent event)
375
      {
376
      int index = event.getActionIndex();
377

    
378
      if( mPointer1==INVALID_POINTER_ID )
379
        {
380
        mPointer1 = event.getPointerId(index);
381
        mX1 = event.getX(index);
382
        mY1 = event.getY(index);
383
        }
384
      else if( mPointer2==INVALID_POINTER_ID )
385
        {
386
        mPointer2 = event.getPointerId(index);
387
        mX2 = event.getX(index);
388
        mY2 = event.getY(index);
389
        }
390
      }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

    
394
    private void prepareUp2(MotionEvent event)
395
      {
396
      int index = event.getActionIndex();
397

    
398
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
399
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
400
      }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

    
404
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
405
      {
406
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
407
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
408

    
409
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
410
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
411

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

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
    private void actionDown(float x, float y, int mode)
436
      {
437
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
438
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
439

    
440
      setUpDragOrRotate(true,mX,mY,mode);
441
      }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

    
445
    private void actionUp()
446
      {
447
      if( mContinuingRotation )
448
        {
449
        finishRotation();
450
        }
451

    
452
      if( mLastCubitColor>=0 )
453
        {
454
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
455
        mLastCubitColor = -1;
456
        }
457
      }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

    
461
    private void actionDown2(float x1, float y1, float x2, float y2)
462
      {
463
      mRotAngle = getAngle(x1,-y1, x2,-y2);
464
      mInitDistance = -1;
465

    
466
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
467
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
468

    
469
      if( mBeginningRotation )
470
        {
471
        mContinuingRotation = false;
472
        mBeginningRotation  = false;
473
        mDragging           = true;
474
        }
475
      else if( mContinuingRotation )
476
        {
477
        finishRotation();
478
        }
479
      }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

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

    
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499
// INTERNAL API (for AutomaticControl)
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

    
502
    public ObjectPreRender getPreRender()
503
      {
504
      return mPreRender;
505
      }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508
// PUBLIC API
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
    public ObjectControl(TwistyActivity act, ObjectStateActioner actioner)
512
      {
513
      mIsAutomatic = false;
514

    
515
      mLastCubitColor = -1;
516
      mCurrRotSpeed   = 0.0f;
517

    
518
      mLastX = new float[NUM_SPEED_PROBES];
519
      mLastY = new float[NUM_SPEED_PROBES];
520
      mLastT = new long[NUM_SPEED_PROBES];
521
      mFirstIndex =0;
522
      mLastIndex  =0;
523

    
524
      DisplayMetrics dm = new DisplayMetrics();
525
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
526

    
527
      mDensity = dm.densityDpi;
528

    
529
      mPreRender = new ObjectPreRender(act,this,actioner);
530
      mAct = new WeakReference<>(act);
531
      mActioner = actioner;
532
      }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535

    
536
    public void setScreenSize(int width, int height)
537
      {
538
      mScreenWidth = width;
539
      mScreenHeight= height;
540
      mScreenMin = Math.min(width, height);
541
      mPreRender.setScreenSize(width);
542
      }
543

    
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545

    
546
    public void initialize()
547
      {
548
      mPointer1 = INVALID_POINTER_ID;
549
      mPointer2 = INVALID_POINTER_ID;
550

    
551
      unlock();
552
      }
553

    
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555

    
556
    public void setQuat()
557
      {
558
      mQuat.set(mTemp);
559
      }
560

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562

    
563
    public Static4D getQuat()
564
      {
565
      return mQuat;
566
      }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

    
570
    public void setMovement(Movement movement)
571
      {
572
      mMovement = movement;
573
      }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576

    
577
    public void preRender()
578
      {
579
      mPreRender.preRender();
580
      }
581

    
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583

    
584
    public void blockEverything(int place)
585
      {
586
      setLock(true);
587
      mPreRender.blockEverything(place);
588
      }
589

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

    
592
    public void blockTouch(int place)
593
      {
594
      setLock(true);
595
      mPreRender.blockTouch(place);
596
      }
597

    
598
///////////////////////////////////////////////////////////////////////////////////////////////////
599

    
600
    public void unblockEverything()
601
      {
602
      unsetLock();
603
      mPreRender.unblockEverything();
604
      }
605

    
606
///////////////////////////////////////////////////////////////////////////////////////////////////
607

    
608
    public void unblockTouch()
609
      {
610
      unsetLock();
611
      mPreRender.unblockTouch();
612
      }
613

    
614
///////////////////////////////////////////////////////////////////////////////////////////////////
615

    
616
    public void unblockUI()
617
      {
618
      mPreRender.unblockUI();
619
      }
620

    
621
///////////////////////////////////////////////////////////////////////////////////////////////////
622

    
623
    public boolean isTouchBlocked()
624
      {
625
      return mPreRender.isTouchBlocked();
626
      }
627

    
628
///////////////////////////////////////////////////////////////////////////////////////////////////
629

    
630
    public boolean isUINotBlocked()
631
      {
632
      return mPreRender.isUINotBlocked();
633
      }
634

    
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636

    
637
    public void initializeObject(int[][] moves)
638
      {
639
      mPreRender.initializeObject(moves);
640
      }
641

    
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643

    
644
    public void changeObject(ObjectType object)
645
      {
646
      mPreRender.changeObject(object);
647
      }
648

    
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650

    
651
    public void setupObject(ObjectType object, int[][] moves)
652
      {
653
      mPreRender.setupObject(object,moves);
654
      }
655

    
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657

    
658
    public void scrambleObject(int num)
659
      {
660
      mPreRender.scrambleObject(num);
661
      }
662

    
663
///////////////////////////////////////////////////////////////////////////////////////////////////
664

    
665
    public void solveObject()
666
      {
667
      mPreRender.solveObject();
668
      }
669

    
670
///////////////////////////////////////////////////////////////////////////////////////////////////
671

    
672
    public void solveOnly()
673
      {
674
      mPreRender.solveOnly();
675
      }
676

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

    
679
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
680
      {
681
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
682
      }
683

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

    
686
    public void resetAllTextureMaps()
687
      {
688
      mPreRender.resetAllTextureMaps();
689
      }
690

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

    
693
    public TwistyObject getObject()
694
      {
695
      return mPreRender.getObject();
696
      }
697

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

    
700
    public void savePreferences(SharedPreferences.Editor editor)
701
      {
702
      mPreRender.savePreferences(editor);
703
      }
704

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

    
707
    public void restorePreferences(SharedPreferences preferences)
708
      {
709
      mPreRender.restorePreferences(preferences);
710
      }
711
///////////////////////////////////////////////////////////////////////////////////////////////////
712

    
713
  public boolean retLocked()
714
      {
715
      return mIsLocked;
716
      }
717

    
718
///////////////////////////////////////////////////////////////////////////////////////////////////
719

    
720
  public void toggleLock()
721
      {
722
      mIsLocked = !mIsLocked;
723
      }
724

    
725
///////////////////////////////////////////////////////////////////////////////////////////////////
726

    
727
  public void unlock()
728
    {
729
    mIsLocked = false;
730
    }
731

    
732
///////////////////////////////////////////////////////////////////////////////////////////////////
733

    
734
  public void setLock(boolean value)
735
    {
736
    mRemLocked = mIsLocked;
737
    mIsLocked = value;
738
    }
739

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

    
742
  public void unsetLock()
743
    {
744
    mIsLocked = mRemLocked;
745
    }
746

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

    
749
    public boolean onTouchEvent(MotionEvent event, int mode)
750
      {
751
      int action = event.getActionMasked();
752

    
753
      switch(action)
754
         {
755
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
756
                                               actionDown(mX1, mY1, mode);
757
                                               break;
758
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
759
                                               actionMove(mX1, mY1, mX2, mY2, mode);
760
                                               break;
761
         case MotionEvent.ACTION_UP          : prepareUp(event);
762
                                               actionUp();
763
                                               break;
764
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
765
                                               actionDown2(mX1, mY1, mX2, mY2);
766
                                               break;
767
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
768
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
769
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
770
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
771
                                               break;
772
         }
773

    
774
      return true;
775
      }
776
}
777

    
(7-7/15)