Project

General

Profile

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

examples / src / main / java / org / distorted / examples / flag / FlagActivity.java @ 77e66c58

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

    
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25
import android.widget.SeekBar;
26
import android.widget.TextView;
27

    
28
import org.distorted.examples.R;
29
import org.distorted.library.main.DistortedLibrary;
30
import org.distorted.library.type.Static5D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public class FlagActivity extends Activity implements SeekBar.OnSeekBarChangeListener
35
{
36
    private TextView textAmplitude, textLength, textAngleA, textAngleB;
37
    private TextView textNoiseAmplitude, textNoiseLength, textNoiseAngleA, textNoiseAngleB;
38
    private Static5D mNoise;
39
    private String mStr;
40

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

    
50
      mNoise = new Static5D(0,0,0,0,0);
51

    
52
      textAmplitude = findViewById(R.id.flagAmplitude);
53
      textLength    = findViewById(R.id.flagLength);
54
      textAngleA    = findViewById(R.id.flagAngleA);
55
      textAngleB    = findViewById(R.id.flagAngleB);
56

    
57
      SeekBar barAmplitude  = findViewById(R.id.flagSeekAmplitude);
58
      SeekBar barLength     = findViewById(R.id.flagSeekLength);
59
      SeekBar barAngleA     = findViewById(R.id.flagSeekAngleA);
60
      SeekBar barAngleB     = findViewById(R.id.flagSeekAngleB);
61

    
62
      barAmplitude.setOnSeekBarChangeListener(this);
63
      barLength.setOnSeekBarChangeListener(this);
64
      barAngleA.setOnSeekBarChangeListener(this);
65
      barAngleB.setOnSeekBarChangeListener(this);
66

    
67
      barAmplitude.setProgress(50);
68
      barLength.setProgress(50);
69
      barAngleA.setProgress(25);
70
      barAngleB.setProgress(1);
71

    
72
      textNoiseAmplitude = findViewById(R.id.flagNoiseAmplitude);
73
      textNoiseLength    = findViewById(R.id.flagNoiseLength);
74
      textNoiseAngleA    = findViewById(R.id.flagNoiseAngleA);
75
      textNoiseAngleB    = findViewById(R.id.flagNoiseAngleB);
76

    
77
      SeekBar barNoiseAmplitude = findViewById(R.id.flagSeekNoiseAmplitude);
78
      SeekBar barNoiseLength    = findViewById(R.id.flagSeekNoiseLength);
79
      SeekBar barNoiseAngleA    = findViewById(R.id.flagSeekNoiseAngleA);
80
      SeekBar barNoiseAngleB    = findViewById(R.id.flagSeekNoiseAngleB);
81

    
82
      barNoiseAmplitude.setOnSeekBarChangeListener(this);
83
      barNoiseLength.setOnSeekBarChangeListener(this);
84
      barNoiseAngleA.setOnSeekBarChangeListener(this);
85
      barNoiseAngleB.setOnSeekBarChangeListener(this);
86

    
87
      barNoiseAmplitude.setProgress( (int)mNoise.get0() );
88
      barNoiseLength.setProgress   ( (int)mNoise.get1() );
89
      barNoiseAngleA.setProgress   ( (int)mNoise.get3() );
90
      barNoiseAngleB.setProgress   ( (int)mNoise.get4() );
91

    
92
      textNoiseAmplitude.setText(getString(R.string.noise_placeholder,"0.00"));
93
      textNoiseLength.setText(getString(R.string.noise_placeholder,"0.00"));
94
      textNoiseAngleA.setText(getString(R.string.noise_placeholder,"0.00"));
95
      textNoiseAngleB.setText(getString(R.string.noise_placeholder,"0.00"));
96
      }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
    
100
    @Override
101
    protected void onPause() 
102
      {
103
      super.onPause();
104
      GLSurfaceView view = findViewById(R.id.flagSurfaceView);
105
      view.onPause();
106
      DistortedLibrary.onPause();
107
      }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
    
111
    @Override
112
    protected void onResume() 
113
      {
114
      super.onResume();
115
      GLSurfaceView view = findViewById(R.id.flagSurfaceView);
116
      view.onResume();
117
      }
118
    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
    
121
    @Override
122
    protected void onDestroy() 
123
      {
124
      DistortedLibrary.onDestroy();
125
      super.onDestroy();
126
      }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
    private void convert(int progress)
131
      {
132
           if( progress==  0 ) mStr="0.00";
133
      else if( progress==100 ) mStr="1.00";
134
      else if( progress< 10  ) mStr="0.0"+progress;
135
      else                     mStr="0."+progress;
136
      }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
141
      {
142
      FlagSurfaceView mView = findViewById(R.id.flagSurfaceView);
143
      FlagRenderer renderer = mView.getRenderer();
144

    
145
      int id = bar.getId();
146

    
147
      if( id== R.id.flagSeekAmplitude )
148
        {
149
        renderer.setAmplitude(progress);
150
        textAmplitude.setText(getString(R.string.amplitude_placeholder,progress));
151
        }
152
      if( id == R.id.flagSeekNoiseAmplitude )
153
        {
154
        mNoise.set0((float)progress/100);
155
        renderer.setNoise(mNoise);
156
        convert(progress);
157
        textNoiseAmplitude.setText(getString(R.string.noise_placeholder,mStr));
158
        }
159
      if( id == R.id.flagSeekLength )
160
        {
161
        progress = progress*2;
162
        renderer.setLength(progress);
163
        textLength.setText(getString(R.string.length_placeholder,progress));
164
        }
165
      if( id == R.id.flagSeekNoiseLength )
166
        {
167
        mNoise.set1((float)progress/100);
168
        renderer.setNoise(mNoise);
169
        convert(progress);
170
        textNoiseLength.setText(getString(R.string.noise_placeholder,mStr));
171
        }
172
      if( id == R.id.flagSeekAngleA )
173
        {
174
        progress = (360*progress)/100;
175
        renderer.setAngleA(progress);
176
        textAngleA.setText(getString(R.string.alpha_placeholder,progress));
177
        }
178
      if( id == R.id.flagSeekNoiseAngleA )
179
        {
180
        mNoise.set3((float)progress/100);
181
        renderer.setNoise(mNoise);
182
        convert(progress);
183
        textNoiseAngleA.setText(getString(R.string.noise_placeholder,mStr));
184
        }
185
      if( id == R.id.flagSeekAngleB )
186
        {
187
        progress = ((360*progress)/100);
188
        renderer.setAngleB(progress);
189
        textAngleB.setText(getString(R.string.beta_placeholder,progress));
190
        }
191
      if( id == R.id.flagSeekNoiseAngleB )
192
        {
193
        mNoise.set4((float)progress/100);
194
        renderer.setNoise(mNoise);
195
        convert(progress);
196
        textNoiseAngleB.setText(getString(R.string.noise_placeholder,mStr));
197
        }
198
      }
199

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

    
202
    public void onStartTrackingTouch(SeekBar bar) { }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
    public void onStopTrackingTouch(SeekBar bar)  { }
207

    
208
}
(1-1/3)