Project

General

Profile

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

examples / src / main / java / org / distorted / examples / flag / FlagActivity.java @ 107e4b72

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.Distorted;
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 = (TextView)findViewById(R.id.flagAmplitude);
52
      textLength    = (TextView)findViewById(R.id.flagLength);
53
      textAngleA    = (TextView)findViewById(R.id.flagAngleA);
54
      textAngleB    = (TextView)findViewById(R.id.flagAngleB);
55

    
56
      SeekBar barAmplitude  = (SeekBar)findViewById(R.id.flagSeekAmplitude);
57
      SeekBar barLength     = (SeekBar)findViewById(R.id.flagSeekLength);
58
      SeekBar barAngleA     = (SeekBar)findViewById(R.id.flagSeekAngleA);
59
      SeekBar barAngleB     = (SeekBar)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 = (TextView)findViewById(R.id.flagNoiseAmplitude);
72
      textNoiseLength    = (TextView)findViewById(R.id.flagNoiseLength);
73
      textNoiseAngleA    = (TextView)findViewById(R.id.flagNoiseAngleA);
74
      textNoiseAngleB    = (TextView)findViewById(R.id.flagNoiseAngleB);
75

    
76
      SeekBar barNoiseAmplitude  = (SeekBar)findViewById(R.id.flagSeekNoiseAmplitude);
77
      SeekBar barNoiseLength     = (SeekBar)findViewById(R.id.flagSeekNoiseLength);
78
      SeekBar barNoiseAngleA     = (SeekBar)findViewById(R.id.flagSeekNoiseAngleA);
79
      SeekBar barNoiseAngleB     = (SeekBar)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.get1() );
87
      barNoiseLength.setProgress   ( (int)mNoise.get2() );
88
      barNoiseAngleA.setProgress   ( (int)mNoise.get4() );
89
      barNoiseAngleB.setProgress   ( (int)mNoise.get5() );
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
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
103
      mView.onPause();
104

    
105
      Distorted.onPause();
106
      super.onPause();
107
      }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
    
111
    @Override
112
    protected void onResume() 
113
      {
114
      super.onResume();
115

    
116
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
117
      mView.onResume();
118
      }
119
    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
    
122
    @Override
123
    protected void onDestroy() 
124
      {
125
      Distorted.onDestroy();  
126
      super.onDestroy();
127
      }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

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

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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

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

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
    public void onStartTrackingTouch(SeekBar bar) { }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
    public void onStopTrackingTouch(SeekBar bar)  { }
193

    
194
}
(1-1/3)