1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.scratchpad;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
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 |
59759251
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic1D;
|
29 |
|
|
import org.distorted.library.type.Static1D;
|
30 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static2D;
|
31 |
|
|
import org.distorted.library.type.Static3D;
|
32 |
|
|
import org.distorted.library.type.Static4D;
|
33 |
|
|
import org.distorted.library.type.Dynamic3D;
|
34 |
427ab7bf
|
Leszek Koltunski
|
|
35 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
427ab7bf
|
Leszek Koltunski
|
|
37 |
|
|
public class ScratchpadSurfaceView extends GLSurfaceView
|
38 |
bc0a685b
|
Leszek Koltunski
|
{
|
39 |
|
|
private ScratchpadRenderer mRenderer;
|
40 |
|
|
private static int mCurrentEffect;
|
41 |
|
|
private static int mDuration;
|
42 |
|
|
private static float mCount;
|
43 |
|
|
private static int mScrW, mScrH;
|
44 |
427ab7bf
|
Leszek Koltunski
|
|
45 |
7589635e
|
Leszek Koltunski
|
private static Static4D region;
|
46 |
|
|
private static Static2D point;
|
47 |
59759251
|
Leszek Koltunski
|
|
48 |
|
|
private static Static4D mRegion;
|
49 |
b5cc7760
|
Leszek Koltunski
|
private static Dynamic1D mInterA, mInterM, mInterB, mInterS;
|
50 |
59759251
|
Leszek Koltunski
|
|
51 |
|
|
private static Dynamic3D mInterD;
|
52 |
7589635e
|
Leszek Koltunski
|
private static Static3D v0, v1, v2, v3;
|
53 |
427ab7bf
|
Leszek Koltunski
|
|
54 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
427ab7bf
|
Leszek Koltunski
|
|
56 |
bc0a685b
|
Leszek Koltunski
|
public ScratchpadSurfaceView(Context c, AttributeSet attrs)
|
57 |
|
|
{
|
58 |
|
|
super(c, attrs);
|
59 |
427ab7bf
|
Leszek Koltunski
|
|
60 |
bc0a685b
|
Leszek Koltunski
|
mDuration = 10000;
|
61 |
|
|
mCount = 1.0f;
|
62 |
427ab7bf
|
Leszek Koltunski
|
|
63 |
59759251
|
Leszek Koltunski
|
mInterD = new Dynamic3D();
|
64 |
|
|
mInterD.setDuration(mDuration);
|
65 |
|
|
mInterD.setCount(mCount);
|
66 |
|
|
|
67 |
|
|
int h = 30;
|
68 |
|
|
int r = 20;
|
69 |
|
|
|
70 |
|
|
v0 = new Static3D( 0, r, h );
|
71 |
|
|
v1 = new Static3D(-r, 0, h );
|
72 |
|
|
v2 = new Static3D( 0,-r, h );
|
73 |
|
|
v3 = new Static3D( r, 0, h );
|
74 |
|
|
|
75 |
|
|
mInterD.add(v0);
|
76 |
|
|
mInterD.add(v1);
|
77 |
|
|
mInterD.add(v2);
|
78 |
|
|
mInterD.add(v3);
|
79 |
|
|
|
80 |
|
|
mInterA = new Dynamic1D();
|
81 |
|
|
mInterA.setDuration(mDuration);
|
82 |
|
|
mInterA.setCount(mCount);
|
83 |
|
|
mInterA.add(new Static1D(1));
|
84 |
|
|
mInterA.add(new Static1D(0));
|
85 |
|
|
|
86 |
b5cc7760
|
Leszek Koltunski
|
mInterS = new Dynamic1D();
|
87 |
|
|
mInterS.setDuration(mDuration);
|
88 |
|
|
mInterS.setCount(mCount);
|
89 |
|
|
mInterS.add(new Static1D(1.0f));
|
90 |
|
|
mInterS.add(new Static1D(0.3f));
|
91 |
|
|
|
92 |
59759251
|
Leszek Koltunski
|
mInterB = new Dynamic1D();
|
93 |
|
|
mInterB.setDuration(mDuration);
|
94 |
|
|
mInterB.setCount(mCount);
|
95 |
|
|
mInterB.add(new Static1D(1));
|
96 |
|
|
mInterB.add(new Static1D(0));
|
97 |
|
|
|
98 |
|
|
mInterM = new Dynamic1D();
|
99 |
|
|
mInterM.setDuration(mDuration);
|
100 |
|
|
mInterM.setCount(mCount);
|
101 |
|
|
mInterM.add(new Static1D(1));
|
102 |
|
|
mInterM.add(new Static1D(10));
|
103 |
427ab7bf
|
Leszek Koltunski
|
|
104 |
bc0a685b
|
Leszek Koltunski
|
if(!isInEditMode())
|
105 |
|
|
{
|
106 |
|
|
setFocusable(true);
|
107 |
|
|
setFocusableInTouchMode(true);
|
108 |
|
|
|
109 |
|
|
setEGLContextClientVersion(2);
|
110 |
427ab7bf
|
Leszek Koltunski
|
|
111 |
bc0a685b
|
Leszek Koltunski
|
if( Build.FINGERPRINT.startsWith("generic") ) // when running on the emulator, insert a magic line that is
|
112 |
|
|
{ // supposed to cure the 'no config chosen' crash on emulator startup
|
113 |
|
|
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
|
114 |
|
|
}
|
115 |
427ab7bf
|
Leszek Koltunski
|
|
116 |
bc0a685b
|
Leszek Koltunski
|
mRenderer = new ScratchpadRenderer(this);
|
117 |
|
|
setRenderer(mRenderer);
|
118 |
427ab7bf
|
Leszek Koltunski
|
|
119 |
7589635e
|
Leszek Koltunski
|
point = new Static2D(0,0);
|
120 |
|
|
region= new Static4D(0,0,60,60);
|
121 |
59759251
|
Leszek Koltunski
|
mRegion = new Static4D(0,0,60,60);
|
122 |
427ab7bf
|
Leszek Koltunski
|
|
123 |
bc0a685b
|
Leszek Koltunski
|
setEffect(0);
|
124 |
427ab7bf
|
Leszek Koltunski
|
}
|
125 |
bc0a685b
|
Leszek Koltunski
|
}
|
126 |
427ab7bf
|
Leszek Koltunski
|
|
127 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128 |
427ab7bf
|
Leszek Koltunski
|
|
129 |
bc0a685b
|
Leszek Koltunski
|
public static void setScreenSize(int width, int height)
|
130 |
|
|
{
|
131 |
|
|
mScrW = width;
|
132 |
|
|
mScrH = height;
|
133 |
|
|
}
|
134 |
427ab7bf
|
Leszek Koltunski
|
|
135 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136 |
427ab7bf
|
Leszek Koltunski
|
|
137 |
bc0a685b
|
Leszek Koltunski
|
public static int getEffect()
|
138 |
|
|
{
|
139 |
|
|
return mCurrentEffect;
|
140 |
|
|
}
|
141 |
427ab7bf
|
Leszek Koltunski
|
|
142 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143 |
427ab7bf
|
Leszek Koltunski
|
|
144 |
bc0a685b
|
Leszek Koltunski
|
public static void setEffect(int effect)
|
145 |
|
|
{
|
146 |
|
|
mCurrentEffect = effect;
|
147 |
|
|
}
|
148 |
427ab7bf
|
Leszek Koltunski
|
|
149 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150 |
427ab7bf
|
Leszek Koltunski
|
|
151 |
bc0a685b
|
Leszek Koltunski
|
public static void setDuration(int duration)
|
152 |
|
|
{
|
153 |
|
|
mDuration = duration;
|
154 |
59759251
|
Leszek Koltunski
|
mInterD.setDuration(duration);
|
155 |
|
|
mInterA.setDuration(duration);
|
156 |
|
|
mInterB.setDuration(duration);
|
157 |
|
|
mInterM.setDuration(duration);
|
158 |
b5cc7760
|
Leszek Koltunski
|
mInterS.setDuration(duration);
|
159 |
bc0a685b
|
Leszek Koltunski
|
}
|
160 |
427ab7bf
|
Leszek Koltunski
|
|
161 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162 |
427ab7bf
|
Leszek Koltunski
|
|
163 |
bc0a685b
|
Leszek Koltunski
|
public static void setCount(float count)
|
164 |
|
|
{
|
165 |
|
|
mCount = count;
|
166 |
59759251
|
Leszek Koltunski
|
mInterD.setCount(count);
|
167 |
|
|
mInterA.setCount(count);
|
168 |
|
|
mInterB.setCount(count);
|
169 |
|
|
mInterM.setCount(count);
|
170 |
b5cc7760
|
Leszek Koltunski
|
mInterS.setCount(count);
|
171 |
bc0a685b
|
Leszek Koltunski
|
}
|
172 |
427ab7bf
|
Leszek Koltunski
|
|
173 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
427ab7bf
|
Leszek Koltunski
|
|
175 |
bc0a685b
|
Leszek Koltunski
|
@Override public boolean onTouchEvent(MotionEvent event)
|
176 |
|
|
{
|
177 |
|
|
int action = event.getAction();
|
178 |
|
|
int x, y;
|
179 |
427ab7bf
|
Leszek Koltunski
|
|
180 |
bc0a685b
|
Leszek Koltunski
|
switch(action)
|
181 |
427ab7bf
|
Leszek Koltunski
|
{
|
182 |
|
|
case MotionEvent.ACTION_DOWN: x = (int)event.getX()*ScratchpadRenderer.BWID/mScrW;
|
183 |
|
|
y = (int)event.getY()*ScratchpadRenderer.BHEI/mScrH;
|
184 |
|
|
point.set(x,y);
|
185 |
59759251
|
Leszek Koltunski
|
mRegion.set(x,y,60,60);
|
186 |
|
|
|
187 |
427ab7bf
|
Leszek Koltunski
|
switch(mCurrentEffect)
|
188 |
|
|
{
|
189 |
b5cc7760
|
Leszek Koltunski
|
case 0: ScratchpadRenderer.mBackground.distort(mInterD, point, region);
|
190 |
427ab7bf
|
Leszek Koltunski
|
break;
|
191 |
b5cc7760
|
Leszek Koltunski
|
case 1: ScratchpadRenderer.mBackground.sink(mInterS, point, region);
|
192 |
427ab7bf
|
Leszek Koltunski
|
break;
|
193 |
59759251
|
Leszek Koltunski
|
case 2: ScratchpadRenderer.mBackground.alpha(mInterA, mRegion, false);
|
194 |
427ab7bf
|
Leszek Koltunski
|
break;
|
195 |
59759251
|
Leszek Koltunski
|
case 3: ScratchpadRenderer.mBackground.macroblock(mInterM, mRegion);
|
196 |
427ab7bf
|
Leszek Koltunski
|
break;
|
197 |
59759251
|
Leszek Koltunski
|
case 4: ScratchpadRenderer.mBackground.brightness(mInterB, mRegion, false);
|
198 |
427ab7bf
|
Leszek Koltunski
|
break;
|
199 |
|
|
}
|
200 |
|
|
break;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
bc0a685b
|
Leszek Koltunski
|
return true;
|
204 |
|
|
}
|
205 |
427ab7bf
|
Leszek Koltunski
|
}
|