TextShape.java
Go to the documentation of this file.
00001 package org.ros.android.view.visualization.shape;
00002 
00003 import org.ros.android.view.visualization.Vertices;
00004 import org.ros.android.view.visualization.VisualizationView;
00005 
00006 import java.nio.FloatBuffer;
00007 
00008 import javax.microedition.khronos.opengles.GL10;
00009 
00010 import uk.co.blogspot.fractiousg.texample.GLText;
00011 
00012 public class TextShape extends BaseShape {
00013 
00014   private final GLText glText;
00015   private final String text;
00016 
00017   private float x;
00018   private float y;
00019   private FloatBuffer lines;
00020 
00021   public TextShape(GLText glText, String text) {
00022     this.glText = glText;
00023     this.text = text;
00024     lines = Vertices.allocateBuffer(4 * 3);
00025   }
00026 
00027   public void setOffset(float x, float y) {
00028     this.x = x;
00029     this.y = y;
00030     lines.put(0.f);
00031     lines.put(0.f);
00032     lines.put(0.f);
00033 
00034     lines.put(x);
00035     lines.put(y);
00036     lines.put(0.f);
00037 
00038     lines.put(x);
00039     lines.put(y);
00040     lines.put(0.f);
00041 
00042     lines.put(x + glText.getLength(text));
00043     lines.put(y);
00044     lines.put(0.f);
00045 
00046     lines.flip();
00047   }
00048 
00049   @Override
00050   protected void scale(VisualizationView view, GL10 gl) {
00051     // Counter adjust for the camera zoom.
00052     gl.glScalef(1 / (float) view.getCamera().getZoom(), 1 / (float) view.getCamera().getZoom(),
00053         1.0f);
00054   }
00055 
00056   @Override
00057   protected void drawShape(VisualizationView view, GL10 gl) {
00058     Vertices.drawLines(gl, lines, getColor(), 3.f);
00059     gl.glEnable(GL10.GL_TEXTURE_2D);
00060     glText.begin(getColor().getRed(), getColor().getGreen(), getColor().getBlue(), getColor()
00061         .getAlpha());
00062     glText.draw(text, x, y);
00063     glText.end();
00064     gl.glDisable(GL10.GL_TEXTURE_2D);
00065   }
00066 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Jun 6 2019 21:20:07