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