Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effectqueue / EffectQueueSurfaceView.java @ 30c47368

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

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class EffectQueueSurfaceView extends GLSurfaceView
41
  {
42
  private static final int RADIUS = 60;
43

    
44
  private EffectQueueRenderer mRenderer;
45
  private int mCurrentEffect;
46
  private int mScrW, mScrH;
47
    
48
  private Static4D mRegionV;
49
  private Dynamic1D mInterA, mInterB, mInterC, mInterS;
50
  private Dynamic3D mInterD;
51

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

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

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

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

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

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

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

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

    
88
    if(!isInEditMode())
89
      {
90
      setFocusable(true);
91
      setFocusableInTouchMode(true);
92
      mRenderer = new EffectQueueRenderer(this);
93
      setRenderer(mRenderer);
94
      mRegionV= new Static4D(0,0,RADIUS,RADIUS);
95
      setEffect(0);  
96
      }
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  EffectQueueRenderer getRenderer()
102
    {
103
    return mRenderer;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public void setScreenSize(int width, int height)
109
    {
110
    mScrW = width;
111
    mScrH = height;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public void setEffect(int effect)
117
    {
118
    mCurrentEffect = effect;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
    
123
  @Override public boolean onTouchEvent(MotionEvent event) 
124
    {
125
    int x,y,action = event.getAction();
126
    boolean success;
127

    
128
    switch(action)
129
      {
130
      case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW;
131
                                    y = (int)event.getY()* mRenderer.BHEI/mScrH;
132
                                    EffectQueueActivity act = (EffectQueueActivity)getContext();
133

    
134
                                    switch(mCurrentEffect)
135
                                      {
136
                                      case 0: VertexEffectDistort distort = new VertexEffectDistort(mInterD, new Static3D(x,y,0), mRegionV);
137
                                              success = mRenderer.getEffects().apply(distort);
138
                                              act.effectAdded(success,distort);
139
                                              break;
140
                                      case 1: VertexEffectSink sink = new VertexEffectSink(mInterS, new Static3D(x,y,0), mRegionV);
141
                                              success = mRenderer.getEffects().apply(sink);
142
                                              act.effectAdded(success,sink);
143
                                              break;
144
                                      case 2: FragmentEffectAlpha alpha = new FragmentEffectAlpha(mInterA, new Static4D(x,y,RADIUS,RADIUS), true);
145
                                              success = mRenderer.getEffects().apply(alpha);
146
                                              act.effectAdded(success,alpha);
147
                                              break;
148
                                      case 3: FragmentEffectSaturation saturation = new FragmentEffectSaturation(mInterB, new Static4D(x,y,RADIUS,RADIUS), false);
149
                                              success = mRenderer.getEffects().apply(saturation);
150
                                              act.effectAdded(success,saturation);
151
                                              break;
152
                                      case 4: FragmentEffectChroma chroma = new FragmentEffectChroma(mInterC, mRED, new Static4D(x,y,RADIUS,RADIUS), true);
153
                                              success = mRenderer.getEffects().apply(chroma);
154
                                              act.effectAdded(success,chroma);
155
                                              break;
156
                                      }
157

    
158
                                    break;
159
      }
160

    
161
    return true;
162
    }
163

    
164
  }
(3-3/3)