Project

General

Profile

« Previous | Next » 

Revision 46ab4363

Added by Leszek Koltunski over 7 years ago

1st attempt to restore internal variables in Multiblur.

View differences:

src/main/java/org/distorted/examples/multiblur/MultiblurActivity.java
78 78
      super.onDestroy();
79 79
      }
80 80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
    @Override
84
    public void onSaveInstanceState(Bundle savedInstanceState)
85
      {
86
      super.onSaveInstanceState(savedInstanceState);
87

  
88
      MultiblurSurfaceView view = (MultiblurSurfaceView) this.findViewById(R.id.multiblurSurfaceView);
89
      MultiblurRenderer renderer = view.getRenderer();
90

  
91
      savedInstanceState.putBooleanArray("checkboxes", renderer.getChecked() );
92
      }
93

  
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

  
96
    @Override
97
    public void onRestoreInstanceState(Bundle savedInstanceState)
98
      {
99
      super.onRestoreInstanceState(savedInstanceState);
100

  
101
      boolean[] checkboxes = savedInstanceState.getBooleanArray("checkboxes");
102

  
103
      MultiblurSurfaceView view = (MultiblurSurfaceView) this.findViewById(R.id.multiblurSurfaceView);
104
      MultiblurRenderer renderer = view.getRenderer();
105

  
106
      if( checkboxes!=null )
107
        {
108
        for(int i=0; i<checkboxes.length; i++)
109
          {
110
          renderer.setChecked(i,checkboxes[i]);
111
          }
112
        }
113
      }
114

  
81 115
///////////////////////////////////////////////////////////////////////////////////////////////////
82 116

  
83 117
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
......
113 147

  
114 148
    switch(id)
115 149
      {
116
      case R.id.multiblurCheckBox0  : sView.getRenderer().pressed(0,checked); break;
117
      case R.id.multiblurCheckBox1  : sView.getRenderer().pressed(1,checked); break;
118
      case R.id.multiblurCheckBox2  : sView.getRenderer().pressed(2,checked); break;
119
      case R.id.multiblurCheckBox3  : sView.getRenderer().pressed(3,checked); break;
120
      case R.id.multiblurCheckBox4  : sView.getRenderer().pressed(4,checked); break;
121
      case R.id.multiblurCheckBox5  : sView.getRenderer().pressed(5,checked); break;
122
      case R.id.multiblurCheckBox6  : sView.getRenderer().pressed(6,checked); break;
123
      case R.id.multiblurCheckBox7  : sView.getRenderer().pressed(7,checked); break;
150
      case R.id.multiblurCheckBox0  : sView.getRenderer().setChecked(0,checked); break;
151
      case R.id.multiblurCheckBox1  : sView.getRenderer().setChecked(1,checked); break;
152
      case R.id.multiblurCheckBox2  : sView.getRenderer().setChecked(2,checked); break;
153
      case R.id.multiblurCheckBox3  : sView.getRenderer().setChecked(3,checked); break;
154
      case R.id.multiblurCheckBox4  : sView.getRenderer().setChecked(4,checked); break;
155
      case R.id.multiblurCheckBox5  : sView.getRenderer().setChecked(5,checked); break;
156
      case R.id.multiblurCheckBox6  : sView.getRenderer().setChecked(6,checked); break;
157
      case R.id.multiblurCheckBox7  : sView.getRenderer().setChecked(7,checked); break;
124 158
      }
125 159
    }
126 160
}
src/main/java/org/distorted/examples/multiblur/MultiblurRenderer.java
73 73
    private DistortedScreen mScreen;
74 74
    private DynamicQuat mQuatInt1, mQuatInt2;
75 75
    private int mDistance;
76
    private boolean[] mBlurStatus;
76 77

  
77 78
    Static4D mQuat1, mQuat2;
78 79
    int mScreenMin;
......
84 85
      mView = v;
85 86
      mDistance = -1;
86 87

  
88
      mBlurStatus = new boolean[NUM_OBJECTS];
87 89
      mMoveDynamic= new Dynamic3D[NUM_OBJECTS];
88 90
      mMoveVector = new Static3D[NUM_OBJECTS];
89 91
      mEffects    = new DistortedEffects[NUM_OBJECTS];
......
95 97
        mMoveDynamic[i] = new Dynamic3D();
96 98

  
97 99
        mMoveDynamic[i].add(mMoveVector[i]);
100
        mBlurStatus[i] = false;
98 101
        }
99 102

  
100 103
      mBlurDynamic= new Dynamic1D();
101 104
      mBlurVector = new Static1D(10);
102 105
      mBlurDynamic.add(mBlurVector);
103 106

  
107
      mBlurStatus[0] = true;
104 108
      mEffects[0].blur(mBlurDynamic);
105 109

  
106 110
      MeshCubes mesh = new MeshCubes(1,1,false);
......
206 210
        }
207 211
      }
208 212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
    int getDistance()
216
      {
217
      return mDistance;
218
      }
219

  
209 220
///////////////////////////////////////////////////////////////////////////////////////////////////
210 221

  
211 222
    void setDistance(int distance)
......
215 226
      android.util.Log.e("renderer", "distance: "+distance);
216 227
      }
217 228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

  
231
    int getRange()
232
      {
233
      return (int)mBlurVector.getX();
234
      }
235

  
218 236
///////////////////////////////////////////////////////////////////////////////////////////////////
219 237

  
220 238
    void setRange(int range)
......
225 243

  
226 244
///////////////////////////////////////////////////////////////////////////////////////////////////
227 245

  
228
   void pressed(int number, boolean checked)
246
   boolean[] getChecked()
247
     {
248
     return mBlurStatus;
249
     }
250

  
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

  
253
   void setChecked(int number, boolean checked)
229 254
     {
230 255
     if( number>=0 && number<=7 && mEffects!=null )
231 256
       {
232 257
       if( checked )
233 258
         {
234
         long effectNum = mEffects[number].blur(mBlurDynamic);
235

  
236
         if( effectNum<0 )
259
         if( !mBlurStatus[number] )
237 260
           {
238
           android.util.Log.e("renderer", "Error, failed to add BLUR effect, number: "+number );
261
           mBlurStatus[number] = true;
262
           mEffects[number].blur(mBlurDynamic);
239 263
           }
240 264
         else
241 265
           {
242
           android.util.Log.e("renderer", "Successfully added BLUR effect, number: "+number );
266
           android.util.Log.e("renderer", "Error, failed to add BLUR effect, number: "+number );
243 267
           }
244 268
         }
245 269
       else
246 270
         {
247
         int numAborted = mEffects[number].abortEffects(EffectNames.BLUR);
248

  
249
         if( numAborted!=1 )
271
         if( mBlurStatus[number] )
272
           {
273
           mBlurStatus[number] = false;
274
           mEffects[number].abortEffects(EffectNames.BLUR);
275
           }
276
         else
250 277
           {
251
           android.util.Log.e("renderer", "Error, number: "+number+" unexpected number of effects aborted ("+numAborted+" - should have been 1)" );
278
           android.util.Log.e("renderer", "Error, failed to remove BLUR effect, number: "+number );
252 279
           }
253 280
         }
254 281
       }

Also available in: Unified diff