Project

General

Profile

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

examples / src / main / java / org / distorted / examples / deform / DeformActivity.java @ 42ec9110

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.deform;
21

    
22
import org.distorted.library.main.DistortedLibrary;
23
import org.distorted.examples.R;
24
import org.distorted.library.effect.EffectName;
25

    
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
    private EffectName mCurrEffect;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
    
44
    @Override
45
    protected void onCreate(Bundle savedState)
46
      {
47
      super.onCreate(savedState);
48
      DistortedLibrary.onCreate();
49
      setContentView(R.layout.deformlayout);
50

    
51
      textR = findViewById(R.id.deformTextRadius);
52

    
53
      SeekBar barR = findViewById(R.id.deformSeekRadius);
54
      barR.setOnSeekBarChangeListener(this);
55

    
56
      if( savedState==null )
57
        {
58
        barR.setProgress(50);
59
        RadioButton effect = findViewById(R.id.deformDistortButton);
60
        effect.setChecked(true);
61
        Distort(null);
62
        }
63
      }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
    
67
    @Override
68
    protected void onPause() 
69
      {
70
      super.onPause();
71
      DeformSurfaceView view = findViewById(R.id.deformSurfaceView);
72
      view.onPause();
73
      DistortedLibrary.onPause();
74
      }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
    
78
    @Override
79
    protected void onResume() 
80
      {
81
      super.onResume();
82
      GLSurfaceView view = findViewById(R.id.deformSurfaceView);
83
      view.onResume();
84
      }
85
 
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87
    
88
    @Override
89
    protected void onDestroy() 
90
      {
91
      DistortedLibrary.onDestroy();
92
      super.onDestroy();
93
      }
94
 
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
    
97
    public void Distort(View v)
98
      {
99
      DeformSurfaceView view = findViewById(R.id.deformSurfaceView);
100
      view.getRenderer().setMode(EffectName.DISTORT);
101
      mCurrEffect = EffectName.DISTORT;
102
      }     
103
    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
    public void Deform(View v)
107
      {
108
      DeformSurfaceView view = findViewById(R.id.deformSurfaceView);
109
      view.getRenderer().setMode(EffectName.DEFORM);
110
      mCurrEffect = EffectName.DEFORM;
111
      }       
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
    public void Shear(View v)
116
      {
117
      DeformSurfaceView view = findViewById(R.id.deformSurfaceView);
118
      view.getRenderer().setMode(EffectName.SHEAR);
119
      mCurrEffect = EffectName.SHEAR;
120
      }       
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
    @Override
125
    public void onSaveInstanceState(Bundle savedInstanceState)
126
      {
127
      super.onSaveInstanceState(savedInstanceState);
128
      savedInstanceState.putInt("effect", mCurrEffect.ordinal() );
129
      }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
    @Override
134
    public void onRestoreInstanceState(Bundle savedInstanceState)
135
      {
136
      super.onRestoreInstanceState(savedInstanceState);
137

    
138
      int effect = savedInstanceState.getInt("effect");
139

    
140
      if( effect == EffectName.DISTORT.ordinal() ) Distort(null);
141
      if( effect == EffectName.DEFORM.ordinal()  ) Deform(null);
142
      if( effect == EffectName.SHEAR.ordinal()   ) Shear(null);
143
      }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
    
147
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
148
      {
149
      if (bar.getId() == R.id.deformSeekRadius)
150
        {
151
        DeformSurfaceView view = findViewById(R.id.deformSurfaceView);
152
        view.getRenderer().setRegionRadius(progress);
153
        textR.setText(getString(R.string.radius_placeholder,(progress<100 ? (""+progress): "Infinity") ));
154
        }
155
      }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
    public void onStartTrackingTouch(SeekBar bar) { }
160
    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
    public void onStopTrackingTouch(SeekBar bar)  { }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
    
167
}
(1-1/3)