Revision 7289fd6c
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
252 | 252 |
|
253 | 253 |
public void Solver(View v) |
254 | 254 |
{ |
255 |
android.util.Log.e("act", "Not implemented yet");
|
|
255 |
RubikState.switchState(this,RubikState.SVER);
|
|
256 | 256 |
} |
257 | 257 |
|
258 | 258 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/object/RubikCube.java | ||
---|---|---|
83 | 83 |
super(size, 60, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.CUBE); |
84 | 84 |
} |
85 | 85 |
|
86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
87 |
// paint the square with upper-right cornder at (left,top) and side length 'side' with texture |
|
88 |
// for face 'face'. |
|
89 |
|
|
90 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side) |
|
91 |
{ |
|
92 |
final float R = side*0.10f; |
|
93 |
final float M = side*0.05f; |
|
94 |
|
|
95 |
paint.setColor(FACE_COLORS[face]); |
|
96 |
canvas.drawRoundRect( left+M, top+M, left+side-M, top+side-M, R, R, paint); |
|
97 |
} |
|
98 |
|
|
86 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
87 | 100 |
|
88 | 101 |
Static3D[] getCubitPositions(int size) |
... | ... | |
145 | 158 |
return new VertexEffectSink( new Static1D(strength), center, region ); |
146 | 159 |
} |
147 | 160 |
|
148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
149 |
// paint only the square with lower-left corner at (face*TEX_H,0) and side length TEX_H |
|
150 |
|
|
151 |
void createFaceTexture(Canvas canvas, Paint paint, int face) |
|
152 |
{ |
|
153 |
final int S = TEXTURE_HEIGHT; |
|
154 |
final int R = TEXTURE_HEIGHT/10; |
|
155 |
final int M = TEXTURE_HEIGHT/20; |
|
156 |
|
|
157 |
paint.setColor(FACE_COLORS[face]); |
|
158 |
canvas.drawRoundRect( (face*S+M), M, (face*S+M) + (S-2*M), M + (S-2*M), R, R, paint); |
|
159 |
} |
|
160 |
|
|
161 | 161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
162 | 162 |
|
163 | 163 |
MeshBase createCubitMesh(int cubit, int vertices) |
src/main/java/org/distorted/object/RubikObject.java | ||
---|---|---|
45 | 45 |
{ |
46 | 46 |
public static final int NODE_FBO_SIZE = 600; |
47 | 47 |
|
48 |
static final int TEXTURE_HEIGHT = 128; |
|
48 |
private static final int TEXTURE_HEIGHT = 128;
|
|
49 | 49 |
final float[] LEGAL_QUATS; |
50 | 50 |
final Static3D[] ROTATION_AXIS; |
51 | 51 |
|
... | ... | |
312 | 312 |
|
313 | 313 |
for(int i=0; i<numColors; i++) |
314 | 314 |
{ |
315 |
createFaceTexture(canvas,paint,i); |
|
315 |
createFaceTexture(canvas,paint,i, i*TEXTURE_HEIGHT, 0, TEXTURE_HEIGHT);
|
|
316 | 316 |
} |
317 | 317 |
|
318 | 318 |
mTexture.setTexture(bitmap); |
... | ... | |
526 | 526 |
abstract Static3D[] getCubitPositions(int size); |
527 | 527 |
abstract float[] getLegalQuats(); |
528 | 528 |
abstract int getNumFaces(); |
529 |
abstract void createFaceTexture(Canvas canvas, Paint paint, int face); |
|
530 | 529 |
abstract MeshBase createCubitMesh(int cubit, int vertices); |
530 |
abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side); |
|
531 | 531 |
public abstract Static3D[] getRotationAxis(); |
532 | 532 |
public abstract int getBasicAngle(); |
533 | 533 |
public abstract int returnRowFromOffset(float offset); |
src/main/java/org/distorted/object/RubikPyraminx.java | ||
---|---|---|
208 | 208 |
return new VertexEffectSink( new Static1D(1.3f), center, region ); |
209 | 209 |
} |
210 | 210 |
|
211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
212 |
|
|
213 |
void createFaceTexture(Canvas canvas, Paint paint, int face) |
|
214 |
{ |
|
215 |
int xoffset = face*TEXTURE_HEIGHT; |
|
216 |
float STROKE = 0.06f*TEXTURE_HEIGHT; |
|
217 |
float OFF = STROKE/2 -1; |
|
218 |
float OFF2 = 0.5f*TEXTURE_HEIGHT + OFF; |
|
219 |
float HEIGHT = TEXTURE_HEIGHT - OFF; |
|
220 |
float RADIUS = TEXTURE_HEIGHT/12.0f; |
|
221 |
float ARC1_H = 0.2f*TEXTURE_HEIGHT; |
|
222 |
float ARC1_W = TEXTURE_HEIGHT*0.5f; |
|
223 |
float ARC2_W = 0.153f*TEXTURE_HEIGHT; |
|
224 |
float ARC2_H = 0.905f*TEXTURE_HEIGHT; |
|
225 |
float ARC3_W = TEXTURE_HEIGHT-ARC2_W; |
|
226 |
|
|
227 |
paint.setAntiAlias(true); |
|
228 |
paint.setStrokeWidth(STROKE); |
|
229 |
paint.setColor(FACE_COLORS[face]); |
|
230 |
paint.setStyle(Paint.Style.FILL); |
|
231 |
|
|
232 |
canvas.drawRect(xoffset,0,xoffset+TEXTURE_HEIGHT,TEXTURE_HEIGHT,paint); |
|
233 |
|
|
234 |
paint.setColor(0xff000000); |
|
235 |
paint.setStyle(Paint.Style.STROKE); |
|
236 |
|
|
237 |
canvas.drawLine( xoffset, HEIGHT, TEXTURE_HEIGHT +xoffset, HEIGHT, paint); |
|
238 |
canvas.drawLine( OFF +xoffset, TEXTURE_HEIGHT, OFF2 +xoffset, 0, paint); |
|
239 |
canvas.drawLine((TEXTURE_HEIGHT-OFF)+xoffset, TEXTURE_HEIGHT, (TEXTURE_HEIGHT-OFF2) +xoffset, 0, paint); |
|
240 |
|
|
241 |
canvas.drawArc( ARC1_W-RADIUS+xoffset, ARC1_H-RADIUS, ARC1_W+RADIUS+xoffset, ARC1_H+RADIUS, 225, 90, false, paint); |
|
242 |
canvas.drawArc( ARC2_W-RADIUS+xoffset, ARC2_H-RADIUS, ARC2_W+RADIUS+xoffset, ARC2_H+RADIUS, 105, 90, false, paint); |
|
243 |
canvas.drawArc( ARC3_W-RADIUS+xoffset, ARC2_H-RADIUS, ARC3_W+RADIUS+xoffset, ARC2_H+RADIUS, 345, 90, false, paint); |
|
244 |
} |
|
245 |
|
|
246 | 211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
247 | 212 |
|
248 | 213 |
MeshBase createCubitMesh(int cubit, int vertices) |
... | ... | |
289 | 254 |
return result; |
290 | 255 |
} |
291 | 256 |
|
257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
258 |
|
|
259 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side) |
|
260 |
{ |
|
261 |
float STROKE = 0.06f*side; |
|
262 |
float OFF = STROKE/2 -1; |
|
263 |
float OFF2 = 0.5f*side + OFF; |
|
264 |
float HEIGHT = side - OFF; |
|
265 |
float RADIUS = side/12.0f; |
|
266 |
float ARC1_H = 0.2f*side; |
|
267 |
float ARC1_W = side*0.5f; |
|
268 |
float ARC2_W = 0.153f*side; |
|
269 |
float ARC2_H = 0.905f*side; |
|
270 |
float ARC3_W = side-ARC2_W; |
|
271 |
|
|
272 |
paint.setAntiAlias(true); |
|
273 |
paint.setStrokeWidth(STROKE); |
|
274 |
paint.setColor(FACE_COLORS[face]); |
|
275 |
paint.setStyle(Paint.Style.FILL); |
|
276 |
|
|
277 |
canvas.drawRect(left,top,left+side,top+side,paint); |
|
278 |
|
|
279 |
paint.setColor(0xff000000); |
|
280 |
paint.setStyle(Paint.Style.STROKE); |
|
281 |
|
|
282 |
canvas.drawLine( left, HEIGHT, side +left, HEIGHT, paint); |
|
283 |
canvas.drawLine( OFF +left, side , OFF2 +left, 0, paint); |
|
284 |
canvas.drawLine((side-OFF)+left, side , (side-OFF2) +left, 0, paint); |
|
285 |
|
|
286 |
canvas.drawArc( ARC1_W-RADIUS+left, ARC1_H-RADIUS, ARC1_W+RADIUS+left, ARC1_H+RADIUS, 225, 90, false, paint); |
|
287 |
canvas.drawArc( ARC2_W-RADIUS+left, ARC2_H-RADIUS, ARC2_W+RADIUS+left, ARC2_H+RADIUS, 105, 90, false, paint); |
|
288 |
canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint); |
|
289 |
} |
|
290 |
|
|
292 | 291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
293 | 292 |
// PUBLIC API |
294 | 293 |
|
src/main/java/org/distorted/uistate/RubikState.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
public enum RubikState |
28 | 28 |
{ |
29 |
MAIN ( null , true , new RubikStateMain() ),
|
|
29 |
MAIN ( null , false, new RubikStateMain() ),
|
|
30 | 30 |
PLAY ( MAIN , true , new RubikStatePlay() ), |
31 | 31 |
SOLV ( PLAY , true , new RubikStateSolving() ), |
32 | 32 |
PATT ( MAIN , false, new RubikStatePattern() ), |
33 |
SVER ( MAIN , false, new RubikStateSolver() ), |
|
33 | 34 |
; |
34 | 35 |
|
35 | 36 |
public static final int LENGTH = values().length; |
src/main/java/org/distorted/uistate/RubikStateMain.java | ||
---|---|---|
67 | 67 |
LayoutInflater inflater = act.getLayoutInflater(); |
68 | 68 |
|
69 | 69 |
// TOP //////////////////////////// |
70 |
LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
|
|
70 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
|
71 | 71 |
layoutTop.removeAllViews(); |
72 | 72 |
final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null); |
73 | 73 |
text.setText(R.string.app_name); |
src/main/java/org/distorted/uistate/RubikStatePattern.java | ||
---|---|---|
98 | 98 |
LayoutInflater inflater = act.getLayoutInflater(); |
99 | 99 |
|
100 | 100 |
// TOP //////////////////////////// |
101 |
LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
|
|
101 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
|
102 | 102 |
layoutTop.removeAllViews(); |
103 | 103 |
mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null); |
104 | 104 |
mText.setText(R.string.patterns); |
src/main/java/org/distorted/uistate/RubikStatePlay.java | ||
---|---|---|
72 | 72 |
// TOP //////////////////////////// |
73 | 73 |
final View viewTop = inflater.inflate(R.layout.play_title, null); |
74 | 74 |
|
75 |
LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
|
|
75 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
|
76 | 76 |
layoutTop.removeAllViews(); |
77 | 77 |
layoutTop.addView(viewTop); |
78 | 78 |
|
src/main/java/org/distorted/uistate/RubikStateSolver.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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.uistate; |
|
21 |
|
|
22 |
import android.content.SharedPreferences; |
|
23 |
import android.graphics.Bitmap; |
|
24 |
import android.graphics.Canvas; |
|
25 |
import android.graphics.Paint; |
|
26 |
import android.util.DisplayMetrics; |
|
27 |
import android.view.View; |
|
28 |
import android.widget.Button; |
|
29 |
import android.widget.ImageButton; |
|
30 |
import android.widget.LinearLayout; |
|
31 |
|
|
32 |
import org.distorted.magic.R; |
|
33 |
import org.distorted.magic.RubikActivity; |
|
34 |
import org.distorted.object.RubikObjectList; |
|
35 |
|
|
36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 |
|
|
38 |
public class RubikStateSolver extends RubikStateAbstract |
|
39 |
{ |
|
40 |
private static final int NUM_FACES = 6; |
|
41 |
private static final int BITMAP_SIZE = 35; |
|
42 |
|
|
43 |
private static final int[] FACE_COLORS = new int[] |
|
44 |
{ |
|
45 |
0xffffff00, 0xffffffff, |
|
46 |
0xff0000ff, 0xff00ff00, |
|
47 |
0xffff0000, 0xffb5651d |
|
48 |
}; |
|
49 |
|
|
50 |
private static Bitmap[] mBitmap; |
|
51 |
private ImageButton[] mColorButton; |
|
52 |
private Button mBackButton; |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
void leaveState(RubikActivity act) |
|
57 |
{ |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 |
|
|
63 |
void enterState(final RubikActivity act) |
|
64 |
{ |
|
65 |
act.changeObject(RubikObjectList.CUBE,3,null); |
|
66 |
|
|
67 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
68 |
final float scale = metrics.density; |
|
69 |
|
|
70 |
// TOP //////////////////////////// |
|
71 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
|
72 |
layoutTop.removeAllViews(); |
|
73 |
|
|
74 |
if( mBitmap ==null ) setupBitmaps(scale); |
|
75 |
if( mColorButton==null ) setupColorButtons(act,scale); |
|
76 |
|
|
77 |
for(ImageButton button: mColorButton) layoutTop.addView(button); |
|
78 |
|
|
79 |
// BOT //////////////////////////// |
|
80 |
if( mBackButton==null ) setupBackButton(act,scale); |
|
81 |
|
|
82 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
83 |
layoutRight.removeAllViews(); |
|
84 |
layoutRight.addView(mBackButton); |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
//createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side); |
|
89 |
|
|
90 |
private void setupBitmaps(float scale) |
|
91 |
{ |
|
92 |
final int SIZE = (int)(scale*BITMAP_SIZE); |
|
93 |
final float R = SIZE*0.10f; |
|
94 |
final float M = SIZE*0.05f; |
|
95 |
|
|
96 |
mBitmap = new Bitmap[NUM_FACES]; |
|
97 |
|
|
98 |
Paint paint = new Paint(); |
|
99 |
paint.setColor(0xff008800); |
|
100 |
paint.setStyle(Paint.Style.FILL); |
|
101 |
|
|
102 |
paint.setAntiAlias(true); |
|
103 |
paint.setTextAlign(Paint.Align.CENTER); |
|
104 |
paint.setStyle(Paint.Style.FILL); |
|
105 |
|
|
106 |
for(int i=0; i<NUM_FACES; i++) |
|
107 |
{ |
|
108 |
mBitmap[i] = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888); |
|
109 |
Canvas canvas = new Canvas(mBitmap[i]); |
|
110 |
|
|
111 |
paint.setColor(0xff000000); |
|
112 |
canvas.drawRect(0, 0, SIZE, SIZE, paint); |
|
113 |
|
|
114 |
paint.setColor(FACE_COLORS[i]); |
|
115 |
canvas.drawRoundRect( M, M, SIZE-M, SIZE-M, R, R, paint); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
120 |
|
|
121 |
private void setupColorButtons(final RubikActivity act, final float scale) |
|
122 |
{ |
|
123 |
mColorButton = new ImageButton[NUM_FACES]; |
|
124 |
|
|
125 |
for(int i=0; i<NUM_FACES; i++) |
|
126 |
{ |
|
127 |
final int ii = i; |
|
128 |
int padding = (int)(3*scale + 0.5f); |
|
129 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
|
130 |
mColorButton[i] = new ImageButton(act); |
|
131 |
mColorButton[i].setLayoutParams(objectParams); |
|
132 |
mColorButton[i].setPadding(padding,0,padding,0); |
|
133 |
mColorButton[i].setImageBitmap(mBitmap[i]); |
|
134 |
|
|
135 |
mColorButton[i].setOnClickListener( new View.OnClickListener() |
|
136 |
{ |
|
137 |
@Override |
|
138 |
public void onClick(View view) |
|
139 |
{ |
|
140 |
android.util.Log.e("solver", "button "+FACE_COLORS[ii]+" clicked"); |
|
141 |
} |
|
142 |
}); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 |
|
|
148 |
private void setupBackButton(final RubikActivity act, final float scale) |
|
149 |
{ |
|
150 |
int padding = (int)(3*scale + 0.5f); |
|
151 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
152 |
mBackButton = new Button(act); |
|
153 |
mBackButton.setLayoutParams(backParams); |
|
154 |
mBackButton.setPadding(padding,0,padding,0); |
|
155 |
mBackButton.setText(R.string.back); |
|
156 |
|
|
157 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
158 |
{ |
|
159 |
@Override |
|
160 |
public void onClick(View v) |
|
161 |
{ |
|
162 |
RubikState.goBack(act); |
|
163 |
} |
|
164 |
}); |
|
165 |
} |
|
166 |
|
|
167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
168 |
|
|
169 |
public void savePreferences(SharedPreferences.Editor editor) |
|
170 |
{ |
|
171 |
mColorButton = null; |
|
172 |
mBackButton = null; |
|
173 |
} |
|
174 |
|
|
175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
176 |
|
|
177 |
public void restorePreferences(SharedPreferences preferences) |
|
178 |
{ |
|
179 |
|
|
180 |
} |
|
181 |
} |
src/main/java/org/distorted/uistate/RubikStateSolving.java | ||
---|---|---|
67 | 67 |
LayoutInflater inflater = act.getLayoutInflater(); |
68 | 68 |
|
69 | 69 |
// TOP //////////////////////////// |
70 |
LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
|
|
70 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
|
71 | 71 |
layoutTop.removeAllViews(); |
72 | 72 |
mTime = (TextView)inflater.inflate(R.layout.upper_text, null); |
73 | 73 |
mTime.setText(R.string.ready); |
src/main/res/layout/main.xml | ||
---|---|---|
5 | 5 |
android:orientation="vertical" > |
6 | 6 |
|
7 | 7 |
<LinearLayout |
8 |
android:id="@+id/mainTitle"
|
|
8 |
android:id="@+id/upperBar"
|
|
9 | 9 |
android:layout_width="fill_parent" |
10 | 10 |
android:layout_height="50dp" |
11 | 11 |
android:gravity="center" |
Also available in: Unified diff
Beginnings of support for the 3x3x3 Solver.