package de.fhpotsdam.unfolding.ui;

import processing.core.PApplet;
import processing.core.PImage;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.mapdisplay.AbstractMapDisplay;

public class CompassUI {
	public static final float X_DEFAULT = 100;
	public static final float Y_DEFAULT = 100;
	public static final String IMG_DEFAULT = "compass_white.png";

	private PApplet p;
	private AbstractMapDisplay mapDisplay;

	public float x;
	public float y;
	public float scale;
	private PImage img;

	public CompassUI(PApplet p, AbstractMapDisplay mapDisplay, PImage img, float x, float y) {
		this.p = p;
		this.mapDisplay = mapDisplay;
		this.x = x;
		this.y = y;
		this.img = img;
		scale = 1;
	}

	public CompassUI(PApplet p, AbstractMapDisplay mapDisplay) {
		this(p, mapDisplay, p.loadImage(IMG_DEFAULT), X_DEFAULT, Y_DEFAULT);
	}

	public CompassUI(PApplet p, UnfoldingMap map) {
		this(p, map.mapDisplay, p.loadImage(IMG_DEFAULT), X_DEFAULT, Y_DEFAULT);
	}

	public void draw() {
		// int zoomLevel = Map.getZoomLevelFromScale(mapDisplay.innerScale);
		// float zoom = Map.getZoomFromScale(mapDisplay.innerScale);
		float dir = mapDisplay.innerAngle;

		if (img != null) {
			p.pushMatrix();
			p.translate(x, y);
			p.rotate(dir);
			p.scale(scale);
			p.image(img, -img.width / 2, -img.height / 2);
			p.popMatrix();
		}
	}

	public void setImage(PImage img) {
		this.img = img;
	}
}

@@ -201,323 +201,679 @@
 ay;%0A
-%0Apublic class CompassUI %7B%0A%09publ
+import de.fhpotsdam.unfolding.utils.ScreenPosition;%0A%0A/**%0A * A simple compass wh
 ic
+h
  s
-tatic final float X_DEFAULT = 100;%0A%09public static final float Y_DEFAULT = 100;%0A%09public static final String IMG_DEFAULT = %22compass_white.png%22;%0A%0A%09private PApplet p;%0A%09private AbstractMapDisplay mapDisplay;%0A%0A%09public float x;%0A%09public float y;%0A%09public float scale;%0A%09private PImage img;%0A
+hows the cardinal directions of the map.%0A */%0Apublic class CompassUI %7B%0A%09private static final ScreenPosition DEFAULT_POS = new ScreenPosition(100, 100);%0A%09private static final String IMG_DEFAULT = %22compass_white.png%22;%0A%0A%09private PApplet p;%0A%09private AbstractMapDisplay mapDisplay;%0A%0A%09private ScreenPosition pos;%0A%09private float scale;%0A%09private PImage img;%0A%0A%09/**%0A%09 * Create CompassUI.%0A%09 * @param p the applet to draw on.%0A%09 * @param mapDisplay the map to draw on.%0A%09 * @param img the image for the compass to show.%0A%09 * @param x x position on the screen.%0A%09 * @param y y position on the screen.%0A%09 */
 %0A%09pu
@@ -1014,16 +1014,20 @@
 %0A%09%09this.
+pos.
 x = x;%0A%09
@@ -1032,16 +1032,20 @@
 %0A%09%09this.
+pos.
 y = y;%0A%09
@@ -1074,24 +1074,162 @@
 le = 1;%0A%09%7D%0A%0A
+%09/**%0A%09 * Create default CompassUI at default position.%0A%09 * @param p the applet to draw on.%0A%09 * @param mapDisplay the map to draw on.%0A%09 */%0A
 %09public Comp
@@ -1330,34 +1330,172 @@
 T), 
-X_
 DEFAULT
-, Y_DEFAULT);%0A%09%7D%0A
+_POS.x, DEFAULT_POS.y);%0A%09%7D%0A%09/**%0A%09 * Create default CompassUI at default position.%0A%09 * @param p the applet to draw on.%0A%09 * @param map the map to draw on.%0A%09 */
 %0A%09pu
@@ -1596,34 +1596,74 @@
 T), 
-X_
 DEFAULT
-, Y_DEFAULT);%0A%09%7D%0A
+_POS.x, DEFAULT_POS.y);%0A%09%7D%0A%0A%09/**%0A%09 * Draw the compass.%0A%09 */
 %0A%09pu
@@ -1908,19 +1908,27 @@
 anslate(
-x, 
+pos.x, pos.
 y);%0A%09%09%09p

Use ScreenPos in CompassUI + Docs.