1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
package org.distorted.examples.effectqueue;
|
21
|
|
22
|
import android.content.Context;
|
23
|
import android.opengl.GLSurfaceView;
|
24
|
import android.view.MotionEvent;
|
25
|
import android.util.AttributeSet;
|
26
|
|
27
|
import org.distorted.library.EffectNames;
|
28
|
import org.distorted.library.EffectTypes;
|
29
|
import org.distorted.library.type.Dynamic1D;
|
30
|
import org.distorted.library.type.Static1D;
|
31
|
import org.distorted.library.type.Static3D;
|
32
|
import org.distorted.library.type.Static4D;
|
33
|
import org.distorted.library.type.Dynamic3D;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
|
37
|
public class EffectQueueSurfaceView extends GLSurfaceView
|
38
|
{
|
39
|
private EffectQueueRenderer mRenderer;
|
40
|
private int mCurrentEffect;
|
41
|
private int mScrW, mScrH;
|
42
|
|
43
|
private Static4D mRegionV, mRegionF;
|
44
|
private Static3D mPoint;
|
45
|
private Dynamic1D mInterA, mInterB, mInterC, mInterS;
|
46
|
private Dynamic3D mInterD;
|
47
|
|
48
|
private final static Static3D mRED = new Static3D(1,0,0);
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
|
52
|
public EffectQueueSurfaceView(Context c, AttributeSet attrs)
|
53
|
{
|
54
|
super(c, attrs);
|
55
|
|
56
|
int duration = 10000;
|
57
|
float count = 1.0f;
|
58
|
int h = 30;
|
59
|
int r = 20;
|
60
|
|
61
|
mInterD = new Dynamic3D(duration,count);
|
62
|
|
63
|
mInterD.add(new Static3D( 0, r, h ));
|
64
|
mInterD.add(new Static3D(-r, 0, h ));
|
65
|
mInterD.add(new Static3D( 0,-r, h ));
|
66
|
mInterD.add(new Static3D( r, 0, h ));
|
67
|
|
68
|
mInterA = new Dynamic1D(duration,count);
|
69
|
mInterA.add(new Static1D(1));
|
70
|
mInterA.add(new Static1D(0));
|
71
|
|
72
|
mInterS = new Dynamic1D(duration,count);
|
73
|
mInterS.add(new Static1D(1.0f));
|
74
|
mInterS.add(new Static1D(0.3f));
|
75
|
|
76
|
mInterC = new Dynamic1D(duration,count);
|
77
|
mInterC.add(new Static1D(1));
|
78
|
mInterC.add(new Static1D(0));
|
79
|
|
80
|
mInterB = new Dynamic1D(duration,count);
|
81
|
mInterB.add(new Static1D(0));
|
82
|
mInterB.add(new Static1D(1));
|
83
|
|
84
|
if(!isInEditMode())
|
85
|
{
|
86
|
setFocusable(true);
|
87
|
setFocusableInTouchMode(true);
|
88
|
setEGLContextClientVersion(2);
|
89
|
|
90
|
mRenderer = new EffectQueueRenderer(this);
|
91
|
setRenderer(mRenderer);
|
92
|
|
93
|
mPoint = new Static3D(0,0,0);
|
94
|
mRegionV= new Static4D(0,0,60,60);
|
95
|
mRegionF= new Static4D(0,0,60,60);
|
96
|
|
97
|
setEffect(0);
|
98
|
}
|
99
|
}
|
100
|
|
101
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
|
103
|
EffectQueueRenderer getRenderer()
|
104
|
{
|
105
|
return mRenderer;
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
|
110
|
public void setScreenSize(int width, int height)
|
111
|
{
|
112
|
mScrW = width;
|
113
|
mScrH = height;
|
114
|
}
|
115
|
|
116
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117
|
|
118
|
public void setEffect(int effect)
|
119
|
{
|
120
|
mCurrentEffect = effect;
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
@Override public boolean onTouchEvent(MotionEvent event)
|
126
|
{
|
127
|
int action = event.getAction();
|
128
|
int x, y;
|
129
|
long id;
|
130
|
|
131
|
switch(action)
|
132
|
{
|
133
|
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW;
|
134
|
y = (int)event.getY()* mRenderer.BHEI/mScrH;
|
135
|
mPoint.set(x,y,0);
|
136
|
mRegionF.set(x,y,60,60);
|
137
|
EffectQueueActivity act = (EffectQueueActivity)getContext();
|
138
|
|
139
|
switch(mCurrentEffect)
|
140
|
{
|
141
|
case 0: id = mRenderer.getEffects().distort(mInterD, mPoint, mRegionV);
|
142
|
act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX);
|
143
|
break;
|
144
|
case 1: id = mRenderer.getEffects().sink(mInterS, mPoint, mRegionV);
|
145
|
act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX);
|
146
|
break;
|
147
|
case 2: id = mRenderer.getEffects().alpha(mInterA, mRegionF, true);
|
148
|
act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT);
|
149
|
break;
|
150
|
case 3: id = mRenderer.getEffects().saturation(mInterB, mRegionF, false);
|
151
|
act.effectAdded(id, EffectNames.SATURATION, EffectTypes.FRAGMENT);
|
152
|
break;
|
153
|
case 4: id = mRenderer.getEffects().chroma(mInterC, mRED, mRegionF, true);
|
154
|
act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT);
|
155
|
break;
|
156
|
}
|
157
|
|
158
|
break;
|
159
|
}
|
160
|
|
161
|
return true;
|
162
|
}
|
163
|
|
164
|
}
|