Revision bcc8e016
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java | ||
---|---|---|
61 | 61 |
private NumberPicker mColsPicker, mRowsPicker; |
62 | 62 |
private LinearLayout mLay; |
63 | 63 |
private boolean[] mShape; |
64 |
private DistortedObject mObject; |
|
65 |
private int mObjectType; |
|
66 |
private int mBitmap; |
|
64 | 67 |
|
65 | 68 |
// fields needed for the second 'apply vertex effects' screen |
66 | 69 |
// |
... | ... | |
77 | 80 |
private float fsinkA; |
78 | 81 |
private float fswirlA; |
79 | 82 |
private float fcenterX, fcenterY; |
80 |
|
|
81 |
private DistortedObject mObject; |
|
82 |
|
|
83 | 83 |
private EffectNames[] effects = new EffectNames[4]; |
84 |
private int mObjectType; |
|
84 |
|
|
85 | 85 |
|
86 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
87 | 87 |
|
... | ... | |
92 | 92 |
|
93 | 93 |
setContentView(R.layout.objectpickerlayout); |
94 | 94 |
|
95 |
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid); |
|
96 |
|
|
97 | 95 |
mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols); |
98 | 96 |
mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows); |
99 | 97 |
|
... | ... | |
107 | 105 |
@Override |
108 | 106 |
public void onValueChange(NumberPicker picker, int oldVal, int newVal) |
109 | 107 |
{ |
110 |
setGrid();
|
|
108 |
mNumCols = mColsPicker.getValue();
|
|
111 | 109 |
} |
112 | 110 |
}); |
113 | 111 |
|
... | ... | |
116 | 114 |
@Override |
117 | 115 |
public void onValueChange(NumberPicker picker, int oldVal, int newVal) |
118 | 116 |
{ |
119 |
setGrid();
|
|
117 |
mNumRows = mRowsPicker.getValue();
|
|
120 | 118 |
} |
121 | 119 |
}); |
122 | 120 |
|
... | ... | |
129 | 127 |
|
130 | 128 |
String[] objectType = new String[] {"DistortedCubes", "DistortedBitmap"}; |
131 | 129 |
|
132 |
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType); |
|
133 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
134 |
typeSpinner.setAdapter(adapter); |
|
130 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType); |
|
131 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
132 |
typeSpinner.setAdapter(adapterType); |
|
133 |
|
|
134 |
Spinner bitmapSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerBitmap); |
|
135 |
bitmapSpinner.setOnItemSelectedListener(this); |
|
136 |
|
|
137 |
String[] objectBitmap = new String[] {"Girl", "Dog", "Cat", "Grid"}; |
|
138 |
|
|
139 |
ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap); |
|
140 |
adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
141 |
bitmapSpinner.setAdapter(adapterBitmap); |
|
135 | 142 |
} |
136 | 143 |
|
137 | 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
138 | 145 |
|
139 | 146 |
private void setGrid() |
140 | 147 |
{ |
141 |
mNumCols = mColsPicker.getValue(); |
|
142 |
mNumRows = mRowsPicker.getValue(); |
|
148 |
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid); |
|
143 | 149 |
|
144 | 150 |
int width = mLay.getWidth(); |
145 | 151 |
int height= mLay.getHeight(); |
... | ... | |
172 | 178 |
b.setOnClickListener(this); |
173 | 179 |
b.setId(rows*mNumCols+cols); |
174 | 180 |
b.setLayoutParams(p); |
175 |
b.setBackgroundColor(COLOR_OFF);
|
|
181 |
b.setBackgroundColor(COLOR_ON);
|
|
176 | 182 |
tr.addView(b, p); |
177 |
mShape[rows*mNumCols+cols] = false;
|
|
183 |
mShape[rows*mNumCols+cols] = true;
|
|
178 | 184 |
} |
179 | 185 |
|
180 | 186 |
mLay.addView(tr); |
... | ... | |
200 | 206 |
|
201 | 207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
202 | 208 |
|
203 |
public void Create(View v)
|
|
209 |
public int getBitmap()
|
|
204 | 210 |
{ |
205 |
firstScreen = false; |
|
211 |
return mBitmap; |
|
212 |
} |
|
213 |
|
|
214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
206 | 215 |
|
216 |
public void Continue(View v) |
|
217 |
{ |
|
207 | 218 |
if( mObjectType==1 ) |
208 | 219 |
{ |
220 |
firstScreen = false; |
|
209 | 221 |
mObject = new DistortedBitmap(100,100,mNumCols); |
222 |
setContentView(R.layout.vertex3dlayout); |
|
223 |
Default(null); |
|
210 | 224 |
} |
211 | 225 |
else |
212 | 226 |
{ |
213 |
String str = "";
|
|
227 |
View view = getLayoutInflater().inflate(R.layout.objectpicker2layout, null);
|
|
214 | 228 |
|
215 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
216 |
str += mShape[i] ? "1" : "0"; |
|
229 |
setContentView(view); |
|
217 | 230 |
|
218 |
mObject = new DistortedCubes(mNumCols, str, 10); |
|
231 |
view.post(new Runnable() { |
|
232 |
@Override |
|
233 |
public void run() { |
|
234 |
setGrid(); |
|
235 |
} |
|
236 |
}); |
|
219 | 237 |
} |
238 |
} |
|
239 |
|
|
240 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
241 |
|
|
242 |
public void Create(View v) |
|
243 |
{ |
|
244 |
firstScreen = false; |
|
245 |
|
|
246 |
String str = ""; |
|
247 |
|
|
248 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
249 |
str += mShape[i] ? "1" : "0"; |
|
250 |
|
|
251 |
mObject = new DistortedCubes(mNumCols, str, 10); |
|
220 | 252 |
|
221 | 253 |
setContentView(R.layout.vertex3dlayout); |
222 | 254 |
Default(null); |
... | ... | |
229 | 261 |
{ |
230 | 262 |
switch(parent.getId()) |
231 | 263 |
{ |
232 |
case R.id.objectpicker_spinnerType: mObjectType = pos; break; |
|
264 |
case R.id.objectpicker_spinnerType : mObjectType = pos; break; |
|
265 |
case R.id.objectpicker_spinnerBitmap: switch(pos) |
|
266 |
{ |
|
267 |
case 0: mBitmap = R.raw.face; break; |
|
268 |
case 1: mBitmap = R.raw.dog; break; |
|
269 |
case 2: mBitmap = R.raw.cat; break; |
|
270 |
case 3: mBitmap = R.raw.grid; break; |
|
271 |
} |
|
272 |
break; |
|
233 | 273 |
} |
234 | 274 |
} |
235 | 275 |
|
... | ... | |
550 | 590 |
{ |
551 | 591 |
mColsPicker.setValue(mNumCols); |
552 | 592 |
mRowsPicker.setValue(mNumRows); |
553 |
|
|
554 |
if( hasFocus ) setGrid(); |
|
555 | 593 |
} |
556 | 594 |
} |
557 | 595 |
|
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java | ||
---|---|---|
251 | 251 |
|
252 | 252 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
253 | 253 |
{ |
254 |
InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.grid); |
|
255 |
InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.center); |
|
254 |
Vertex3DActivity act = (Vertex3DActivity)mView.getContext(); |
|
255 |
|
|
256 |
InputStream is1 = act.getResources().openRawResource(act.getBitmap()); |
|
257 |
InputStream is2 = act.getResources().openRawResource(R.raw.center); |
|
256 | 258 |
|
257 | 259 |
Bitmap bitmap1,bitmap2; |
258 | 260 |
|
src/main/res/layout/objectpicker2layout.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
|
|
3 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
4 |
android:orientation="vertical" |
|
5 |
android:layout_width="match_parent" |
|
6 |
android:layout_height="match_parent"> |
|
7 |
|
|
8 |
<Button |
|
9 |
android:id="@+id/objectpicker_create" |
|
10 |
android:onClick="Create" |
|
11 |
android:text="@string/Create" |
|
12 |
android:layout_width="match_parent" |
|
13 |
android:layout_height="80dp" |
|
14 |
android:layout_span="3" |
|
15 |
android:layout_marginTop="5dp"/> |
|
16 |
|
|
17 |
<LinearLayout |
|
18 |
android:id="@+id/objectpicker_buttongrid" |
|
19 |
android:layout_width="match_parent" |
|
20 |
android:layout_height="fill_parent" |
|
21 |
android:gravity="center" |
|
22 |
android:orientation="vertical" |
|
23 |
android:layout_weight="0.8"> |
|
24 |
</LinearLayout> |
|
25 |
|
|
26 |
</LinearLayout> |
src/main/res/layout/objectpickerlayout.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
2 | 2 |
|
3 | 3 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
4 |
android:orientation="vertical" |
|
5 |
android:layout_width="match_parent" |
|
6 |
android:layout_height="match_parent"> |
|
4 |
android:orientation="vertical" |
|
5 |
android:layout_width="match_parent" |
|
6 |
android:layout_height="match_parent" |
|
7 |
android:gravity="center_vertical"> |
|
7 | 8 |
|
8 | 9 |
<TableLayout |
9 |
android:layout_width="match_parent" |
|
10 |
android:layout_height="wrap_content" |
|
11 |
android:stretchColumns="1,2,3" |
|
12 |
android:shrinkColumns="1,2,3"> |
|
10 |
android:layout_width="match_parent" |
|
11 |
android:layout_height="wrap_content" |
|
12 |
android:stretchColumns="1,2,3,4" |
|
13 |
android:shrinkColumns="1,2,3,4" |
|
14 |
> |
|
13 | 15 |
|
14 | 16 |
<TableRow |
15 | 17 |
android:layout_width="match_parent" |
16 |
android:layout_height="match_parent"> |
|
18 |
android:layout_height="match_parent" |
|
19 |
android:paddingTop="10dp"> |
|
17 | 20 |
|
18 | 21 |
<TextView |
19 | 22 |
android:layout_width="wrap_content" |
... | ... | |
28 | 31 |
android:layout_width="fill_parent" |
29 | 32 |
android:layout_height="50dp" |
30 | 33 |
android:id="@+id/objectpicker_spinnerType" |
31 |
android:layout_span="3"/>
|
|
34 |
android:layout_span="4"/>
|
|
32 | 35 |
</TableRow> |
33 | 36 |
|
34 |
<TableRow |
|
37 |
<TableRow |
|
38 |
android:layout_width="match_parent" |
|
39 |
android:layout_height="match_parent" |
|
40 |
android:paddingTop="10dp"> |
|
41 |
|
|
42 |
<TextView |
|
43 |
android:layout_width="wrap_content" |
|
44 |
android:layout_height="wrap_content" |
|
45 |
android:textAppearance="?android:attr/textAppearanceMedium" |
|
46 |
android:text="@string/Bitmap" |
|
47 |
android:id="@+id/textView7" |
|
48 |
android:layout_marginLeft="10dp" |
|
49 |
android:layout_gravity="center_vertical"/> |
|
50 |
|
|
51 |
<Spinner |
|
52 |
android:layout_width="wrap_content" |
|
53 |
android:layout_height="50dp" |
|
54 |
android:id="@+id/objectpicker_spinnerBitmap" |
|
55 |
android:layout_span="4"/> |
|
56 |
</TableRow> |
|
57 |
|
|
58 |
<TableRow |
|
35 | 59 |
android:layout_width="match_parent" |
36 |
android:layout_height="match_parent"> |
|
60 |
android:layout_height="match_parent" |
|
61 |
android:paddingTop="10dp" |
|
62 |
android:paddingBottom="10dp"> |
|
37 | 63 |
|
38 | 64 |
<TextView |
39 | 65 |
android:layout_width="wrap_content" |
... | ... | |
42 | 68 |
android:text="@string/rows" |
43 | 69 |
android:id="@+id/textView8" |
44 | 70 |
android:layout_gravity="center_vertical" |
45 |
android:layout_marginLeft="10dp"/> |
|
71 |
android:layout_marginLeft="10dp" |
|
72 |
/> |
|
46 | 73 |
|
47 | 74 |
<NumberPicker |
48 | 75 |
android:id="@+id/objectpicker_rows" |
49 | 76 |
android:layout_width="wrap_content" |
50 | 77 |
android:layout_height="wrap_content" |
51 | 78 |
android:orientation="vertical" |
52 |
android:layout_span="1" |
|
53 | 79 |
/> |
54 | 80 |
|
55 | 81 |
<TextView |
... | ... | |
59 | 85 |
android:text="@string/cols" |
60 | 86 |
android:id="@+id/textView9" |
61 | 87 |
android:layout_marginLeft="10dp" |
62 |
android:layout_gravity="center_vertical"/> |
|
88 |
android:layout_gravity="center_vertical" |
|
89 |
/> |
|
63 | 90 |
|
64 | 91 |
<NumberPicker |
65 | 92 |
android:id="@+id/objectpicker_cols" |
... | ... | |
71 | 98 |
|
72 | 99 |
</TableLayout> |
73 | 100 |
|
74 |
<LinearLayout |
|
75 |
android:id="@+id/objectpicker_buttongrid" |
|
76 |
android:layout_width="match_parent" |
|
77 |
android:layout_height="0dp" |
|
78 |
android:gravity="center" |
|
79 |
android:orientation="vertical" |
|
80 |
android:layout_weight="0.8"> |
|
81 |
</LinearLayout> |
|
82 |
|
|
83 | 101 |
<Button |
84 | 102 |
android:id="@+id/objectpicker_create" |
85 |
android:onClick="Create"
|
|
86 |
android:text="@string/Create"
|
|
103 |
android:onClick="Continue"
|
|
104 |
android:text="@string/continu"
|
|
87 | 105 |
android:layout_width="match_parent" |
88 | 106 |
android:layout_height="50dp" |
89 | 107 |
android:layout_span="4" |
src/main/res/values/strings.xml | ||
---|---|---|
46 | 46 |
<string name="Default">Default</string> |
47 | 47 |
<string name="save">Save</string> |
48 | 48 |
<string name="Create">Create</string> |
49 |
<string name="Bitmap">Bitmap</string> |
|
49 | 50 |
|
50 | 51 |
<string name="example_monalisa">Mona Lisa</string> |
51 | 52 |
<string name="example_monalisa_subtitle">The basics of Distortions.</string> |
Also available in: Unified diff
Improve the Vertex3D app some more.