Project

General

Profile

« Previous | Next » 

Revision b4a73ea5

Added by Leszek Koltunski almost 8 years ago

Essentially revert the last commit :)

View differences:

src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java
42 42
import org.distorted.library.DistortedObject;
43 43
import org.distorted.library.EffectNames;
44 44

  
45
import java.util.ArrayList;
46

  
47 45
///////////////////////////////////////////////////////////////////////////////////////////////////
48 46

  
49 47
public class Fragment3DActivity extends Activity
50
                                implements View.OnClickListener,
48
                                implements OnSeekBarChangeListener,
49
                                           View.OnClickListener,
51 50
                                           AdapterView.OnItemSelectedListener
52 51
  {
53 52
  private static final int COLOR_OFF = 0xffffe81f;
......
55 54

  
56 55
  private boolean firstScreen;
57 56

  
57
  // fields needed for the first 'pick-a-shape' screen
58
  //
58 59
  private int mNumCols = 3;
59 60
  private int mNumRows = 3;
60 61
  private NumberPicker mColsPicker, mRowsPicker;
......
64 65
  private int mObjectType;
65 66
  private int mBitmap;
66 67

  
67
  private ArrayList<Fragment3DEffect> mEffects = new ArrayList<>();
68
  private DistortedBitmap mCenter = null;
68
  // fields needed for the second 'apply fragment effects' screen
69
  //
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;
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
  private float fcenterX, fcenterY;
83
  private EffectNames[] effects = new EffectNames[4];
69 84

  
70 85
///////////////////////////////////////////////////////////////////////////////////////////////////
71 86
    
......
204 219
      firstScreen = false;
205 220
      mObject = new DistortedBitmap(100,100,mNumCols);
206 221
      setContentView(R.layout.fragment3dlayout);
222
      Default(null);
207 223
      }
208 224
    else
209 225
      {
......
232 248
      str += mShape[i] ? "1" : "0";
233 249

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

  
235 252
    setContentView(R.layout.fragment3dlayout);
253
    Default(null);
236 254
    }
237 255

  
238 256

  
......
263 281
///////////////////////////////////////////////////////////////////////////////////////////////////
264 282
// 'second screen' methods
265 283

  
266
  private void removeAllViews()
284
  public void Default(View view)
267 285
    {
268
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
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;
295

  
296
    alphaL     = 0;
297
    brightnessL= 0;
298
    saturationL= 0;
299

  
300
    centerX = 50;
301
    centerY = 50;
302

  
303
    textCenter = (TextView)findViewById(R.id.fragment3dcenterText);
304
    computeCenter();
305
    setCenterText();
269 306

  
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
    
270 319
    layout.removeAllViews();
271
    mEffects.clear();
272
    mCenter = null;
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);
273 358
    }
274 359

  
275 360
///////////////////////////////////////////////////////////////////////////////////////////////////
276 361

  
277
  private void addView(EffectNames name)
362
  private void moveUp(EffectNames name)
278 363
    {
279
    Fragment3DEffect newInfo = new Fragment3DEffect(name);
280
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
281
    newInfo.addView(layout);
282
    mEffects.add(newInfo);
364
    int len = effects.length-1;
365
    int index = -1;
366

  
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
///////////////////////////////////////////////////////////////////////////////////////////////////
393

  
394
  public void ButtonChroma(View v)
395
    {
396
    moveUp(EffectNames.CHROMA);
397
    }
398

  
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

  
401
  public void ButtonAlpha(View v)
402
    {
403
    moveUp(EffectNames.ALPHA);
404
    }
405

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

  
408
  public void ButtonBrightness(View v)
409
    {
410
    moveUp(EffectNames.BRIGHTNESS);
411
    }
412

  
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

  
415
  public void ButtonSaturation(View v)
416
    {
417
    moveUp(EffectNames.SATURATION);
418
    }
419

  
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

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

  
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

  
431
  private void computeChroma()
432
    {
433
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
434
    Fragment3DRenderer renderer = view.getRenderer();
435

  
436
    fchromaL = chromaL/100.0f;
437
    fchromaR = chromaR*255/100.0f;
438
    fchromaG = chromaG*255/100.0f;
439
    fchromaB = chromaB*255/100.0f;
440

  
441
    renderer.setChroma( fchromaL, fchromaR, fchromaG, fchromaB );
283 442
    }
284 443

  
285 444
///////////////////////////////////////////////////////////////////////////////////////////////////
286 445

  
287
  public void Remove(View v)
446
  private void setChromaText()
288 447
    {
289
    removeAllViews();
448
    fchromaL = ((int)(100*fchromaL))/100.0f;
449
    fchromaR = (float)((int)fchromaR);
450
    fchromaG = (float)((int)fchromaG);
451
    fchromaB = (float)((int)fchromaB);
452

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

  
292 456
///////////////////////////////////////////////////////////////////////////////////////////////////
293 457

  
294
  public void newChroma(View v)
458
  private void computeAlpha()
295 459
    {
296
    addView(EffectNames.CHROMA);
460
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
461

  
462
    falphaL = alphaL/100.0f;
463

  
464
    view.getRenderer().setAlpha(falphaL);
297 465
    }
298 466

  
299 467
///////////////////////////////////////////////////////////////////////////////////////////////////
300 468

  
301
  public void newAlpha(View v)
469
  private void setAlphaText()
302 470
    {
303
    addView(EffectNames.ALPHA);
471
    falphaL = ((int)(100*falphaL))/100.0f;
472

  
473
    textAlpha.setText("alpha("+falphaL+")");
304 474
    }
305 475

  
306 476
///////////////////////////////////////////////////////////////////////////////////////////////////
307 477

  
308
  public void newBrightness(View v)
478
  private void computeBrightness()
309 479
    {
310
    addView(EffectNames.BRIGHTNESS);
480
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
481

  
482
    fbrightnessL = brightnessL/100.0f;
483

  
484
    view.getRenderer().setBrightness( fbrightnessL );
311 485
    }
312 486

  
313 487
///////////////////////////////////////////////////////////////////////////////////////////////////
314 488

  
315
  public void newSaturation(View v)
489
  private void setBrightnessText()
316 490
    {
317
    addView(EffectNames.SATURATION);
491
    fbrightnessL = ((int)(100*fbrightnessL))/100.0f;
492

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

  
320 496
///////////////////////////////////////////////////////////////////////////////////////////////////
321 497

  
322
  public DistortedBitmap getCenter()
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()
323 510
    {
324
    return mCenter;
511
    fsaturationL = ((int)(100*fsaturationL))/100.0f;
512

  
513
    textSaturation.setText("saturation("+fsaturationL+")");
325 514
    }
326 515

  
327 516
///////////////////////////////////////////////////////////////////////////////////////////////////
328 517

  
329
  public void setCenter(DistortedBitmap center  )
518
  private void computeCenter()
330 519
    {
331
    mCenter = center;
520
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
521

  
522
    fcenterX = centerX;
523
    fcenterY = centerY;
524

  
525
    view.getRenderer().setCenter( fcenterX, fcenterY );
526
    }
527

  
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529

  
530
  private void setCenterText()
531
    {
532
    fcenterX = ((int)(100*fcenterX))/100.0f;
533
    fcenterY = ((int)(100*fcenterY))/100.0f;
534

  
535
    textCenter.setText("center("+fcenterX+","+fcenterY+")");
536
    }
537

  
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539

  
540
  public float getCenterX()
541
    {
542
    return fcenterX;
543
    }
544

  
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546

  
547
  public float getCenterY()
548
    {
549
    return fcenterY;
332 550
    }
333 551

  
334 552
///////////////////////////////////////////////////////////////////////////////////////////////////
......
374 592
    Distorted.onDestroy();
375 593
    super.onDestroy();
376 594
    }
595
    
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597
    
598
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
599
    {
600
    switch (bar.getId())
601
      {
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;
611
      }
612
    }
613

  
614
///////////////////////////////////////////////////////////////////////////////////////////////////
615

  
616
  public void onStartTrackingTouch(SeekBar bar) { }
617
    
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

  
620
  public void onStopTrackingTouch(SeekBar bar)  { }
377 621
  }

Also available in: Unified diff