1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted 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
|
// Distorted 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 Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.examples.inflate;
|
21
|
|
22
|
import android.app.Activity;
|
23
|
import android.graphics.Bitmap;
|
24
|
import android.graphics.BitmapFactory;
|
25
|
import android.graphics.Canvas;
|
26
|
import android.graphics.Paint;
|
27
|
import android.opengl.GLSurfaceView;
|
28
|
import android.os.Bundle;
|
29
|
import android.widget.SeekBar;
|
30
|
import android.widget.TextView;
|
31
|
|
32
|
import org.distorted.examples.R;
|
33
|
import org.distorted.library.main.Distorted;
|
34
|
import org.distorted.library.main.DistortedTexture;
|
35
|
import org.distorted.library.mesh.MeshBase;
|
36
|
import org.distorted.library.mesh.MeshCubes;
|
37
|
import org.distorted.library.mesh.MeshFlat;
|
38
|
import org.distorted.library.mesh.MeshQuad;
|
39
|
import org.distorted.library.mesh.MeshSphere;
|
40
|
|
41
|
import java.io.IOException;
|
42
|
import java.io.InputStream;
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
public class InflateActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener
|
47
|
{
|
48
|
private DistortedTexture mTexture;
|
49
|
private MeshBase mMesh;
|
50
|
private TextView mTextLevel;
|
51
|
private int mBitmapID;
|
52
|
private Bitmap mBitmap;
|
53
|
private int mNumCols;
|
54
|
private int mNumRows;
|
55
|
private int mNumSlic;
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
@Override
|
60
|
protected void onPause()
|
61
|
{
|
62
|
GLSurfaceView mView = this.findViewById(R.id.inflateSurfaceView);
|
63
|
if( mView!=null ) mView.onPause();
|
64
|
|
65
|
Distorted.onPause();
|
66
|
super.onPause();
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
|
71
|
@Override
|
72
|
protected void onResume()
|
73
|
{
|
74
|
super.onResume();
|
75
|
|
76
|
GLSurfaceView mView = this.findViewById(R.id.inflateSurfaceView);
|
77
|
if( mView!=null ) mView.onResume();
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
@Override
|
83
|
protected void onDestroy()
|
84
|
{
|
85
|
Distorted.onDestroy();
|
86
|
super.onDestroy();
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
@Override
|
92
|
protected void onCreate(Bundle savedState)
|
93
|
{
|
94
|
super.onCreate(savedState);
|
95
|
|
96
|
Bundle b = getIntent().getExtras();
|
97
|
|
98
|
String str = b.getString("string");
|
99
|
int objectType = b.getInt("type");
|
100
|
mNumCols = b.getInt("cols");
|
101
|
mNumRows = b.getInt("rows");
|
102
|
mNumSlic = b.getInt("slices");
|
103
|
mBitmapID = b.getInt("bitmap");
|
104
|
|
105
|
switch(objectType)
|
106
|
{
|
107
|
case 0: mMesh = new MeshCubes(mNumCols, str, mNumSlic);
|
108
|
break;
|
109
|
case 1: mMesh = new MeshFlat(mNumCols,mNumRows);
|
110
|
break;
|
111
|
case 2: mMesh = new MeshSphere(mNumRows);
|
112
|
break;
|
113
|
case 3: mMesh = new MeshQuad();
|
114
|
break;
|
115
|
}
|
116
|
|
117
|
mTexture= new DistortedTexture(mNumCols,mNumRows);
|
118
|
|
119
|
setContentView(R.layout.inflatelayout);
|
120
|
|
121
|
mTextLevel = findViewById(R.id.inflateText);
|
122
|
SeekBar levelBar = findViewById(R.id.inflateLevel);
|
123
|
levelBar.setOnSeekBarChangeListener(this);
|
124
|
|
125
|
InflateSurfaceView view = this.findViewById(R.id.inflateSurfaceView);
|
126
|
float level = view.getRenderer().setLevel(50);
|
127
|
mTextLevel.setText(getString(R.string.inflate_placeholder, level));
|
128
|
levelBar.setProgress(50);
|
129
|
}
|
130
|
|
131
|
|
132
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133
|
|
134
|
public Bitmap getBitmap()
|
135
|
{
|
136
|
if( mBitmap==null )
|
137
|
{
|
138
|
if( mBitmapID!=-1)
|
139
|
{
|
140
|
InputStream is = getResources().openRawResource(mBitmapID);
|
141
|
|
142
|
try
|
143
|
{
|
144
|
mBitmap = BitmapFactory.decodeStream(is);
|
145
|
}
|
146
|
finally
|
147
|
{
|
148
|
try
|
149
|
{
|
150
|
is.close();
|
151
|
}
|
152
|
catch(IOException e) { }
|
153
|
}
|
154
|
}
|
155
|
else
|
156
|
{
|
157
|
final int W = 64*mNumCols;
|
158
|
final int H = 64*mNumRows;
|
159
|
|
160
|
Paint paint = new Paint();
|
161
|
mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
|
162
|
Canvas canvas = new Canvas(mBitmap);
|
163
|
|
164
|
paint.setAntiAlias(true);
|
165
|
paint.setTextAlign(Paint.Align.CENTER);
|
166
|
paint.setColor(0xff008800);
|
167
|
paint.setStyle(Paint.Style.FILL);
|
168
|
canvas.drawRect(0, 0, W, H, paint);
|
169
|
paint.setColor(0xffffffff);
|
170
|
|
171
|
for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint);
|
172
|
for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W, H*i/mNumRows+1, paint);
|
173
|
}
|
174
|
}
|
175
|
|
176
|
return mBitmap;
|
177
|
}
|
178
|
|
179
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180
|
|
181
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
182
|
{
|
183
|
switch (bar.getId())
|
184
|
{
|
185
|
case R.id.inflateLevel: InflateSurfaceView view = this.findViewById(R.id.inflateSurfaceView);
|
186
|
float level = view.getRenderer().setLevel(progress);
|
187
|
mTextLevel.setText(getString(R.string.inflate_placeholder, level));
|
188
|
break;
|
189
|
}
|
190
|
}
|
191
|
|
192
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
193
|
|
194
|
public void onStartTrackingTouch(SeekBar bar) { }
|
195
|
|
196
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197
|
|
198
|
public void onStopTrackingTouch(SeekBar bar) { }
|
199
|
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
|
202
|
public DistortedTexture getTexture()
|
203
|
{
|
204
|
return mTexture;
|
205
|
}
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
|
209
|
public MeshBase getMesh()
|
210
|
{
|
211
|
return mMesh;
|
212
|
}
|
213
|
}
|