Android Open Source - java-androidframework Basic Shape






From Project

Back to project page java-androidframework.

License

The source code is released under:

This project is licensed under the [CC0 1.0 Agreement](http://creativecommons.org/publicdomain/zero/1.0/). To the extent possible under law, Pete Schmitz has waived all copyright and related or neigh...

If you think the Android project java-androidframework 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 com.gamepatriot.framework2d.implementation;
/*from   w w  w . j  a  v a  2s  .  co m*/
import android.graphics.Paint;
import android.graphics.Path;

import com.gamepatriot.androidframework.framework.AndroidBasicShape;
import com.gamepatriot.framework2d.implementation.Shape.ShapeType;

/**
 * The BasicShape retains a reference to a single shape draw instruction.
 * 
 * @author Pete Schmitz, May 11, 2013
 *
 */
public class BasicShape implements AndroidBasicShape {
  
  /** (Read-only) The {@link ShapeType type} of shape to be drawn. **/
  public ShapeType type;
  
  /** (Read-only) Stores the radius size of a circle when {@link ShapeType} circle, and font size when ShapeType text. **/
  public float radius;
  
  /** (Read-only) Stores the string to be drawn. Null if not type {@link ShapeType#TEXT TEXT}. **/
  public String text;
  
  /** (Read-only) Contains points used to draw the shape type ({x1, y1, x2, y2, ...}). **/
  public float[] points;
  
  /** (Read-only) The shape path defined for type {@link ShapeType#POLY POLY}; Otherwise null. **/
  public Path path;
  
  /** Reference to the supplied paint that this BasicShape will be drawn with. Altering this will adjust other BasicShapes that share the same paint; Forces {@link Shape}'s default paint when null. **/
  public Paint paint;
  
  public BasicShape(){
    
    //Initialize empty array
    points = new float[0];
  }

  @Override
  public void setAsLine(float $x1, float $y1, float $x2, float $y2, Paint $paint) {
    type = ShapeType.LINE;
    paint = $paint;
    text = null;
    path = null;
    
    registerPoints(new float[]{$x1, $y1, $x2, $y2});
  }

  @Override
  public void setAsRectangle(float $left, float $top, float $right, float $bottom, Paint $paint) {
    type = ShapeType.RECTANGLE;
    paint = $paint;
    text = null;
    path = null;
    
    registerPoints(new float[]{$left, $top, $right, $bottom});
  }

  @Override
  public void setAsCircle(float $x, float $y, float $radius, Paint $paint) {
    type = ShapeType.CIRCLE;
    radius = $radius;
    paint = $paint;
    text = null;
    path = null;
    
    registerPoints(new float[]{$x, $y});
  }

  @Override
  public void setAsPoly(float[] $points, Paint $paint) {
    type = ShapeType.POLY;
    paint = $paint;
    text = null;
    
    registerPoints($points);
    buildPath();
  }

  @Override
  public void setAsText(String $text, float $size, float $x, float $y, Paint $paint) {
    type = ShapeType.TEXT;
    text = $text;
    radius = $size;
    paint = $paint;
    path = null;
    
    registerPoints(new float[]{$x, $y});
  }
  
  @Override
  public void buildPath(){
    buildPath(0f, 0f);
  }
  
  @Override
  public void buildPath(float $offsetX, float $offsetY){
    int $i;
    
    if (path == null) path = new Path();
    else path.reset();
    
    path.moveTo(points[0] + $offsetX, points[1] + $offsetY);
    
    for ($i = 1; $i < points.length/2; $i++){
      path.lineTo(points[$i * 2] + $offsetX, points[$i * 2 + 1] + $offsetY);
    }
    
    path.lineTo(points[0] + $offsetX, points[1] + $offsetY);
  }
  
  @Override
  public Paint getPaint() {
    return paint;
  }
  
  @Override
  public Paint setPaint(Paint $paint) {
    Paint $old = paint;
    paint = $paint;
    
    return $old;
  }
  
  /**
   * Set the reference points to be used during drawing calls.
   * @param $points    Array of points designated for use in {@link Shape#draw(android.graphics.Canvas) Shape.draw()}.
   */
  private void registerPoints(float[] $points){
    points = $points;
  }

  @Override
  public void setText(String $text) {
    text = $text;
  }
  
  
  
}




Java Source Code List

com.gamepatriot.androidframework.framework.AndroidAnimationData.java
com.gamepatriot.androidframework.framework.AndroidAtlas.java
com.gamepatriot.androidframework.framework.AndroidBasicShape.java
com.gamepatriot.androidframework.framework.AndroidGameData.java
com.gamepatriot.androidframework.framework.AndroidImage.java
com.gamepatriot.androidframework.framework.AndroidInputter.java
com.gamepatriot.androidframework.framework.AndroidMain.java
com.gamepatriot.androidframework.framework.AndroidMusicHandler.java
com.gamepatriot.androidframework.framework.AndroidPool.java
com.gamepatriot.androidframework.framework.AndroidRenderer.java
com.gamepatriot.androidframework.framework.AndroidScreen.java
com.gamepatriot.androidframework.framework.AndroidShape.java
com.gamepatriot.androidframework.framework.AndroidSoundHandler.java
com.gamepatriot.framework2d.classes.FPS.java
com.gamepatriot.framework2d.implementation.AnimationData.java
com.gamepatriot.framework2d.implementation.Atlas.java
com.gamepatriot.framework2d.implementation.BasicShape.java
com.gamepatriot.framework2d.implementation.GameData.java
com.gamepatriot.framework2d.implementation.Image.java
com.gamepatriot.framework2d.implementation.Inputter.java
com.gamepatriot.framework2d.implementation.Main.java
com.gamepatriot.framework2d.implementation.MusicHandler.java
com.gamepatriot.framework2d.implementation.Pool.java
com.gamepatriot.framework2d.implementation.Renderer.java
com.gamepatriot.framework2d.implementation.Screen.java
com.gamepatriot.framework2d.implementation.Shape.java
com.gamepatriot.framework2d.implementation.SoundHandler.java
com.gamepatriot.framework2d.screens.Example.java