Revision af225332
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
import org.distorted.library.Distorted; |
| 23 | 23 |
import org.distorted.examples.R; |
| 24 |
import org.distorted.library.EffectNames; |
|
| 25 |
import org.distorted.library.EffectTypes; |
|
| 24 | 26 |
|
| 25 | 27 |
import android.app.Activity; |
| 26 | 28 |
import android.opengl.GLSurfaceView; |
| ... | ... | |
| 30 | 32 |
import android.widget.ArrayAdapter; |
| 31 | 33 |
import android.widget.Spinner; |
| 32 | 34 |
|
| 35 |
import java.util.ArrayList; |
|
| 36 |
|
|
| 33 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | 38 |
|
| 35 | 39 |
public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener |
| 36 | 40 |
{
|
| 37 | 41 |
private Spinner mID, mName, mType; |
| 38 |
private ArrayAdapter<String> mAdapterID, mAdapterName, mAdapterType; |
|
| 42 |
private static ArrayAdapter<String> mAdapterName, mAdapterType; |
|
| 43 |
private static ArrayAdapter<Long> mAdapterID; |
|
| 44 |
|
|
| 45 |
private int mPosID, mPosName, mPosType; |
|
| 39 | 46 |
|
| 40 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 41 | 48 |
|
| ... | ... | |
| 46 | 53 |
|
| 47 | 54 |
setContentView(R.layout.effects2dlayout); |
| 48 | 55 |
|
| 56 |
mPosID = 0; |
|
| 57 |
mPosName = 0; |
|
| 58 |
mPosType = 0; |
|
| 59 |
|
|
| 49 | 60 |
mID = (Spinner)findViewById(R.id.effects2d_spinnerID ); |
| 50 | 61 |
mName = (Spinner)findViewById(R.id.effects2d_spinnerName); |
| 51 | 62 |
mType = (Spinner)findViewById(R.id.effects2d_spinnerType); |
| ... | ... | |
| 54 | 65 |
mName.setOnItemSelectedListener(this); |
| 55 | 66 |
mType.setOnItemSelectedListener(this); |
| 56 | 67 |
|
| 57 |
String[] itemsID = new String[] {"1", "2", "3"};
|
|
| 68 |
ArrayList<Long> itemsID = new ArrayList<>(); |
|
| 69 |
|
|
| 58 | 70 |
String[] itemsName = new String[] { getText(R.string.distort ).toString(),
|
| 59 | 71 |
getText(R.string.sink ).toString(), |
| 60 | 72 |
getText(R.string.transparency).toString(), |
| 61 | 73 |
getText(R.string.macroblock ).toString(), |
| 62 | 74 |
getText(R.string.chroma ).toString()}; |
| 75 |
|
|
| 63 | 76 |
String[] itemsType = new String[] {"VERTEX", "FRAGMENT"};
|
| 64 | 77 |
|
| 65 | 78 |
mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID); |
| ... | ... | |
| 82 | 95 |
{
|
| 83 | 96 |
super.onResume(); |
| 84 | 97 |
|
| 85 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
|
|
| 98 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
|
|
| 86 | 99 |
mView.onResume(); |
| 87 | 100 |
} |
| 88 | 101 |
|
| ... | ... | |
| 91 | 104 |
@Override |
| 92 | 105 |
protected void onPause() |
| 93 | 106 |
{
|
| 94 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
|
|
| 107 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
|
|
| 95 | 108 |
mView.onPause(); |
| 96 | 109 |
|
| 97 | 110 |
super.onPause(); |
| ... | ... | |
| 153 | 166 |
|
| 154 | 167 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
| 155 | 168 |
{
|
| 156 |
// An item was selected. You can retrieve the selected item using |
|
| 157 |
// parent.getItemAtPosition(pos) |
|
| 158 |
|
|
| 159 | 169 |
switch(parent.getId()) |
| 160 | 170 |
{
|
| 161 |
case R.id.effects2d_spinnerID : android.util.Log.d("EFFECTS2D", "ID spinner!!" ); break;
|
|
| 162 |
case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "Name spinner!!"); break;
|
|
| 163 |
case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "Type spinner!!"); break;
|
|
| 171 |
case R.id.effects2d_spinnerID : mPosID = pos; break;
|
|
| 172 |
case R.id.effects2d_spinnerName: mPosName = pos; break;
|
|
| 173 |
case R.id.effects2d_spinnerType: mPosType = pos; break;
|
|
| 164 | 174 |
} |
| 165 | 175 |
} |
| 166 | 176 |
|
| ... | ... | |
| 168 | 178 |
|
| 169 | 179 |
public void onNothingSelected(AdapterView<?> parent) |
| 170 | 180 |
{
|
| 171 |
switch(parent.getId()) |
|
| 181 |
} |
|
| 182 |
|
|
| 183 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 184 |
|
|
| 185 |
public void removeByID(View view) |
|
| 186 |
{
|
|
| 187 |
Long currID = (Long) mID.getItemAtPosition(mPosID); |
|
| 188 |
|
|
| 189 |
Effects2DRenderer.mBackground.abortEffect(currID); |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 193 |
|
|
| 194 |
public void removeByName(View view) |
|
| 195 |
{
|
|
| 196 |
EffectNames name; |
|
| 197 |
|
|
| 198 |
switch(mPosName) |
|
| 172 | 199 |
{
|
| 173 |
case R.id.effects2d_spinnerID : android.util.Log.d("EFFECTS2D", "(nothing) ID spinner!!" ); break;
|
|
| 174 |
case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "(nothing) Name spinner!!"); break;
|
|
| 175 |
case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "(nothing) Type spinner!!"); break;
|
|
| 200 |
case 0: name = EffectNames.DISTORT ; break; |
|
| 201 |
case 1: name = EffectNames.SINK ; break; |
|
| 202 |
case 2: name = EffectNames.ALPHA ; break; |
|
| 203 |
case 3: name = EffectNames.MACROBLOCK; break; |
|
| 204 |
case 4: name = EffectNames.CHROMA ; break; |
|
| 205 |
default: name = EffectNames.CONTRAST ; |
|
| 176 | 206 |
} |
| 207 |
|
|
| 208 |
Effects2DRenderer.mBackground.abortEffects(name); |
|
| 177 | 209 |
} |
| 210 |
|
|
| 211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 212 |
|
|
| 213 |
public void removeByType(View view) |
|
| 214 |
{
|
|
| 215 |
EffectTypes type; |
|
| 216 |
|
|
| 217 |
switch(mPosType) |
|
| 218 |
{
|
|
| 219 |
case 0: type = EffectTypes.VERTEX ; break; |
|
| 220 |
case 1: type = EffectTypes.FRAGMENT; break; |
|
| 221 |
default: type = EffectTypes.MATRIX; |
|
| 222 |
} |
|
| 223 |
|
|
| 224 |
Effects2DRenderer.mBackground.abortEffects(type); |
|
| 225 |
} |
|
| 226 |
|
|
| 227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 228 |
|
|
| 229 |
public void effectAdded(final long id, final int type) |
|
| 230 |
{
|
|
| 231 |
android.util.Log.d("EFFECTS2D", "new effect added, id="+id+" type="+type);
|
|
| 232 |
|
|
| 233 |
mAdapterID.add( new Long(id) ); |
|
| 234 |
mAdapterID.notifyDataSetChanged(); |
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
|
|
| 239 |
public void effectRemoved(final long id) |
|
| 240 |
{
|
|
| 241 |
android.util.Log.d("EFFECTS2D", "new effect removed, id="+id);
|
|
| 242 |
|
|
| 243 |
runOnUiThread(new Runnable() |
|
| 244 |
{
|
|
| 245 |
public void run() |
|
| 246 |
{
|
|
| 247 |
mAdapterID.remove( new Long(id) ); |
|
| 248 |
mAdapterID.notifyDataSetChanged(); |
|
| 249 |
} |
|
| 250 |
}); |
|
| 251 |
|
|
| 252 |
|
|
| 253 |
} |
|
| 254 |
|
|
| 255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 256 |
|
|
| 257 |
public void effectFinished(final long id) |
|
| 258 |
{
|
|
| 259 |
android.util.Log.d("EFFECTS2D", "new effect finished, id="+id);
|
|
| 260 |
} |
|
| 261 |
|
|
| 178 | 262 |
} |
| src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java | ||
|---|---|---|
| 32 | 32 |
import org.distorted.library.DistortedBitmap; |
| 33 | 33 |
import org.distorted.library.Distorted; |
| 34 | 34 |
import org.distorted.library.EffectTypes; |
| 35 |
import org.distorted.library.message.EffectListener; |
|
| 36 |
import org.distorted.library.message.EffectMessage; |
|
| 35 | 37 |
import org.distorted.library.type.Static3D; |
| 36 | 38 |
|
| 37 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | 40 |
|
| 39 |
public class Effects2DRenderer implements GLSurfaceView.Renderer |
|
| 41 |
public class Effects2DRenderer implements GLSurfaceView.Renderer, EffectListener
|
|
| 40 | 42 |
{
|
| 41 | 43 |
public static final int NUMLINES = 10; |
| 42 | 44 |
public static final int BWID = 300; |
| ... | ... | |
| 81 | 83 |
} |
| 82 | 84 |
|
| 83 | 85 |
mBackground.setBitmap(bitmap); |
| 84 |
|
|
| 86 |
mBackground.addEventListener(this); |
|
| 87 |
|
|
| 85 | 88 |
try |
| 86 | 89 |
{
|
| 87 | 90 |
Distorted.onSurfaceCreated(mView.getContext()); |
| ... | ... | |
| 109 | 112 |
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); |
| 110 | 113 |
mBackground.draw(System.currentTimeMillis()); |
| 111 | 114 |
} |
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
// the library sending messages to us |
|
| 118 |
|
|
| 119 |
public void effectMessage(final EffectMessage em, final long effectID, final int effectName, final long bitmapID, final String message) |
|
| 120 |
{
|
|
| 121 |
Effects2DActivity act = (Effects2DActivity)mView.getContext(); |
|
| 122 |
|
|
| 123 |
switch(em) |
|
| 124 |
{
|
|
| 125 |
case EFFECT_REMOVED : act.effectRemoved(effectID) ; break; |
|
| 126 |
case EFFECT_FINISHED: act.effectFinished(effectID); break; |
|
| 127 |
default : break; |
|
| 128 |
} |
|
| 129 |
} |
|
| 112 | 130 |
} |
| src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java | ||
|---|---|---|
| 107 | 107 |
|
| 108 | 108 |
mRenderer = new Effects2DRenderer(this); |
| 109 | 109 |
setRenderer(mRenderer); |
| 110 |
|
|
| 110 |
|
|
| 111 | 111 |
point = new Static2D(0,0); |
| 112 | 112 |
region= new Static4D(0,0,60,60); |
| 113 | 113 |
mRegion = new Static4D(0,0,60,60); |
| ... | ... | |
| 137 | 137 |
{
|
| 138 | 138 |
int action = event.getAction(); |
| 139 | 139 |
int x, y; |
| 140 |
|
|
| 140 |
long id = -1; |
|
| 141 |
|
|
| 141 | 142 |
switch(action) |
| 142 | 143 |
{
|
| 143 | 144 |
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* Effects2DRenderer.BWID/mScrW; |
| ... | ... | |
| 147 | 148 |
|
| 148 | 149 |
switch(mCurrentEffect) |
| 149 | 150 |
{
|
| 150 |
case 0: Effects2DRenderer.mBackground.distort(mInterD, point, region); |
|
| 151 |
case 0: id = Effects2DRenderer.mBackground.distort(mInterD, point, region);
|
|
| 151 | 152 |
break; |
| 152 |
case 1: Effects2DRenderer.mBackground.sink(mInterS, point, region); |
|
| 153 |
case 1: id = Effects2DRenderer.mBackground.sink(mInterS, point, region);
|
|
| 153 | 154 |
break; |
| 154 |
case 2: Effects2DRenderer.mBackground.alpha(mInterA, mRegion, false); |
|
| 155 |
case 2: id = Effects2DRenderer.mBackground.alpha(mInterA, mRegion, false);
|
|
| 155 | 156 |
break; |
| 156 |
case 3: Effects2DRenderer.mBackground.macroblock(mInterM, mRegion); |
|
| 157 |
case 3: id = Effects2DRenderer.mBackground.macroblock(mInterM, mRegion);
|
|
| 157 | 158 |
break; |
| 158 |
case 4: Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, false); |
|
| 159 |
case 4: id = Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, false);
|
|
| 159 | 160 |
break; |
| 160 | 161 |
} |
| 162 |
|
|
| 163 |
Effects2DActivity act = (Effects2DActivity)getContext(); |
|
| 164 |
act.effectAdded(id, mCurrentEffect); |
|
| 165 |
|
|
| 161 | 166 |
break; |
| 162 | 167 |
} |
| 163 |
|
|
| 168 |
|
|
| 164 | 169 |
return true; |
| 165 | 170 |
} |
| 171 |
|
|
| 166 | 172 |
} |
| src/main/res/layout/effects2dlayout.xml | ||
|---|---|---|
| 5 | 5 |
android:orientation="vertical" > |
| 6 | 6 |
|
| 7 | 7 |
<org.distorted.examples.effects2d.Effects2DSurfaceView |
| 8 |
android:id="@+id/scratchpadSurfaceView"
|
|
| 8 |
android:id="@+id/effects2dSurfaceView"
|
|
| 9 | 9 |
android:layout_width="fill_parent" |
| 10 | 10 |
android:layout_height="0dp" |
| 11 | 11 |
android:layout_weight="1" /> |
| 12 | 12 |
|
| 13 |
<ScrollView |
|
| 14 |
android:id="@+id/effects2dscrollView" |
|
| 15 |
android:layout_width="match_parent" |
|
| 16 |
android:layout_height="0dp" |
|
| 17 |
android:layout_weight="0.82" > |
|
| 18 |
|
|
| 13 | 19 |
<LinearLayout |
| 14 | 20 |
android:id="@+id/linearLayout1" |
| 15 | 21 |
android:layout_width="fill_parent" |
| ... | ... | |
| 42 | 48 |
android:layout_gravity="center_horizontal"> |
| 43 | 49 |
|
| 44 | 50 |
<RadioButton |
| 45 |
android:id="@+id/scratchpadDistort"
|
|
| 51 |
android:id="@+id/effects2dDistort"
|
|
| 46 | 52 |
android:layout_width="wrap_content" |
| 47 | 53 |
android:layout_height="wrap_content" |
| 48 | 54 |
android:checked="true" |
| ... | ... | |
| 51 | 57 |
android:textSize="12dp"/> |
| 52 | 58 |
|
| 53 | 59 |
<RadioButton |
| 54 |
android:id="@+id/scratchpadSink"
|
|
| 60 |
android:id="@+id/effects2dSink"
|
|
| 55 | 61 |
android:layout_width="wrap_content" |
| 56 | 62 |
android:layout_height="wrap_content" |
| 57 | 63 |
android:onClick="Sink" |
| ... | ... | |
| 59 | 65 |
android:textSize="12dp"/> |
| 60 | 66 |
|
| 61 | 67 |
<RadioButton |
| 62 |
android:id="@+id/scratchpadTransparency"
|
|
| 68 |
android:id="@+id/effects2dTransparency"
|
|
| 63 | 69 |
android:layout_width="wrap_content" |
| 64 | 70 |
android:layout_height="wrap_content" |
| 65 | 71 |
android:onClick="Transparency" |
| ... | ... | |
| 67 | 73 |
android:textSize="12dp"/> |
| 68 | 74 |
|
| 69 | 75 |
<RadioButton |
| 70 |
android:id="@+id/scratchpadMacroblock"
|
|
| 76 |
android:id="@+id/effects2dMacroblock"
|
|
| 71 | 77 |
android:layout_width="wrap_content" |
| 72 | 78 |
android:layout_height="wrap_content" |
| 73 | 79 |
android:onClick="Macroblock" |
| ... | ... | |
| 75 | 81 |
android:textSize="12dp"/> |
| 76 | 82 |
|
| 77 | 83 |
<RadioButton |
| 78 |
android:id="@+id/scratchpadBrightness"
|
|
| 84 |
android:id="@+id/effects2dBrightness"
|
|
| 79 | 85 |
android:layout_width="wrap_content" |
| 80 | 86 |
android:layout_height="wrap_content" |
| 81 | 87 |
android:onClick="Chroma" |
| ... | ... | |
| 89 | 95 |
android:background="#FF0000" |
| 90 | 96 |
android:layout_width="match_parent"/> |
| 91 | 97 |
|
| 92 |
<TextView |
|
| 93 |
android:layout_width="wrap_content" |
|
| 94 |
android:layout_height="wrap_content" |
|
| 95 |
android:text="@string/remove" |
|
| 96 |
android:id="@+id/textView2" |
|
| 97 |
android:layout_gravity="center_horizontal"/> |
|
| 98 |
|
|
| 99 | 98 |
<TableLayout |
| 100 | 99 |
android:layout_width="fill_parent" |
| 101 | 100 |
android:layout_height="wrap_content" |
| 102 |
android:paddingTop="10dp"
|
|
| 103 |
android:paddingBottom="10dp"
|
|
| 104 |
android:stretchColumns="0,1" |
|
| 101 |
android:paddingTop="2dp"
|
|
| 102 |
android:paddingBottom="2dp"
|
|
| 103 |
android:stretchColumns="0,1,2"
|
|
| 105 | 104 |
android:paddingLeft="10dp" |
| 106 | 105 |
android:paddingRight="10dp"> |
| 107 | 106 |
|
| ... | ... | |
| 111 | 110 |
android:layout_gravity="center" |
| 112 | 111 |
android:orientation="vertical"> |
| 113 | 112 |
|
| 113 |
<Button |
|
| 114 |
android:layout_width="wrap_content" |
|
| 115 |
android:layout_height="40dp" |
|
| 116 |
android:text="@string/removebut" |
|
| 117 |
android:id="@+id/effects2dRemoveID" |
|
| 118 |
android:onClick="removeByID"/> |
|
| 119 |
|
|
| 114 | 120 |
<TextView |
| 115 | 121 |
android:layout_width="match_parent" |
| 116 | 122 |
android:layout_height="wrap_content" |
| ... | ... | |
| 129 | 135 |
android:layout_height="wrap_content" |
| 130 | 136 |
android:layout_gravity="center"> |
| 131 | 137 |
|
| 138 |
<Button |
|
| 139 |
android:layout_width="wrap_content" |
|
| 140 |
android:layout_height="40dp" |
|
| 141 |
android:text="@string/removebut" |
|
| 142 |
android:id="@+id/effects2dRemoveName" |
|
| 143 |
android:onClick="removeByName"/> |
|
| 144 |
|
|
| 132 | 145 |
<TextView |
| 133 | 146 |
android:layout_width="match_parent" |
| 134 | 147 |
android:layout_height="wrap_content" |
| ... | ... | |
| 147 | 160 |
android:layout_height="wrap_content" |
| 148 | 161 |
android:layout_gravity="center"> |
| 149 | 162 |
|
| 163 |
<Button |
|
| 164 |
android:layout_width="wrap_content" |
|
| 165 |
android:layout_height="40dp" |
|
| 166 |
android:text="@string/removebut" |
|
| 167 |
android:id="@+id/effects2dRemoveType" |
|
| 168 |
android:onClick="removeByType"/> |
|
| 169 |
|
|
| 150 | 170 |
<TextView |
| 151 | 171 |
android:layout_width="wrap_content" |
| 152 | 172 |
android:layout_height="wrap_content" |
| ... | ... | |
| 174 | 194 |
android:id="@+id/textView6" |
| 175 | 195 |
android:layout_gravity="center_horizontal"/> |
| 176 | 196 |
</LinearLayout> |
| 177 |
|
|
| 197 |
</ScrollView> |
|
| 178 | 198 |
</LinearLayout> |
| src/main/res/values/strings.xml | ||
|---|---|---|
| 21 | 21 |
<string name="chroma">Chroma</string> |
| 22 | 22 |
<string name="add">Touch screen to add new</string> |
| 23 | 23 |
<string name="remove">Remove existing effect(s) by</string> |
| 24 |
<string name="name">Name</string> |
|
| 25 |
<string name="type">Type</string> |
|
| 26 |
<string name="id">ID</string> |
|
| 24 |
<string name="removebut">Remove</string> |
|
| 25 |
<string name="name">effects by name</string> |
|
| 26 |
<string name="type">effects by type</string> |
|
| 27 |
<string name="id">effects by ID</string> |
|
| 27 | 28 |
<string name="list">List of all existing effects</string> |
| 28 | 29 |
<string name="swirl">Swirl</string> |
| 29 | 30 |
<string name="print">Print</string> |
Also available in: Unified diff
More progress with Effects2D app.