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 |
e5424523
|
Leszek Koltunski
|
package org.distorted.examples.effects2d;
|
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 |
e5424523
|
Leszek Koltunski
|
public class Effects2DSurfaceView extends GLSurfaceView
|
38 |
bc0a685b
|
Leszek Koltunski
|
{
|
39 |
e5424523
|
Leszek Koltunski
|
private Effects2DRenderer mRenderer;
|
40 |
bc0a685b
|
Leszek Koltunski
|
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 |
f9afbbf3
|
Leszek Koltunski
|
private static Dynamic1D mInterA, mInterM, mInterC, mInterS;
|
50 |
59759251
|
Leszek Koltunski
|
|
51 |
|
|
private static Dynamic3D mInterD;
|
52 |
7589635e
|
Leszek Koltunski
|
private static Static3D v0, v1, v2, v3;
|
53 |
f9afbbf3
|
Leszek Koltunski
|
|
54 |
|
|
private final static Static3D mRED = new Static3D(1,0,0);
|
55 |
|
|
|
56 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
427ab7bf
|
Leszek Koltunski
|
|
58 |
e5424523
|
Leszek Koltunski
|
public Effects2DSurfaceView(Context c, AttributeSet attrs)
|
59 |
bc0a685b
|
Leszek Koltunski
|
{
|
60 |
|
|
super(c, attrs);
|
61 |
427ab7bf
|
Leszek Koltunski
|
|
62 |
bc0a685b
|
Leszek Koltunski
|
mDuration = 10000;
|
63 |
|
|
mCount = 1.0f;
|
64 |
427ab7bf
|
Leszek Koltunski
|
|
65 |
f988589e
|
Leszek Koltunski
|
mInterD = new Dynamic3D(mDuration,mCount);
|
66 |
59759251
|
Leszek Koltunski
|
|
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 |
f988589e
|
Leszek Koltunski
|
mInterA = new Dynamic1D(mDuration,mCount);
|
81 |
59759251
|
Leszek Koltunski
|
mInterA.add(new Static1D(1));
|
82 |
|
|
mInterA.add(new Static1D(0));
|
83 |
|
|
|
84 |
f988589e
|
Leszek Koltunski
|
mInterS = new Dynamic1D(mDuration,mCount);
|
85 |
b5cc7760
|
Leszek Koltunski
|
mInterS.add(new Static1D(1.0f));
|
86 |
|
|
mInterS.add(new Static1D(0.3f));
|
87 |
|
|
|
88 |
f9afbbf3
|
Leszek Koltunski
|
mInterC = new Dynamic1D(mDuration,mCount);
|
89 |
|
|
mInterC.add(new Static1D(1));
|
90 |
|
|
mInterC.add(new Static1D(0));
|
91 |
59759251
|
Leszek Koltunski
|
|
92 |
f988589e
|
Leszek Koltunski
|
mInterM = new Dynamic1D(mDuration,mCount);
|
93 |
59759251
|
Leszek Koltunski
|
mInterM.add(new Static1D(1));
|
94 |
|
|
mInterM.add(new Static1D(10));
|
95 |
427ab7bf
|
Leszek Koltunski
|
|
96 |
bc0a685b
|
Leszek Koltunski
|
if(!isInEditMode())
|
97 |
|
|
{
|
98 |
|
|
setFocusable(true);
|
99 |
|
|
setFocusableInTouchMode(true);
|
100 |
|
|
|
101 |
|
|
setEGLContextClientVersion(2);
|
102 |
427ab7bf
|
Leszek Koltunski
|
|
103 |
bc0a685b
|
Leszek Koltunski
|
if( Build.FINGERPRINT.startsWith("generic") ) // when running on the emulator, insert a magic line that is
|
104 |
|
|
{ // supposed to cure the 'no config chosen' crash on emulator startup
|
105 |
|
|
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
|
106 |
|
|
}
|
107 |
427ab7bf
|
Leszek Koltunski
|
|
108 |
e5424523
|
Leszek Koltunski
|
mRenderer = new Effects2DRenderer(this);
|
109 |
bc0a685b
|
Leszek Koltunski
|
setRenderer(mRenderer);
|
110 |
af225332
|
Leszek Koltunski
|
|
111 |
7589635e
|
Leszek Koltunski
|
point = new Static2D(0,0);
|
112 |
|
|
region= new Static4D(0,0,60,60);
|
113 |
59759251
|
Leszek Koltunski
|
mRegion = new Static4D(0,0,60,60);
|
114 |
427ab7bf
|
Leszek Koltunski
|
|
115 |
bc0a685b
|
Leszek Koltunski
|
setEffect(0);
|
116 |
427ab7bf
|
Leszek Koltunski
|
}
|
117 |
bc0a685b
|
Leszek Koltunski
|
}
|
118 |
427ab7bf
|
Leszek Koltunski
|
|
119 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
427ab7bf
|
Leszek Koltunski
|
|
121 |
bc0a685b
|
Leszek Koltunski
|
public static void setScreenSize(int width, int height)
|
122 |
|
|
{
|
123 |
|
|
mScrW = width;
|
124 |
|
|
mScrH = height;
|
125 |
|
|
}
|
126 |
427ab7bf
|
Leszek Koltunski
|
|
127 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128 |
427ab7bf
|
Leszek Koltunski
|
|
129 |
bc0a685b
|
Leszek Koltunski
|
public static void setEffect(int effect)
|
130 |
|
|
{
|
131 |
|
|
mCurrentEffect = effect;
|
132 |
|
|
}
|
133 |
427ab7bf
|
Leszek Koltunski
|
|
134 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
427ab7bf
|
Leszek Koltunski
|
|
136 |
bc0a685b
|
Leszek Koltunski
|
@Override public boolean onTouchEvent(MotionEvent event)
|
137 |
|
|
{
|
138 |
|
|
int action = event.getAction();
|
139 |
|
|
int x, y;
|
140 |
af225332
|
Leszek Koltunski
|
long id = -1;
|
141 |
|
|
|
142 |
bc0a685b
|
Leszek Koltunski
|
switch(action)
|
143 |
427ab7bf
|
Leszek Koltunski
|
{
|
144 |
e5424523
|
Leszek Koltunski
|
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* Effects2DRenderer.BWID/mScrW;
|
145 |
|
|
y = (int)event.getY()* Effects2DRenderer.BHEI/mScrH;
|
146 |
427ab7bf
|
Leszek Koltunski
|
point.set(x,y);
|
147 |
59759251
|
Leszek Koltunski
|
mRegion.set(x,y,60,60);
|
148 |
|
|
|
149 |
427ab7bf
|
Leszek Koltunski
|
switch(mCurrentEffect)
|
150 |
|
|
{
|
151 |
af225332
|
Leszek Koltunski
|
case 0: id = Effects2DRenderer.mBackground.distort(mInterD, point, region);
|
152 |
427ab7bf
|
Leszek Koltunski
|
break;
|
153 |
af225332
|
Leszek Koltunski
|
case 1: id = Effects2DRenderer.mBackground.sink(mInterS, point, region);
|
154 |
427ab7bf
|
Leszek Koltunski
|
break;
|
155 |
af225332
|
Leszek Koltunski
|
case 2: id = Effects2DRenderer.mBackground.alpha(mInterA, mRegion, false);
|
156 |
427ab7bf
|
Leszek Koltunski
|
break;
|
157 |
af225332
|
Leszek Koltunski
|
case 3: id = Effects2DRenderer.mBackground.macroblock(mInterM, mRegion);
|
158 |
427ab7bf
|
Leszek Koltunski
|
break;
|
159 |
af225332
|
Leszek Koltunski
|
case 4: id = Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, false);
|
160 |
427ab7bf
|
Leszek Koltunski
|
break;
|
161 |
|
|
}
|
162 |
af225332
|
Leszek Koltunski
|
|
163 |
|
|
Effects2DActivity act = (Effects2DActivity)getContext();
|
164 |
|
|
act.effectAdded(id, mCurrentEffect);
|
165 |
|
|
|
166 |
427ab7bf
|
Leszek Koltunski
|
break;
|
167 |
|
|
}
|
168 |
af225332
|
Leszek Koltunski
|
|
169 |
bc0a685b
|
Leszek Koltunski
|
return true;
|
170 |
|
|
}
|
171 |
af225332
|
Leszek Koltunski
|
|
172 |
427ab7bf
|
Leszek Koltunski
|
}
|