Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effectqueue / EffectQueueSurfaceView.java @ 1585ba24

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.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLSurfaceView;
26
import android.view.MotionEvent;
27
import android.util.AttributeSet;
28

    
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 static final int RADIUS = EffectQueueRenderer.BWID/6;
45

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

    
54
  private final static Static3D mRED    = new Static3D(1,0,0);
55
  private final static Static3D mREGION = new Static3D(RADIUS,RADIUS,RADIUS);
56

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

    
68
    mInterD = new Dynamic3D(duration,count);
69

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

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

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

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

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

    
91
    if(!isInEditMode())
92
      {
93
      setFocusable(true);
94
      setFocusableInTouchMode(true);
95
      mRenderer = new EffectQueueRenderer(this);
96
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
97
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
98
      setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
99
      setRenderer(mRenderer);
100
      mRegionV= new Static4D(0,0,0,RADIUS);
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
                                    EffectQueueActivity act = (EffectQueueActivity)getContext();
139

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

    
164
                                    break;
165
      }
166

    
167
    return true;
168
    }
169

    
170
  }
(3-3/3)