Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 2fca02cf

1 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 b3fff6fb Leszek Koltunski
import android.app.Activity;
23 9276dced Leszek Koltunski
import android.content.SharedPreferences;
24 880beeea Leszek Koltunski
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 2fca02cf Leszek Koltunski
import org.distorted.objectlib.helpers.BlockController;
32 9276dced Leszek Koltunski
import org.distorted.objectlib.helpers.MovesFinished;
33 b3fff6fb Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectLibInterface;
34 880beeea Leszek Koltunski
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 b3fff6fb Leszek Koltunski
    private final ObjectLibInterface mInterface;
55 880beeea Leszek Koltunski
    private final ObjectPreRender mPreRender;
56
    private Movement mMovement;
57
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
58
    private int mScreenWidth, mScreenHeight, mScreenMin;
59
60
    private float mRotAngle, mInitDistance;
61
    private float mStartRotX, mStartRotY;
62
    private float mAxisX, mAxisY;
63
    private float mRotationFactor;
64
    private int mLastCubitColor, mLastCubitFace, mLastCubit;
65
    private int mCurrentAxis, mCurrentRow;
66
    private float mCurrentAngle, mCurrRotSpeed;
67
    private final float[] mLastX;
68
    private final float[] mLastY;
69
    private final long[] mLastT;
70
    private int mFirstIndex, mLastIndex;
71
    private final int mDensity;
72
73
    private int mPointer1, mPointer2;
74
    private float mX1, mY1, mX2, mY2, mX, mY;
75 046104f5 Leszek Koltunski
    private final boolean mIsAutomatic;
76 880beeea Leszek Koltunski
77 b9956428 Leszek Koltunski
    private boolean mIsLocked, mRemLocked;
78
79 880beeea Leszek Koltunski
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
80
    private static final Static4D mTemp= new Static4D(0,0,0,1);
81
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
84
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
85
86
    private void computeCurrentAxis(Static4D axis)
87
      {
88
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
89
90
      mAxisX =result.get0();
91
      mAxisY =result.get1();
92
93
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
94
      mAxisX /= len;
95
      mAxisY /= len;
96
      }
97
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100
    private void addSpeedProbe(float x, float y)
101
      {
102
      long currTime = System.currentTimeMillis();
103
      boolean theSame = mLastIndex==mFirstIndex;
104
105
      mLastIndex++;
106
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
107
108
      mLastT[mLastIndex] = currTime;
109
      mLastX[mLastIndex] = x;
110
      mLastY[mLastIndex] = y;
111
112
      if( mLastIndex==mFirstIndex)
113
        {
114
        mFirstIndex++;
115
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
116
        }
117
118
      if( theSame )
119
        {
120
        mLastT[mFirstIndex] = currTime;
121
        mLastX[mFirstIndex] = x;
122
        mLastY[mFirstIndex] = y;
123
        }
124
      }
125
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
128
    private void computeCurrentSpeedInInchesPerSecond()
129
      {
130
      long firstTime = mLastT[mFirstIndex];
131
      long lastTime  = mLastT[mLastIndex];
132
      float fX = mLastX[mFirstIndex];
133
      float fY = mLastY[mFirstIndex];
134
      float lX = mLastX[mLastIndex];
135
      float lY = mLastY[mLastIndex];
136
137
      long timeDiff = lastTime-firstTime;
138
139
      mLastIndex = 0;
140
      mFirstIndex= 0;
141
142
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
143
      }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
147
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
148
      {
149
      float xDist = mScreenWidth*(xFrom-xTo);
150
      float yDist = mScreenHeight*(yFrom-yTo);
151
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
152
153
      return distInPixels/mDensity;
154
      }
155
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
158
    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
159
      {
160
      if( mode==MODE_DRAG )
161
        {
162
        mDragging           = true;
163
        mBeginningRotation  = false;
164
        mContinuingRotation = false;
165
        }
166
      else
167
        {
168
        TwistyObject object = mPreRender.getObject();
169
        CAMERA_POINT.set2( object==null ? 1.21f : object.getCameraDist() );
170
171
        Static4D touchPoint = new Static4D(x, y, 0, 0);
172
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
173
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
174
175
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
176
          {
177
          mDragging           = false;
178
          mContinuingRotation = false;
179
180
          if( mode==MODE_ROTATE )
181
            {
182
            mBeginningRotation= !mPreRender.isTouchBlocked();
183
            }
184
          else if( mode==MODE_REPLACE )
185
            {
186
            mBeginningRotation= false;
187
188
            if( down )
189
              {
190 b3fff6fb Leszek Koltunski
              int color = mInterface.getCurrentColor();
191 880beeea Leszek Koltunski
              mLastCubitFace = mMovement.getTouchedFace();
192
              float[] point = mMovement.getTouchedPoint3D();
193
              mLastCubit = object.getCubit(point);
194
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
195 b3fff6fb Leszek Koltunski
              mLastCubitColor = mInterface.cubitIsLocked(object.getObjectType(),mLastCubit);
196 880beeea Leszek Koltunski
              }
197
            }
198
          }
199
        else
200
          {
201 b9956428 Leszek Koltunski
          mDragging           = (!mIsLocked || mIsAutomatic);
202 880beeea Leszek Koltunski
          mBeginningRotation  = false;
203
          mContinuingRotation = false;
204 b3fff6fb Leszek Koltunski
          if( !mDragging ) mInterface.failedToDrag();
205 880beeea Leszek Koltunski
          }
206
        }
207
      }
208
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210
211
    private void drag(float x, float y)
212
      {
213
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
214
        {
215
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
216
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
217
218
        float angleNow = getAngle(x,y,x2,y2);
219
        float angleDiff = angleNow-mRotAngle;
220
        float sinA =-(float)Math.sin(angleDiff);
221
        float cosA = (float)Math.cos(angleDiff);
222
223
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
224
        mTemp.set(dragQuat);
225
226
        mRotAngle = angleNow;
227
228
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
229
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
230
        mInitDistance = distNow;
231
        TwistyObject object = mPreRender.getObject();
232
        if( object!=null ) object.setObjectRatio(distQuot);
233
        }
234
      else
235
        {
236
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
237
        mTemp.set(dragQuat);
238
        }
239
240
      mPreRender.setQuatOnNextRender();
241
      mX = x;
242
      mY = y;
243
      }
244
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246
247
    private void finishRotation()
248
      {
249
      computeCurrentSpeedInInchesPerSecond();
250 2df35810 Leszek Koltunski
      TwistyObject object = mPreRender.getObject();
251
      int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
252 880beeea Leszek Koltunski
      mPreRender.finishRotation(angle);
253
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
254
255
      if( angle!=0 )
256
        {
257 2df35810 Leszek Koltunski
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
258
        int realAngle = (angle*basicAngle)/360;
259 b3fff6fb Leszek Koltunski
        mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
260 880beeea Leszek Koltunski
        }
261
262
      mContinuingRotation = false;
263
      mBeginningRotation  = false;
264
      mDragging           = true;
265
      }
266
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268
269
    private void continueRotation(float x, float y)
270
      {
271
      float dx = x-mStartRotX;
272
      float dy = y-mStartRotY;
273
      float alpha = dx*mAxisX + dy*mAxisY;
274
      float x2 = dx - alpha*mAxisX;
275
      float y2 = dy - alpha*mAxisY;
276
277
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
278
279
      // we have the length of 1D vector 'angle', now the direction:
280
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
281
282
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
283
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
284
      mPreRender.getObject().continueRotation(mCurrentAngle);
285
286
      addSpeedProbe(x2,y2);
287
      }
288
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290
291
    private void beginRotation(float x, float y)
292
      {
293
      mStartRotX = x;
294
      mStartRotY = y;
295
296
      TwistyObject object = mPreRender.getObject();
297
      int numLayers = object.getNumLayers();
298
299
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
300
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
301
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
302
303
      mCurrentAxis = (int)res.get0();
304
      mCurrentRow  = (int)res.get1();
305
306
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
307
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
308
309
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
310
311 b3fff6fb Leszek Koltunski
      mInterface.onBeginRotation();
312 880beeea Leszek Koltunski
313
      addSpeedProbe(x,y);
314
315
      mBeginningRotation = false;
316
      mContinuingRotation= true;
317
      }
318
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
321
    private float getAngle(float x1, float y1, float x2, float y2)
322
      {
323
      return (float) Math.atan2(y1-y2, x1-x2);
324
      }
325
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328
    private void prepareDown(MotionEvent event)
329
      {
330
      mPointer1 = event.getPointerId(0);
331
      mX1 = event.getX();
332
      mY1 = event.getY();
333
      mPointer2 = INVALID_POINTER_ID;
334
      }
335
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337
338
    private void prepareMove(MotionEvent event)
339
      {
340
      int index1 = event.findPointerIndex(mPointer1);
341
342
      if( index1>=0 )
343
        {
344
        mX1 = event.getX(index1);
345
        mY1 = event.getY(index1);
346
        }
347
348
      int index2 = event.findPointerIndex(mPointer2);
349
350
      if( index2>=0 )
351
        {
352
        mX2 = event.getX(index2);
353
        mY2 = event.getY(index2);
354
        }
355
      }
356
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358
359
    private void prepareUp(MotionEvent event)
360
      {
361
      mPointer1 = INVALID_POINTER_ID;
362
      mPointer2 = INVALID_POINTER_ID;
363
      }
364
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366
367
    private void prepareDown2(MotionEvent event)
368
      {
369
      int index = event.getActionIndex();
370
371
      if( mPointer1==INVALID_POINTER_ID )
372
        {
373
        mPointer1 = event.getPointerId(index);
374
        mX1 = event.getX(index);
375
        mY1 = event.getY(index);
376
        }
377
      else if( mPointer2==INVALID_POINTER_ID )
378
        {
379
        mPointer2 = event.getPointerId(index);
380
        mX2 = event.getX(index);
381
        mY2 = event.getY(index);
382
        }
383
      }
384
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386
387
    private void prepareUp2(MotionEvent event)
388
      {
389
      int index = event.getActionIndex();
390
391
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
392
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
393
      }
394
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396
397
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
398
      {
399
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
400
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
401
402
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
403
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
404
405
      if( mBeginningRotation )
406
        {
407
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
408
          {
409
          beginRotation(x,y);
410
          }
411
        }
412
      else if( mContinuingRotation )
413
        {
414
        continueRotation(x,y);
415
        }
416
      else if( mDragging )
417
        {
418
        drag(x,y);
419
        }
420
      else
421
        {
422
        setUpDragOrRotate(false,x,y,mode);
423
        }
424
      }
425
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
428
    private void actionDown(float x, float y, int mode)
429
      {
430
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
431
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
432
433
      setUpDragOrRotate(true,mX,mY,mode);
434
      }
435
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437
438
    private void actionUp()
439
      {
440
      if( mContinuingRotation )
441
        {
442
        finishRotation();
443
        }
444
445
      if( mLastCubitColor>=0 )
446
        {
447
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
448
        mLastCubitColor = -1;
449
        }
450
      }
451
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
454
    private void actionDown2(float x1, float y1, float x2, float y2)
455
      {
456
      mRotAngle = getAngle(x1,-y1, x2,-y2);
457
      mInitDistance = -1;
458
459
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
460
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
461
462
      if( mBeginningRotation )
463
        {
464
        mContinuingRotation = false;
465
        mBeginningRotation  = false;
466
        mDragging           = true;
467
        }
468
      else if( mContinuingRotation )
469
        {
470
        finishRotation();
471
        }
472
      }
473
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475
476
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
477
      {
478
      if( p1isUp )
479
        {
480
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
481
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
482
        }
483
      if( p2isUp )
484
        {
485
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
486
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
487
        }
488
      }
489
490 9276dced Leszek Koltunski
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492
// INTERNAL API (for AutomaticControl)
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494
495
    public ObjectPreRender getPreRender()
496
      {
497
      return mPreRender;
498
      }
499
500 b3fff6fb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
501
502
    public ObjectLibInterface getInterface()
503
      {
504
      return mInterface;
505
      }
506
507 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
508
// PUBLIC API
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510
511 b3fff6fb Leszek Koltunski
    public ObjectControl(Activity act, ObjectLibInterface actioner)
512 880beeea Leszek Koltunski
      {
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 15e5214c Leszek Koltunski
      mPreRender = new ObjectPreRender(act,this,actioner);
530 b3fff6fb Leszek Koltunski
      mInterface = actioner;
531 880beeea Leszek Koltunski
      }
532
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534
535
    public void setScreenSize(int width, int height)
536
      {
537
      mScreenWidth = width;
538
      mScreenHeight= height;
539
      mScreenMin = Math.min(width, height);
540 9276dced Leszek Koltunski
      mPreRender.setScreenSize(width);
541 880beeea Leszek Koltunski
      }
542
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544
545 2fca02cf Leszek Koltunski
    public void onPause()
546
      {
547
      BlockController.onPause();
548
      }
549
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551
552
    public void onResume()
553 880beeea Leszek Koltunski
      {
554
      mPointer1 = INVALID_POINTER_ID;
555
      mPointer2 = INVALID_POINTER_ID;
556 b9956428 Leszek Koltunski
557
      unlock();
558 2fca02cf Leszek Koltunski
559
      BlockController.onResume();
560 880beeea Leszek Koltunski
      }
561
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563
564
    public void setQuat()
565
      {
566
      mQuat.set(mTemp);
567
      }
568
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570
571
    public Static4D getQuat()
572
      {
573
      return mQuat;
574
      }
575
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577
578
    public void setMovement(Movement movement)
579
      {
580
      mMovement = movement;
581
      }
582
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584
585 9276dced Leszek Koltunski
    public void preRender()
586 880beeea Leszek Koltunski
      {
587 9276dced Leszek Koltunski
      mPreRender.preRender();
588
      }
589
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591
592
    public void blockEverything(int place)
593
      {
594 b9956428 Leszek Koltunski
      setLock(true);
595 9276dced Leszek Koltunski
      mPreRender.blockEverything(place);
596
      }
597
598
///////////////////////////////////////////////////////////////////////////////////////////////////
599
600
    public void blockTouch(int place)
601
      {
602 b9956428 Leszek Koltunski
      setLock(true);
603 9276dced Leszek Koltunski
      mPreRender.blockTouch(place);
604
      }
605
606
///////////////////////////////////////////////////////////////////////////////////////////////////
607
608
    public void unblockEverything()
609
      {
610 b9956428 Leszek Koltunski
      unsetLock();
611 9276dced Leszek Koltunski
      mPreRender.unblockEverything();
612
      }
613
614
///////////////////////////////////////////////////////////////////////////////////////////////////
615
616
    public void unblockTouch()
617
      {
618 b9956428 Leszek Koltunski
      unsetLock();
619 9276dced Leszek Koltunski
      mPreRender.unblockTouch();
620
      }
621
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623
624
    public void unblockUI()
625
      {
626
      mPreRender.unblockUI();
627
      }
628
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630
631
    public boolean isTouchBlocked()
632
      {
633
      return mPreRender.isTouchBlocked();
634
      }
635
636
///////////////////////////////////////////////////////////////////////////////////////////////////
637
638
    public boolean isUINotBlocked()
639
      {
640
      return mPreRender.isUINotBlocked();
641
      }
642
643
///////////////////////////////////////////////////////////////////////////////////////////////////
644
645
    public void initializeObject(int[][] moves)
646
      {
647
      mPreRender.initializeObject(moves);
648
      }
649
650
///////////////////////////////////////////////////////////////////////////////////////////////////
651
652
    public void changeObject(ObjectType object)
653
      {
654
      mPreRender.changeObject(object);
655
      }
656
657
///////////////////////////////////////////////////////////////////////////////////////////////////
658
659
    public void setupObject(ObjectType object, int[][] moves)
660
      {
661
      mPreRender.setupObject(object,moves);
662
      }
663
664
///////////////////////////////////////////////////////////////////////////////////////////////////
665
666
    public void scrambleObject(int num)
667
      {
668
      mPreRender.scrambleObject(num);
669
      }
670
671
///////////////////////////////////////////////////////////////////////////////////////////////////
672
673
    public void solveObject()
674
      {
675
      mPreRender.solveObject();
676
      }
677
678 17d623f1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
679
680
    public void solveOnly()
681
      {
682
      mPreRender.solveOnly();
683
      }
684
685 9276dced Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
686
687 2df35810 Leszek Koltunski
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
688 9276dced Leszek Koltunski
      {
689
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
690
      }
691
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693
694
    public void resetAllTextureMaps()
695
      {
696
      mPreRender.resetAllTextureMaps();
697
      }
698
699
///////////////////////////////////////////////////////////////////////////////////////////////////
700
701
    public TwistyObject getObject()
702
      {
703
      return mPreRender.getObject();
704
      }
705
706
///////////////////////////////////////////////////////////////////////////////////////////////////
707
708
    public void savePreferences(SharedPreferences.Editor editor)
709
      {
710
      mPreRender.savePreferences(editor);
711
      }
712
713
///////////////////////////////////////////////////////////////////////////////////////////////////
714
715
    public void restorePreferences(SharedPreferences preferences)
716
      {
717
      mPreRender.restorePreferences(preferences);
718 880beeea Leszek Koltunski
      }
719 b9956428 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
720
721
  public boolean retLocked()
722
      {
723
      return mIsLocked;
724
      }
725
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727
728
  public void toggleLock()
729
      {
730
      mIsLocked = !mIsLocked;
731
      }
732
733
///////////////////////////////////////////////////////////////////////////////////////////////////
734
735
  public void unlock()
736
    {
737
    mIsLocked = false;
738
    }
739
740
///////////////////////////////////////////////////////////////////////////////////////////////////
741
742
  public void setLock(boolean value)
743
    {
744
    mRemLocked = mIsLocked;
745
    mIsLocked = value;
746
    }
747
748
///////////////////////////////////////////////////////////////////////////////////////////////////
749
750
  public void unsetLock()
751
    {
752
    mIsLocked = mRemLocked;
753
    }
754 880beeea Leszek Koltunski
755
///////////////////////////////////////////////////////////////////////////////////////////////////
756
757
    public boolean onTouchEvent(MotionEvent event, int mode)
758
      {
759
      int action = event.getActionMasked();
760
761
      switch(action)
762
         {
763
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
764
                                               actionDown(mX1, mY1, mode);
765
                                               break;
766
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
767
                                               actionMove(mX1, mY1, mX2, mY2, mode);
768
                                               break;
769
         case MotionEvent.ACTION_UP          : prepareUp(event);
770
                                               actionUp();
771
                                               break;
772
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
773
                                               actionDown2(mX1, mY1, mX2, mY2);
774
                                               break;
775
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
776
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
777
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
778
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
779
                                               break;
780
         }
781
782
      return true;
783
      }
784
}