Android Open Source - block-composer U I Element Picture






From Project

Back to project page block-composer.

License

The source code is released under:

MIT License

If you think the Android project block-composer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package bwr.blockcomposer.ui;
/*ww w  .  j  a va2s  .com*/
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import javax.microedition.khronos.opengles.GL10;

import bwr.blockcomposer.GameResources;
import bwr.blockcomposer.R;

import android.content.Context;

public class UIElementPicture implements UIElement {
  public final int id;
  public final int x, y, width, height;
  public boolean hidden = false;
  
  public final IntBuffer mVertexBuffer;
  public final ByteBuffer mIndexBuffer;
  private IntBuffer textureBuffer;
    
  public static final int BUTTON_UP = 0;
  public static final int BUTTON_DOWN = 1;
  public static final int BUTTON_LEFT = 2;
  public static final int BUTTON_RIGHT = 3;
  
  final int textureVertices[][] = {
    {    0,     0,  // UP
       0, 1<<16,
     1<<16, 1<<16,
     1<<16,     0, },
    {1<<16, 1<<16,  // DOWN
     1<<16,     0,
         0,     0,
         0, 1<<16, },
        {    0,     0,  // LEFT
     1<<16,     0,
       1<<16, 1<<16,
         0, 1<<16, },
    {1<<16, 1<<16,  // RIGHT
         0, 1<<16,
       0,     0,
     1<<16,     0 },
  };
  
  public UIElementPicture(int id, int x, int y, int width, int height, int direction) {
    this.id = id;
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    
    final int vertices[] = {
        x<<16, y<<16, 0,
        x<<16, (y-height)<<16, 0,
        (x+width)<<16, (y-height)<<16, 0,
        (x+width)<<16, y<<16, 0
    };
    
      final byte indices[] = {
          0, 1, 2,
          0, 2, 3
      };
    
    ByteBuffer tmp = ByteBuffer.allocateDirect(vertices.length*4);
    tmp.order(ByteOrder.nativeOrder());
    mVertexBuffer = tmp.asIntBuffer();
    mVertexBuffer.put(vertices);
    mVertexBuffer.position(0);
    
    tmp = ByteBuffer.allocateDirect(textureVertices[direction].length * 4);
    tmp.order(ByteOrder.nativeOrder());
    textureBuffer = tmp.asIntBuffer();
    textureBuffer.put(textureVertices[direction]);
    textureBuffer.position(0);
    
        mIndexBuffer = ByteBuffer.allocateDirect(indices.length);
        mIndexBuffer.put(indices);
        mIndexBuffer.position(0);
  }

  
  public boolean isHit(int x, int y) {
    return x >= this.x && x <= (this.x+width) && y<=this.y && y >= (this.y-height);
  }
  
  public void draw(GL10 gl, GameResources gameResources) {
    gameResources.bindTexture(gl, R.drawable.up);

        gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, textureBuffer);
        gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
  }


  public void update(Context context, GL10 gl, long dt) {
    // nothing
  }


  public int getId() {
    return id;
  }
  
}




Java Source Code List

bwr.blockcomposer.AnimationFinishedListener.java
bwr.blockcomposer.BlockComposerActivity.java
bwr.blockcomposer.BlockComposerRenderer.java
bwr.blockcomposer.BlockComposer.java
bwr.blockcomposer.Camera.java
bwr.blockcomposer.GameResources.java
bwr.blockcomposer.OnUpdateAction.java
bwr.blockcomposer.gamedata.Block.java
bwr.blockcomposer.gamedata.GameEntity.java
bwr.blockcomposer.gamedata.GameState.java
bwr.blockcomposer.gamedata.LevelDimensions.java
bwr.blockcomposer.gamedata.LevelMask.java
bwr.blockcomposer.gamedata.LevelMetadata.java
bwr.blockcomposer.gamedata.LevelStore.java
bwr.blockcomposer.gamedata.Level.java
bwr.blockcomposer.gamedata.Move.java
bwr.blockcomposer.gamedata.StaticLevelStore.java
bwr.blockcomposer.gamedata.UserLevelStore.java
bwr.blockcomposer.misc.GLUtility.java
bwr.blockcomposer.misc.Timer.java
bwr.blockcomposer.models.AxisRenderer.java
bwr.blockcomposer.models.Model.java
bwr.blockcomposer.models.SelectBoxRenderer.java
bwr.blockcomposer.modes.EditMode.java
bwr.blockcomposer.modes.GameDialogMode.java
bwr.blockcomposer.modes.GameMode.java
bwr.blockcomposer.modes.LevelImportMode.java
bwr.blockcomposer.modes.LevelSelectMode.java
bwr.blockcomposer.modes.LogoDisplayMode.java
bwr.blockcomposer.modes.ModeController.java
bwr.blockcomposer.modes.Mode.java
bwr.blockcomposer.modes.OverlayMode.java
bwr.blockcomposer.types.FlipRotateFloat.java
bwr.blockcomposer.types.FloatValueVector3.java
bwr.blockcomposer.types.FloatValue.java
bwr.blockcomposer.types.IntVector.java
bwr.blockcomposer.types.RotatingFloat.java
bwr.blockcomposer.ui.TextRenderer.java
bwr.blockcomposer.ui.UIElementPicture.java
bwr.blockcomposer.ui.UIElementText.java
bwr.blockcomposer.ui.UIElement.java