package net.mostlyoriginal.game.component;

import com.artemis.Component;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import net.mostlyoriginal.game.Path;
import net.mostlyoriginal.game.manager.LayerManager;
import org.xguzm.pathfinding.grid.GridCell;

import java.util.List;

/**
 * Bitmap layer.
 */
public class Layer extends Component {

	public Pixmap pixmap;

	public Layer() {
		pixmap = new Pixmap(LayerManager.LAYER_WIDTH, LayerManager.LAYER_HEIGHT, Pixmap.Format.RGBA8888);
	}

	public void drawPixel(int x, int y, Color color) {
		pixmap.setColor(color);
		pixmap.drawPixel(x, y);
	}

	public void drawPixmapToFit(Pixmap source) {

		float aspectRatio = source.getWidth() / source.getHeight();

		// bind pixmap to window.
		Rectangle dest = new Rectangle(0, 0, source.getWidth(), source.getHeight())
				.fitInside(new Rectangle(0, 0, pixmap.getWidth(), pixmap.getHeight()));

		pixmap.drawPixmap(source,
				0, 0, source.getWidth(), source.getHeight(),
				0, 0, (int) dest.width, (int) dest.height);
	}


	public void drawPath(Path path, Color color, boolean shadow) {

		// shadow.
		final List<GridCell> cells = path.cells;

		if (shadow) {
			pixmap.setColor(new Color(0, 0, 0, 0.35f));
			for (int i = 1; i < cells.size(); i++) {
				GridCell p1 = cells.get(i - 1);
				pixmap.drawPixel(
						p1.x, pixmap.getHeight() - p1.y + 1);
			}
		}

		pixmap.setColor(color);
		for (int i = 1; i < cells.size(); i++) {
			GridCell p1 = cells.get(i - 1);
			GridCell p2 = cells.get(i);
			pixmap.drawLine(
					p1.x, pixmap.getHeight() - p1.y,
					p2.x, pixmap.getHeight() - p2.y);
		}
	}

	public Texture getTexture() {
		if (texture == null) {
			refresh();
		}
		return texture;
	}

	private Texture texture;

	public void refresh() {
		if (texture != null) {
			texture.dispose();
			texture = null;
		}
		texture = new Texture(pixmap);
	}

	public void dispose() {
		if (texture != null) {
			texture.dispose();
			texture = null;
		}
		pixmap.dispose();
	}

	public void clear() {
		if (texture != null) {
			texture.dispose();
			texture = null;
		}
		pixmap.setColor(Color.CLEAR);
		pixmap.fill();
	}
}

@@ -818,16 +818,66 @@
 ght();%0A%0A
+%09%09int paddingTop = 50;%0A%09%09int paddingBottom = 50;%0A%0A
 %09%09// bin
@@ -896,16 +896,16 @@
 window.%0A
-
 %09%09Rectan
@@ -1006,17 +1006,26 @@
 ngle(0, 
-0
+paddingTop
 , pixmap
@@ -1055,16 +1055,41 @@
 Height()
+-paddingBottom-paddingTop
 ));%0A%0A%09%09p
@@ -1166,20 +1166,40 @@
 (),%0A%09%09%09%09
-0, 0
+(int)dest.x, (int)dest.y
 , (int) 

Make sure the map doesn't overlap the menu and title.