Revision e4b7d0f9
Added by Leszek Koltunski 8 months ago
| src/main/java/org/distorted/bandaged/BandagedRenderer.java | ||
|---|---|---|
| 17 | 17 |
import java.io.InputStream; |
| 18 | 18 |
import java.nio.ByteBuffer; |
| 19 | 19 |
import java.nio.ByteOrder; |
| 20 |
import java.util.Stack; |
|
| 20 | 21 |
|
| 21 | 22 |
import javax.microedition.khronos.egl.EGLConfig; |
| 22 | 23 |
import javax.microedition.khronos.opengles.GL10; |
| ... | ... | |
| 66 | 67 |
private boolean mInitialPhase; |
| 67 | 68 |
private long mStartTime; |
| 68 | 69 |
private float mQuatX, mQuatY, mQuatZ, mQuatW; |
| 69 |
private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits, mCreatingCubits, mRescaling; |
|
| 70 |
private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits; |
|
| 71 |
private boolean mCreatingCubits, mRescaling, mUndoingObject; |
|
| 70 | 72 |
private int mIndex1, mIndex2; |
| 71 | 73 |
private int mSaveIcon; |
| 72 | 74 |
private DistortedFramebuffer mFramebuffer; |
| ... | ... | |
| 75 | 77 |
private int mWidth, mHeight; |
| 76 | 78 |
private float mScaleValue, mObjectScreenRatio; |
| 77 | 79 |
|
| 80 |
private final Stack<Integer> mPairs; // each Integer holds a packed pair in ints |
|
| 81 |
|
|
| 78 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 79 | 83 |
|
| 80 | 84 |
BandagedRenderer(BandagedView v, int ordinal) |
| ... | ... | |
| 92 | 96 |
mCubitsCreated = false; |
| 93 | 97 |
mCreatingCubits = false; |
| 94 | 98 |
mRescaling = false; |
| 99 |
mUndoingObject = false; |
|
| 95 | 100 |
|
| 96 | 101 |
mSaveIcon = -1; |
| 97 | 102 |
|
| ... | ... | |
| 105 | 110 |
|
| 106 | 111 |
mInitRatio = mObject.getScreenRatio(); |
| 107 | 112 |
mObjectScreenRatio= mInitRatio; |
| 113 |
|
|
| 114 |
mPairs = new Stack<>(); |
|
| 108 | 115 |
} |
| 109 | 116 |
|
| 110 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 147 | 154 |
if( mResettingObject ) |
| 148 | 155 |
{
|
| 149 | 156 |
boolean done = continueResetting(time); |
| 150 |
if( done ) mResettingObject = false; |
|
| 157 |
if( done ) |
|
| 158 |
{
|
|
| 159 |
mResettingObject = false; |
|
| 160 |
mPairs.clear(); |
|
| 161 |
} |
|
| 151 | 162 |
} |
| 152 | 163 |
|
| 153 | 164 |
if( mSaveIcon>=0 ) |
| ... | ... | |
| 163 | 174 |
|
| 164 | 175 |
if( mConnectingCubits ) |
| 165 | 176 |
{
|
| 166 |
mObject.tryConnectingCubits(mIndex1,mIndex2,mScaleValue); |
|
| 177 |
boolean success = mObject.tryConnectingCubits(mIndex1,mIndex2,mScaleValue); |
|
| 178 |
if( success ) mPairs.add( packTwoIntsIntoPair(mIndex1,mIndex2) ); |
|
| 167 | 179 |
mConnectingCubits = false; |
| 168 | 180 |
} |
| 181 |
if( mUndoingObject ) |
|
| 182 |
{
|
|
| 183 |
int num = mPairs.size(); |
|
| 184 |
|
|
| 185 |
if( num>0 ) |
|
| 186 |
{
|
|
| 187 |
int pair = mPairs.pop(); |
|
| 188 |
int first = getFirstFromPair(pair); |
|
| 189 |
int second= getSecondFromPair(pair); |
|
| 190 |
mObject.disconnectCubits(first, second, mScaleValue); |
|
| 191 |
} |
|
| 192 |
|
|
| 193 |
mUndoingObject = false; |
|
| 194 |
} |
|
| 169 | 195 |
|
| 170 | 196 |
if( mCreatingCubits ) |
| 171 | 197 |
{
|
| ... | ... | |
| 296 | 322 |
} |
| 297 | 323 |
} |
| 298 | 324 |
|
| 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 326 |
|
|
| 327 |
private int packTwoIntsIntoPair(int index1, int index2) |
|
| 328 |
{
|
|
| 329 |
return (index1<<16) + index2; |
|
| 330 |
} |
|
| 331 |
|
|
| 332 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 333 |
|
|
| 334 |
private int getFirstFromPair(int pair) |
|
| 335 |
{
|
|
| 336 |
return pair>>16; |
|
| 337 |
} |
|
| 338 |
|
|
| 339 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 340 |
|
|
| 341 |
private int getSecondFromPair(int pair) |
|
| 342 |
{
|
|
| 343 |
return pair&0xffff; |
|
| 344 |
} |
|
| 345 |
|
|
| 299 | 346 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 300 | 347 |
|
| 301 | 348 |
private boolean createObjectJson(TwistyObject object, Activity act) |
| ... | ... | |
| 469 | 516 |
mStartTime = System.currentTimeMillis(); |
| 470 | 517 |
} |
| 471 | 518 |
|
| 519 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 520 |
|
|
| 521 |
public void setupUndo() |
|
| 522 |
{
|
|
| 523 |
mUndoingObject = true; |
|
| 524 |
} |
|
| 525 |
|
|
| 472 | 526 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 473 | 527 |
|
| 474 | 528 |
public boolean continueResetting(long time) |
| src/main/java/org/distorted/bandaged/BandagedScreen.java | ||
|---|---|---|
| 36 | 36 |
public class BandagedScreen implements AdapterView.OnItemSelectedListener |
| 37 | 37 |
{
|
| 38 | 38 |
private WeakReference<BandagedActivity> mAct; |
| 39 |
private TransparentImageButton mBackButton, mResetButton, mDoneButton; |
|
| 39 |
private TransparentImageButton mBackButton, mResetButton, mUndoButton, mDoneButton;
|
|
| 40 | 40 |
private LinearLayout mObjectView; |
| 41 | 41 |
private int mNumObjects, mX, mY, mZ; |
| 42 | 42 |
private final ArrayList<BandagedObjectView> mViews; |
| ... | ... | |
| 96 | 96 |
}); |
| 97 | 97 |
} |
| 98 | 98 |
|
| 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 100 |
|
|
| 101 |
private void setupUndoButton(final BandagedActivity act) |
|
| 102 |
{
|
|
| 103 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 104 |
mUndoButton = new TransparentImageButton(act,R.drawable.ui_left,params); |
|
| 105 |
|
|
| 106 |
mUndoButton.setOnClickListener( new View.OnClickListener() |
|
| 107 |
{
|
|
| 108 |
@Override |
|
| 109 |
public void onClick(View v) |
|
| 110 |
{
|
|
| 111 |
BandagedRenderer renderer = act.getRenderer(); |
|
| 112 |
if( !renderer.isBusy() ) renderer.setupUndo(); |
|
| 113 |
} |
|
| 114 |
}); |
|
| 115 |
} |
|
| 116 |
|
|
| 99 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 100 | 118 |
|
| 101 | 119 |
private void setupResetButton(final BandagedActivity act) |
| ... | ... | |
| 152 | 170 |
int height = act.getScreenHeightInPixels(); |
| 153 | 171 |
int padding= (int)(height*BandagedActivity.PADDING/3); |
| 154 | 172 |
|
| 155 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 156 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 157 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 173 |
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 174 |
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 175 |
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 176 |
LinearLayout.LayoutParams params4 = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 158 | 177 |
|
| 159 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
| 160 |
layoutLeft.setLayoutParams(paramsL); |
|
| 161 |
LinearLayout layoutMid = new LinearLayout(act); |
|
| 162 |
layoutMid.setLayoutParams(paramsM); |
|
| 163 |
LinearLayout layoutRight= new LinearLayout(act); |
|
| 164 |
layoutRight.setLayoutParams(paramsR); |
|
| 178 |
LinearLayout layout1 = new LinearLayout(act); |
|
| 179 |
layout1.setLayoutParams(params1); |
|
| 180 |
LinearLayout layout2 = new LinearLayout(act); |
|
| 181 |
layout2.setLayoutParams(params2); |
|
| 182 |
LinearLayout layout3 = new LinearLayout(act); |
|
| 183 |
layout3.setLayoutParams(params3); |
|
| 184 |
LinearLayout layout4 = new LinearLayout(act); |
|
| 185 |
layout4.setLayoutParams(params4); |
|
| 165 | 186 |
|
| 166 | 187 |
setupBackButton(act); |
| 167 |
layoutRight.addView(mBackButton);
|
|
| 188 |
layout4.addView(mBackButton);
|
|
| 168 | 189 |
setupDoneButton(act); |
| 169 |
layoutMid.addView(mDoneButton); |
|
| 190 |
layout3.addView(mDoneButton); |
|
| 191 |
setupUndoButton(act); |
|
| 192 |
layout2.addView(mUndoButton); |
|
| 170 | 193 |
setupResetButton(act); |
| 171 |
layoutLeft.addView(mResetButton);
|
|
| 194 |
layout1.addView(mResetButton);
|
|
| 172 | 195 |
|
| 173 | 196 |
LinearLayout layout = act.findViewById(R.id.lowerBar); |
| 174 | 197 |
layout.removeAllViews(); |
| 175 |
layout.addView(layoutLeft); |
|
| 176 |
layout.addView(layoutMid); |
|
| 177 |
layout.addView(layoutRight); |
|
| 198 |
layout.addView(layout1); |
|
| 199 |
layout.addView(layout2); |
|
| 200 |
layout.addView(layout3); |
|
| 201 |
layout.addView(layout4); |
|
| 178 | 202 |
|
| 179 | 203 |
mSpinnerX = act.findViewById(R.id.bandagedCreatorX); |
| 180 | 204 |
mSpinnerY = act.findViewById(R.id.bandagedCreatorY); |
Also available in: Unified diff
add an 'undo' button to the Bandaged Creators.