Project

General

Profile

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

examples / src / main / java / org / distorted / examples / deform / DeformActivity.java @ 107e4b72

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 427ab7bf Leszek Koltunski
20 5068fa06 Leszek Koltunski
package org.distorted.examples.deform;
21 427ab7bf Leszek Koltunski
22 01782e85 Leszek Koltunski
import org.distorted.library.main.Distorted;
23 5068fa06 Leszek Koltunski
import org.distorted.examples.R;
24 42f65cb4 Leszek Koltunski
import org.distorted.library.effect.EffectName;
25 427ab7bf Leszek Koltunski
26
import android.app.Activity;
27
import android.opengl.GLSurfaceView;
28
import android.os.Bundle;
29
import android.view.View;
30
import android.widget.RadioButton;
31
import android.widget.SeekBar;
32
import android.widget.TextView;
33
import android.widget.SeekBar.OnSeekBarChangeListener;
34
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37
public class DeformActivity extends Activity implements OnSeekBarChangeListener
38
{
39
    private TextView textR;
40 42f65cb4 Leszek Koltunski
    private EffectName mCurrEffect;
41 7abd1d00 Leszek Koltunski
42 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
43
    
44
    @Override
45 baeda47e Leszek Koltunski
    protected void onCreate(Bundle savedState)
46 427ab7bf Leszek Koltunski
      {
47 baeda47e Leszek Koltunski
      super.onCreate(savedState);
48 427ab7bf Leszek Koltunski
      setContentView(R.layout.deformlayout);
49 7abd1d00 Leszek Koltunski
50 427ab7bf Leszek Koltunski
      textR = (TextView)findViewById(R.id.deformTextRadius);
51 30c71dd5 Leszek Koltunski
52 baeda47e Leszek Koltunski
      SeekBar barR = (SeekBar)findViewById(R.id.deformSeekRadius);
53
      barR.setOnSeekBarChangeListener(this);
54
55
      if( savedState==null )
56
        {
57
        barR.setProgress(50);
58
        RadioButton effect = (RadioButton)findViewById(R.id.deformDistortButton);
59
        effect.setChecked(true);
60
        Distort(null);
61
        }
62 427ab7bf Leszek Koltunski
      }
63
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
    
66
    @Override
67
    protected void onPause() 
68
      {
69 30c71dd5 Leszek Koltunski
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
70
71 b0ebdf5e Leszek Koltunski
      Distorted.onPause();
72 30c71dd5 Leszek Koltunski
      view.onPause();
73 427ab7bf Leszek Koltunski
      super.onPause();
74
      }
75
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
    
78
    @Override
79
    protected void onResume() 
80
      {
81
      super.onResume();
82
      
83 30c71dd5 Leszek Koltunski
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.deformSurfaceView);
84
      view.onResume();
85 427ab7bf Leszek Koltunski
      }
86
 
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
    
89
    @Override
90
    protected void onDestroy() 
91
      {
92 7abd1d00 Leszek Koltunski
      Distorted.onDestroy();
93 427ab7bf Leszek Koltunski
      super.onDestroy();
94
      }
95
 
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97
    
98
    public void Distort(View v)
99
      {
100 30c71dd5 Leszek Koltunski
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
101 42f65cb4 Leszek Koltunski
      view.getRenderer().setMode(EffectName.DISTORT);
102
      mCurrEffect = EffectName.DISTORT;
103 427ab7bf Leszek Koltunski
      }     
104
    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
107
    public void Deform(View v)
108
      {
109 30c71dd5 Leszek Koltunski
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
110 42f65cb4 Leszek Koltunski
      view.getRenderer().setMode(EffectName.DEFORM);
111
      mCurrEffect = EffectName.DEFORM;
112 427ab7bf Leszek Koltunski
      }       
113
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
116
    public void Shear(View v)
117
      {
118 30c71dd5 Leszek Koltunski
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
119 42f65cb4 Leszek Koltunski
      view.getRenderer().setMode(EffectName.SHEAR);
120
      mCurrEffect = EffectName.SHEAR;
121 427ab7bf Leszek Koltunski
      }       
122 baeda47e Leszek Koltunski
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125
    @Override
126
    public void onSaveInstanceState(Bundle savedInstanceState)
127
      {
128
      super.onSaveInstanceState(savedInstanceState);
129
      savedInstanceState.putInt("effect", mCurrEffect.ordinal() );
130
      }
131
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
134
    @Override
135
    public void onRestoreInstanceState(Bundle savedInstanceState)
136
      {
137
      super.onRestoreInstanceState(savedInstanceState);
138
139
      int effect = savedInstanceState.getInt("effect");
140
141 42f65cb4 Leszek Koltunski
      if( effect == EffectName.DISTORT.ordinal() ) Distort(null);
142
      if( effect == EffectName.DEFORM.ordinal()  ) Deform(null);
143
      if( effect == EffectName.SHEAR.ordinal()   ) Shear(null);
144 baeda47e Leszek Koltunski
      }
145
146 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
147
    
148
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
149
      {
150
      switch (bar.getId()) 
151
        {
152 30c71dd5 Leszek Koltunski
        case R.id.deformSeekRadius: DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
153
                                    view.getRenderer().setRegionRadius(progress);
154 6f3024ae Leszek Koltunski
                                    textR.setText(getString(R.string.radius_placeholder,(progress<100 ? (""+progress): "Infinity") ));
155 30c71dd5 Leszek Koltunski
                                    break;
156 427ab7bf Leszek Koltunski
        }
157
      }
158
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
161
    public void onStartTrackingTouch(SeekBar bar) { }
162
    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
165
    public void onStopTrackingTouch(SeekBar bar)  { }
166
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
    
169
}