Project

General

Profile

« Previous | Next » 

Revision 9167cfd4

Added by Leszek Koltunski over 8 years ago

Vertex3D: Add the new 'Grid' bitmap option!

View differences:

src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
20 20
package org.distorted.examples.vertex3d;
21 21

  
22 22
import android.app.Activity;
23
import android.graphics.Bitmap;
24
import android.graphics.BitmapFactory;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
23 27
import android.opengl.GLSurfaceView;
24 28
import android.os.Bundle;
25 29
import android.view.Gravity;
......
43 47
import org.distorted.library.type.Dynamic2D;
44 48
import org.distorted.library.type.Dynamic3D;
45 49
import org.distorted.library.type.Dynamic4D;
50
import org.distorted.library.type.Static3D;
46 51

  
52
import java.io.IOException;
53
import java.io.InputStream;
47 54
import java.util.ArrayList;
48 55

  
49 56
///////////////////////////////////////////////////////////////////////////////////////////////////
......
125 132
    Spinner bitmapSpinner  = (Spinner)findViewById(R.id.objectpicker_spinnerBitmap);
126 133
    bitmapSpinner.setOnItemSelectedListener(this);
127 134

  
128
    String[] objectBitmap = new String[] {"Girl", "Dog", "Cat", "Grid"};
135
    String[] objectBitmap = new String[] { "Grid", "Girl", "Dog", "Cat", "Squares"};
129 136

  
130 137
    ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
131 138
    adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
......
187 194

  
188 195
///////////////////////////////////////////////////////////////////////////////////////////////////
189 196

  
190
  public int getBitmap()
197
  public Bitmap getBitmap()
191 198
    {
192
    return mBitmap;
199
    Bitmap bmp;
200

  
201
    if( mBitmap!=-1)
202
      {
203
      InputStream is = getResources().openRawResource(mBitmap);
204

  
205
      try
206
        {
207
        bmp = BitmapFactory.decodeStream(is);
208
        }
209
      finally
210
        {
211
        try
212
          {
213
          is.close();
214
          }
215
        catch(IOException e) { }
216
        }
217
      }
218
    else
219
      {
220
      final int W = 640;
221
      final int H = 640;
222

  
223
      Paint paint = new Paint();
224
      bmp = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
225
      Canvas canvas = new Canvas(bmp);
226

  
227
      paint.setAntiAlias(true);
228
      paint.setTextAlign(Paint.Align.CENTER);
229
      paint.setColor(0xff008800);
230
      paint.setStyle(Paint.Style.FILL);
231
      canvas.drawRect(0, 0, W, H, paint);
232
      paint.setColor(0xffffffff);
233

  
234
      for(int i=0; i<=mNumCols ; i++ )
235
        {
236
        canvas.drawRect(W*i/mNumCols - 1,                0,  W*i/mNumCols + 1,  H               , paint);
237
        canvas.drawRect(               0, H *i/mNumCols -1,  W               ,  H*i/mNumCols + 1, paint);
238
        }
239
      }
240

  
241
    return bmp;
193 242
    }
194 243

  
195 244
///////////////////////////////////////////////////////////////////////////////////////////////////
......
315 364
                                            break;
316 365
      case R.id.objectpicker_spinnerBitmap: switch(pos)
317 366
                                              {
318
                                              case 0: mBitmap = R.raw.face; break;
319
                                              case 1: mBitmap = R.raw.dog;  break;
320
                                              case 2: mBitmap = R.raw.cat;  break;
321
                                              case 3: mBitmap = R.raw.grid; break;
367
                                              case 0: mBitmap = -1        ; break;
368
                                              case 1: mBitmap = R.raw.face; break;
369
                                              case 2: mBitmap = R.raw.dog;  break;
370
                                              case 3: mBitmap = R.raw.cat;  break;
371
                                              case 4: mBitmap = R.raw.grid; break;
322 372
                                              }
323 373
                                            break;
324 374
      case R.id.vertex3dspinner           : mEffectAdd = pos;
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
198 198
      {
199 199
      Vertex3DActivity act = (Vertex3DActivity)mView.getContext();
200 200

  
201
      InputStream is1 = act.getResources().openRawResource(act.getBitmap());
202
      InputStream is2 = act.getResources().openRawResource(R.raw.water);
203
      InputStream is3 = act.getResources().openRawResource(R.raw.center);
204
      InputStream is4 = act.getResources().openRawResource(R.raw.region);
201
      InputStream is1 = act.getResources().openRawResource(R.raw.water);
202
      InputStream is2 = act.getResources().openRawResource(R.raw.center);
203
      InputStream is3 = act.getResources().openRawResource(R.raw.region);
205 204

  
206
      Bitmap bitmap1,bitmap2,bitmap3,bitmap4;
205
      Bitmap bitmap1,bitmap2,bitmap3;
207 206
        
208 207
      try 
209 208
        {
210 209
        bitmap1 = BitmapFactory.decodeStream(is1);
211 210
        bitmap2 = BitmapFactory.decodeStream(is2);
212 211
        bitmap3 = BitmapFactory.decodeStream(is3);
213
        bitmap4 = BitmapFactory.decodeStream(is4);
214 212
        }
215 213
      finally 
216 214
        {
......
219 217
          is1.close();
220 218
          is2.close();
221 219
          is3.close();
222
          is4.close();
223
          } 
220
          }
224 221
        catch(IOException e) { }
225 222
        }  
226 223
      
227
      mObject.setBitmap(bitmap1);
228
      mBackground.setBitmap(bitmap2);
229
      mCenter.setBitmap(bitmap3);
230
      mRegion.setBitmap(bitmap4);
224
      mObject.setBitmap( act.getBitmap() );
225
      mBackground.setBitmap(bitmap1);
226
      mCenter.setBitmap(bitmap2);
227
      mRegion.setBitmap(bitmap3);
231 228

  
232 229
      try
233 230
        {

Also available in: Unified diff