Project

General

Profile

« Previous | Next » 

Revision 9df01f21

Added by Leszek Koltunski over 4 years ago

Progress with Predeform: UI for the list of Vertex effects to preapply.

View differences:

src/main/java/org/distorted/examples/earth/EarthActivity.java
172 172

  
173 173
      int numEffects=0;
174 174

  
175
      for(int i=0; i<names.length; i++)
175
      for (EffectName effectName : names)
176 176
        {
177
        type = names[i].getType();
177
        type = effectName.getType();
178 178
        if (type == EffectType.FRAGMENT || type == EffectType.VERTEX) numEffects++;
179 179
        }
180 180

  
......
183 183

  
184 184
      numEffects=0;
185 185

  
186
      for(int i=0; i<names.length; i++)
186
      for (EffectName name : names)
187 187
        {
188
        type = names[i].getType();
188
        type = name.getType();
189 189

  
190 190
        if (type == EffectType.FRAGMENT || type == EffectType.VERTEX)
191 191
          {
192
          mEffectNames[numEffects]  = names[i];
193
          effectStrings[numEffects] = names[i].name();
192
          mEffectNames[numEffects] = name;
193
          effectStrings[numEffects] = name.name();
194 194

  
195 195
          numEffects++;
196 196
          }
src/main/java/org/distorted/examples/predeform/PredeformActivity.java
22 22
import android.app.Activity;
23 23
import android.content.Intent;
24 24
import android.os.Bundle;
25
import android.view.Gravity;
26 25
import android.view.View;
27 26
import android.widget.AdapterView;
28 27
import android.widget.ArrayAdapter;
......
30 29
import android.widget.LinearLayout;
31 30
import android.widget.NumberPicker;
32 31
import android.widget.Spinner;
33
import android.widget.TableRow;
34 32

  
35 33
import org.distorted.examples.R;
34
import org.distorted.library.effect.Effect;
35
import org.distorted.library.effect.EffectName;
36
import org.distorted.library.effect.EffectType;
37
import org.distorted.library.type.Static4D;
38

  
39
import java.util.ArrayList;
36 40

  
37 41
///////////////////////////////////////////////////////////////////////////////////////////////////
38 42

  
39
public class PredeformActivity extends Activity
40
                               implements View.OnClickListener, AdapterView.OnItemSelectedListener
43
public class PredeformActivity extends Activity implements View.OnClickListener, AdapterView.OnItemSelectedListener
41 44
  {
42
  private static final int COLOR_OFF = 0xffffe81f;
43
  private static final int COLOR_ON  = 0xff0000ff;
44
  private static final int COLOR_INAC= 0xff999999;
45

  
46 45
  private int mNumCols = 1;
47 46
  private int mNumRows = 1;
48 47
  private int mNumSlic = 1;
49
  private boolean mGridInitialized;
50 48
  private NumberPicker mColsPicker, mRowsPicker, mSlicPicker;
51
  private boolean[] mShape;
52 49
  private int mObjectType;
53 50
  private int mBitmapID;
54
  private LinearLayout mLay;
51
  private EffectName[] mEffectNames;
52
  private int mEffectAdd;
53
  private LinearLayout mLayout;
54
  private int mChildren;
55
  private ArrayList<PredeformEffect> mList;
55 56

  
56 57
///////////////////////////////////////////////////////////////////////////////////////////////////
57 58

  
......
60 61
    {
61 62
    super.onCreate(savedState);
62 63

  
63
    setContentView(R.layout.objectpickerlayout);
64
    setContentView(R.layout.predeformpickerlayout);
64 65

  
65
    mLay = findViewById(R.id.objectpicker_buttongrid);
66
    mLayout = findViewById(R.id.predeformLayout);
67
    mChildren = 0;
68
    mList = new ArrayList<>();
66 69

  
67
    mColsPicker = findViewById(R.id.objectpicker_cols);
68
    mRowsPicker = findViewById(R.id.objectpicker_rows);
69
    mSlicPicker = findViewById(R.id.objectpicker_slices);
70
    mColsPicker = findViewById(R.id.predeformCols);
71
    mRowsPicker = findViewById(R.id.predeformRows);
72
    mSlicPicker = findViewById(R.id.predeformSlices);
70 73

  
71 74
    mColsPicker.setMaxValue(40);
72 75
    mColsPicker.setMinValue( 1);
......
80 83
         @Override
81 84
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
82 85
           {
83
           setGrid();
86
           mNumCols = newVal;
84 87
           }
85 88
         });
86 89

  
......
89 92
         @Override
90 93
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
91 94
           {
92
           setGrid();
95
           mNumRows = newVal;
93 96
           }
94 97
         });
95 98

  
......
98 101
         @Override
99 102
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
100 103
           {
101
           mNumSlic = mSlicPicker.getValue();
104
           mNumSlic = newVal;
102 105
           }
103 106
         });
104 107

  
105 108
    mObjectType = 0;
106
    mGridInitialized = false;
107 109

  
108
    Spinner typeSpinner  = findViewById(R.id.objectpicker_spinnerType);
110
    Spinner typeSpinner  = findViewById(R.id.predeformSpinnerType);
109 111
    typeSpinner.setOnItemSelectedListener(this);
110 112

  
111 113
    String[] objectType = new String[PredeformMeshList.LENGTH];
......
119 121
    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
120 122
    typeSpinner.setAdapter(adapterType);
121 123

  
122
    Spinner bitmapSpinner  = findViewById(R.id.objectpicker_spinnerBitmap);
124
    Spinner bitmapSpinner  = findViewById(R.id.predeformSpinnerBitmap);
123 125
    bitmapSpinner.setOnItemSelectedListener(this);
124 126

  
125 127
    String[] objectBitmap = new String[] { "Texture: Grid", "Texture: Girl", "Texture: Dog", "Texture: Cat",
......
128 130
    ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
129 131
    adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
130 132
    bitmapSpinner.setAdapter(adapterBitmap);
131
    }
132 133

  
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
    Spinner effectSpinner  = findViewById(R.id.predeformSpinnerEffect);
135
    effectSpinner.setOnItemSelectedListener(this);
134 136

  
135
  private void setGrid()
136
    {
137
    mGridInitialized = true;
137
    ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, createEffectNames());
138
    adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
139
    effectSpinner.setAdapter(adapterEffect);
138 140

  
139
    mNumCols = mColsPicker.getValue();
140
    mNumRows = mRowsPicker.getValue();
141
    Button add = findViewById(R.id.predeformAddEffect);
142
    add.setOnClickListener(this);
143
    Button rem = findViewById(R.id.predeformRemoveEffect);
144
    rem.setOnClickListener(this);
145
    Button cre = findViewById(R.id.predeformCreate);
146
    cre.setOnClickListener(this);
147
    }
141 148

  
142
    int width = mLay.getWidth();
143
    int height= mLay.getHeight();
144
    int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0;
145
    int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0;
146
    int size= Math.min(w, h);
147
    int pad = size<20 ? 1 : size/20;
149
///////////////////////////////////////////////////////////////////////////////////////////////////
148 150

  
149
    mLay.removeAllViews();
151
    private String[] createEffectNames()
152
      {
153
      EffectType type;
154
      EffectName[] names = EffectName.values();
150 155

  
151
    mShape = new boolean[mNumRows*mNumCols];
156
      int numEffects=0;
152 157

  
153
    TableRow.LayoutParams p = new TableRow.LayoutParams();
158
      for (EffectName effectName : names)
159
        {
160
        type = effectName.getType();
161
        if (type == EffectType.VERTEX) numEffects++;
162
        }
154 163

  
155
    p.rightMargin  = pad;
156
    p.leftMargin   = pad;
157
    p.topMargin    = pad;
158
    p.bottomMargin = pad;
159
    p.height       = size;
160
    p.width        = size;
164
      mEffectNames = new EffectName[numEffects];
165
      String[] effectStrings = new String[numEffects];
161 166

  
162
    for (int rows=0; rows<mNumRows; rows++)
163
      {
164
      TableRow tr = new TableRow(this);
165
      tr.setGravity(Gravity.CENTER);
167
      numEffects=0;
166 168

  
167
      for(int cols=0; cols<mNumCols; cols++)
169
      for (EffectName name : names)
168 170
        {
169
        Button b = new Button(this);
170
        b.setOnClickListener(this);
171
        b.setId(rows*mNumCols+cols);
172
        b.setLayoutParams(p);
173
        b.setBackgroundColor(mObjectType==0 ? COLOR_ON:COLOR_INAC);
174
        tr.addView(b, p);
175
        mShape[rows*mNumCols+cols] = true;
171
        type = name.getType();
172

  
173
        if (type == EffectType.VERTEX)
174
          {
175
          mEffectNames[numEffects] = name;
176
          effectStrings[numEffects] = name.name();
177

  
178
          numEffects++;
179
          }
176 180
        }
177 181

  
178
      mLay.addView(tr);
182
      return effectStrings;
179 183
      }
180
    }
181 184

  
182 185
///////////////////////////////////////////////////////////////////////////////////////////////////
183 186

  
184
  public void onClick(View view)
187
  public void newEffect()
185 188
    {
186
    if( mObjectType==0 )  // cubes
189
    PredeformEffect eff = new PredeformEffect(mEffectNames[mEffectAdd], this );
190
    mList.add(eff);
191

  
192
    mChildren++;
193

  
194
    View view = eff.createView(mChildren);
195
    mLayout.addView(view);
196

  
197
    int dimension = eff.getDimension();
198
    Button butt;
199

  
200
    switch(dimension)
201
      {
202
      case 1: butt = view.findViewById(R.id.button1dRemove);
203
              butt.setOnClickListener(this);
204
              break;
205
      case 2: butt = view.findViewById(R.id.button2dRemove);
206
              butt.setOnClickListener(this);
207
              break;
208
      case 3: butt = view.findViewById(R.id.button3dRemove);
209
              butt.setOnClickListener(this);
210
              break;
211
      case 4: butt = view.findViewById(R.id.button4dRemove);
212
              butt.setOnClickListener(this);
213
              break;
214
      case 5: butt = view.findViewById(R.id.button5dRemove);
215
              butt.setOnClickListener(this);
216
              break;
217
      }
218

  
219
    if( mEffectNames[mEffectAdd].getCenterDimension() > 0 )
220
      {
221
      View center = eff.createCenter(mChildren);
222
      mLayout.addView(center);
223
      }
224

  
225
    if( mEffectNames[mEffectAdd].getRegionDimension() > 0 )
187 226
      {
188
      Button tmp = (Button)view;
189
      int id = tmp.getId();
190
      mShape[id] = !mShape[id];
191
      tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
227
      View region = eff.createRegion(mChildren);
228
      mLayout.addView(region);
192 229
      }
230

  
231
    Effect effect = eff.createEffect();
232

  
233
    PredeformEffectList.addNew(effect);
193 234
    }
194 235

  
195 236
///////////////////////////////////////////////////////////////////////////////////////////////////
196 237

  
197
  private void uncheckAll()
238
  public void removeAll()
198 239
    {
199
    TableRow tr;
200
    Button butt;
240
    mChildren = 0;
241
    mList.clear();
242
    mLayout.removeAllViews();
243
    PredeformEffectList.removeAll();
244
    }
201 245

  
202
    for (int row=0; row<mNumRows; row++)
203
      {
204
      tr = (TableRow)mLay.getChildAt(row);
246
///////////////////////////////////////////////////////////////////////////////////////////////////
205 247

  
206
      for(int col=0; col<mNumCols; col++)
248
  public void remove(View v)
249
    {
250
    for(PredeformEffect effect: mList)
251
      {
252
      if( effect.thisView(v) )
207 253
        {
208
        butt = (Button)tr.getVirtualChildAt(col);
209
        butt.setBackgroundColor(mObjectType==0 ? COLOR_ON : COLOR_INAC);
210
        mShape[row*mNumCols+col] = true;
254
        View view;
255

  
256
        view = effect.getEffect();
257
        if( view!=null ) mLayout.removeView(view);
258
        view = effect.getCenter();
259
        if( view!=null ) mLayout.removeView(view);
260
        view = effect.getRegion();
261
        if( view!=null ) mLayout.removeView(view);
262

  
263
        PredeformEffectList.remove(effect.getId());
264

  
265
        int index = mList.indexOf(effect);
266
        int capac = mList.size();
267

  
268
        for(int i=index+1; i<capac; i++)
269
          {
270
          mList.get(i).setBackground(i-1);
271
          }
272

  
273
        mList.remove(effect);
274
        mChildren--;
275

  
276
        break;
211 277
        }
212 278
      }
213 279
    }
214 280

  
215 281
///////////////////////////////////////////////////////////////////////////////////////////////////
216 282

  
217
  public void Create(View v)
283
  public void create()
218 284
    {
219 285
    Intent mainInt = new Intent( getApplicationContext(), PredeformActivity2.class);
220 286
    Bundle b = new Bundle();
......
225 291
    b.putInt("slices", PredeformMeshList.getSlic(mObjectType, mNumCols, mNumRows, mNumSlic) );
226 292
    b.putInt("bitmap", mBitmapID);
227 293

  
228
    b.putString("string", PredeformMeshList.getString(mObjectType, mNumCols, mNumRows, mShape));
229

  
230 294
    mainInt.putExtras(b);
231 295
    startActivity(mainInt);
232 296
    }
233 297

  
234 298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
// TODO
235 300

  
236
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
301
  int getScreenWidth()
237 302
    {
238
    switch(parent.getId())
239
      {
240
      case R.id.objectpicker_spinnerType  : if( mObjectType!=pos )
241
                                              {
242
                                              mObjectType = pos;
243
                                              uncheckAll();
244

  
245
                                              int dim = PredeformMeshList.getDimension(mObjectType);
246

  
247
                                              mRowsPicker.setEnabled(dim>=1);
248
                                              mColsPicker.setEnabled(dim>=2);
249
                                              mSlicPicker.setEnabled(dim>=3);
250
                                              }
251
                                            break;
252
      case R.id.objectpicker_spinnerBitmap: switch(pos)
253
                                              {
254
                                              case 0: mBitmapID = -1            ; break;
255
                                              case 1: mBitmapID = R.raw.face    ; break;
256
                                              case 2: mBitmapID = R.raw.dog     ; break;
257
                                              case 3: mBitmapID = R.raw.cat     ; break;
258
                                              case 4: mBitmapID = R.raw.grid    ; break;
259
                                              case 5: mBitmapID = R.raw.bean    ; break;
260
                                              case 6: mBitmapID = R.raw.monalisa; break;
261
                                              case 7: mBitmapID = R.raw.world   ; break;
262
                                              }
263
                                            break;
264
      }
303
    return 1080;
265 304
    }
266 305

  
267 306
///////////////////////////////////////////////////////////////////////////////////////////////////
307
// only important for matrix effects, ignore here
268 308

  
269
  public void onNothingSelected(AdapterView<?> parent)
309
  float getScaleFactor()
270 310
    {
311
    return 1.0f;
271 312
    }
272 313

  
273 314
///////////////////////////////////////////////////////////////////////////////////////////////////
274
// Overrides
315
// TODO
316

  
317
  void setCenter(float x, float y, float z)
318
    {
319

  
320
    }
321

  
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323
// TODO
324

  
325
  void setRegion(Static4D region)
326
    {
327

  
328
    }
329

  
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

  
332
  int getWidth()
333
    {
334
    return mNumCols;
335
    }
336

  
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

  
339
  int getHeight()
340
    {
341
    return mNumRows;
342
    }
343

  
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

  
346
  int getDepth()
347
    {
348
    return mNumSlic;
349
    }
350

  
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

  
353
  @Override
354
  public void onClick(View v)
355
    {
356
    switch (v.getId())
357
      {
358
      case R.id.predeformAddEffect   : newEffect(); break;
359
      case R.id.predeformRemoveEffect: removeAll(); break;
360
      case R.id.predeformCreate      : create();    break;
361
      case R.id.button1dRemove       :
362
      case R.id.button2dRemove       :
363
      case R.id.button3dRemove       :
364
      case R.id.button4dRemove       :
365
      case R.id.button5dRemove       : remove(v)  ; break;
366
      }
367
    }
368

  
275 369
///////////////////////////////////////////////////////////////////////////////////////////////////
276 370

  
277 371
  @Override
......
282 376
    mColsPicker.setValue(mNumCols);
283 377
    mRowsPicker.setValue(mNumRows);
284 378
    mSlicPicker.setValue(mNumSlic);
379
    }
380

  
381
///////////////////////////////////////////////////////////////////////////////////////////////////
285 382

  
286
    if( !mGridInitialized ) setGrid();
383
  @Override
384
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
385
    {
386
    switch(parent.getId())
387
      {
388
      case R.id.predeformSpinnerType  : if( mObjectType!=pos )
389
                                          {
390
                                          mObjectType = pos;
391

  
392
                                          int dim = PredeformMeshList.getDimension(mObjectType);
393

  
394
                                          mRowsPicker.setEnabled(dim>=1);
395
                                          mColsPicker.setEnabled(dim>=2);
396
                                          mSlicPicker.setEnabled(dim>=3);
397
                                          }
398
                                        break;
399
      case R.id.predeformSpinnerBitmap: switch(pos)
400
                                          {
401
                                          case 0: mBitmapID = -1            ; break;
402
                                          case 1: mBitmapID = R.raw.face    ; break;
403
                                          case 2: mBitmapID = R.raw.dog     ; break;
404
                                          case 3: mBitmapID = R.raw.cat     ; break;
405
                                          case 4: mBitmapID = R.raw.grid    ; break;
406
                                          case 5: mBitmapID = R.raw.bean    ; break;
407
                                          case 6: mBitmapID = R.raw.monalisa; break;
408
                                          case 7: mBitmapID = R.raw.world   ; break;
409
                                          }
410
                                        break;
411
      case R.id.predeformSpinnerEffect: mEffectAdd = pos;
412
                                        break;
413
      }
414
    }
415

  
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

  
418
  @Override
419
  public void onNothingSelected(AdapterView<?> parent)
420
    {
287 421
    }
288 422
  }
src/main/java/org/distorted/examples/predeform/PredeformActivity2.java
92 92

  
93 93
      Bundle b = getIntent().getExtras();
94 94

  
95
      String str     = b.getString("string");
96 95
      int objectType = b.getInt("type");
97 96
      int bitmapID   = b.getInt("bitmap");
98 97
      mNumCols       = b.getInt("cols");
99 98
      mNumRows       = b.getInt("rows");
100 99
      mNumSlic       = b.getInt("slices");
101 100

  
101
      StringBuilder strBuilder = new StringBuilder();
102
      for(int i=0; i<mNumCols*mNumRows; i++) strBuilder.append('1');
103

  
102 104
      int maxsize = mNumCols > mNumRows ? (Math.max(mNumCols, mNumSlic)) : (Math.max(mNumRows, mNumSlic));
103 105
      createBitmap(maxsize,bitmapID);
104
      mMesh =  PredeformMeshList.createMesh(objectType, mNumCols, mNumRows, mNumSlic, bitmapID, str);
106
      mMesh =  PredeformMeshList.createMesh(objectType, mNumCols, mNumRows, mNumSlic, bitmapID, strBuilder.toString() );
105 107

  
106 108
      mTexture = new DistortedTexture();
107 109

  
src/main/java/org/distorted/examples/predeform/PredeformEffect.java
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.predeform;
21

  
22
import android.view.View;
23
import android.widget.SeekBar;
24
import android.widget.TextView;
25

  
26
import org.distorted.examples.R;
27
import org.distorted.library.effect.Effect;
28
import org.distorted.library.effect.EffectName;
29
import org.distorted.library.effect.EffectType;
30
import org.distorted.library.effect.FragmentEffectAlpha;
31
import org.distorted.library.effect.FragmentEffectBrightness;
32
import org.distorted.library.effect.FragmentEffectChroma;
33
import org.distorted.library.effect.FragmentEffectContrast;
34
import org.distorted.library.effect.FragmentEffectSaturation;
35
import org.distorted.library.effect.MatrixEffectMove;
36
import org.distorted.library.effect.MatrixEffectQuaternion;
37
import org.distorted.library.effect.MatrixEffectRotate;
38
import org.distorted.library.effect.MatrixEffectScale;
39
import org.distorted.library.effect.MatrixEffectShear;
40
import org.distorted.library.effect.PostprocessEffectBlur;
41
import org.distorted.library.effect.PostprocessEffectGlow;
42
import org.distorted.library.effect.VertexEffectDeform;
43
import org.distorted.library.effect.VertexEffectDistort;
44
import org.distorted.library.effect.VertexEffectMove;
45
import org.distorted.library.effect.VertexEffectPinch;
46
import org.distorted.library.effect.VertexEffectQuaternion;
47
import org.distorted.library.effect.VertexEffectRotate;
48
import org.distorted.library.effect.VertexEffectScale;
49
import org.distorted.library.effect.VertexEffectShear;
50
import org.distorted.library.effect.VertexEffectSink;
51
import org.distorted.library.effect.VertexEffectSwirl;
52
import org.distorted.library.effect.VertexEffectWave;
53
import org.distorted.library.type.Dynamic1D;
54
import org.distorted.library.type.Dynamic2D;
55
import org.distorted.library.type.Dynamic3D;
56
import org.distorted.library.type.Dynamic4D;
57
import org.distorted.library.type.Dynamic5D;
58
import org.distorted.library.type.Static1D;
59
import org.distorted.library.type.Static2D;
60
import org.distorted.library.type.Static3D;
61
import org.distorted.library.type.Static4D;
62
import org.distorted.library.type.Static5D;
63

  
64
import java.lang.ref.WeakReference;
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
class PredeformEffect implements SeekBar.OnSeekBarChangeListener
69
  {
70
  private static final int BACKGROUND_ODD = 0xff555555;
71
  private static final int BACKGROUND_EVEN= 0xff333333;
72

  
73
  private WeakReference<PredeformActivity> mAct;
74

  
75
  private EffectName mName;
76
  private int[] mInter;
77
  private int[] mInterRegion;
78
  private int[] mInterCenter;
79
  private int[] mSeekID;
80
  private int[] mSeekRegionID;
81
  private int[] mSeekCenterID;
82
  private int mDimension, mRegionDimension;
83
  private TextView mText,mTextRegion,mTextCenter;
84

  
85
  private Dynamic1D mDyn1;
86
  private Dynamic2D mDyn2;
87
  private Dynamic3D mDyn3;
88
  private Dynamic4D mDyn4;
89
  private Dynamic5D mDyn5;
90
  private Static1D  mSta1;
91
  private Static2D  mSta2;
92
  private Static3D  mSta3;
93
  private Static4D  mSta4;
94
  private Static5D  mSta5;
95
  private Dynamic4D mRegion4Dyn;
96
  private Static4D  mRegion4Sta;
97
  private Dynamic3D mRegion3Dyn;
98
  private Static3D  mRegion3Sta;
99
  private Dynamic3D mCenterDyn;
100
  private Static3D  mCenterSta;
101

  
102
  private View mButton, mEffect, mCenter, mRegion;
103
  private long mId;
104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
// requires knowledge about effect nature
107

  
108
  Effect createEffect()
109
    {
110
    Effect effect=null;
111

  
112
    switch(mName)
113
      {
114
      case ROTATE           : effect = new MatrixEffectRotate      (mDyn1, mDyn3, mCenterDyn); break;
115
      case QUATERNION       : effect = new MatrixEffectQuaternion  (mDyn4, mCenterDyn)       ; break;
116
      case MOVE             : effect = new MatrixEffectMove        (mDyn3)                   ; break;
117
      case SCALE            : effect = new MatrixEffectScale       (mDyn3)                   ; break;
118
      case SHEAR            : effect = new MatrixEffectShear       (mDyn3, mCenterDyn)       ; break;
119

  
120
      case DISTORT          : effect = new VertexEffectDistort     (mDyn3, mCenterDyn, mRegion4Dyn)              ; break;
121
      case DEFORM           : effect = new VertexEffectDeform      (mDyn3, mDyn1, mCenterDyn, mRegion4Dyn)       ; break;
122
      case SINK             : effect = new VertexEffectSink        (mDyn1, mCenterDyn, mRegion4Dyn)              ; break;
123
      case PINCH            : effect = new VertexEffectPinch       (mDyn3, mCenterDyn, mRegion4Dyn)              ; break;
124
      case SWIRL            : effect = new VertexEffectSwirl       (mDyn1, mCenterDyn, mRegion4Dyn)              ; break;
125
      case WAVE             : effect = new VertexEffectWave        (mDyn5, mCenterDyn, mRegion4Dyn)              ; break;
126
      case VERTEX_MOVE      : effect = new VertexEffectMove        (mDyn3)                                       ; break;
127
      case VERTEX_QUATERNION: effect = new VertexEffectQuaternion  (mDyn4, mCenterDyn)                           ; break;
128
      case VERTEX_ROTATE    : effect = new VertexEffectRotate      (mDyn1, mDyn3, mCenterDyn)                    ; break;
129
      case VERTEX_SCALE     : effect = new VertexEffectScale       (mDyn3)                                       ; break;
130
      case VERTEX_SHEAR     : effect = new VertexEffectShear       (mDyn3, mCenterDyn)                           ; break;
131

  
132
      case ALPHA            : effect = new FragmentEffectAlpha     (mDyn1,        mCenterDyn, mRegion3Dyn, false); break;
133
      case SMOOTH_ALPHA     : effect = new FragmentEffectAlpha     (mDyn1,        mCenterDyn, mRegion3Dyn, true ); break;
134
      case CHROMA           : effect = new FragmentEffectChroma    (mDyn1, mDyn3, mCenterDyn, mRegion3Dyn, false); break;
135
      case SMOOTH_CHROMA    : effect = new FragmentEffectChroma    (mDyn1, mDyn3, mCenterDyn, mRegion3Dyn, true ); break;
136
      case BRIGHTNESS       : effect = new FragmentEffectBrightness(mDyn1,        mCenterDyn, mRegion3Dyn, false); break;
137
      case SMOOTH_BRIGHTNESS: effect = new FragmentEffectBrightness(mDyn1,        mCenterDyn, mRegion3Dyn, true ); break;
138
      case SATURATION       : effect = new FragmentEffectSaturation(mDyn1,        mCenterDyn, mRegion3Dyn, false); break;
139
      case SMOOTH_SATURATION: effect = new FragmentEffectSaturation(mDyn1,        mCenterDyn, mRegion3Dyn, true ); break;
140
      case CONTRAST         : effect = new FragmentEffectContrast  (mDyn1,        mCenterDyn, mRegion3Dyn, false); break;
141
      case SMOOTH_CONTRAST  : effect = new FragmentEffectContrast  (mDyn1,        mCenterDyn, mRegion3Dyn, true ); break;
142

  
143
      case BLUR             : effect = new PostprocessEffectBlur   (mDyn2      ); break;
144
      case GLOW             : effect = new PostprocessEffectGlow   (mDyn2,mDyn4); break;
145
      }
146

  
147
    mId = effect.getID();
148

  
149
    return effect;
150
    }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
// requires knowledge about effect nature
154

  
155
  private void fillStatics()
156
    {
157
    switch(mName)
158
      {
159
      ///////////////////////////////////////////////////////////////////////////////////////
160
      // MATRIX (and VERTEX-pseudo-matrix)
161
      ///////////////////////////////////////////////////////////////////////////////////////
162

  
163
      case VERTEX_ROTATE    :
164
      case ROTATE           : float an = (mInter[0]-50)*180/50.0f;
165
                              float rx = (mInter[1]-50)/ 50.0f;
166
                              float ry = (mInter[2]-50)/ 50.0f;
167
                              float rz = (mInter[3]-50)/ 50.0f;
168
                              mSta1.set(an);
169
                              mSta3.set(rx,ry,rz);
170
                              break;
171
      case VERTEX_QUATERNION:
172
      case QUATERNION       : float qx = (mInter[0]-50)/ 50.0f;
173
                              float qy = (mInter[1]-50)/ 50.0f;
174
                              float qz = (mInter[2]-50)/ 50.0f;
175
                              float qw = (mInter[3]-50)*3.1415f/50;
176
                              float cosA = (float)Math.cos(qw/2);
177
                              float len = (float)Math.sqrt(qx*qx+qy*qy+qz*qz);
178
                              float sinAnorm = (float)Math.sin(qw/2)/len;
179
                              mSta4.set(sinAnorm*qx,sinAnorm*qy,sinAnorm*qz, cosA);
180
                              break;
181
      case MOVE             : float scr= mAct.get().getScreenWidth();
182
                              float sw = scr/200.0f;
183
                              float sh = scr/200.0f;
184
                              float xm = (mInter[0]-50)*sw;
185
                              float ym = (mInter[1]-50)*sh;
186
                              float zm = (mInter[2]-50)*(sw+sh)/2;
187
                              mSta3.set(xm,ym,zm);
188
                              break;
189
      case VERTEX_SCALE     :
190
      case SCALE            : float xs = (mInter[0]>50 ? 0.04f : 0.013f)*(mInter[0]-50) + 1;
191
                              float ys = (mInter[1]>50 ? 0.04f : 0.013f)*(mInter[1]-50) + 1;
192
                              float zs = (mInter[2]>50 ? 0.04f : 0.013f)*(mInter[2]-50) + 1;
193
                              mSta3.set(xs,ys,zs);
194
                              break;
195
      case VERTEX_SHEAR     :
196
      case SHEAR            : float xsh = (mInter[0]-50)/25.0f;
197
                              float ysh = (mInter[1]-50)/25.0f;
198
                              float zsh = (mInter[2]-50)/25.0f;
199
                              mSta3.set(xsh,ysh,zsh);
200
                              break;
201

  
202
      ///////////////////////////////////////////////////////////////////////////////////////
203
      // VERTEX
204
      ///////////////////////////////////////////////////////////////////////////////////////
205

  
206
      case VERTEX_MOVE      :
207
      case DISTORT          : float ld = mAct.get().getWidth()/50.0f;
208
                              float xd = (mInter[0]-50)*ld;
209
                              float yd = (mInter[1]-50)*ld;
210
                              float zd = (mInter[2]-50)*ld;
211
                              mSta3.set(xd,yd,zd);
212
                              break;
213
      case DEFORM           : float le = mAct.get().getWidth()/50.0f;
214
                              float xe = (mInter[0]-50)*le;
215
                              float ye = (mInter[1]-50)*le;
216
                              float ze = (mInter[2]-50)*le;
217
                              mSta3.set(xe,ye,ze);
218
                              float re = (mInter[3])*le;
219
                              mSta1.set(re);
220
                              break;
221
      case WAVE             : float l2 = mAct.get().getWidth()/50.0f;
222
                              float x2 = (mInter[0]-50)*l2;
223
                              float y2 = (mInter[1]-50)*l2;
224
                              float z2 = (mInter[2]-50)*180 / 50.0f;
225
                              float w2 = (mInter[3]-50)*180 / 50.0f;
226
                              float v2 = (mInter[4]-50)*180 / 50.0f;
227
                              mSta5.set(x2,y2,z2,w2,v2);
228
                              break;
229
      case SWIRL            : mSta1.set( 3.6f*(mInter[0]-50) );
230
                              break;
231
      case SINK             : mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
232
                              break;
233
      case PINCH            : float dp = mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f;
234
                              float ap = (mInter[1]-50)*180 / 50.0f;
235
                              float bp = (mInter[2]-50)*180 / 50.0f;
236
                              mSta3.set(dp,ap,bp);
237
                              break;
238

  
239
      ///////////////////////////////////////////////////////////////////////////////////////
240
      // FRAGMENT
241
      ///////////////////////////////////////////////////////////////////////////////////////
242

  
243
      case ALPHA            :
244
      case SMOOTH_ALPHA     : mSta1.set(mInter[0]/100.0f);
245
                              break;
246
      case SATURATION       :
247
      case SMOOTH_SATURATION:
248
      case CONTRAST         :
249
      case SMOOTH_CONTRAST  :
250
      case BRIGHTNESS       :
251
      case SMOOTH_BRIGHTNESS: mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
252
                              break;
253
      case CHROMA           :
254
      case SMOOTH_CHROMA    : mSta1.set(mInter[0]/100.0f);
255
                              mSta3.set(mInter[1]/100.0f,
256
                                        mInter[2]/100.0f,
257
                                        mInter[3]/100.0f);
258
                              break;
259

  
260
      ///////////////////////////////////////////////////////////////////////////////////////
261
      // POSTPROCESS
262
      ///////////////////////////////////////////////////////////////////////////////////////
263

  
264
      case BLUR             : mSta2.set(mInter[0]/2.0f,
265
                                        mInter[1]/2.0f);
266
                              break;
267
      case GLOW             : mSta2.set(mInter[0]/2.0f,
268
                                        mInter[1]/2.0f);
269
                              mSta4.set(mInter[2]/100.0f,
270
                                        mInter[3]/100.0f,
271
                                        mInter[4]/100.0f,
272
                                        mInter[5]/100.0f );
273
                              break;
274
      }
275
    }
276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

  
279
  private void setDefaultInter()
280
    {
281
    switch(mDimension)
282
      {
283
      case 6: mInter[5] = 50;
284
      case 5: mInter[4] = 50;
285
      case 4: mInter[3] = 50;
286
      case 3: mInter[2] = 50;
287
      case 2: mInter[1] = 50;
288
      case 1: mInter[0] = 50;
289
      }
290

  
291
    if( mName==EffectName.ROTATE         ||
292
        mName==EffectName.VERTEX_ROTATE   )
293
      {
294
      mInter[1]= 100;
295
      }
296
    if( mName==EffectName.QUATERNION     ||
297
        mName==EffectName.VERTEX_QUATERNION )
298
      {
299
      mInter[0]= 100;
300
      }
301
    }
302

  
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

  
305
  private void setText()
306
    {
307
    String text = mName.name();
308

  
309
    if( mSta1 !=null )
310
      {
311
      float f1 = ((int)(mSta1.get0()*100))/100.0f;
312
      text += " "+f1;
313
      }
314

  
315
    if( mSta2 !=null )
316
      {
317
      float f1 = ((int)(mSta2.get0()*100))/100.0f;
318
      float f2 = ((int)(mSta2.get1()*100))/100.0f;
319
      text += " ("+f1+","+f2+")";
320
      }
321

  
322
    if( mSta3 !=null )
323
      {
324
      float f1 = ((int)(mSta3.get0()*100))/100.0f;
325
      float f2 = ((int)(mSta3.get1()*100))/100.0f;
326
      float f3 = ((int)(mSta3.get2()*100))/100.0f;
327
      text += " ("+f1+","+f2+","+f3+")";
328
      }
329

  
330
    if( mSta4 !=null )
331
      {
332
      float f1 = ((int)(mSta4.get0()*100))/100.0f;
333
      float f2 = ((int)(mSta4.get1()*100))/100.0f;
334
      float f3 = ((int)(mSta4.get2()*100))/100.0f;
335
      float f4 = ((int)(mSta4.get3()*100))/100.0f;
336
      text += " ("+f1+","+f2+","+f3+","+f4+")";
337
      }
338

  
339
    if( mSta5 !=null )
340
      {
341
      float f1 = ((int)(mSta5.get0()*100))/100.0f;
342
      float f2 = ((int)(mSta5.get1()*100))/100.0f;
343
      float f3 = ((int)(mSta5.get2()*100))/100.0f;
344
      float f4 = ((int)(mSta5.get3()*100))/100.0f;
345
      float f5 = ((int)(mSta5.get4()*100))/100.0f;
346
      text += " ("+f1+","+f2+","+f3+","+f4+","+f5+")";
347
      }
348

  
349
    mText.setText(text);
350
    }
351

  
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

  
354
  private void fillCenterStatics()
355
    {
356
    PredeformActivity act = mAct.get();
357

  
358
    float x = (mInterCenter[0]*0.012f - 0.6f)*act.getWidth();
359
    float y = (mInterCenter[1]*0.012f - 0.6f)*act.getHeight();
360
    float z = (mInterCenter[2]*0.012f - 0.6f)*act.getDepth();
361

  
362
    if( mName.getType() == EffectType.MATRIX )
363
      {
364
      float factor = act.getScaleFactor();
365
      x *= factor;
366
      y *= factor;
367
      z *= factor;
368
      }
369

  
370
    mCenterSta.set(x,y,z);
371
    }
372

  
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

  
375
  private void setDefaultCenterInter()
376
    {
377
    mInterCenter[0] = 50;
378
    mInterCenter[1] = 50;
379
    mInterCenter[2] = 50;
380
    }
381

  
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

  
384
  private void setCenterText()
385
    {
386
    float f0 = ((int)(mCenterSta.get0()*100))/100.0f;
387
    float f1 = ((int)(mCenterSta.get1()*100))/100.0f;
388
    float f2 = ((int)(mCenterSta.get2()*100))/100.0f;
389

  
390
    mTextCenter.setText("center ("+f0+","+f1+","+f2+")");
391
    }
392

  
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

  
395
  private void fillRegionStatics()
396
    {
397
    PredeformActivity act = mAct.get();
398

  
399
    float factorX = act.getWidth() / 100.0f;
400
    float factorY = act.getHeight()/ 100.0f;
401
 // float factorZ = act.getDepth() / 100.0f;
402

  
403
    int deduct = (mName.getType() == EffectType.VERTEX ? 50:0);
404

  
405
    float x = (mInterRegion[0]-deduct)*factorX;
406
    float y = (mInterRegion[1]-deduct)*factorY;
407
    float z = (mInterRegion[2]-deduct)*factorX;   // ??
408
    float r =  mInterRegion[3]        *(factorX+factorY)/2;
409

  
410
    mRegion4Sta.set(x,y,z,r);
411
    mRegion3Sta.set(x,y,z);
412
    }
413

  
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

  
416
  private void setDefaultRegionInter()
417
    {
418
    mInterRegion[0] = 50;
419
    mInterRegion[1] = 50;
420
    mInterRegion[2] = 50;
421
    mInterRegion[3] = 50;
422
    }
423

  
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425

  
426
  private void setRegionText()
427
    {
428
    if( mRegionDimension==4 )
429
      {
430
      float f0 = ((int)(mRegion4Sta.get0()*100))/100.0f;
431
      float f1 = ((int)(mRegion4Sta.get1()*100))/100.0f;
432
      float f2 = ((int)(mRegion4Sta.get2()*100))/100.0f;
433
      float f3 = ((int)(mRegion4Sta.get3()*100))/100.0f;
434

  
435
      mTextRegion.setText("region (" + f0 + "," + f1 + "," + f2 + "," + f3 + ")");
436
      }
437

  
438
    if( mRegionDimension==3 )
439
      {
440
      float f0 = ((int)(mRegion4Sta.get0()*100))/100.0f;
441
      float f1 = ((int)(mRegion4Sta.get1()*100))/100.0f;
442
      float f2 = ((int)(mRegion4Sta.get2()*100))/100.0f;
443

  
444
      mTextRegion.setText("region (" + f0 + "," + f1 + "," + f2 + ")");
445
      }
446
    }
447

  
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

  
450
  private void setCenter(PredeformActivity act)
451
    {
452
    float factor = ( mName.getType() == EffectType.MATRIX ? act.getScaleFactor() : 1.0f);
453
    act.setCenter( mCenterSta.get0()/factor, mCenterSta.get1()/factor, mCenterSta.get2()/factor );
454
    }
455

  
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

  
458
  void setBackground(int pos)
459
    {
460
    int color = (pos%2==1 ? BACKGROUND_ODD:BACKGROUND_EVEN);
461

  
462
    if( mEffect!=null ) mEffect.setBackgroundColor(color);
463
    if( mCenter!=null ) mCenter.setBackgroundColor(color);
464
    if( mRegion!=null ) mRegion.setBackgroundColor(color);
465
    }
466

  
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

  
469
  PredeformEffect(EffectName name, PredeformActivity act)
470
    {
471
    mAct = new WeakReference<>(act);
472
    mName = name;
473

  
474
    mDyn1 = null;
475
    mDyn2 = null;
476
    mDyn3 = null;
477
    mDyn4 = null;
478
    mDyn5 = null;
479
    mSta1 = null;
480
    mSta2 = null;
481
    mSta3 = null;
482
    mSta4 = null;
483
    mSta5 = null;
484

  
485
    mDimension = mName.getEffectDimension();
486
    mRegionDimension = mName.getRegionDimension();
487

  
488
    switch(mDimension)
489
      {
490
      case 1 : mDyn1 = new Dynamic1D();
491
               mSta1 = new Static1D(0);
492
               mDyn1.add(mSta1);
493
               break;
494
      case 2 : mDyn2 = new Dynamic2D();
495
               mSta2 = new Static2D(0,0);
496
               mDyn2.add(mSta2);
497
               break;
498
      case 3 : mDyn3 = new Dynamic3D();
499
               mSta3 = new Static3D(0,0,0);
500
               mDyn3.add(mSta3);
501
               break;
502
      case 4 : if( mName == EffectName.QUATERNION || mName == EffectName.VERTEX_QUATERNION )
503
                 {
504
                 mDyn4 = new Dynamic4D();
505
                 mSta4 = new Static4D(0,0,0,0);
506
                 mDyn4.add(mSta4);
507
                 }
508
               else
509
                 {
510
                 mDyn3 = new Dynamic3D();
511
                 mSta3 = new Static3D(0,0,0);
512
                 mDyn3.add(mSta3);
513
                 mDyn1 = new Dynamic1D();
514
                 mSta1 = new Static1D(0);
515
                 mDyn1.add(mSta1);
516
                 }
517
               break;
518
      case 5 : if( mName == EffectName.WAVE )
519
                 {
520
                 mDyn5 = new Dynamic5D();
521
                 mSta5 = new Static5D(0, 0, 0, 0, 0);
522
                 mDyn5.add(mSta5);
523
                 }
524
               else
525
                 {
526
                 mDyn4 = new Dynamic4D();
527
                 mSta4 = new Static4D(0,0,0,0);
528
                 mDyn4.add(mSta4);
529
                 mDyn1 = new Dynamic1D();
530
                 mSta1 = new Static1D(0);
531
                 mDyn1.add(mSta1);
532
                 }
533
               break;
534
      case 6 : mDyn2 = new Dynamic2D();
535
               mSta2 = new Static2D(0,0);
536
               mDyn2.add(mSta2);
537
               mDyn4 = new Dynamic4D();
538
               mSta4 = new Static4D(0,0,0,0);
539
               mDyn4.add(mSta4);
540
               break;
541
      default: throw new RuntimeException("unsupported effect");
542
      }
543

  
544
    mInter = new int[mDimension];
545
    mSeekID= new int[mDimension];
546

  
547
    mInterRegion = new int[4];
548
    mSeekRegionID= new int[4];
549
    mRegion4Dyn  = new Dynamic4D();
550
    mRegion4Sta  = new Static4D(0,0,0,0);
551
    mRegion4Dyn.add(mRegion4Sta);
552
    mRegion3Dyn  = new Dynamic3D();
553
    mRegion3Sta  = new Static3D(0,0,0);
554
    mRegion3Dyn.add(mRegion3Sta);
555

  
556
    mInterCenter = new int[3];
557
    mSeekCenterID= new int[3];
558
    mCenterDyn   = new Dynamic3D();
559
    mCenterSta   = new Static3D(0,0,0);
560
    mCenterDyn.add(mCenterSta);
561

  
562
    mButton = null;
563
    mEffect = null;
564
    mCenter = null;
565
    mRegion = null;
566
    }
567

  
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

  
570
  View createView(int num)
571
    {
572
    SeekBar[] seek = new SeekBar[mDimension];
573

  
574
    PredeformActivity act = mAct.get();
575

  
576
    switch(mDimension)
577
      {
578
      case 1 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect1d, null);
579
               mText      = mEffect.findViewById(R.id.effect1dText);
580
               seek[0]    = mEffect.findViewById(R.id.effect1dbar1);
581
               mSeekID[0] = seek[0].getId();
582
               mButton    = mEffect.findViewById(R.id.button1dRemove);
583
               break;
584
      case 2 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect2d, null);
585
               mText      = mEffect.findViewById(R.id.effect2dText);
586
               seek[0]    = mEffect.findViewById(R.id.effect2dbar1);
587
               seek[1]    = mEffect.findViewById(R.id.effect2dbar2);
588
               mSeekID[0] = seek[0].getId();
589
               mSeekID[1] = seek[1].getId();
590
               mButton    = mEffect.findViewById(R.id.button2dRemove);
591
               break;
592
      case 3 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect3d, null);
593
               mText      = mEffect.findViewById(R.id.effect3dText);
594
               seek[0]    = mEffect.findViewById(R.id.effect3dbar1);
595
               seek[1]    = mEffect.findViewById(R.id.effect3dbar2);
596
               seek[2]    = mEffect.findViewById(R.id.effect3dbar3);
597
               mSeekID[0] = seek[0].getId();
598
               mSeekID[1] = seek[1].getId();
599
               mSeekID[2] = seek[2].getId();
600
               mButton    = mEffect.findViewById(R.id.button3dRemove);
601
               break;
602
      case 4 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect4d, null);
603
               mText      = mEffect.findViewById(R.id.effect4dText);
604
               seek[0]    = mEffect.findViewById(R.id.effect4dbar1);
605
               seek[1]    = mEffect.findViewById(R.id.effect4dbar2);
606
               seek[2]    = mEffect.findViewById(R.id.effect4dbar3);
607
               seek[3]    = mEffect.findViewById(R.id.effect4dbar4);
608
               mSeekID[0] = seek[0].getId();
609
               mSeekID[1] = seek[1].getId();
610
               mSeekID[2] = seek[2].getId();
611
               mSeekID[3] = seek[3].getId();
612
               mButton    = mEffect.findViewById(R.id.button4dRemove);
613
               break;
614
      case 5 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect5d, null);
615
               mText      = mEffect.findViewById(R.id.effect5dText);
616
               seek[0]    = mEffect.findViewById(R.id.effect5dbar1);
617
               seek[1]    = mEffect.findViewById(R.id.effect5dbar2);
618
               seek[2]    = mEffect.findViewById(R.id.effect5dbar3);
619
               seek[3]    = mEffect.findViewById(R.id.effect5dbar4);
620
               seek[4]    = mEffect.findViewById(R.id.effect5dbar5);
621
               mSeekID[0] = seek[0].getId();
622
               mSeekID[1] = seek[1].getId();
623
               mSeekID[2] = seek[2].getId();
624
               mSeekID[3] = seek[3].getId();
625
               mSeekID[4] = seek[4].getId();
626
               mButton    = mEffect.findViewById(R.id.button5dRemove);
627
               break;
628
      case 6 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect6d, null);
629
               mText      = mEffect.findViewById(R.id.effect6dText);
630
               seek[0]    = mEffect.findViewById(R.id.effect6dbar1);
631
               seek[1]    = mEffect.findViewById(R.id.effect6dbar2);
632
               seek[2]    = mEffect.findViewById(R.id.effect6dbar3);
633
               seek[3]    = mEffect.findViewById(R.id.effect6dbar4);
634
               seek[4]    = mEffect.findViewById(R.id.effect6dbar5);
635
               seek[5]    = mEffect.findViewById(R.id.effect6dbar6);
636
               mSeekID[0] = seek[0].getId();
637
               mSeekID[1] = seek[1].getId();
638
               mSeekID[2] = seek[2].getId();
639
               mSeekID[3] = seek[3].getId();
640
               mSeekID[4] = seek[4].getId();
641
               mSeekID[5] = seek[5].getId();
642
               mButton    = mEffect.findViewById(R.id.button6dRemove);
643
               break;
644
      default: android.util.Log.e("GenericEffect", "dimension "+mDimension+" not supported!");
645
               return null;
646
      }
647

  
648
    mEffect.setBackgroundColor( num%2==1 ? BACKGROUND_EVEN: BACKGROUND_ODD );
649

  
650
    setDefaultInter();
651

  
652
    for(int i=0; i<mDimension; i++)
653
      {
654
      seek[i].setOnSeekBarChangeListener(this);
655
      seek[i].setProgress( mInter[i] );
656
      }
657

  
658
    return mEffect;
659
    }
660

  
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662

  
663
  View createRegion(int num)
664
    {
665
    PredeformActivity act = mAct.get();
666

  
667
    if( mRegionDimension== 4 )
668
      {
669
      mRegion = act.getLayoutInflater().inflate(R.layout.effectregion4, null);
670
      mRegion.setBackgroundColor(num % 2 == 1 ? BACKGROUND_EVEN : BACKGROUND_ODD);
671

  
672
      SeekBar[] seek = new SeekBar[4];
673

  
674
      seek[0] = mRegion.findViewById(R.id.effectRegion4BarX);
675
      seek[1] = mRegion.findViewById(R.id.effectRegion4BarY);
676
      seek[2] = mRegion.findViewById(R.id.effectRegion4BarZ);
677
      seek[3] = mRegion.findViewById(R.id.effectRegion4BarR);
678

  
679
      mSeekRegionID[0] = seek[0].getId();
680
      mSeekRegionID[1] = seek[1].getId();
681
      mSeekRegionID[2] = seek[2].getId();
682
      mSeekRegionID[3] = seek[3].getId();
683

  
684
      mTextRegion = mRegion.findViewById(R.id.effectRegion4Text);
685

  
686
      setDefaultRegionInter();
687

  
688
      for (int i = 0; i < 4; i++)
689
        {
690
        seek[i].setOnSeekBarChangeListener(this);
691
        seek[i].setProgress(mInterRegion[i]);
692
        }
693

  
694
      act.setRegion(mRegion4Sta);
695
      }
696
    else
697
      {
698
      mRegion = act.getLayoutInflater().inflate(R.layout.effectregion3, null);
699
      mRegion.setBackgroundColor(num % 2 == 1 ? BACKGROUND_EVEN : BACKGROUND_ODD);
700

  
701
      SeekBar[] seek = new SeekBar[3];
702

  
703
      seek[0] = mRegion.findViewById(R.id.effectRegion3BarRX);
704
      seek[1] = mRegion.findViewById(R.id.effectRegion3BarRY);
705
      seek[2] = mRegion.findViewById(R.id.effectRegion3BarRZ);
706

  
707
      mSeekRegionID[0] = seek[0].getId();
708
      mSeekRegionID[1] = seek[1].getId();
709
      mSeekRegionID[2] = seek[2].getId();
710

  
711
      mTextRegion = mRegion.findViewById(R.id.effectRegion3Text);
712

  
713
      setDefaultRegionInter();
714

  
715
      for (int i = 0; i < 3; i++)
716
        {
717
        seek[i].setOnSeekBarChangeListener(this);
718
        seek[i].setProgress(mInterRegion[i]);
719
        }
720

  
721
      act.setRegion( new Static4D( mRegion3Sta.get0(), mRegion3Sta.get1(), mRegion3Sta.get2(), 1.0f) );
722
      }
723

  
724
    return mRegion;
725
    }
726

  
727
///////////////////////////////////////////////////////////////////////////////////////////////////
728

  
729
  View createCenter(int num)
730
    {
731
    PredeformActivity act = mAct.get();
732

  
733
    mCenter = act.getLayoutInflater().inflate(R.layout.effectcenter, null);
734
    mCenter.setBackgroundColor( num%2==1 ? BACKGROUND_EVEN: BACKGROUND_ODD );
735

  
736
    SeekBar[] seek = new SeekBar[3];
737

  
738
    seek[0] = mCenter.findViewById(R.id.effectCenterBarX );
739
    seek[1] = mCenter.findViewById(R.id.effectCenterBarY );
740
    seek[2] = mCenter.findViewById(R.id.effectCenterBarZ );
741

  
742
    mSeekCenterID[0] = seek[0].getId();
743
    mSeekCenterID[1] = seek[1].getId();
744
    mSeekCenterID[2] = seek[2].getId();
745

  
746
    mTextCenter = mCenter.findViewById(R.id.effectCenterText);
747

  
748
    setDefaultCenterInter();
749

  
750
    for(int i=0; i<3; i++)
751
      {
752
      seek[i].setOnSeekBarChangeListener(this);
753
      seek[i].setProgress( mInterCenter[i] );
754
      }
755

  
756
    setCenter(act);
757

  
758
    return mCenter;
759
    }
760

  
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762

  
763
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
764
    {
765
    boolean vectorChanged=false;
766
    boolean regionChanged=false;
767
    boolean centerChanged=false;
768

  
769
    for(int dim=0; dim<6; dim++)
770
      {
771
      if ( mDimension>dim && bar.getId()==mSeekID[dim] )
772
        {
773
        mInter[dim] = progress;
774
        vectorChanged = true;
775
        }
776
      }
777

  
778
    if( vectorChanged )
779
      {
780
      fillStatics();
781
      setText();
782
      }
783

  
784
    for(int reg=0; reg<4; reg++)
785
      {
786
      if( mRegionDimension>reg && bar.getId() == mSeekRegionID[reg] )
787
        {
788
        mInterRegion[reg] = progress;
789
        regionChanged = true;
790
        }
791
      }
792

  
793
    if( regionChanged )
794
      {
795
      fillRegionStatics();
796
      setRegionText();
797
      }
798

  
799
    for(int cen=0; cen<3; cen++)
800
      {
801
      if( bar.getId() == mSeekCenterID[cen] )
802
        {
803
        mInterCenter[cen] = progress;
804
        centerChanged = true;
805
        }
806
      }
807

  
808
    if( centerChanged )
809
      {
810
      fillCenterStatics();
811
      setCenterText();
812
      }
813

  
814
    if( fromUser )
815
      {
816
      PredeformActivity act = mAct.get();
817
      setCenter(act);
818
      act.setRegion(mRegion4Sta);
819
      }
820
    }
821

  
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823

  
824
  boolean thisView(View v)
825
    {
826
    return v==mButton;
827
    }
828

  
829
///////////////////////////////////////////////////////////////////////////////////////////////////
830

  
831
  public long getId()
832
    {
833
    return mId;
834
    }
835

  
836
///////////////////////////////////////////////////////////////////////////////////////////////////
837

  
838
  public int getDimension()
839
    {
840
    return mDimension;
841
    }
842

  
843
///////////////////////////////////////////////////////////////////////////////////////////////////
844

  
845
  public View getEffect()
846
    {
847
    return mEffect;
848
    }
849

  
850
///////////////////////////////////////////////////////////////////////////////////////////////////
851

  
852
  public View getRegion()
853
    {
854
    return mRegion;
855
    }
856

  
857
///////////////////////////////////////////////////////////////////////////////////////////////////
858

  
859
  public View getCenter()
860
    {
861
    return mCenter;
862
    }
863

  
864
///////////////////////////////////////////////////////////////////////////////////////////////////
865

  
866
  public void onStartTrackingTouch(SeekBar bar) { }
867

  
868
///////////////////////////////////////////////////////////////////////////////////////////////////
869

  
870
  public void onStopTrackingTouch(SeekBar bar)  { }
871
  }
src/main/java/org/distorted/examples/predeform/PredeformEffectList.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.predeform;
21

  
22
import org.distorted.library.effect.Effect;
23

  
24
import java.util.ArrayList;
25

  
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

  
28
public class PredeformEffectList
29
  {
30
  private static ArrayList<Effect> mList = new ArrayList<>();
31

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

  
34
  static void addNew(Effect effect)
35
    {
36
    mList.add(effect);
37
    }
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
  static void removeAll()
42
    {
43
    mList.clear();
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  static void remove(long id)
49
    {
50
    int size = mList.size();
51
    Effect effect;
52

  
53
    for (int i=0; i<size; i++)
54
      {
55
      effect = mList.get(i);
56

  
57
      if (effect.getID() == id )
58
        {
59
        mList.remove(i);
60
        break;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff