commit af225332843914450505e7db502323de773b882d
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Mon Jun 20 23:47:58 2016 +0100

    More progress with Effects2D app.

diff --git a/src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java b/src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java
index 277e577..7191316 100644
--- a/src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java
+++ b/src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java
@@ -21,6 +21,8 @@ package org.distorted.examples.effects2d;
 
 import org.distorted.library.Distorted;
 import org.distorted.examples.R;
+import org.distorted.library.EffectNames;
+import org.distorted.library.EffectTypes;
 
 import android.app.Activity;
 import android.opengl.GLSurfaceView;
@@ -30,12 +32,17 @@ import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.Spinner;
 
+import java.util.ArrayList;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener
   {
   private Spinner mID, mName, mType;
-  private ArrayAdapter<String> mAdapterID, mAdapterName, mAdapterType;
+  private static ArrayAdapter<String> mAdapterName, mAdapterType;
+  private static ArrayAdapter<Long> mAdapterID;
+
+  private int mPosID, mPosName, mPosType;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -46,6 +53,10 @@ public class Effects2DActivity extends Activity implements AdapterView.OnItemSel
  
     setContentView(R.layout.effects2dlayout);
 
+    mPosID   = 0;
+    mPosName = 0;
+    mPosType = 0;
+
     mID   = (Spinner)findViewById(R.id.effects2d_spinnerID  );
     mName = (Spinner)findViewById(R.id.effects2d_spinnerName);
     mType = (Spinner)findViewById(R.id.effects2d_spinnerType);
@@ -54,12 +65,14 @@ public class Effects2DActivity extends Activity implements AdapterView.OnItemSel
     mName.setOnItemSelectedListener(this);
     mType.setOnItemSelectedListener(this);
 
-    String[] itemsID   = new String[] {"1", "2", "3"};
+    ArrayList<Long> itemsID  = new ArrayList<>();
+
     String[] itemsName = new String[] { getText(R.string.distort     ).toString(),
                                         getText(R.string.sink        ).toString(),
                                         getText(R.string.transparency).toString(),
                                         getText(R.string.macroblock  ).toString(),
                                         getText(R.string.chroma      ).toString()};
+
     String[] itemsType = new String[] {"VERTEX", "FRAGMENT"};
 
     mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID);
@@ -82,7 +95,7 @@ public class Effects2DActivity extends Activity implements AdapterView.OnItemSel
     {
     super.onResume();
       
-    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
+    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
     mView.onResume();
     }
 
@@ -91,7 +104,7 @@ public class Effects2DActivity extends Activity implements AdapterView.OnItemSel
   @Override
   protected void onPause() 
     {
-    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
+    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
     mView.onPause();
       
     super.onPause();
@@ -153,14 +166,11 @@ public class Effects2DActivity extends Activity implements AdapterView.OnItemSel
 
   public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
     {
-    // An item was selected. You can retrieve the selected item using
-    // parent.getItemAtPosition(pos)
-
     switch(parent.getId())
       {
-      case R.id.effects2d_spinnerID  : android.util.Log.d("EFFECTS2D", "ID spinner!!"  ); break;
-      case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "Name spinner!!"); break;
-      case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "Type spinner!!"); break;
+      case R.id.effects2d_spinnerID  : mPosID   = pos; break;
+      case R.id.effects2d_spinnerName: mPosName = pos; break;
+      case R.id.effects2d_spinnerType: mPosType = pos; break;
       }
     }
 
@@ -168,11 +178,85 @@ public class Effects2DActivity extends Activity implements AdapterView.OnItemSel
 
   public void onNothingSelected(AdapterView<?> parent)
     {
-    switch(parent.getId())
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void removeByID(View view)
+    {
+    Long currID   = (Long)  mID.getItemAtPosition(mPosID);
+
+    Effects2DRenderer.mBackground.abortEffect(currID);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void removeByName(View view)
+    {
+    EffectNames name;
+
+    switch(mPosName)
       {
-      case R.id.effects2d_spinnerID  : android.util.Log.d("EFFECTS2D", "(nothing) ID spinner!!"  ); break;
-      case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "(nothing) Name spinner!!"); break;
-      case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "(nothing) Type spinner!!"); break;
+      case  0: name = EffectNames.DISTORT   ; break;
+      case  1: name = EffectNames.SINK      ; break;
+      case  2: name = EffectNames.ALPHA     ; break;
+      case  3: name = EffectNames.MACROBLOCK; break;
+      case  4: name = EffectNames.CHROMA    ; break;
+      default: name = EffectNames.CONTRAST  ;
       }
+
+    Effects2DRenderer.mBackground.abortEffects(name);
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void removeByType(View view)
+    {
+    EffectTypes type;
+
+    switch(mPosType)
+      {
+      case  0: type = EffectTypes.VERTEX  ; break;
+      case  1: type = EffectTypes.FRAGMENT; break;
+      default: type = EffectTypes.MATRIX;
+      }
+
+    Effects2DRenderer.mBackground.abortEffects(type);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void effectAdded(final long id, final int type)
+    {
+    android.util.Log.d("EFFECTS2D", "new effect added, id="+id+" type="+type);
+
+    mAdapterID.add( new Long(id) );
+    mAdapterID.notifyDataSetChanged();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void effectRemoved(final long id)
+    {
+    android.util.Log.d("EFFECTS2D", "new effect removed, id="+id);
+
+    runOnUiThread(new Runnable()
+        {
+        public void run()
+          {
+          mAdapterID.remove( new Long(id) );
+          mAdapterID.notifyDataSetChanged();
+          }
+        });
+
+
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void effectFinished(final long id)
+    {
+    android.util.Log.d("EFFECTS2D", "new effect finished, id="+id);
+    }
+
   }
diff --git a/src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java b/src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java
index 9cbfc53..bb955a1 100644
--- a/src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java
+++ b/src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java
@@ -32,11 +32,13 @@ import android.opengl.GLSurfaceView;
 import org.distorted.library.DistortedBitmap;
 import org.distorted.library.Distorted;
 import org.distorted.library.EffectTypes;
+import org.distorted.library.message.EffectListener;
+import org.distorted.library.message.EffectMessage;
 import org.distorted.library.type.Static3D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-public class Effects2DRenderer implements GLSurfaceView.Renderer
+public class Effects2DRenderer implements GLSurfaceView.Renderer, EffectListener
   {  
   public static final int NUMLINES = 10;
   public static final int BWID = 300;
@@ -81,7 +83,8 @@ public class Effects2DRenderer implements GLSurfaceView.Renderer
       }
           
     mBackground.setBitmap(bitmap);
-          
+    mBackground.addEventListener(this);
+
     try
       {
       Distorted.onSurfaceCreated(mView.getContext());
@@ -109,4 +112,19 @@ public class Effects2DRenderer implements GLSurfaceView.Renderer
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
     mBackground.draw(System.currentTimeMillis());
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// the library sending messages to us
+
+  public void effectMessage(final EffectMessage em, final long effectID, final int effectName, final long bitmapID, final String message)
+    {
+    Effects2DActivity act = (Effects2DActivity)mView.getContext();
+
+    switch(em)
+      {
+      case EFFECT_REMOVED : act.effectRemoved(effectID) ; break;
+      case EFFECT_FINISHED: act.effectFinished(effectID); break;
+      default             : break;
+      }
+    }
   }
diff --git a/src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java b/src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java
index da2922e..3bc1fd0 100644
--- a/src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java
+++ b/src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java
@@ -107,7 +107,7 @@ public class Effects2DSurfaceView extends GLSurfaceView
         
       mRenderer = new Effects2DRenderer(this);
       setRenderer(mRenderer);
-        
+
       point = new Static2D(0,0);
       region= new Static4D(0,0,60,60);
       mRegion = new Static4D(0,0,60,60);
@@ -137,7 +137,8 @@ public class Effects2DSurfaceView extends GLSurfaceView
     {
     int action = event.getAction();
     int x, y;
-      
+    long id = -1;
+
     switch(action)
       {
       case MotionEvent.ACTION_DOWN: x = (int)event.getX()* Effects2DRenderer.BWID/mScrW;
@@ -147,20 +148,25 @@ public class Effects2DSurfaceView extends GLSurfaceView
 
                                     switch(mCurrentEffect)
                                       {
-                                      case 0: Effects2DRenderer.mBackground.distort(mInterD, point, region);
+                                      case 0: id = Effects2DRenderer.mBackground.distort(mInterD, point, region);
                                            break;
-                                      case 1: Effects2DRenderer.mBackground.sink(mInterS, point, region);
+                                      case 1: id = Effects2DRenderer.mBackground.sink(mInterS, point, region);
                                            break;
-                                      case 2: Effects2DRenderer.mBackground.alpha(mInterA, mRegion, false);
+                                      case 2: id = Effects2DRenderer.mBackground.alpha(mInterA, mRegion, false);
                                            break;  
-                                      case 3: Effects2DRenderer.mBackground.macroblock(mInterM, mRegion);
+                                      case 3: id = Effects2DRenderer.mBackground.macroblock(mInterM, mRegion);
                                            break;
-                                      case 4: Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, false);
+                                      case 4: id = Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, false);
                                            break;      
                                       }
+
+                                    Effects2DActivity act = (Effects2DActivity)getContext();
+                                    act.effectAdded(id, mCurrentEffect);
+
                                     break;
       }
-            
+
     return true;
     }
+
   }
diff --git a/src/main/res/layout/effects2dlayout.xml b/src/main/res/layout/effects2dlayout.xml
index 3e6427f..0913f2c 100644
--- a/src/main/res/layout/effects2dlayout.xml
+++ b/src/main/res/layout/effects2dlayout.xml
@@ -5,11 +5,17 @@
     android:orientation="vertical" >
 
     <org.distorted.examples.effects2d.Effects2DSurfaceView
-        android:id="@+id/scratchpadSurfaceView"
+        android:id="@+id/effects2dSurfaceView"
         android:layout_width="fill_parent"
         android:layout_height="0dp"
         android:layout_weight="1" />
 
+    <ScrollView
+        android:id="@+id/effects2dscrollView"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="0.82" >
+
     <LinearLayout
         android:id="@+id/linearLayout1"
         android:layout_width="fill_parent"
@@ -42,7 +48,7 @@
             android:layout_gravity="center_horizontal">
 
             <RadioButton
-                android:id="@+id/scratchpadDistort"
+                android:id="@+id/effects2dDistort"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:checked="true"
@@ -51,7 +57,7 @@
                 android:textSize="12dp"/>
 
             <RadioButton
-                android:id="@+id/scratchpadSink"
+                android:id="@+id/effects2dSink"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:onClick="Sink"
@@ -59,7 +65,7 @@
                 android:textSize="12dp"/>
 
             <RadioButton
-                android:id="@+id/scratchpadTransparency"
+                android:id="@+id/effects2dTransparency"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:onClick="Transparency"
@@ -67,7 +73,7 @@
                 android:textSize="12dp"/>
 
             <RadioButton
-                android:id="@+id/scratchpadMacroblock"
+                android:id="@+id/effects2dMacroblock"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:onClick="Macroblock"
@@ -75,7 +81,7 @@
                 android:textSize="12dp"/>
 
             <RadioButton
-                android:id="@+id/scratchpadBrightness"
+                android:id="@+id/effects2dBrightness"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:onClick="Chroma"
@@ -89,19 +95,12 @@
             android:background="#FF0000"
             android:layout_width="match_parent"/>
 
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="@string/remove"
-            android:id="@+id/textView2"
-            android:layout_gravity="center_horizontal"/>
-
         <TableLayout
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:paddingTop="10dp"
-            android:paddingBottom="10dp"
-            android:stretchColumns="0,1"
+            android:paddingTop="2dp"
+            android:paddingBottom="2dp"
+            android:stretchColumns="0,1,2"
             android:paddingLeft="10dp"
             android:paddingRight="10dp">
 
@@ -111,6 +110,13 @@
                 android:layout_gravity="center"
                 android:orientation="vertical">
 
+                <Button
+                    android:layout_width="wrap_content"
+                    android:layout_height="40dp"
+                    android:text="@string/removebut"
+                    android:id="@+id/effects2dRemoveID"
+                    android:onClick="removeByID"/>
+
                 <TextView
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
@@ -129,6 +135,13 @@
                 android:layout_height="wrap_content"
                 android:layout_gravity="center">
 
+                <Button
+                    android:layout_width="wrap_content"
+                    android:layout_height="40dp"
+                    android:text="@string/removebut"
+                    android:id="@+id/effects2dRemoveName"
+                    android:onClick="removeByName"/>
+
                 <TextView
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
@@ -147,6 +160,13 @@
                 android:layout_height="wrap_content"
                 android:layout_gravity="center">
 
+                <Button
+                    android:layout_width="wrap_content"
+                    android:layout_height="40dp"
+                    android:text="@string/removebut"
+                    android:id="@+id/effects2dRemoveType"
+                    android:onClick="removeByType"/>
+
                 <TextView
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
@@ -174,5 +194,5 @@
             android:id="@+id/textView6"
             android:layout_gravity="center_horizontal"/>
     </LinearLayout>
-
+    </ScrollView>
 </LinearLayout>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index a279fb1..4ad0e87 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -21,9 +21,10 @@
     <string name="chroma">Chroma</string>
     <string name="add">Touch screen to add new</string>
     <string name="remove">Remove existing effect(s) by</string>
-    <string name="name">Name</string>
-    <string name="type">Type</string>
-    <string name="id">ID</string>
+    <string name="removebut">Remove</string>
+    <string name="name">effects by name</string>
+    <string name="type">effects by type</string>
+    <string name="id">effects by ID</string>
     <string name="list">List of all existing effects</string>
     <string name="swirl">Swirl</string>
     <string name="print">Print</string>
