Fix fountain and more rollo ui work.
diff --git a/java/Fountain/AndroidManifest.xml b/java/Fountain/AndroidManifest.xml
index a10938b..dd0e428 100644
--- a/java/Fountain/AndroidManifest.xml
+++ b/java/Fountain/AndroidManifest.xml
@@ -3,7 +3,7 @@
     package="com.android.fountain">
     <application android:label="Fountain">
         <activity android:name="Fountain"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
+                  android:theme="@android:style/Theme.Translucent">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
diff --git a/java/Fountain/res/raw/fountain.c b/java/Fountain/res/raw/fountain.c
index 6919565..99551fc 100644
--- a/java/Fountain/res/raw/fountain.c
+++ b/java/Fountain/res/raw/fountain.c
@@ -2,8 +2,8 @@
 
 #pragma version(1)
 #pragma stateVertex(default)
-#pragma stateFragment(PgmFragBackground)
-#pragma stateFragmentStore(PFSReplace)
+#pragma stateFragment(PgmFragParts)
+#pragma stateFragmentStore(PFSBlend)
 
 
 int main(int launchID) {
@@ -34,15 +34,11 @@
         }
     }
 
-    drawRect(0, 256, 0, 512);
-    contextBindProgramFragment(NAMED_PgmFragParts);
-    contextBindProgramFragmentStore(NAMED_PFSBlend);
-
     if (touch) {
         newPart = loadI32(2, 0);
         for (ct2=0; ct2<rate; ct2++) {
-            dx = scriptRand(0x10000) - 0x8000;
-            dy = scriptRand(0x10000) - 0x8000;
+            dx = (int)((randf(1.f) - 0.5f) * 0x10000);
+            dy = (int)((randf(1.f) - 0.5f) * 0x10000);
 
             idx = newPart * 5 + 1;
             storeI32(2, idx, dx);
@@ -74,15 +70,15 @@
                 dstIdx = drawCount * 9;
                 c = 0xffafcf | ((life >> lifeShift) << 24);
 
-                storeU32(1, dstIdx, c);
+                storeI32(1, dstIdx, c);
                 storeI32(1, dstIdx + 1, posx);
                 storeI32(1, dstIdx + 2, posy);
 
-                storeU32(1, dstIdx + 3, c);
+                storeI32(1, dstIdx + 3, c);
                 storeI32(1, dstIdx + 4, posx + 0x10000);
                 storeI32(1, dstIdx + 5, posy + dy * 4);
 
-                storeU32(1, dstIdx + 6, c);
+                storeI32(1, dstIdx + 6, c);
                 storeI32(1, dstIdx + 7, posx - 0x10000);
                 storeI32(1, dstIdx + 8, posy + dy * 4);
                 drawCount ++;
diff --git a/java/Fountain/src/com/android/fountain/FountainRS.java b/java/Fountain/src/com/android/fountain/FountainRS.java
index 745635f..c8e9a1e 100644
--- a/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -56,11 +56,7 @@
     private RenderScript.Allocation mVertAlloc;
     private RenderScript.Script mScript;
     private RenderScript.ProgramFragmentStore mPFS;
-    private RenderScript.ProgramFragmentStore mPFS2;
     private RenderScript.ProgramFragment mPF;
-    private RenderScript.ProgramFragment mPF2;
-    private RenderScript.Allocation mTexture;
-    private RenderScript.Sampler mSampler;
 
     private Bitmap mBackground;
 
@@ -74,16 +70,6 @@
         mPartAlloc.setName("PartBuffer");
         mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);
 
-        {
-            Drawable d = mRes.getDrawable(R.drawable.gadgets_clock_mp3);
-            BitmapDrawable bd = (BitmapDrawable)d;
-            Bitmap b = bd.getBitmap();
-            mTexture = mRS.allocationCreateFromBitmap(b,
-                                                      RenderScript.ElementPredefined.RGB_565,
-                                                      false);
-            mTexture.uploadToTexture(0);
-        }
-
         mRS.programFragmentStoreBegin(null, null);
         mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
         mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
@@ -92,33 +78,10 @@
         mPFS = mRS.programFragmentStoreCreate();
         mPFS.setName("PFSBlend");
 
-        mRS.programFragmentStoreBegin(null, null);
-        mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
-        mRS.programFragmentStoreDepthMask(false);
-        mRS.programFragmentStoreDitherEnable(false);
-        mPFS2 = mRS.programFragmentStoreCreate();
-        mPFS2.setName("PFSReplace");
-        mRS.contextBindProgramFragmentStore(mPFS2);
-
-        mRS.samplerBegin();
-        mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, RenderScript.SamplerValue.NEAREST);
-        mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, RenderScript.SamplerValue.NEAREST);
-        mSampler = mRS.samplerCreate();
-
-
         mRS.programFragmentBegin(null, null);
         mPF = mRS.programFragmentCreate();
         mPF.setName("PgmFragParts");
 
-        mRS.programFragmentBegin(null, null);
-        mRS.programFragmentSetTexEnable(0, true);
-        mPF2 = mRS.programFragmentCreate();
-        mRS.contextBindProgramFragment(mPF2);
-        mPF2.bindTexture(mTexture, 0);
-        mPF2.bindSampler(mSampler, 0);
-        mPF2.setName("PgmFragBackground");
-
-
         mParams[0] = 0;
         mParams[1] = partCount;
         mParams[2] = 0;
diff --git a/java/RenderScript/android/renderscript/RenderScript.java b/java/RenderScript/android/renderscript/RenderScript.java
index 09d1836..733009e 100644
--- a/java/RenderScript/android/renderscript/RenderScript.java
+++ b/java/RenderScript/android/renderscript/RenderScript.java
@@ -846,6 +846,10 @@
         nProgramFragmentSetTexEnable(slot, enable);
     }
 
+    public void programFragmentSetTexEnvMode(int slot, EnvMode env) {
+        nProgramFragmentSetEnvMode(slot, env.mID);
+    }
+
     public ProgramFragment programFragmentCreate() {
         int id = nProgramFragmentCreate();
         return new ProgramFragment(id);
diff --git a/java/Rollo/res/raw/rollo.c b/java/Rollo/res/raw/rollo.c
index 0f68372..70b48fa 100644
--- a/java/Rollo/res/raw/rollo.c
+++ b/java/Rollo/res/raw/rollo.c
@@ -8,11 +8,11 @@
 #define SCRATCH_ZOOM 1
 #define SCRATCH_ROT 2
 
-#define STATE_POS_X             0
-#define STATE_POS_Y             1
-#define STATE_PRESSURE          2
+//#define STATE_POS_X             0
+#define STATE_DONE              1
+//#define STATE_PRESSURE          2
 #define STATE_ZOOM              3
-#define STATE_WARP              4
+//#define STATE_WARP              4
 #define STATE_ORIENTATION       5
 #define STATE_SELECTION         6
 #define STATE_FIRST_VISIBLE     7
@@ -31,13 +31,22 @@
     int row;
     int col;
     int imageID;
-    int iconCount;
+    int done = loadI32(0, STATE_DONE);
+    int selectedID = loadI32(0, STATE_SELECTION);
 
     float f = loadF(2, 0);
+
     pfClearColor(0.0f, 0.0f, 0.0f, f);
-    if (f < 0.8f) {
-        f = f + 0.02f;
-        storeF(2, 0, f);
+    if (done) {
+        if (f > 0.02f) {
+            //f = f - 0.02f;
+            //storeF(2, 0, f);
+        }
+    } else {
+        if (f < 0.8f) {
+            f = f + 0.02f;
+            storeF(2, 0, f);
+        }
     }
 
     float touchCut = 1.f;
@@ -45,7 +54,8 @@
         touchCut = 5.f;
     }
 
-    float targetZoom = ((float)loadI32(0, STATE_ZOOM)) / 10.f;
+
+    float targetZoom = ((float)loadI32(0, STATE_ZOOM)) / 1000.f;
     float zoom = filter(loadF(2, SCRATCH_ZOOM), targetZoom, 0.15 * touchCut);
     storeF(2, SCRATCH_ZOOM, zoom);
 
@@ -59,7 +69,8 @@
     rot = rot * scale;
     float rotStep = 20.0f / 180.0f * 3.14f * scale;
     rowCount = 4;
-    iconCount = 32;//loadI32(0, 1);
+    int index = 0;
+    int iconCount = loadI32(0, STATE_COUNT);
     while (iconCount) {
         float tmpSin = sinf(rot);
         float tmpCos = cosf(rot);
@@ -70,15 +81,20 @@
         float tz2 = tz1 - (tmpSin * scale * 2.f);
 
         int y;
-        for (y = 0; (y < rowCount) && iconCount; y++) {
+        for (y = rowCount -1; (y >= 0) && iconCount; y--) {
             float ty1 = ((y * 3.0f) - 4.5f) * scale;
             float ty2 = ty1 + scale * 2.f;
             pfBindTexture(NAMED_PF, 0, loadI32(1, y));
+            color(1.0f, 1.0f, 1.0f, 1.0f);
+            if (done && (index != selectedID)) {
+                color(0.4f, 0.4f, 0.4f, 1.0f);
+            }
             drawQuad(tx1, ty1, tz1,
                      tx2, ty1, tz2,
                      tx2, ty2, tz2,
                      tx1, ty2, tz1);
             iconCount--;
+            index++;
         }
         rot = rot + rotStep;
     }
diff --git a/java/Rollo/src/com/android/rollo/RolloRS.java b/java/Rollo/src/com/android/rollo/RolloRS.java
index eb8189a..8f48335 100644
--- a/java/Rollo/src/com/android/rollo/RolloRS.java
+++ b/java/Rollo/src/com/android/rollo/RolloRS.java
@@ -38,11 +38,11 @@
 import android.view.MotionEvent;
 
 public class RolloRS {
-    public static final int STATE_POS_X = 0;
-    public static final int STATE_POS_Y = 1;
-    public static final int STATE_PRESSURE = 2;
+    //public static final int STATE_SELECTED_ID = 0;
+    public static final int STATE_DONE = 1;
+    //public static final int STATE_PRESSURE = 2;
     public static final int STATE_ZOOM = 3;
-    public static final int STATE_WARP = 4;
+    //public static final int STATE_WARP = 4;
     public static final int STATE_ORIENTATION = 5;
     public static final int STATE_SELECTION = 6;
     public static final int STATE_FIRST_VISIBLE = 7;
@@ -61,7 +61,7 @@
     }
 
     public void setPosition(float column) {
-        mAllocStateBuf[STATE_FIRST_VISIBLE] = (int)(column * 20);
+        mAllocStateBuf[STATE_FIRST_VISIBLE] = (int)(column * (-20));
         mAllocState.data(mAllocStateBuf);
     }
 
@@ -73,23 +73,22 @@
     public void setZoom(float z) {
         //Log.e("rs", "zoom " + Float.toString(z));
 
-        mAllocStateBuf[STATE_ZOOM] = (int)(z * 10.f);
+        mAllocStateBuf[STATE_ZOOM] = (int)(z * 1000.f);
         mAllocState.data(mAllocStateBuf);
     }
 
-    public void setCurve(float c) {
-        mAllocStateBuf[STATE_WARP] = (int)(c * 100);
-        Log.e("rs", "curve " + Integer.toString(mAllocStateBuf[STATE_WARP]));
+    public void setSelected(int index) {
+        Log.e("rs",  "setSelected " + Integer.toString(index));
+
+        mAllocStateBuf[STATE_SELECTION] = index;
+        mAllocStateBuf[STATE_DONE] = 1;
         mAllocState.data(mAllocStateBuf);
     }
 
 
     private Resources mRes;
     private RenderScript mRS;
-
-
     private RenderScript.Script mScript;
-
     private RenderScript.Sampler mSampler;
     private RenderScript.ProgramFragmentStore mPFSBackground;
     private RenderScript.ProgramFragment mPFBackground;
@@ -123,13 +122,10 @@
 
         mRS.programFragmentBegin(null, null);
         mRS.programFragmentSetTexEnable(0, true);
-        //mRS.programFragmentSetTexEnable(1, true);
-        //mRS.programFragmentSetEnvMode(0, RS_TEX_ENV_MODE_REPLACE);
-        //mRS.programFragmentSetEnvMode(1, RS_TEX_ENV_MODE_MODULATE);
+        mRS.programFragmentSetTexEnvMode(0, RenderScript.EnvMode.MODULATE);
         mPFImages = mRS.programFragmentCreate();
         mPFImages.setName("PF");
         mPFImages.bindSampler(mSampler, 0);
-        mPFImages.bindSampler(mSampler, 1);
 
         mRS.programFragmentStoreBegin(null, null);
         mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.LESS);
diff --git a/java/Rollo/src/com/android/rollo/RolloView.java b/java/Rollo/src/com/android/rollo/RolloView.java
index 5f11a1f..eefebf8 100644
--- a/java/Rollo/src/com/android/rollo/RolloView.java
+++ b/java/Rollo/src/com/android/rollo/RolloView.java
@@ -40,8 +40,8 @@
 import android.view.MotionEvent;
 import android.graphics.PixelFormat;
 
-public class RolloView extends RSSurfaceView {
 
+public class RolloView extends RSSurfaceView {
     public RolloView(Context context) {
         super(context);
         setFocusable(true);
@@ -68,13 +68,48 @@
     }
 
     boolean mControlMode = false;
+    boolean mZoomMode = false;
     boolean mFlingMode = false;
     float mFlingX = 0;
     float mFlingY = 0;
     float mColumn = -1;
-    float mCurve = 1;
+    float mOldColumn;
     float mZoom = 1;
 
+    int mIconCount = 38;
+    int mRows = 4;
+    int mColumns = (mIconCount + mRows - 1) / mRows;
+
+    float mMaxZoom = ((float)mColumns) / 3.f;
+
+
+    void setColumn(boolean clamp)
+    {
+        //Log.e("rs", " col = " + Float.toString(mColumn));
+        float c = mColumn;
+        if(c > (mColumns -2)) {
+            c = (mColumns -2);
+        }
+        if(c < 1) {
+            c = 1;
+        }
+        mRender.setPosition(c);
+        if(clamp) {
+            mColumn = c;
+        }
+    }
+
+    void computeSelection(float x, float y)
+    {
+        float col = mColumn + (x - 0.5f) * 3;
+        int iCol = (int)(col + 0.25f);
+
+        float row = (y / 0.8f) * mRows;
+        int iRow = (int)(row - 0.25f);
+
+        mRender.setSelected(iCol * mRows + iRow);
+    }
+
     @Override
     public boolean onTouchEvent(MotionEvent ev)
     {
@@ -95,61 +130,53 @@
             // Projector control
             if((nx > 0.2f) && (nx < 0.8f) || mControlMode) {
                 if(act != ev.ACTION_UP) {
-                    float zoom = 5.f;//1.f + 10.f * ev.getSize();
+                    float zoom = mMaxZoom;
                     if(mControlMode) {
+                        if(!mZoomMode) {
+                            zoom = 1.f;
+                        }
                         float dx = nx - mFlingX;
 
-                        if(ny < 0.9) {
-                            zoom = 5.f - ((0.9f - ny) * 15.f);
+                        if((ny < 0.9) && mZoomMode) {
+                            zoom = mMaxZoom - ((0.9f - ny) * 10.f);
                             if(zoom < 1) {
                                 zoom = 1;
-                                mControlMode = false;
+                                mZoomMode = false;
                             }
+                            mOldColumn = mColumn;
                         }
-                        mColumn += -dx * 2.3;// * zoom;
-                        mColumn += -(mZoom - zoom) * (nx - 0.5f) * 2 * zoom;
-                        mZoom = zoom;
-
-                        if(mColumn > 1) {
-                            mColumn = 1;
+                        mColumn += dx * 4;// * zoom;
+                        if(zoom > 1.01f) {
+                            mColumn += (mZoom - zoom) * (nx - 0.5f) * 4 * zoom;
                         }
-                        mRender.setPosition(mColumn);
                     } else {
+                        mOldColumn = mColumn;
+                        mColumn = ((float)mColumns) / 2;
                         mControlMode = true;
-                        mZoom = 5;
+                        mZoomMode = true;
                     }
+                    mZoom = zoom;
                     mFlingX = nx;
                     mRender.setZoom(zoom);
                 } else {
+                    if(mControlMode && (mZoom < 1.01f)) {
+                        computeSelection(nx, ny);
+                    }
                     mControlMode = false;
+                    mColumn = mOldColumn;
                     mRender.setZoom(1.f);
                 }
             } else {
-                if(nx > 0.2f) {
-                    mCurve += 0.1f;
-                    if(mCurve > 2) {
-                        mCurve = 2;
-                    }
-                }
-                if(nx < 0.8f) {
-                    mCurve -= 0.1f;
-                    if(mCurve < (-2)) {
-                        mCurve = -2;
-                    }
-                }
-                mRender.setCurve(mCurve);
+                // Do something with corners here....
             }
+            setColumn(true);
 
         } else {
             // icon control
             if(act != ev.ACTION_UP) {
                 if(mFlingMode) {
-                    float dx = nx - mFlingX;
-                    mColumn += dx * 5;
-                    if(mColumn > 1) {
-                        mColumn = 1;
-                    }
-                    mRender.setPosition(mColumn);
+                    mColumn += (mFlingX - nx) * 5;
+                    setColumn(true);
                 }
                 mFlingMode = true;
                 mFlingX = nx;
@@ -175,7 +202,7 @@
 
         return true;
     }
-       
+
 }
 
 
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 82bad7c..e9fc4d0 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -197,7 +197,7 @@
 }
 
 
-extern "C" void color(float r, float g, float b, float a)
+static void SC_color(float r, float g, float b, float a)
 {
     glColor4f(r, g, b, a);
 }
@@ -253,15 +253,17 @@
     glDisable(p);
 }
 
-extern "C" uint32_t scriptRand(uint32_t max)
+static float SC_randf(float max)
 {
-    return (uint32_t)(((float)rand()) * max / RAND_MAX);
+    float r = (float)rand();
+    return r / RAND_MAX * max;
 }
 
 // Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a
-extern "C" void drawTriangleArray(RsAllocation alloc, uint32_t count)
+static void SC_drawTriangleArray(int ialloc, uint32_t count)
 {
     GET_TLS();
+    RsAllocation alloc = (RsAllocation)ialloc;
 
     const Allocation *a = (const Allocation *)alloc;
     const uint32_t *ptr = (const uint32_t *)a->getPtr();
@@ -398,7 +400,8 @@
 }
 
 
-static rsc_FunctionTable scriptCPtrTable = {
+static rsc_FunctionTable scriptCPtrTable;
+/* = {
     loadVp,
     SC_loadF,
     SC_loadI32,
@@ -424,7 +427,7 @@
     matrixScale,
     matrixTranslate,
 
-    color,
+    SC_color,
 
     pfBindTexture,
     pfBindSampler,
@@ -437,7 +440,7 @@
     enable,
     disable,
 
-    scriptRand,
+    SC_randf,
     contextBindProgramFragment,
     contextBindProgramFragmentStore,
 
@@ -445,11 +448,11 @@
     renderTriangleMesh,
     renderTriangleMeshRange,
 
-    drawTriangleArray,
+    SC_drawTriangleArray,
     drawRect
 
 };
-
+*/
 
 bool ScriptC::run(Context *rsc, uint32_t launchIndex)
 {
@@ -503,18 +506,29 @@
 }
 
 ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
+    // IO
     { "loadI32", (void *)&SC_loadI32, "int loadI32(int, int)" },
+    //{ "loadU32", (void *)&SC_loadU32, "unsigned int loadU32(int, int)" },
     { "loadF", (void *)&SC_loadF, "float loadF(int, int)" },
     { "storeI32", (void *)&SC_storeI32, "void storeI32(int, int, int)" },
+    //{ "storeU32", (void *)&SC_storeU32, "void storeU32(int, int, unsigned int)" },
     { "storeF", (void *)&SC_storeF, "void storeF(int, int, float)" },
-    { "drawQuad", (void *)&SC_drawQuad, "void drawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
+
+    // math
     { "sinf", (void *)&sinf, "float sinf(float)" },
     { "cosf", (void *)&cosf, "float cosf(float)" },
     { "fabs", (void *)&fabs, "float fabs(float)" },
+    { "randf", (void *)&SC_randf, "float randf(float)" },
+
+    // context
+    { "drawQuad", (void *)&SC_drawQuad, "void drawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
     { "contextBindProgramFragmentStore", (void *)&contextBindProgramFragmentStore, "void contextBindProgramFragmentStore(int)" },
     { "pfClearColor", (void *)&pfClearColor, "void pfClearColor(float, float, float, float)" },
     { "pfBindTexture", (void *)&pfBindTexture, "void pfBindTexture(int, int, int)" },
 
+    { "color", (void *)&SC_color, "void color(float, float, float, float)" },
+    { "drawTriangleArray", (void *)&SC_drawTriangleArray, "void drawTriangleArray(int ialloc, int count)" },
+
 
     { NULL, NULL, NULL }
 };