Revision 758303a3
Added by Leszek Koltunski almost 9 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 27 | 27 |
<activity android:name=".movingeffects.MovingEffectsActivity" /> |
| 28 | 28 |
<activity android:name=".differenteffects.DifferentEffectsActivity" /> |
| 29 | 29 |
<activity android:name=".differentbitmaps.DifferentBitmapsActivity" /> |
| 30 |
<activity android:name=".effects2d.Effects2DActivity" />
|
|
| 30 |
<activity android:name=".effectqueue.EffectQueueActivity" />
|
|
| 31 | 31 |
<activity android:name=".check.CheckActivity" /> |
| 32 | 32 |
<activity android:name=".fbo.FBOActivity" /> |
| 33 | 33 |
<activity android:name=".starwars.StarWarsActivity" /> |
| src/main/java/org/distorted/examples/TableOfContents.java | ||
|---|---|---|
| 46 | 46 |
import org.distorted.examples.olimpic.OlimpicActivity; |
| 47 | 47 |
import org.distorted.examples.differenteffects.DifferentEffectsActivity; |
| 48 | 48 |
import org.distorted.examples.differentbitmaps.DifferentBitmapsActivity; |
| 49 |
import org.distorted.examples.effects2d.Effects2DActivity;
|
|
| 49 |
import org.distorted.examples.effectqueue.EffectQueueActivity;
|
|
| 50 | 50 |
import org.distorted.examples.check.CheckActivity; |
| 51 | 51 |
import org.distorted.examples.bean.BeanActivity; |
| 52 | 52 |
import org.distorted.examples.fbo.FBOActivity; |
| ... | ... | |
| 191 | 191 |
|
| 192 | 192 |
{
|
| 193 | 193 |
final Map<String, Object> item = new HashMap<>(); |
| 194 |
item.put(ITEM_IMAGE, R.drawable.icon_example_effects2d);
|
|
| 195 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_effects2d));
|
|
| 196 |
item.put(ITEM_SUBTITLE, getText(R.string.example_effects2d_subtitle));
|
|
| 194 |
item.put(ITEM_IMAGE, R.drawable.icon_example_effectqueue);
|
|
| 195 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_effectqueue));
|
|
| 196 |
item.put(ITEM_SUBTITLE, getText(R.string.example_effectqueue_subtitle));
|
|
| 197 | 197 |
data.add(item); |
| 198 |
activityMapping.put(i++, Effects2DActivity.class);
|
|
| 198 |
activityMapping.put(i++, EffectQueueActivity.class);
|
|
| 199 | 199 |
} |
| 200 | 200 |
|
| 201 | 201 |
{
|
| src/main/java/org/distorted/examples/effectqueue/EffectQueueActivity.java | ||
|---|---|---|
| 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.effectqueue; |
|
| 21 |
|
|
| 22 |
import org.distorted.library.Distorted; |
|
| 23 |
import org.distorted.examples.R; |
|
| 24 |
import org.distorted.library.EffectNames; |
|
| 25 |
import org.distorted.library.EffectTypes; |
|
| 26 |
|
|
| 27 |
import android.app.Activity; |
|
| 28 |
import android.opengl.GLSurfaceView; |
|
| 29 |
import android.os.Bundle; |
|
| 30 |
import android.view.View; |
|
| 31 |
import android.widget.AdapterView; |
|
| 32 |
import android.widget.ArrayAdapter; |
|
| 33 |
import android.widget.Spinner; |
|
| 34 |
import android.widget.TableLayout; |
|
| 35 |
import android.widget.TableRow; |
|
| 36 |
import android.widget.TextView; |
|
| 37 |
import android.widget.Toast; |
|
| 38 |
|
|
| 39 |
import java.util.ArrayList; |
|
| 40 |
import java.util.HashMap; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
public class EffectQueueActivity extends Activity implements AdapterView.OnItemSelectedListener |
|
| 45 |
{
|
|
| 46 |
private Spinner mAdd, mID, mName, mType; |
|
| 47 |
private static ArrayAdapter<Long> mAdapterID; |
|
| 48 |
|
|
| 49 |
private int mPosID, mPosName, mPosType; |
|
| 50 |
private TableLayout mLayoutList; |
|
| 51 |
|
|
| 52 |
private HashMap<Long,TableRow> mMap = new HashMap<>(); |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
@Override |
|
| 57 |
protected void onCreate(Bundle savedInstanceState) |
|
| 58 |
{
|
|
| 59 |
super.onCreate(savedInstanceState); |
|
| 60 |
|
|
| 61 |
setContentView(R.layout.effects2dlayout); |
|
| 62 |
|
|
| 63 |
mPosID = 0; |
|
| 64 |
mPosName = 0; |
|
| 65 |
mPosType = 0; |
|
| 66 |
|
|
| 67 |
mAdd = (Spinner)findViewById(R.id.effects2d_spinnerAdd ); |
|
| 68 |
mID = (Spinner)findViewById(R.id.effects2d_spinnerID ); |
|
| 69 |
mName = (Spinner)findViewById(R.id.effects2d_spinnerName); |
|
| 70 |
mType = (Spinner)findViewById(R.id.effects2d_spinnerType); |
|
| 71 |
|
|
| 72 |
mAdd.setOnItemSelectedListener(this); |
|
| 73 |
mID.setOnItemSelectedListener(this); |
|
| 74 |
mName.setOnItemSelectedListener(this); |
|
| 75 |
mType.setOnItemSelectedListener(this); |
|
| 76 |
|
|
| 77 |
ArrayList<Long> itemsID = new ArrayList<>(); |
|
| 78 |
|
|
| 79 |
String[] itemsName = new String[] { getText(R.string.distort ).toString(),
|
|
| 80 |
getText(R.string.sink ).toString(), |
|
| 81 |
getText(R.string.alpha ).toString(), |
|
| 82 |
getText(R.string.saturation).toString(), |
|
| 83 |
getText(R.string.chroma).toString()}; |
|
| 84 |
|
|
| 85 |
String[] itemsType = new String[] {"VERTEX", "FRAGMENT"};
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID); |
|
| 89 |
mAdapterID.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 90 |
mID.setAdapter(mAdapterID); |
|
| 91 |
|
|
| 92 |
ArrayAdapter<String> adapterAdd = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName); |
|
| 93 |
adapterAdd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 94 |
mAdd.setAdapter(adapterAdd); |
|
| 95 |
|
|
| 96 |
ArrayAdapter<String> adapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName); |
|
| 97 |
adapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 98 |
mName.setAdapter(adapterName); |
|
| 99 |
|
|
| 100 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType); |
|
| 101 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 102 |
mType.setAdapter(adapterType); |
|
| 103 |
|
|
| 104 |
mLayoutList = (TableLayout)findViewById(R.id.effects2dTableList); |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
@Override |
|
| 110 |
protected void onResume() |
|
| 111 |
{
|
|
| 112 |
super.onResume(); |
|
| 113 |
|
|
| 114 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 115 |
mView.onResume(); |
|
| 116 |
} |
|
| 117 |
|
|
| 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
|
|
| 120 |
@Override |
|
| 121 |
protected void onPause() |
|
| 122 |
{
|
|
| 123 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 124 |
mView.onPause(); |
|
| 125 |
|
|
| 126 |
super.onPause(); |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
@Override |
|
| 132 |
public void onStop() |
|
| 133 |
{
|
|
| 134 |
super.onStop(); |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 138 |
|
|
| 139 |
@Override |
|
| 140 |
public void onDestroy() |
|
| 141 |
{
|
|
| 142 |
Distorted.onDestroy(); |
|
| 143 |
super.onDestroy(); |
|
| 144 |
} |
|
| 145 |
|
|
| 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 147 |
|
|
| 148 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 149 |
{
|
|
| 150 |
switch(parent.getId()) |
|
| 151 |
{
|
|
| 152 |
case R.id.effects2d_spinnerAdd : EffectQueueSurfaceView v = (EffectQueueSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 153 |
v.setEffect(pos); break; |
|
| 154 |
case R.id.effects2d_spinnerID : mPosID = pos; break; |
|
| 155 |
case R.id.effects2d_spinnerName: mPosName = pos; break; |
|
| 156 |
case R.id.effects2d_spinnerType: mPosType = pos; break; |
|
| 157 |
} |
|
| 158 |
} |
|
| 159 |
|
|
| 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 161 |
|
|
| 162 |
public void onNothingSelected(AdapterView<?> parent) |
|
| 163 |
{
|
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 167 |
|
|
| 168 |
public void removeByID(View view) |
|
| 169 |
{
|
|
| 170 |
Long currID = (Long)mID.getItemAtPosition(mPosID); |
|
| 171 |
|
|
| 172 |
EffectQueueSurfaceView v = (EffectQueueSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 173 |
v.getRenderer().mBackground.abortEffect(currID); |
|
| 174 |
} |
|
| 175 |
|
|
| 176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 177 |
|
|
| 178 |
public void removeByName(View view) |
|
| 179 |
{
|
|
| 180 |
EffectNames name; |
|
| 181 |
|
|
| 182 |
switch(mPosName) |
|
| 183 |
{
|
|
| 184 |
case 0: name = EffectNames.DISTORT ; break; |
|
| 185 |
case 1: name = EffectNames.SINK ; break; |
|
| 186 |
case 2: name = EffectNames.SMOOTH_ALPHA ; break; |
|
| 187 |
case 3: name = EffectNames.SATURATION ; break; |
|
| 188 |
case 4: name = EffectNames.SMOOTH_CHROMA; break; |
|
| 189 |
default: name = EffectNames.CONTRAST ; |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
EffectQueueSurfaceView v = (EffectQueueSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 193 |
v.getRenderer().mBackground.abortEffects(name); |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 197 |
|
|
| 198 |
public void removeByType(View view) |
|
| 199 |
{
|
|
| 200 |
EffectTypes type; |
|
| 201 |
|
|
| 202 |
switch(mPosType) |
|
| 203 |
{
|
|
| 204 |
case 0: type = EffectTypes.VERTEX ; break; |
|
| 205 |
case 1: type = EffectTypes.FRAGMENT; break; |
|
| 206 |
default: type = EffectTypes.MATRIX; |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
EffectQueueSurfaceView v = (EffectQueueSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 210 |
v.getRenderer().mBackground.abortEffects(type); |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 214 |
|
|
| 215 |
public void effectAdded(final long id, final EffectNames name, final EffectTypes type) |
|
| 216 |
{
|
|
| 217 |
if( id>=0 ) // we really added a new effect |
|
| 218 |
{
|
|
| 219 |
mAdapterID.add(id); |
|
| 220 |
mAdapterID.notifyDataSetChanged(); |
|
| 221 |
|
|
| 222 |
TableRow tr = new TableRow(this); |
|
| 223 |
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 224 |
|
|
| 225 |
TextView b1 = new TextView(this); |
|
| 226 |
b1.setText("ID: "+id);
|
|
| 227 |
b1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 228 |
tr.addView(b1); |
|
| 229 |
|
|
| 230 |
TextView b2 = new TextView(this); |
|
| 231 |
b2.setText(name.name()); |
|
| 232 |
b2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 233 |
tr.addView(b2); |
|
| 234 |
|
|
| 235 |
TextView b3 = new TextView(this); |
|
| 236 |
b3.setText(type.name()); |
|
| 237 |
b3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 238 |
tr.addView(b3); |
|
| 239 |
|
|
| 240 |
TextView b4 = new TextView(this); |
|
| 241 |
b4.setText("LIVE");
|
|
| 242 |
b4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 243 |
tr.addView(b4); |
|
| 244 |
|
|
| 245 |
mMap.put(id,tr); |
|
| 246 |
|
|
| 247 |
mLayoutList.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); |
|
| 248 |
} |
|
| 249 |
else // id=-1, i.e. we failed to add new effect due to too many effects already |
|
| 250 |
{
|
|
| 251 |
Toast.makeText(this, R.string.example_effects2d_toast , Toast.LENGTH_LONG).show(); |
|
| 252 |
} |
|
| 253 |
} |
|
| 254 |
|
|
| 255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 256 |
|
|
| 257 |
public void effectRemoved(final long id) |
|
| 258 |
{
|
|
| 259 |
runOnUiThread(new Runnable() |
|
| 260 |
{
|
|
| 261 |
public void run() |
|
| 262 |
{
|
|
| 263 |
mAdapterID.remove(id); |
|
| 264 |
mAdapterID.notifyDataSetChanged(); |
|
| 265 |
|
|
| 266 |
TableRow row = mMap.remove(id); |
|
| 267 |
|
|
| 268 |
if( row!=null ) |
|
| 269 |
{
|
|
| 270 |
mLayoutList.removeView(row); |
|
| 271 |
} |
|
| 272 |
else |
|
| 273 |
{
|
|
| 274 |
android.util.Log.e("EFFECTS2D", "Impossible: id="+id+" not in the map!");
|
|
| 275 |
} |
|
| 276 |
} |
|
| 277 |
}); |
|
| 278 |
} |
|
| 279 |
|
|
| 280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 281 |
|
|
| 282 |
public void effectFinished(final long id) |
|
| 283 |
{
|
|
| 284 |
runOnUiThread(new Runnable() |
|
| 285 |
{
|
|
| 286 |
public void run() |
|
| 287 |
{
|
|
| 288 |
TableRow row = mMap.get(id); |
|
| 289 |
|
|
| 290 |
if( row!=null ) |
|
| 291 |
{
|
|
| 292 |
TextView v = (TextView)row.getVirtualChildAt(3); |
|
| 293 |
v.setText("FINISHED");
|
|
| 294 |
} |
|
| 295 |
} |
|
| 296 |
}); |
|
| 297 |
} |
|
| 298 |
} |
|
| src/main/java/org/distorted/examples/effectqueue/EffectQueueRenderer.java | ||
|---|---|---|
| 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.effectqueue; |
|
| 21 |
|
|
| 22 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 23 |
import javax.microedition.khronos.opengles.GL10; |
|
| 24 |
|
|
| 25 |
import android.graphics.Bitmap; |
|
| 26 |
import android.graphics.Canvas; |
|
| 27 |
import android.graphics.Paint; |
|
| 28 |
import android.graphics.Paint.Style; |
|
| 29 |
import android.opengl.GLES20; |
|
| 30 |
import android.opengl.GLSurfaceView; |
|
| 31 |
|
|
| 32 |
import org.distorted.library.DistortedBitmap; |
|
| 33 |
import org.distorted.library.Distorted; |
|
| 34 |
import org.distorted.library.EffectNames; |
|
| 35 |
import org.distorted.library.EffectTypes; |
|
| 36 |
import org.distorted.library.message.EffectListener; |
|
| 37 |
import org.distorted.library.message.EffectMessage; |
|
| 38 |
import org.distorted.library.type.Static3D; |
|
| 39 |
|
|
| 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 41 |
|
|
| 42 |
public class EffectQueueRenderer implements GLSurfaceView.Renderer, EffectListener |
|
| 43 |
{
|
|
| 44 |
private static final int NUMLINES = 10; |
|
| 45 |
static final int BWID = 300; |
|
| 46 |
static final int BHEI = 400; |
|
| 47 |
|
|
| 48 |
private EffectQueueSurfaceView mView; |
|
| 49 |
private Paint mPaint; |
|
| 50 |
private int texWidth, texHeight; |
|
| 51 |
|
|
| 52 |
DistortedBitmap mBackground; |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
EffectQueueRenderer(EffectQueueSurfaceView v) |
|
| 57 |
{
|
|
| 58 |
mPaint = new Paint(); |
|
| 59 |
mPaint.setAntiAlias(true); |
|
| 60 |
mPaint.setFakeBoldText(true); |
|
| 61 |
mPaint.setStyle(Style.FILL); |
|
| 62 |
|
|
| 63 |
mView = v; |
|
| 64 |
|
|
| 65 |
texWidth = BWID; |
|
| 66 |
texHeight= BHEI; |
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
|
|
| 71 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 72 |
{
|
|
| 73 |
mBackground = new DistortedBitmap(texWidth,texHeight, 80); |
|
| 74 |
Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888); |
|
| 75 |
Canvas canvas = new Canvas(bitmap); |
|
| 76 |
|
|
| 77 |
mPaint.setColor(0xff008800); |
|
| 78 |
canvas.drawRect(0, 0, texWidth, texHeight, mPaint); |
|
| 79 |
mPaint.setColor(0xffffffff); |
|
| 80 |
|
|
| 81 |
for(int i=0; i<=NUMLINES ; i++ ) |
|
| 82 |
{
|
|
| 83 |
canvas.drawRect(texWidth*i/NUMLINES - 1, 0, texWidth*i/NUMLINES + 1, texHeight , mPaint); |
|
| 84 |
canvas.drawRect( 0, texHeight*i/NUMLINES -1, texWidth , texHeight*i/NUMLINES + 1, mPaint); |
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
mBackground.setBitmap(bitmap); |
|
| 88 |
mBackground.addEventListener(this); |
|
| 89 |
|
|
| 90 |
try |
|
| 91 |
{
|
|
| 92 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
| 93 |
} |
|
| 94 |
catch(Exception ex) |
|
| 95 |
{
|
|
| 96 |
android.util.Log.e("Effects2D", ex.getMessage() );
|
|
| 97 |
} |
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 101 |
|
|
| 102 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 103 |
{
|
|
| 104 |
mBackground.abortEffects(EffectTypes.MATRIX); |
|
| 105 |
mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) ); |
|
| 106 |
Distorted.onSurfaceChanged(width,height); |
|
| 107 |
mView.setScreenSize(width,height); |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 111 |
|
|
| 112 |
public void onDrawFrame(GL10 glUnused) |
|
| 113 |
{
|
|
| 114 |
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); |
|
| 115 |
mBackground.draw(System.currentTimeMillis()); |
|
| 116 |
} |
|
| 117 |
|
|
| 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
// the library sending messages to us. This is running on a library 'MessageSender' thread. |
|
| 120 |
|
|
| 121 |
public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID, final String message) |
|
| 122 |
{
|
|
| 123 |
EffectQueueActivity act = (EffectQueueActivity)mView.getContext(); |
|
| 124 |
|
|
| 125 |
switch(em) |
|
| 126 |
{
|
|
| 127 |
case EFFECT_REMOVED : act.effectRemoved(effectID) ; break; |
|
| 128 |
case EFFECT_FINISHED: act.effectFinished(effectID); break; |
|
| 129 |
default : break; |
|
| 130 |
} |
|
| 131 |
} |
|
| 132 |
} |
|
| src/main/java/org/distorted/examples/effectqueue/EffectQueueSurfaceView.java | ||
|---|---|---|
| 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.effectqueue; |
|
| 21 |
|
|
| 22 |
import android.content.Context; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
import android.os.Build; |
|
| 25 |
import android.view.MotionEvent; |
|
| 26 |
import android.util.AttributeSet; |
|
| 27 |
|
|
| 28 |
import org.distorted.library.EffectNames; |
|
| 29 |
import org.distorted.library.EffectTypes; |
|
| 30 |
import org.distorted.library.type.Dynamic1D; |
|
| 31 |
import org.distorted.library.type.Static1D; |
|
| 32 |
import org.distorted.library.type.Static2D; |
|
| 33 |
import org.distorted.library.type.Static3D; |
|
| 34 |
import org.distorted.library.type.Static4D; |
|
| 35 |
import org.distorted.library.type.Dynamic3D; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
public class EffectQueueSurfaceView extends GLSurfaceView |
|
| 40 |
{
|
|
| 41 |
private EffectQueueRenderer mRenderer; |
|
| 42 |
private int mCurrentEffect; |
|
| 43 |
private int mScrW, mScrH; |
|
| 44 |
|
|
| 45 |
private Static4D mRegionV, mRegionF; |
|
| 46 |
private Static2D mPoint; |
|
| 47 |
private Dynamic1D mInterA, mInterB, mInterC, mInterS; |
|
| 48 |
private Dynamic3D mInterD; |
|
| 49 |
|
|
| 50 |
private final static Static3D mRED = new Static3D(1,0,0); |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
public EffectQueueSurfaceView(Context c, AttributeSet attrs) |
|
| 55 |
{
|
|
| 56 |
super(c, attrs); |
|
| 57 |
|
|
| 58 |
int duration = 10000; |
|
| 59 |
float count = 1.0f; |
|
| 60 |
int h = 30; |
|
| 61 |
int r = 20; |
|
| 62 |
|
|
| 63 |
mInterD = new Dynamic3D(duration,count); |
|
| 64 |
|
|
| 65 |
mInterD.add(new Static3D( 0, r, h )); |
|
| 66 |
mInterD.add(new Static3D(-r, 0, h )); |
|
| 67 |
mInterD.add(new Static3D( 0,-r, h )); |
|
| 68 |
mInterD.add(new Static3D( r, 0, h )); |
|
| 69 |
|
|
| 70 |
mInterA = new Dynamic1D(duration,count); |
|
| 71 |
mInterA.add(new Static1D(1)); |
|
| 72 |
mInterA.add(new Static1D(0)); |
|
| 73 |
|
|
| 74 |
mInterS = new Dynamic1D(duration,count); |
|
| 75 |
mInterS.add(new Static1D(1.0f)); |
|
| 76 |
mInterS.add(new Static1D(0.3f)); |
|
| 77 |
|
|
| 78 |
mInterC = new Dynamic1D(duration,count); |
|
| 79 |
mInterC.add(new Static1D(1)); |
|
| 80 |
mInterC.add(new Static1D(0)); |
|
| 81 |
|
|
| 82 |
mInterB = new Dynamic1D(duration,count); |
|
| 83 |
mInterB.add(new Static1D(0)); |
|
| 84 |
mInterB.add(new Static1D(1)); |
|
| 85 |
|
|
| 86 |
if(!isInEditMode()) |
|
| 87 |
{
|
|
| 88 |
setFocusable(true); |
|
| 89 |
setFocusableInTouchMode(true); |
|
| 90 |
|
|
| 91 |
setEGLContextClientVersion(2); |
|
| 92 |
|
|
| 93 |
if( Build.FINGERPRINT.startsWith("generic") ) // when running on the emulator, insert a magic line that is
|
|
| 94 |
{ // supposed to cure the 'no config chosen' crash on emulator startup
|
|
| 95 |
setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
mRenderer = new EffectQueueRenderer(this); |
|
| 99 |
setRenderer(mRenderer); |
|
| 100 |
|
|
| 101 |
mPoint = new Static2D(0,0); |
|
| 102 |
mRegionV= new Static4D(0,0,60,60); |
|
| 103 |
mRegionF= new Static4D(0,0,60,60); |
|
| 104 |
|
|
| 105 |
setEffect(0); |
|
| 106 |
} |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 |
|
|
| 111 |
EffectQueueRenderer getRenderer() |
|
| 112 |
{
|
|
| 113 |
return mRenderer; |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
|
|
| 118 |
public void setScreenSize(int width, int height) |
|
| 119 |
{
|
|
| 120 |
mScrW = width; |
|
| 121 |
mScrH = height; |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 125 |
|
|
| 126 |
public void setEffect(int effect) |
|
| 127 |
{
|
|
| 128 |
mCurrentEffect = effect; |
|
| 129 |
} |
|
| 130 |
|
|
| 131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 132 |
|
|
| 133 |
@Override public boolean onTouchEvent(MotionEvent event) |
|
| 134 |
{
|
|
| 135 |
int action = event.getAction(); |
|
| 136 |
int x, y; |
|
| 137 |
long id; |
|
| 138 |
|
|
| 139 |
switch(action) |
|
| 140 |
{
|
|
| 141 |
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW; |
|
| 142 |
y = (int)event.getY()* mRenderer.BHEI/mScrH; |
|
| 143 |
mPoint.set(x,y); |
|
| 144 |
mRegionF.set(x,y,60,60); |
|
| 145 |
EffectQueueActivity act = (EffectQueueActivity)getContext(); |
|
| 146 |
|
|
| 147 |
switch(mCurrentEffect) |
|
| 148 |
{
|
|
| 149 |
case 0: id = mRenderer.mBackground.distort(mInterD, mPoint, mRegionV); |
|
| 150 |
act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX); |
|
| 151 |
break; |
|
| 152 |
case 1: id = mRenderer.mBackground.sink(mInterS, mPoint, mRegionV); |
|
| 153 |
act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX); |
|
| 154 |
break; |
|
| 155 |
case 2: id = mRenderer.mBackground.alpha(mInterA, mRegionF, true); |
|
| 156 |
act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT); |
|
| 157 |
break; |
|
| 158 |
case 3: id = mRenderer.mBackground.saturation(mInterB, mRegionF, false); |
|
| 159 |
act.effectAdded(id, EffectNames.SATURATION, EffectTypes.FRAGMENT); |
|
| 160 |
break; |
|
| 161 |
case 4: id = mRenderer.mBackground.chroma(mInterC, mRED, mRegionF, true); |
|
| 162 |
act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT); |
|
| 163 |
break; |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
break; |
|
| 167 |
} |
|
| 168 |
|
|
| 169 |
return true; |
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
} |
|
| src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java | ||
|---|---|---|
| 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.effects2d; |
|
| 21 |
|
|
| 22 |
import org.distorted.library.Distorted; |
|
| 23 |
import org.distorted.examples.R; |
|
| 24 |
import org.distorted.library.EffectNames; |
|
| 25 |
import org.distorted.library.EffectTypes; |
|
| 26 |
|
|
| 27 |
import android.app.Activity; |
|
| 28 |
import android.opengl.GLSurfaceView; |
|
| 29 |
import android.os.Bundle; |
|
| 30 |
import android.view.View; |
|
| 31 |
import android.widget.AdapterView; |
|
| 32 |
import android.widget.ArrayAdapter; |
|
| 33 |
import android.widget.Spinner; |
|
| 34 |
import android.widget.TableLayout; |
|
| 35 |
import android.widget.TableRow; |
|
| 36 |
import android.widget.TextView; |
|
| 37 |
import android.widget.Toast; |
|
| 38 |
|
|
| 39 |
import java.util.ArrayList; |
|
| 40 |
import java.util.HashMap; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener |
|
| 45 |
{
|
|
| 46 |
private Spinner mAdd, mID, mName, mType; |
|
| 47 |
private static ArrayAdapter<Long> mAdapterID; |
|
| 48 |
|
|
| 49 |
private int mPosID, mPosName, mPosType; |
|
| 50 |
private TableLayout mLayoutList; |
|
| 51 |
|
|
| 52 |
private HashMap<Long,TableRow> mMap = new HashMap<>(); |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
@Override |
|
| 57 |
protected void onCreate(Bundle savedInstanceState) |
|
| 58 |
{
|
|
| 59 |
super.onCreate(savedInstanceState); |
|
| 60 |
|
|
| 61 |
setContentView(R.layout.effects2dlayout); |
|
| 62 |
|
|
| 63 |
mPosID = 0; |
|
| 64 |
mPosName = 0; |
|
| 65 |
mPosType = 0; |
|
| 66 |
|
|
| 67 |
mAdd = (Spinner)findViewById(R.id.effects2d_spinnerAdd ); |
|
| 68 |
mID = (Spinner)findViewById(R.id.effects2d_spinnerID ); |
|
| 69 |
mName = (Spinner)findViewById(R.id.effects2d_spinnerName); |
|
| 70 |
mType = (Spinner)findViewById(R.id.effects2d_spinnerType); |
|
| 71 |
|
|
| 72 |
mAdd.setOnItemSelectedListener(this); |
|
| 73 |
mID.setOnItemSelectedListener(this); |
|
| 74 |
mName.setOnItemSelectedListener(this); |
|
| 75 |
mType.setOnItemSelectedListener(this); |
|
| 76 |
|
|
| 77 |
ArrayList<Long> itemsID = new ArrayList<>(); |
|
| 78 |
|
|
| 79 |
String[] itemsName = new String[] { getText(R.string.distort ).toString(),
|
|
| 80 |
getText(R.string.sink ).toString(), |
|
| 81 |
getText(R.string.alpha ).toString(), |
|
| 82 |
getText(R.string.saturation).toString(), |
|
| 83 |
getText(R.string.chroma).toString()}; |
|
| 84 |
|
|
| 85 |
String[] itemsType = new String[] {"VERTEX", "FRAGMENT"};
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID); |
|
| 89 |
mAdapterID.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 90 |
mID.setAdapter(mAdapterID); |
|
| 91 |
|
|
| 92 |
ArrayAdapter<String> adapterAdd = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName); |
|
| 93 |
adapterAdd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 94 |
mAdd.setAdapter(adapterAdd); |
|
| 95 |
|
|
| 96 |
ArrayAdapter<String> adapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName); |
|
| 97 |
adapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 98 |
mName.setAdapter(adapterName); |
|
| 99 |
|
|
| 100 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType); |
|
| 101 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 102 |
mType.setAdapter(adapterType); |
|
| 103 |
|
|
| 104 |
mLayoutList = (TableLayout)findViewById(R.id.effects2dTableList); |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
@Override |
|
| 110 |
protected void onResume() |
|
| 111 |
{
|
|
| 112 |
super.onResume(); |
|
| 113 |
|
|
| 114 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 115 |
mView.onResume(); |
|
| 116 |
} |
|
| 117 |
|
|
| 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
|
|
| 120 |
@Override |
|
| 121 |
protected void onPause() |
|
| 122 |
{
|
|
| 123 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 124 |
mView.onPause(); |
|
| 125 |
|
|
| 126 |
super.onPause(); |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
@Override |
|
| 132 |
public void onStop() |
|
| 133 |
{
|
|
| 134 |
super.onStop(); |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 138 |
|
|
| 139 |
@Override |
|
| 140 |
public void onDestroy() |
|
| 141 |
{
|
|
| 142 |
Distorted.onDestroy(); |
|
| 143 |
super.onDestroy(); |
|
| 144 |
} |
|
| 145 |
|
|
| 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 147 |
|
|
| 148 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 149 |
{
|
|
| 150 |
switch(parent.getId()) |
|
| 151 |
{
|
|
| 152 |
case R.id.effects2d_spinnerAdd : Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 153 |
v.setEffect(pos); break; |
|
| 154 |
case R.id.effects2d_spinnerID : mPosID = pos; break; |
|
| 155 |
case R.id.effects2d_spinnerName: mPosName = pos; break; |
|
| 156 |
case R.id.effects2d_spinnerType: mPosType = pos; break; |
|
| 157 |
} |
|
| 158 |
} |
|
| 159 |
|
|
| 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 161 |
|
|
| 162 |
public void onNothingSelected(AdapterView<?> parent) |
|
| 163 |
{
|
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 167 |
|
|
| 168 |
public void removeByID(View view) |
|
| 169 |
{
|
|
| 170 |
Long currID = (Long)mID.getItemAtPosition(mPosID); |
|
| 171 |
|
|
| 172 |
Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 173 |
v.getRenderer().mBackground.abortEffect(currID); |
|
| 174 |
} |
|
| 175 |
|
|
| 176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 177 |
|
|
| 178 |
public void removeByName(View view) |
|
| 179 |
{
|
|
| 180 |
EffectNames name; |
|
| 181 |
|
|
| 182 |
switch(mPosName) |
|
| 183 |
{
|
|
| 184 |
case 0: name = EffectNames.DISTORT ; break; |
|
| 185 |
case 1: name = EffectNames.SINK ; break; |
|
| 186 |
case 2: name = EffectNames.SMOOTH_ALPHA ; break; |
|
| 187 |
case 3: name = EffectNames.SATURATION ; break; |
|
| 188 |
case 4: name = EffectNames.SMOOTH_CHROMA; break; |
|
| 189 |
default: name = EffectNames.CONTRAST ; |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 193 |
v.getRenderer().mBackground.abortEffects(name); |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 197 |
|
|
| 198 |
public void removeByType(View view) |
|
| 199 |
{
|
|
| 200 |
EffectTypes type; |
|
| 201 |
|
|
| 202 |
switch(mPosType) |
|
| 203 |
{
|
|
| 204 |
case 0: type = EffectTypes.VERTEX ; break; |
|
| 205 |
case 1: type = EffectTypes.FRAGMENT; break; |
|
| 206 |
default: type = EffectTypes.MATRIX; |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
| 210 |
v.getRenderer().mBackground.abortEffects(type); |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 214 |
|
|
| 215 |
public void effectAdded(final long id, final EffectNames name, final EffectTypes type) |
|
| 216 |
{
|
|
| 217 |
if( id>=0 ) // we really added a new effect |
|
| 218 |
{
|
|
| 219 |
mAdapterID.add(id); |
|
| 220 |
mAdapterID.notifyDataSetChanged(); |
|
| 221 |
|
|
| 222 |
TableRow tr = new TableRow(this); |
|
| 223 |
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 224 |
|
|
| 225 |
TextView b1 = new TextView(this); |
|
| 226 |
b1.setText("ID: "+id);
|
|
| 227 |
b1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 228 |
tr.addView(b1); |
|
| 229 |
|
|
| 230 |
TextView b2 = new TextView(this); |
|
| 231 |
b2.setText(name.name()); |
|
| 232 |
b2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 233 |
tr.addView(b2); |
|
| 234 |
|
|
| 235 |
TextView b3 = new TextView(this); |
|
| 236 |
b3.setText(type.name()); |
|
| 237 |
b3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 238 |
tr.addView(b3); |
|
| 239 |
|
|
| 240 |
TextView b4 = new TextView(this); |
|
| 241 |
b4.setText("LIVE");
|
|
| 242 |
b4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
|
| 243 |
tr.addView(b4); |
|
| 244 |
|
|
| 245 |
mMap.put(id,tr); |
|
| 246 |
|
|
| 247 |
mLayoutList.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); |
|
| 248 |
} |
|
| 249 |
else // id=-1, i.e. we failed to add new effect due to too many effects already |
|
| 250 |
{
|
|
| 251 |
Toast.makeText(this, R.string.example_effects2d_toast , Toast.LENGTH_LONG).show(); |
|
| 252 |
} |
|
| 253 |
} |
|
| 254 |
|
|
| 255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 256 |
|
|
| 257 |
public void effectRemoved(final long id) |
|
| 258 |
{
|
|
| 259 |
runOnUiThread(new Runnable() |
|
| 260 |
{
|
|
| 261 |
public void run() |
|
| 262 |
{
|
|
| 263 |
mAdapterID.remove(id); |
|
| 264 |
mAdapterID.notifyDataSetChanged(); |
|
| 265 |
|
|
| 266 |
TableRow row = mMap.remove(id); |
|
| 267 |
|
|
| 268 |
if( row!=null ) |
|
| 269 |
{
|
|
| 270 |
mLayoutList.removeView(row); |
|
| 271 |
} |
|
| 272 |
else |
|
| 273 |
{
|
|
| 274 |
android.util.Log.e("EFFECTS2D", "Impossible: id="+id+" not in the map!");
|
|
| 275 |
} |
|
| 276 |
} |
|
| 277 |
}); |
|
| 278 |
} |
|
| 279 |
|
|
| 280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 281 |
|
|
| 282 |
public void effectFinished(final long id) |
|
| 283 |
{
|
|
| 284 |
runOnUiThread(new Runnable() |
|
| 285 |
{
|
|
| 286 |
public void run() |
|
| 287 |
{
|
|
| 288 |
TableRow row = mMap.get(id); |
|
| 289 |
|
|
| 290 |
if( row!=null ) |
|
| 291 |
{
|
|
| 292 |
TextView v = (TextView)row.getVirtualChildAt(3); |
|
| 293 |
v.setText("FINISHED");
|
|
| 294 |
} |
|
| 295 |
} |
|
| 296 |
}); |
|
| 297 |
} |
|
| 298 |
} |
|
| src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java | ||
|---|---|---|
| 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.effects2d; |
|
| 21 |
|
|
| 22 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 23 |
import javax.microedition.khronos.opengles.GL10; |
|
| 24 |
|
|
| 25 |
import android.graphics.Bitmap; |
|
| 26 |
import android.graphics.Canvas; |
|
| 27 |
import android.graphics.Paint; |
|
| 28 |
import android.graphics.Paint.Style; |
|
| 29 |
import android.opengl.GLES20; |
|
| 30 |
import android.opengl.GLSurfaceView; |
|
| 31 |
|
|
| 32 |
import org.distorted.library.DistortedBitmap; |
|
| 33 |
import org.distorted.library.Distorted; |
|
| 34 |
import org.distorted.library.EffectNames; |
|
| 35 |
import org.distorted.library.EffectTypes; |
|
| 36 |
import org.distorted.library.message.EffectListener; |
|
| 37 |
import org.distorted.library.message.EffectMessage; |
|
| 38 |
import org.distorted.library.type.Static3D; |
|
| 39 |
|
|
| 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 41 |
|
|
| 42 |
public class Effects2DRenderer implements GLSurfaceView.Renderer, EffectListener |
|
| 43 |
{
|
|
| 44 |
private static final int NUMLINES = 10; |
|
| 45 |
static final int BWID = 300; |
|
| 46 |
static final int BHEI = 400; |
|
| 47 |
|
|
| 48 |
private Effects2DSurfaceView mView; |
|
| 49 |
private Paint mPaint; |
|
| 50 |
private int texWidth, texHeight; |
|
| 51 |
|
|
| 52 |
DistortedBitmap mBackground; |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
Effects2DRenderer(Effects2DSurfaceView v) |
|
| 57 |
{
|
|
| 58 |
mPaint = new Paint(); |
|
| 59 |
mPaint.setAntiAlias(true); |
|
| 60 |
mPaint.setFakeBoldText(true); |
|
| 61 |
mPaint.setStyle(Style.FILL); |
|
| 62 |
|
|
| 63 |
mView = v; |
|
| 64 |
|
|
| 65 |
texWidth = BWID; |
|
| 66 |
texHeight= BHEI; |
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
|
|
| 71 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 72 |
{
|
|
| 73 |
mBackground = new DistortedBitmap(texWidth,texHeight, 80); |
|
| 74 |
Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888); |
|
| 75 |
Canvas canvas = new Canvas(bitmap); |
|
| 76 |
|
|
| 77 |
mPaint.setColor(0xff008800); |
|
| 78 |
canvas.drawRect(0, 0, texWidth, texHeight, mPaint); |
|
| 79 |
mPaint.setColor(0xffffffff); |
|
| 80 |
|
|
| 81 |
for(int i=0; i<=NUMLINES ; i++ ) |
|
| 82 |
{
|
|
| 83 |
canvas.drawRect(texWidth*i/NUMLINES - 1, 0, texWidth*i/NUMLINES + 1, texHeight , mPaint); |
|
| 84 |
canvas.drawRect( 0, texHeight*i/NUMLINES -1, texWidth , texHeight*i/NUMLINES + 1, mPaint); |
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
mBackground.setBitmap(bitmap); |
|
| 88 |
mBackground.addEventListener(this); |
|
| 89 |
|
|
| 90 |
try |
|
| 91 |
{
|
|
| 92 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
| 93 |
} |
|
| 94 |
catch(Exception ex) |
|
| 95 |
{
|
|
| 96 |
android.util.Log.e("Effects2D", ex.getMessage() );
|
|
| 97 |
} |
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 101 |
|
|
| 102 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 103 |
{
|
|
| 104 |
mBackground.abortEffects(EffectTypes.MATRIX); |
|
| 105 |
mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) ); |
|
| 106 |
Distorted.onSurfaceChanged(width,height); |
|
| 107 |
mView.setScreenSize(width,height); |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 111 |
|
|
| 112 |
public void onDrawFrame(GL10 glUnused) |
|
| 113 |
{
|
|
| 114 |
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); |
|
| 115 |
mBackground.draw(System.currentTimeMillis()); |
|
| 116 |
} |
|
| 117 |
|
|
| 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
// the library sending messages to us. This is running on a library 'MessageSender' thread. |
|
| 120 |
|
|
| 121 |
public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID, final String message) |
|
| 122 |
{
|
|
| 123 |
Effects2DActivity act = (Effects2DActivity)mView.getContext(); |
|
| 124 |
|
|
| 125 |
switch(em) |
|
| 126 |
{
|
|
| 127 |
case EFFECT_REMOVED : act.effectRemoved(effectID) ; break; |
|
| 128 |
case EFFECT_FINISHED: act.effectFinished(effectID); break; |
|
| 129 |
default : break; |
|
| 130 |
} |
|
| 131 |
} |
|
| 132 |
} |
|
| src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java | ||
|---|---|---|
| 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.effects2d; |
|
| 21 |
|
|
| 22 |
import android.content.Context; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
import android.os.Build; |
|
| 25 |
import android.view.MotionEvent; |
|
| 26 |
import android.util.AttributeSet; |
|
| 27 |
|
|
| 28 |
import org.distorted.library.EffectNames; |
|
| 29 |
import org.distorted.library.EffectTypes; |
|
| 30 |
import org.distorted.library.type.Dynamic1D; |
|
| 31 |
import org.distorted.library.type.Static1D; |
|
| 32 |
import org.distorted.library.type.Static2D; |
|
| 33 |
import org.distorted.library.type.Static3D; |
|
| 34 |
import org.distorted.library.type.Static4D; |
|
| 35 |
import org.distorted.library.type.Dynamic3D; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
public class Effects2DSurfaceView extends GLSurfaceView |
|
| 40 |
{
|
|
| 41 |
private Effects2DRenderer mRenderer; |
|
| 42 |
private int mCurrentEffect; |
|
| 43 |
private int mScrW, mScrH; |
|
| 44 |
|
|
| 45 |
private Static4D mRegionV, mRegionF; |
|
| 46 |
private Static2D mPoint; |
|
| 47 |
private Dynamic1D mInterA, mInterB, mInterC, mInterS; |
|
| 48 |
private Dynamic3D mInterD; |
|
| 49 |
|
|
| 50 |
private final static Static3D mRED = new Static3D(1,0,0); |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
public Effects2DSurfaceView(Context c, AttributeSet attrs) |
|
| 55 |
{
|
|
| 56 |
super(c, attrs); |
|
| 57 |
|
|
| 58 |
int duration = 10000; |
|
| 59 |
float count = 1.0f; |
|
| 60 |
int h = 30; |
|
| 61 |
int r = 20; |
|
| 62 |
|
|
| 63 |
mInterD = new Dynamic3D(duration,count); |
|
| 64 |
|
|
| 65 |
mInterD.add(new Static3D( 0, r, h )); |
|
| 66 |
mInterD.add(new Static3D(-r, 0, h )); |
|
| 67 |
mInterD.add(new Static3D( 0,-r, h )); |
|
| 68 |
mInterD.add(new Static3D( r, 0, h )); |
|
| 69 |
|
|
| 70 |
mInterA = new Dynamic1D(duration,count); |
|
| 71 |
mInterA.add(new Static1D(1)); |
|
| 72 |
mInterA.add(new Static1D(0)); |
|
| 73 |
|
|
| 74 |
mInterS = new Dynamic1D(duration,count); |
|
| 75 |
mInterS.add(new Static1D(1.0f)); |
|
| 76 |
mInterS.add(new Static1D(0.3f)); |
|
| 77 |
|
|
| 78 |
mInterC = new Dynamic1D(duration,count); |
|
| 79 |
mInterC.add(new Static1D(1)); |
|
| 80 |
mInterC.add(new Static1D(0)); |
|
| 81 |
|
|
| 82 |
mInterB = new Dynamic1D(duration,count); |
|
| 83 |
mInterB.add(new Static1D(0)); |
|
| 84 |
mInterB.add(new Static1D(1)); |
|
| 85 |
|
|
| 86 |
if(!isInEditMode()) |
|
| 87 |
{
|
|
| 88 |
setFocusable(true); |
|
| 89 |
setFocusableInTouchMode(true); |
|
| 90 |
|
|
| 91 |
setEGLContextClientVersion(2); |
|
| 92 |
|
|
| 93 |
if( Build.FINGERPRINT.startsWith("generic") ) // when running on the emulator, insert a magic line that is
|
|
| 94 |
{ // supposed to cure the 'no config chosen' crash on emulator startup
|
|
| 95 |
setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
mRenderer = new Effects2DRenderer(this); |
|
| 99 |
setRenderer(mRenderer); |
|
| 100 |
|
|
| 101 |
mPoint = new Static2D(0,0); |
|
| 102 |
mRegionV= new Static4D(0,0,60,60); |
|
| 103 |
mRegionF= new Static4D(0,0,60,60); |
|
| 104 |
|
|
| 105 |
setEffect(0); |
|
| 106 |
} |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 |
|
|
| 111 |
Effects2DRenderer getRenderer() |
|
| 112 |
{
|
|
| 113 |
return mRenderer; |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
|
|
| 118 |
public void setScreenSize(int width, int height) |
|
| 119 |
{
|
|
| 120 |
mScrW = width; |
|
| 121 |
mScrH = height; |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 125 |
|
|
| 126 |
public void setEffect(int effect) |
|
| 127 |
{
|
|
| 128 |
mCurrentEffect = effect; |
|
| 129 |
} |
|
| 130 |
|
|
| 131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 132 |
|
|
| 133 |
@Override public boolean onTouchEvent(MotionEvent event) |
|
| 134 |
{
|
|
| 135 |
int action = event.getAction(); |
|
| 136 |
int x, y; |
|
| 137 |
long id; |
|
| 138 |
|
|
| 139 |
switch(action) |
|
| 140 |
{
|
|
| 141 |
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW; |
|
| 142 |
y = (int)event.getY()* mRenderer.BHEI/mScrH; |
|
| 143 |
mPoint.set(x,y); |
|
| 144 |
mRegionF.set(x,y,60,60); |
|
| 145 |
Effects2DActivity act = (Effects2DActivity)getContext(); |
|
| 146 |
|
|
| 147 |
switch(mCurrentEffect) |
|
| 148 |
{
|
|
| 149 |
case 0: id = mRenderer.mBackground.distort(mInterD, mPoint, mRegionV); |
|
| 150 |
act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX); |
|
| 151 |
break; |
|
| 152 |
case 1: id = mRenderer.mBackground.sink(mInterS, mPoint, mRegionV); |
|
| 153 |
act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX); |
|
| 154 |
break; |
|
| 155 |
case 2: id = mRenderer.mBackground.alpha(mInterA, mRegionF, true); |
|
| 156 |
act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT); |
|
| 157 |
break; |
|
| 158 |
case 3: id = mRenderer.mBackground.saturation(mInterB, mRegionF, false); |
|
| 159 |
act.effectAdded(id, EffectNames.SATURATION, EffectTypes.FRAGMENT); |
|
| 160 |
break; |
|
| 161 |
case 4: id = mRenderer.mBackground.chroma(mInterC, mRED, mRegionF, true); |
|
| 162 |
act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT); |
|
| 163 |
break; |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
break; |
|
| 167 |
} |
|
| 168 |
|
|
| 169 |
return true; |
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
} |
|
| src/main/res/layout/effects2dlayout.xml | ||
|---|---|---|
| 4 | 4 |
android:layout_height="fill_parent" |
| 5 | 5 |
android:orientation="vertical" > |
| 6 | 6 |
|
| 7 |
<org.distorted.examples.effects2d.Effects2DSurfaceView
|
|
| 7 |
<org.distorted.examples.effectqueue.EffectQueueSurfaceView
|
|
| 8 | 8 |
android:id="@+id/effects2dSurfaceView" |
| 9 | 9 |
android:layout_width="fill_parent" |
| 10 | 10 |
android:layout_height="0dp" |
| src/main/res/values/strings.xml | ||
|---|---|---|
| 82 | 82 |
<string name="example_differenteffects_subtitle">See how to draw the same bitmap multiple times, each time with different set of effects applied.</string> |
| 83 | 83 |
<string name="example_differentbitmaps">Different Bitmaps</string> |
| 84 | 84 |
<string name="example_differentbitmaps_subtitle">Draw 3 different bitmaps, apply the same set of effects to each one in one go.</string> |
| 85 |
<string name="example_effects2d">Effects 2D</string>
|
|
| 86 |
<string name="example_effects2d_subtitle">Add, remove and list all effects currently acting on a Bitmap.</string>
|
|
| 85 |
<string name="example_effectqueue">Effect Queue</string>
|
|
| 86 |
<string name="example_effectqueue_subtitle">Add, remove and list all effects currently acting on a Bitmap.</string>
|
|
| 87 | 87 |
<string name="example_check">Check</string> |
| 88 | 88 |
<string name="example_check_subtitle">Check the maximum number of effects (separately for vertex and fragment shaders) we can apply to a single bitmap.</string> |
| 89 | 89 |
<string name="example_fbo">Bitmap Tree</string> |
Also available in: Unified diff
Rename Effects2D to EffectQueue