Project

General

Profile

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

examples / src / main / java / org / distorted / examples / flag / FlagActivity.java @ 6f3024ae

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.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.getX() );
87
      barNoiseLength.setProgress   ( (int)mNoise.getY() );
88
      barNoiseAngleA.setProgress   ( (int)mNoise.getW() );
89
      barNoiseAngleB.setProgress   ( (int)mNoise.getV() );
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
      super.onPause();
106
      }
107

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

    
115
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
116
      mView.onResume();
117
      }
118
    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
    
121
    @Override
122
    protected void onDestroy() 
123
      {
124
      Distorted.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 = (FlagSurfaceView) this.findViewById(R.id.flagSurfaceView);
143
      FlagRenderer renderer = mView.getRenderer();
144

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

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
    public void onStartTrackingTouch(SeekBar bar) { }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
    public void onStopTrackingTouch(SeekBar bar)  { }
192

    
193
}
(1-1/3)