polished PolygonRegionDrawable
2 files changed, 45 insertions(+), 34 deletions(-)

M core/build.gradle
M core/src/net/dermetfan/jigsawPuzzle/utils/PolygonRegionDrawable.java
M core/build.gradle +1 -1
@@ 1,6 1,6 @@ 
 apply plugin: "java"
 
-sourceCompatibility = 1.6
+sourceCompatibility = 1.7
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
 
 sourceSets.main.java.srcDirs = [ "src/" ]

          
M core/src/net/dermetfan/jigsawPuzzle/utils/PolygonRegionDrawable.java +44 -33
@@ 17,75 17,86 @@ package net.dermetfan.jigsawPuzzle.utils
 import com.badlogic.gdx.graphics.g2d.Batch;
 import com.badlogic.gdx.graphics.g2d.PolygonRegion;
 import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable;
 import com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable;
 import net.dermetfan.utils.libgdx.math.GeometryUtils;
 
-/** @author dermetfan */
+/** Drawable for a {@link PolygonRegion}.
+ *  @author dermetfan */
 public class PolygonRegionDrawable extends BaseDrawable implements TransformDrawable {
 
 	/** the region to draw */
 	private PolygonRegion region;
 
-	/** the min x and y of the {@link #region region's} vertices */
-	private float minX, minY;
+	/** the min x and y values of the vertices of {@link #region} */
+	private float polygonX, polygonY;
 
-	/** Creates an uninitialized PolygonTextureRegionDrawable. The texture region must be set before use. */
+	/** the size of the vertices of {@link #region} */
+	private float polygonWidth, polygonHeight;
+
+	/** Creates an uninitialized instance. The region must be {@link #setRegion(PolygonRegion) set} before use. */
 	public PolygonRegionDrawable() {}
 
-	/** copies the region
-	 *  @see #PolygonRegionDrawable(PolygonRegion, boolean) */
+	/** @param region the region to use */
 	public PolygonRegionDrawable(PolygonRegion region) {
-		this(region, true);
+		setRegion(region);
 	}
 
-	public PolygonRegionDrawable(PolygonRegion region, boolean copyRegion) {
-		setRegion(region, copyRegion);
-	}
-
-	/** copies the region
-	 *  @see #PolygonRegionDrawable(PolygonRegionDrawable, boolean) */
+	/** @param drawable the drawable to copy */
 	public PolygonRegionDrawable(PolygonRegionDrawable drawable) {
-		this(drawable, true);
-	}
-
-	public PolygonRegionDrawable(PolygonRegionDrawable drawable, boolean copyRegion) {
 		super(drawable);
-		setRegion(drawable.region, copyRegion);
+		this.region = drawable.region;
+		this.polygonX = drawable.polygonX;
+		this.polygonY = drawable.polygonY;
+		this.polygonWidth = drawable.polygonWidth;
+		this.polygonHeight = drawable.polygonHeight;
 	}
 
 	@Override
 	public void draw(Batch batch, float x, float y, float width, float height) {
+		width += region.getRegion().getRegionWidth() - polygonWidth;
+		height += region.getRegion().getRegionHeight() - polygonHeight;
 		if(batch instanceof PolygonSpriteBatch)
-			((PolygonSpriteBatch) batch).draw(region, x - minX, y - minY, width, height);
+			((PolygonSpriteBatch) batch).draw(region, x - polygonX, y - polygonY, width, height);
 		else
 			batch.draw(region.getRegion(), x, y, width, height);
 	}
 
 	@Override
 	public void draw(Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) {
+		width += region.getRegion().getRegionWidth() - polygonWidth;
+		height += region.getRegion().getRegionHeight() - polygonHeight;
 		if(batch instanceof PolygonSpriteBatch)
-			((PolygonSpriteBatch) batch).draw(region, x - minX, y - minY, originX, originY, width, height, scaleX, scaleY, rotation);
+			((PolygonSpriteBatch) batch).draw(region, x - polygonX, y - polygonY, originX, originY, width, height, scaleX, scaleY, rotation);
 		else
 			batch.draw(region.getRegion(), x, y, originX, originY, width, height, scaleX, scaleY, rotation);
 	}
 
-	public void setRegion(PolygonRegion region, boolean copy) {
-		PolygonRegion use = copy ? new PolygonRegion(new TextureRegion(region.getRegion()), region.getVertices(), region.getTriangles()) : region;
-		this.region = use;
-		float[] vertices = use.getVertices();
-		float polyWidth = GeometryUtils.width(vertices), polyHeight = GeometryUtils.height(vertices);
-		minX = GeometryUtils.minX(vertices);
-		minY = GeometryUtils.minY(vertices);
-		use.getRegion().setRegionWidth((int) polyWidth);
-		use.getRegion().setRegionHeight((int) polyHeight);
-		setMinWidth(polyWidth);
-		setMinHeight(polyHeight);
+	/** @param region the {@link #region} to set */
+	public void setRegion(PolygonRegion region) {
+		this.region = region;
+		float[] vertices = region.getVertices();
+		polygonWidth = GeometryUtils.width(vertices);
+		polygonHeight = GeometryUtils.height(vertices);
+		polygonX = GeometryUtils.minX(vertices);
+		polygonY = GeometryUtils.minY(vertices);
+		setMinWidth(polygonWidth);
+		setMinHeight(polygonHeight);
 	}
 
+	/** @return the {@link #region} */
 	public PolygonRegion getRegion() {
 		return region;
 	}
 
-}
  No newline at end of file
+	/** @return the {@link #polygonX} */
+	public float getPolygonX() {
+		return polygonX;
+	}
+
+	/** @return the {@link #polygonY} */
+	public float getPolygonY() {
+		return polygonY;
+	}
+
+}