/TheElements/src/sand/falling/opengl/SandView.java

http://thelements.googlecode.com/ · Java · 89 lines · 70 code · 13 blank · 6 comment · 11 complexity · 10692b093680e7ef535431ca97a63c39 MD5 · raw file

  1. package sand.falling.opengl;
  2. import javax.microedition.khronos.egl.EGLConfig;
  3. import javax.microedition.khronos.opengles.GL10;
  4. import android.content.Context;
  5. import android.opengl.GLSurfaceView;
  6. import android.util.AttributeSet;
  7. import android.util.Log;
  8. import android.view.MotionEvent;
  9. public class SandView extends GLSurfaceView
  10. {
  11. private static int fd; //Set the "finger down" variable
  12. public SandView(Context context, AttributeSet attrs)
  13. {
  14. super(context, attrs);
  15. mRenderer = new DemoRenderer(); //Set up the Renderer for the View
  16. setRenderer(mRenderer); //Set it as the main
  17. Log.v("DemoActivity", "SandView Constructor");
  18. }
  19. //When finger is held down, flood of events killing framerate, need to put in it's own thread at some point
  20. //and then use the sleep tactic
  21. public boolean onTouchEvent(final MotionEvent event) //Finger down
  22. {
  23. // Gets the mouse position
  24. if (event.getAction() == MotionEvent.ACTION_DOWN)
  25. {
  26. if (fd != 1) //if it has changed
  27. {
  28. MainActivity.setFingerState(1); //sets the finger state in jni
  29. }
  30. else
  31. {
  32. fd = 1;
  33. }
  34. }
  35. else if (event.getAction() == MotionEvent.ACTION_UP)
  36. {
  37. MainActivity.setFingerState(2);
  38. }
  39. if(MainActivity.size == 0)
  40. {
  41. //Both x and y are halved because it needs to be zoomed in
  42. MainActivity.setMouseLocation((int)event.getX()/2, (int)event.getY()/2); //sets the mouse position in jdk
  43. }
  44. else
  45. {
  46. //Not zoomed in
  47. MainActivity.setMouseLocation((int)event.getX(), (int)event.getY()); //sets the mouse position in jdk
  48. }
  49. return true;
  50. }
  51. DemoRenderer mRenderer; //Declare the renderer
  52. }
  53. class DemoRenderer implements GLSurfaceView.Renderer
  54. {
  55. public void onSurfaceCreated(GL10 gl, EGLConfig config)
  56. {
  57. nativeInit();
  58. }
  59. public void onSurfaceChanged(GL10 gl, int w, int h)
  60. {
  61. //gl.glViewport(0, 0, w, h);
  62. nativeResize(w, h);
  63. if (MainActivity.loaddemov == true) //loads the demo from the sdcard on first run.
  64. {
  65. MainActivity.loadDemo();
  66. MainActivity.loaddemov = false;
  67. }
  68. }
  69. public void onDrawFrame(GL10 gl)
  70. {
  71. nativeRender(); //Actual rendering - everything happens here
  72. }
  73. private static native void nativeInit(); //Jni init
  74. private static native void nativeResize(int w, int h); //Jni resize
  75. private static native void nativeRender(); //Jni rendering function - everything happens here
  76. }