1 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.scratchpad;
|
2 |
427ab7bf
|
Leszek Koltunski
|
|
3 |
|
|
import android.content.Context;
|
4 |
|
|
import android.opengl.GLSurfaceView;
|
5 |
|
|
import android.os.Build;
|
6 |
|
|
import android.view.MotionEvent;
|
7 |
|
|
import android.util.AttributeSet;
|
8 |
|
|
|
9 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Float2D;
|
10 |
|
|
import org.distorted.library.Float3D;
|
11 |
|
|
import org.distorted.library.Float4D;
|
12 |
|
|
import org.distorted.library.Interpolator3D;
|
13 |
427ab7bf
|
Leszek Koltunski
|
|
14 |
|
|
///////////////////////////////////////////////////////////////////
|
15 |
|
|
|
16 |
|
|
public class ScratchpadSurfaceView extends GLSurfaceView
|
17 |
|
|
{
|
18 |
|
|
private ScratchpadRenderer mRenderer;
|
19 |
|
|
private static int mCurrentEffect;
|
20 |
|
|
private static int mDuration;
|
21 |
|
|
private static float mCount;
|
22 |
|
|
private static int mScrW, mScrH;
|
23 |
|
|
|
24 |
|
|
private static Float4D region;
|
25 |
|
|
private static Float2D point;
|
26 |
|
|
|
27 |
|
|
private static Interpolator3D di;
|
28 |
|
|
private static Float3D v0, v1, v2, v3;
|
29 |
|
|
|
30 |
|
|
///////////////////////////////////////////////////////////////////
|
31 |
|
|
|
32 |
|
|
public ScratchpadSurfaceView(Context c, AttributeSet attrs)
|
33 |
|
|
{
|
34 |
|
|
super(c, attrs);
|
35 |
|
|
|
36 |
|
|
mDuration = 10000;
|
37 |
|
|
mCount = 1.0f;
|
38 |
|
|
|
39 |
|
|
di = new Interpolator3D();
|
40 |
|
|
|
41 |
|
|
di.setDuration(mDuration);
|
42 |
|
|
di.setCount(mCount);
|
43 |
|
|
|
44 |
|
|
if(!isInEditMode())
|
45 |
|
|
{
|
46 |
|
|
setFocusable(true);
|
47 |
|
|
setFocusableInTouchMode(true);
|
48 |
|
|
|
49 |
|
|
setEGLContextClientVersion(2);
|
50 |
|
|
|
51 |
|
|
if( Build.FINGERPRINT.startsWith("generic") ) // when running on the emulator, insert a magic line that is
|
52 |
|
|
{ // supposed to cure the 'no config chosen' crash on emulator startup
|
53 |
|
|
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
mRenderer = new ScratchpadRenderer(this);
|
57 |
|
|
setRenderer(mRenderer);
|
58 |
|
|
|
59 |
|
|
point = new Float2D(0,0);
|
60 |
|
|
region= new Float4D(0,0,60,60);
|
61 |
|
|
|
62 |
|
|
int h = 30;
|
63 |
|
|
int r = 20;
|
64 |
|
|
|
65 |
|
|
v0 = new Float3D( 0, r, h );
|
66 |
|
|
v1 = new Float3D(-r, 0, h );
|
67 |
|
|
v2 = new Float3D( 0,-r, h );
|
68 |
|
|
v3 = new Float3D( r, 0, h );
|
69 |
|
|
|
70 |
|
|
di.add(v0);
|
71 |
|
|
di.add(v1);
|
72 |
|
|
di.add(v2);
|
73 |
|
|
di.add(v3);
|
74 |
|
|
|
75 |
|
|
setEffect(0);
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
|
|
public static void setScreenSize(int width, int height)
|
82 |
|
|
{
|
83 |
|
|
mScrW = width;
|
84 |
|
|
mScrH = height;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
///////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
|
|
public static int getEffect()
|
90 |
|
|
{
|
91 |
|
|
return mCurrentEffect;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
///////////////////////////////////////////////////////////////////
|
95 |
|
|
|
96 |
|
|
public static void setEffect(int effect)
|
97 |
|
|
{
|
98 |
|
|
mCurrentEffect = effect;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
public static void setDuration(int duration)
|
104 |
|
|
{
|
105 |
|
|
mDuration = duration;
|
106 |
|
|
di.setDuration(duration);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
///////////////////////////////////////////////////////////////////
|
110 |
|
|
|
111 |
|
|
public static void setCount(float count)
|
112 |
|
|
{
|
113 |
|
|
mCount = count;
|
114 |
|
|
di.setCount(count);
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
///////////////////////////////////////////////////////////////////
|
118 |
|
|
|
119 |
|
|
@Override public boolean onTouchEvent(MotionEvent event)
|
120 |
|
|
{
|
121 |
|
|
int action = event.getAction();
|
122 |
|
|
int x, y;
|
123 |
|
|
|
124 |
|
|
switch(action)
|
125 |
|
|
{
|
126 |
|
|
case MotionEvent.ACTION_DOWN: x = (int)event.getX()*ScratchpadRenderer.BWID/mScrW;
|
127 |
|
|
y = (int)event.getY()*ScratchpadRenderer.BHEI/mScrH;
|
128 |
|
|
point.set(x,y);
|
129 |
|
|
|
130 |
|
|
switch(mCurrentEffect)
|
131 |
|
|
{
|
132 |
|
|
case 0: ScratchpadRenderer.mBackground.distort(di, region, point);
|
133 |
|
|
break;
|
134 |
|
|
case 1: ScratchpadRenderer.mBackground.sink(0.3f, region, point, mDuration, mCount);
|
135 |
|
|
break;
|
136 |
|
|
case 2: ScratchpadRenderer.mBackground.alpha(0.0f, region, point, mDuration, mCount);
|
137 |
|
|
break;
|
138 |
|
|
case 3: ScratchpadRenderer.mBackground.macroblock(10, region, point, mDuration, mCount);
|
139 |
|
|
break;
|
140 |
|
|
case 4: ScratchpadRenderer.mBackground.brightness(0.0f, region, point, mDuration, mCount);
|
141 |
|
|
break;
|
142 |
|
|
}
|
143 |
|
|
break;
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
return true;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
///////////////////////////////////////////////////////////////////
|
150 |
|
|
// end of file
|
151 |
|
|
|
152 |
|
|
}
|