Project

General

Profile

« Previous | Next » 

Revision 7e9be46d

Added by Leszek Koltunski almost 8 years ago

Improve Fragment3D app some more!

View differences:

src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java
41 41
import org.distorted.library.DistortedCubes;
42 42
import org.distorted.library.DistortedObject;
43 43
import org.distorted.library.EffectNames;
44
import org.distorted.library.EffectTypes;
45
import org.distorted.library.type.Dynamic1D;
46
import org.distorted.library.type.Dynamic3D;
47

  
48
import java.util.ArrayList;
44 49

  
45 50
///////////////////////////////////////////////////////////////////////////////////////////////////
46 51

  
......
67 72

  
68 73
  // fields needed for the second 'apply fragment effects' screen
69 74
  //
70
  private SeekBar bar;
71
  private TextView textChroma, textAlpha, textBrightness, textSaturation, textCenter;
72
  private int chromaL, chromaR, chromaG, chromaB;
73
  private int alphaL;
74
  private int brightnessL;
75
  private int saturationL;
75
  private TextView textCenter;
76 76
  private int centerX, centerY;
77

  
78
  private float fchromaL, fchromaR, fchromaG, fchromaB;
79
  private float falphaL;
80
  private float fbrightnessL;
81
  private float fsaturationL;
82 77
  private float fcenterX, fcenterY;
83
  private EffectNames[] effects = new EffectNames[4];
78
  private ArrayList<Fragment3DEffect> mEffects;
84 79

  
85 80
///////////////////////////////////////////////////////////////////////////////////////////////////
86 81
    
......
89 84
    {
90 85
    super.onCreate(savedState);
91 86

  
87
    mEffects = new ArrayList<>();
88

  
92 89
    setContentView(R.layout.objectpickerlayout);
93 90

  
94 91
    mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
......
195 192

  
196 193
///////////////////////////////////////////////////////////////////////////////////////////////////
197 194

  
198
  public void onClick(View view)
195
  public int getBitmap()
199 196
    {
200
    Button tmp = (Button)view;
201
    int id = tmp.getId();
202
    mShape[id] = !mShape[id];
203
    tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
197
    return mBitmap;
204 198
    }
205 199

  
206 200
///////////////////////////////////////////////////////////////////////////////////////////////////
207 201

  
208
  public int getBitmap()
202
  public void onClick(View view)
209 203
    {
210
    return mBitmap;
204
    Button tmp = (Button)view;
205
    int id = tmp.getId();
206
    mShape[id] = !mShape[id];
207
    tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
211 208
    }
212 209

  
213 210
///////////////////////////////////////////////////////////////////////////////////////////////////
214 211

  
215 212
  public void Continue(View v)
216 213
    {
214
    firstScreen = false;
215

  
217 216
    if( mObjectType==1 )
218 217
      {
219
      firstScreen = false;
220 218
      mObject = new DistortedBitmap(100,100,mNumCols);
221
      setContentView(R.layout.fragment3dlayout);
222
      Default(null);
219
      setFragmentView();
223 220
      }
224 221
    else
225 222
      {
......
249 246

  
250 247
    mObject = new DistortedCubes(mNumCols, str, 10);
251 248

  
252
    setContentView(R.layout.fragment3dlayout);
253
    Default(null);
249
    setFragmentView();
254 250
    }
255 251

  
256 252

  
......
281 277
///////////////////////////////////////////////////////////////////////////////////////////////////
282 278
// 'second screen' methods
283 279

  
284
  public void Default(View view)
280
  private void setFragmentView()
285 281
    {
286
    effects[0] = EffectNames.CHROMA;
287
    effects[1] = EffectNames.ALPHA;
288
    effects[2] = EffectNames.BRIGHTNESS;
289
    effects[3] = EffectNames.SATURATION;
290
    
291
    chromaL = 0;
292
    chromaR = 0;
293
    chromaG = 0;
294
    chromaB = 0;
282
    final View view = getLayoutInflater().inflate(R.layout.fragment3dlayout, null);
295 283

  
296
    alphaL     = 0;
297
    brightnessL= 0;
298
    saturationL= 0;
284
    setContentView(view);
299 285

  
300 286
    centerX = 50;
301 287
    centerY = 50;
302 288

  
303
    textCenter = (TextView)findViewById(R.id.fragment3dcenterText);
289
    textCenter = (TextView)view.findViewById(R.id.fragment3dcenterText);
304 290
    computeCenter();
305 291
    setCenterText();
306 292

  
307
    setBar(R.id.fragment3dcenterX, centerX);
308
    setBar(R.id.fragment3dcenterY, centerY);
309

  
310
    addViews();
311
    }
312
    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314
    
315
  private void addViews()
316
    {
317
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
318
    
319
    layout.removeAllViews();
320
      
321
    View chroma    = getLayoutInflater().inflate(R.layout.fragment3dchroma    , null);
322
    View alpha     = getLayoutInflater().inflate(R.layout.fragment3dalpha     , null);
323
    View brightness= getLayoutInflater().inflate(R.layout.fragment3dbrightness, null);
324
    View saturation= getLayoutInflater().inflate(R.layout.fragment3dsaturation, null);
325
     
326
    for( int i=effects.length-1 ; i>=0 ; i-- )
327
      {
328
      switch(effects[i])
329
        {
330
        case CHROMA     : layout.addView(chroma    , 0); break;
331
        case ALPHA      : layout.addView(alpha     , 0); break;
332
        case BRIGHTNESS : layout.addView(brightness, 0); break;
333
        case SATURATION : layout.addView(saturation, 0); break;
334
        }
335
      }
336
      
337
    textChroma    = (TextView)findViewById(R.id.fragment3dchromaText);
338
    textAlpha     = (TextView)findViewById(R.id.fragment3dalphaText);
339
    textBrightness= (TextView)findViewById(R.id.fragment3dbrightnessText);
340
    textSaturation= (TextView)findViewById(R.id.fragment3dsaturationText);
341
     
342
    setChromaText();
343
    setAlphaText();
344
    setBrightnessText();
345
    setSaturationText();
346
      
347
    setBar(R.id.fragment3dchromaBar1, chromaL);
348
    setBar(R.id.fragment3dchromaBar2, chromaR);
349
    setBar(R.id.fragment3dchromaBar3, chromaG);
350
    setBar(R.id.fragment3dchromaBar4, chromaB);
351

  
352
    setBar(R.id.fragment3dalphaBar1     , alphaL);
353
    setBar(R.id.fragment3dbrightnessBar1, brightnessL);
354
    setBar(R.id.fragment3dsaturationBar1, saturationL);
355

  
356
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
357
    view.getRenderer().setOrder(effects);
358
    }
359

  
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

  
362
  private void moveUp(EffectNames name)
363
    {
364
    int len = effects.length-1;
365
    int index = -1;
293
    SeekBar bar;
366 294

  
367
    for(int i=0; i<=len; i++)
368
      {
369
      if( effects[i]==name )
370
        {
371
        index=i;
372
        break;
373
        }
374
      }
375

  
376
    if( index==0 )
377
      {
378
      for(int i=0; i<len; i++)
379
        effects[i] = effects[i+1];
380

  
381
      effects[len] = name;
382
      }
383
    else if( index>0 )
384
      {
385
      effects[index]   = effects[index-1];
386
      effects[index-1] = name;
387
      }
388

  
389
    addViews();
390
    }
391

  
392
///////////////////////////////////////////////////////////////////////////////////////////////////
295
    bar = (SeekBar)view.findViewById(R.id.fragment3dcenterX);
296
    bar.setOnSeekBarChangeListener(this);
297
    bar.setProgress(centerX);
393 298

  
394
  public void ButtonChroma(View v)
395
    {
396
    moveUp(EffectNames.CHROMA);
299
    bar = (SeekBar)view.findViewById(R.id.fragment3dcenterY);
300
    bar.setOnSeekBarChangeListener(this);
301
    bar.setProgress(centerY);
397 302
    }
398 303

  
399 304
///////////////////////////////////////////////////////////////////////////////////////////////////
400 305

  
401
  public void ButtonAlpha(View v)
306
  public void newChroma(View v)
402 307
    {
403
    moveUp(EffectNames.ALPHA);
404
    }
308
    Fragment3DEffect chroma = new Fragment3DEffect(EffectNames.CHROMA);
309
    mEffects.add(chroma);
405 310

  
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

  
408
  public void ButtonBrightness(View v)
409
    {
410
    moveUp(EffectNames.BRIGHTNESS);
411
    }
311
    View view = chroma.createView(this);
312
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
313
    layout.addView(view,0);
412 314

  
413
///////////////////////////////////////////////////////////////////////////////////////////////////
315
    Dynamic1D dyn1 = chroma.getDyn1();
316
    Dynamic3D dyn3 = chroma.getDyn3();
414 317

  
415
  public void ButtonSaturation(View v)
416
    {
417
    moveUp(EffectNames.SATURATION);
318
    mObject.chroma(dyn1,dyn3);
418 319
    }
419 320

  
420 321
///////////////////////////////////////////////////////////////////////////////////////////////////
421 322

  
422
  private void setBar(int id, int value)
323
  public void newAlpha(View v)
423 324
    {
424
    bar = (SeekBar)findViewById(id);
425
    bar.setOnSeekBarChangeListener(this);
426
    bar.setProgress(value);
427
    }
428

  
429
///////////////////////////////////////////////////////////////////////////////////////////////////
325
    Fragment3DEffect alpha = new Fragment3DEffect(EffectNames.ALPHA);
326
    mEffects.add(alpha);
430 327

  
431
  private void computeChroma()
432
    {
433
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
434
    Fragment3DRenderer renderer = view.getRenderer();
328
    View view = alpha.createView(this);
329
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
330
    layout.addView(view,0);
435 331

  
436
    fchromaL = chromaL/100.0f;
437
    fchromaR = chromaR*255/100.0f;
438
    fchromaG = chromaG*255/100.0f;
439
    fchromaB = chromaB*255/100.0f;
332
    Dynamic1D dyn1 = alpha.getDyn1();
440 333

  
441
    renderer.setChroma( fchromaL, fchromaR, fchromaG, fchromaB );
334
    mObject.alpha(dyn1);
442 335
    }
443 336

  
444 337
///////////////////////////////////////////////////////////////////////////////////////////////////
445 338

  
446
  private void setChromaText()
339
  public void newBrightness(View v)
447 340
    {
448
    fchromaL = ((int)(100*fchromaL))/100.0f;
449
    fchromaR = (float)((int)fchromaR);
450
    fchromaG = (float)((int)fchromaG);
451
    fchromaB = (float)((int)fchromaB);
341
    Fragment3DEffect brightness = new Fragment3DEffect(EffectNames.BRIGHTNESS);
342
    mEffects.add(brightness);
452 343

  
453
    textChroma.setText("chroma("+fchromaL+"( "+fchromaR+" , "+fchromaG+" , "+fchromaB+" )");
454
    }
455

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

  
458
  private void computeAlpha()
459
    {
460
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
344
    View view = brightness.createView(this);
345
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
346
    layout.addView(view,0);
461 347

  
462
    falphaL = alphaL/100.0f;
348
    Dynamic1D dyn1 = brightness.getDyn1();
463 349

  
464
    view.getRenderer().setAlpha(falphaL);
350
    mObject.brightness(dyn1);
465 351
    }
466 352

  
467 353
///////////////////////////////////////////////////////////////////////////////////////////////////
468 354

  
469
  private void setAlphaText()
355
  public void newSaturation(View v)
470 356
    {
471
    falphaL = ((int)(100*falphaL))/100.0f;
472

  
473
    textAlpha.setText("alpha("+falphaL+")");
474
    }
357
    Fragment3DEffect saturation = new Fragment3DEffect(EffectNames.SATURATION);
358
    mEffects.add(saturation);
475 359

  
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

  
478
  private void computeBrightness()
479
    {
480
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
360
    View view = saturation.createView(this);
361
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
362
    layout.addView(view,0);
481 363

  
482
    fbrightnessL = brightnessL/100.0f;
364
    Dynamic1D dyn1 = saturation.getDyn1();
483 365

  
484
    view.getRenderer().setBrightness( fbrightnessL );
366
    mObject.saturation(dyn1);
485 367
    }
486 368

  
487 369
///////////////////////////////////////////////////////////////////////////////////////////////////
488 370

  
489
  private void setBrightnessText()
371
  public void removeAll(View v)
490 372
    {
491
    fbrightnessL = ((int)(100*fbrightnessL))/100.0f;
492

  
493
    textBrightness.setText("brightness("+fbrightnessL+")");
494
    }
495

  
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

  
498
  private void computeSaturation()
499
    {
500
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
501

  
502
    fsaturationL = saturationL/100.0f;
503

  
504
    view.getRenderer().setSaturation( fsaturationL );
505
    }
506
    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

  
509
  private void setSaturationText()
510
    {
511
    fsaturationL = ((int)(100*fsaturationL))/100.0f;
512

  
513
    textSaturation.setText("saturation("+fsaturationL+")");
373
    mEffects.clear();
374
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
375
    layout.removeAllViews();
376
    mObject.abortEffects(EffectTypes.FRAGMENT);
514 377
    }
515 378

  
516 379
///////////////////////////////////////////////////////////////////////////////////////////////////
......
599 462
    {
600 463
    switch (bar.getId())
601 464
      {
602
      case R.id.fragment3dcenterX       : centerX    = progress; computeCenter()    ; setCenterText()    ; break;
603
      case R.id.fragment3dcenterY       : centerY    = progress; computeCenter()    ; setCenterText()    ; break;
604
      case R.id.fragment3dchromaBar1    : chromaL    = progress; computeChroma()    ; setChromaText()    ; break;
605
      case R.id.fragment3dchromaBar2    : chromaR    = progress; computeChroma()    ; setChromaText()    ; break;
606
      case R.id.fragment3dchromaBar3    : chromaG    = progress; computeChroma()    ; setChromaText()    ; break;
607
      case R.id.fragment3dchromaBar4    : chromaB    = progress; computeChroma()    ; setChromaText()    ; break;
608
      case R.id.fragment3dalphaBar1     : alphaL     = progress; computeAlpha()     ; setAlphaText()     ; break;
609
      case R.id.fragment3dbrightnessBar1: brightnessL= progress; computeBrightness(); setBrightnessText(); break;
610
      case R.id.fragment3dsaturationBar1: saturationL= progress; computeSaturation(); setSaturationText(); break;
465
      case R.id.fragment3dcenterX: centerX    = progress; computeCenter()    ; setCenterText()    ; break;
466
      case R.id.fragment3dcenterY: centerY    = progress; computeCenter()    ; setCenterText()    ; break;
611 467
      }
612 468
    }
613 469

  

Also available in: Unified diff