Project

General

Profile

Download (7.4 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / effectqueue / EffectQueueSurfaceView.java @ 8dfa45c4

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.effect.EffectName;
28
import org.distorted.library.effect.EffectType;
29
import org.distorted.library.effect.FragmentEffectAlpha;
30
import org.distorted.library.effect.FragmentEffectChroma;
31
import org.distorted.library.effect.FragmentEffectSaturation;
32
import org.distorted.library.effect.VertexEffectDistort;
33
import org.distorted.library.effect.VertexEffectSink;
34
import org.distorted.library.type.Dynamic1D;
35
import org.distorted.library.type.Static1D;
36
import org.distorted.library.type.Static3D;
37
import org.distorted.library.type.Static4D;
38
import org.distorted.library.type.Dynamic3D;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
public class EffectQueueSurfaceView extends GLSurfaceView
43
  {
44
  private EffectQueueRenderer mRenderer;
45
  private int mCurrentEffect;
46
  private int mScrW, mScrH;
47
    
48
  private Static4D mRegionV, mRegionF;
49
  private Static3D mPoint;
50
  private Dynamic1D mInterA, mInterB, mInterC, mInterS;
51
  private Dynamic3D mInterD;
52

    
53
  private final static Static3D mRED = new Static3D(1,0,0);
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
    
57
  public EffectQueueSurfaceView(Context context, AttributeSet attrs)
58
    {
59
    super(context, attrs);
60
      
61
    int duration = 10000;
62
    float count  = 1.0f;
63
    int h = 30;
64
    int r = 20;
65

    
66
    mInterD = new Dynamic3D(duration,count);
67

    
68
    mInterD.add(new Static3D( 0, r, h ));
69
    mInterD.add(new Static3D(-r, 0, h ));
70
    mInterD.add(new Static3D( 0,-r, h ));
71
    mInterD.add(new Static3D( r, 0, h ));
72

    
73
    mInterA = new Dynamic1D(duration,count);
74
    mInterA.add(new Static1D(1));
75
    mInterA.add(new Static1D(0));
76

    
77
    mInterS = new Dynamic1D(duration,count);
78
    mInterS.add(new Static1D(1.0f));
79
    mInterS.add(new Static1D(0.3f));
80

    
81
    mInterC = new Dynamic1D(duration,count);
82
    mInterC.add(new Static1D(1));
83
    mInterC.add(new Static1D(0));
84

    
85
    mInterB = new Dynamic1D(duration,count);
86
    mInterB.add(new Static1D(0));
87
    mInterB.add(new Static1D(1));
88

    
89
    if(!isInEditMode())
90
      {
91
      setFocusable(true);
92
      setFocusableInTouchMode(true);
93

    
94
      mRenderer = new EffectQueueRenderer(this);
95
      setRenderer(mRenderer);
96

    
97
      mPoint  = new Static3D(0,0,0);
98
      mRegionV= new Static4D(0,0,60,60);
99
      mRegionF= new Static4D(0,0,60,60);
100
        
101
      setEffect(0);  
102
      }
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  EffectQueueRenderer getRenderer()
108
    {
109
    return mRenderer;
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public void setScreenSize(int width, int height)
115
    {
116
    mScrW = width;
117
    mScrH = height;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  public void setEffect(int effect)
123
    {
124
    mCurrentEffect = effect;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
    
129
  @Override public boolean onTouchEvent(MotionEvent event) 
130
    {
131
    int x,y,action = event.getAction();
132
    boolean success;
133

    
134
    switch(action)
135
      {
136
      case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW;
137
                                    y = (int)event.getY()* mRenderer.BHEI/mScrH;
138
                                    mPoint.set(x,y,0);
139
                                    mRegionF.set(x,y,60,60);
140
                                    EffectQueueActivity act = (EffectQueueActivity)getContext();
141

    
142
                                    switch(mCurrentEffect)
143
                                      {
144
                                      case 0: VertexEffectDistort distort = new VertexEffectDistort(mInterD, mPoint, mRegionV);
145
                                              success = mRenderer.getEffects().apply(distort);
146
                                              act.effectAdded(success,distort);
147
                                              break;
148
                                      case 1: VertexEffectSink sink = new VertexEffectSink(mInterS, mPoint, mRegionV);
149
                                              success = mRenderer.getEffects().apply(sink);
150
                                              act.effectAdded(success,sink);
151
                                              break;
152
                                      case 2: FragmentEffectAlpha alpha = new FragmentEffectAlpha(mInterA, mRegionF, true);
153
                                              success = mRenderer.getEffects().apply(alpha);
154
                                              act.effectAdded(success,alpha);
155
                                              break;
156
                                      case 3: FragmentEffectSaturation saturation = new FragmentEffectSaturation(mInterB, mRegionF, false);
157
                                              success = mRenderer.getEffects().apply(saturation);
158
                                              act.effectAdded(success,saturation);
159
                                              break;
160
                                      case 4: FragmentEffectChroma chroma = new FragmentEffectChroma(mInterC, mRED, mRegionF, true);
161
                                              success = mRenderer.getEffects().apply(chroma);
162
                                              act.effectAdded(success,chroma);
163
                                              break;
164
                                      }
165

    
166
                                    break;
167
      }
168

    
169
    return true;
170
    }
171

    
172
  }
(3-3/3)