Project

General

Profile

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

examples / src / main / java / org / distorted / examples / flag / FlagActivity.java @ c0f27889

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
      setContentView(R.layout.flaglayout);
48

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

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

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

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

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

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

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

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

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

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

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

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

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

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

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

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

    
144
      switch (bar.getId())
145
        {
146
        case R.id.flagSeekAmplitude     : renderer.setAmplitude(progress);
147
                                          textAmplitude.setText(getString(R.string.amplitude_placeholder,progress));
148
                                          break;
149
        case R.id.flagSeekNoiseAmplitude: mNoise.set0((float)progress/100);
150
                                          renderer.setNoise(mNoise);
151
                                          convert(progress);
152
                                          textNoiseAmplitude.setText(getString(R.string.noise_placeholder,mStr));
153
                                          break;
154
        case R.id.flagSeekLength        : progress = progress*2;
155
                                          renderer.setLength(progress);
156
                                          textLength.setText(getString(R.string.length_placeholder,progress));
157
                                          break;
158
        case R.id.flagSeekNoiseLength   : mNoise.set1((float)progress/100);
159
                                          renderer.setNoise(mNoise);
160
                                          convert(progress);
161
                                          textNoiseLength.setText(getString(R.string.noise_placeholder,mStr));
162
                                          break;
163
        case R.id.flagSeekAngleA        : progress = (360*progress)/100;
164
                                          renderer.setAngleA(progress);
165
                                          textAngleA.setText(getString(R.string.alpha_placeholder,progress));
166
                                          break;
167
        case R.id.flagSeekNoiseAngleA   : mNoise.set3((float)progress/100);
168
                                          renderer.setNoise(mNoise);
169
                                          convert(progress);
170
                                          textNoiseAngleA.setText(getString(R.string.noise_placeholder,mStr));
171
                                          break;
172
        case R.id.flagSeekAngleB        : progress = ((360*progress)/100);
173
                                          renderer.setAngleB(progress);
174
                                          textAngleB.setText(getString(R.string.beta_placeholder,progress));
175
                                          break;
176
        case R.id.flagSeekNoiseAngleB   : mNoise.set4((float)progress/100);
177
                                          renderer.setNoise(mNoise);
178
                                          convert(progress);
179
                                          textNoiseAngleB.setText(getString(R.string.noise_placeholder,mStr));
180
                                          break;
181
        }
182
      }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
    public void onStartTrackingTouch(SeekBar bar) { }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
    public void onStopTrackingTouch(SeekBar bar)  { }
191

    
192
}
(1-1/3)