Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effectqueue / EffectQueueSurfaceView.java @ 1f9a52f1

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 context, AttributeSet attrs)
53
    {
54
    super(context, 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

    
89
      mRenderer = new EffectQueueRenderer(this);
90
      setRenderer(mRenderer);
91

    
92
      mPoint  = new Static3D(0,0,0);
93
      mRegionV= new Static4D(0,0,60,60);
94
      mRegionF= new Static4D(0,0,60,60);
95
        
96
      setEffect(0);  
97
      }
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

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

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

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

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

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

    
138
                                    switch(mCurrentEffect)
139
                                      {
140
                                      case 0: id = mRenderer.getEffects().distort(mInterD, mPoint, mRegionV);
141
                                              act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX);
142
                                              break;
143
                                      case 1: id = mRenderer.getEffects().sink(mInterS, mPoint, mRegionV);
144
                                              act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX);
145
                                              break;
146
                                      case 2: id = mRenderer.getEffects().alpha(mInterA, mRegionF, true);
147
                                              act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT);
148
                                              break;
149
                                      case 3: id = mRenderer.getEffects().saturation(mInterB, mRegionF, false);
150
                                              act.effectAdded(id, EffectNames.SATURATION, EffectTypes.FRAGMENT);
151
                                              break;
152
                                      case 4: id = mRenderer.getEffects().chroma(mInterC, mRED, mRegionF, true);
153
                                              act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT);
154
                                              break;
155
                                      }
156

    
157
                                    break;
158
      }
159

    
160
    return true;
161
    }
162

    
163
  }
(3-3/3)