diff options
Diffstat (limited to 'altoslib')
| -rw-r--r-- | altoslib/AltosMap.java | 103 | ||||
| -rw-r--r-- | altoslib/AltosMapInterface.java | 11 | ||||
| -rw-r--r-- | altoslib/AltosMapLine.java | 4 | ||||
| -rw-r--r-- | altoslib/AltosMapMark.java | 4 | ||||
| -rw-r--r-- | altoslib/AltosMapTile.java | 1 | ||||
| -rw-r--r-- | altoslib/AltosMapTileListener.java | 2 | 
6 files changed, 79 insertions, 46 deletions
diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index 7c7c7305..b54c66cf 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -22,7 +22,7 @@ import java.lang.*;  import java.util.*;  import java.util.concurrent.*; -public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, AltosMapStoreListener { +public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {  	public static final int px_size = 512; @@ -54,18 +54,12 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos  	AltosMapCache		cache; -	LinkedList<AltosMapMark> marks = new LinkedList<AltosMapMark>(); - -	LinkedList<AltosMapZoomListener> zoom_listeners = new LinkedList<AltosMapZoomListener>(); +	public AltosMapCache cache() { return cache; } -	public void add_zoom_listener(AltosMapZoomListener listener) { -		if (!zoom_listeners.contains(listener)) -			zoom_listeners.add(listener); -	} +	LinkedList<AltosMapMark> marks = new LinkedList<AltosMapMark>(); -	public void remove_zoom_listener(AltosMapZoomListener listener) { -		zoom_listeners.remove(listener); -	} +	AltosMapPath	path; +	AltosMapLine	line;  	boolean		have_boost = false;  	boolean		have_landed = false; @@ -84,7 +78,7 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos  	 */  	static final long auto_scroll_delay = 20 * 1000; -	AltosMapTransform	transform; +	public AltosMapTransform	transform;  	AltosLatLon		centre;  	public void reset() { @@ -92,16 +86,14 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos  	}  	/* MapInterface wrapping functions */ -	public void set_units() { -		map_interface.set_units(); -	} -	public void repaint(AltosMapRectangle damage, int pad) { -		map_interface.repaint(damage, pad); +	public void repaint(int x, int y, int w, int h) { +		map_interface.repaint(new AltosRectangle(x, y, w, h));  	} -	public void repaint(double x, double y, double w, double h) { -		map_interface.repaint(x, y, w, h); +	public void repaint(AltosMapRectangle damage, int pad) { +		AltosRectangle r = transform.screen(damage); +		repaint(r.x - pad, r.y - pad, r.width + pad * 2, r.height + pad * 2);  	}  	public void repaint() { @@ -156,30 +148,22 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos  		return false;  	} -	public void font_size_changed(int font_size) { -		map_interface.line().font_size_changed(font_size); -		for (AltosMapTile tile : tiles.values()) -			tile.font_size_changed(font_size); +	public void set_transform() { +		transform = new AltosMapTransform(width(), height(), zoom, centre);  		repaint();  	} -	public void units_changed(boolean imperial_units) { +	private void set_zoom_label() { +		map_interface.set_zoom_label(String.format("Zoom %d", get_zoom() - default_zoom));  	} -	private void set_transform() { -		transform = new AltosMapTransform(width(), height(), zoom, centre); -		repaint(); -	}  	public boolean set_zoom(int zoom) {  		if (AltosMap.min_zoom <= zoom && zoom <= AltosMap.max_zoom && zoom != this.zoom) {  			this.zoom = zoom;  			tiles.clear();  			set_transform(); - -			for (AltosMapZoomListener listener : zoom_listeners) -				listener.zoom_changed(this.zoom); - +			set_zoom_label();  			return true;  		}  		return false; @@ -211,7 +195,7 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos  		if (!gps.locked && gps.nsat < 4)  			return; -		AltosMapRectangle	damage = map_interface.path().add(gps.lat, gps.lon, state.state); +		AltosMapRectangle	damage = path.add(gps.lat, gps.lon, state.state);  		switch (state.state) {  		case AltosLib.ao_flight_boost: @@ -339,9 +323,9 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos  				mark.paint(transform);  		} -		map_interface.path().paint(transform); +		path.paint(transform); -		map_interface.line().paint(transform); +		line.paint(transform);  	}  	/* AltosMapTileListener methods */ @@ -363,9 +347,58 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos  		}  	} +	/* UI elements */ + +	AltosPointInt	drag_start; + +	private void drag(int x, int y) { +		if (drag_start == null) +			return; + +		int dx = x - drag_start.x; +		int dy = y - drag_start.y; + +		AltosLatLon new_centre = transform.screen_lat_lon(new AltosPointInt(width() / 2 - dx, height() / 2 - dy)); +		centre(new_centre); +		drag_start = new AltosPointInt(x, y); +	} + +	private void drag_start(int x, int y) { +		drag_start = new AltosPointInt(x, y); +	} + +	private void line_start(int x, int y) { +		line.pressed(new AltosPointInt(x, y), transform); +		repaint(); +	} + +	private void line(int x, int y) { +		line.dragged(new AltosPointInt(x, y), transform); +		repaint(); +	} + +	public void touch_start(int x, int y, boolean is_drag) { +		notice_user_input(); +		if (is_drag) +			drag_start(x, y); +		else +			line_start(x, y); +	} + +	public void touch_continue(int x, int y, boolean is_drag) { +		notice_user_input(); +		if (is_drag) +			drag(x, y); +		else +			line(x, y); +	} +  	public AltosMap(AltosMapInterface map_interface) {  		this.map_interface = map_interface;  		cache = new AltosMapCache(map_interface); +		line = map_interface.new_line(); +		path = map_interface.new_path(); +		set_zoom_label();  		centre(0, 0);  	}  } diff --git a/altoslib/AltosMapInterface.java b/altoslib/AltosMapInterface.java index 0dcd646e..195574e9 100644 --- a/altoslib/AltosMapInterface.java +++ b/altoslib/AltosMapInterface.java @@ -21,8 +21,9 @@ import java.io.*;  import java.net.*;  public interface AltosMapInterface { -	public abstract AltosMapPath path(); -	public abstract AltosMapLine line(); +	public abstract AltosMapPath new_path(); + +	public abstract AltosMapLine new_line();  	public abstract AltosImage load_image(File file) throws Exception; @@ -36,9 +37,7 @@ public interface AltosMapInterface {  	public abstract void repaint(); -	public abstract void repaint(AltosMapRectangle damage, int pad); - -	public abstract void repaint(double x, double y, double w, double h); +	public abstract void repaint(AltosRectangle damage); -	public abstract void set_units(); +	public abstract void set_zoom_label(String label);  } diff --git a/altoslib/AltosMapLine.java b/altoslib/AltosMapLine.java index e727e338..23a6f889 100644 --- a/altoslib/AltosMapLine.java +++ b/altoslib/AltosMapLine.java @@ -22,13 +22,11 @@ import java.lang.Math;  import java.util.*;  import java.util.concurrent.*; -public abstract class AltosMapLine implements AltosFontListener { +public abstract class AltosMapLine {  	public AltosLatLon	start, end;  	static public int stroke_width = 6; -	public abstract void font_size_changed(int font_size); -  	public abstract void paint(AltosMapTransform t);  	private AltosLatLon lat_lon(AltosPointInt pt, AltosMapTransform t) { diff --git a/altoslib/AltosMapMark.java b/altoslib/AltosMapMark.java index 5eb1907b..74e6790f 100644 --- a/altoslib/AltosMapMark.java +++ b/altoslib/AltosMapMark.java @@ -24,8 +24,8 @@ import java.util.concurrent.*;  public abstract class AltosMapMark { -	AltosLatLon	lat_lon; -	int		state; +	public AltosLatLon	lat_lon; +	public int		state;  	static public int stroke_width = 6; diff --git a/altoslib/AltosMapTile.java b/altoslib/AltosMapTile.java index e61746f8..165f9e6f 100644 --- a/altoslib/AltosMapTile.java +++ b/altoslib/AltosMapTile.java @@ -99,6 +99,7 @@ public abstract class AltosMapTile implements AltosFontListener {  	public AltosMapTile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) {  		this.listener = listener;  		this.upper_left = upper_left; +		this.cache = listener.cache();  		while (center.lon < -180.0)  			center.lon += 360.0; diff --git a/altoslib/AltosMapTileListener.java b/altoslib/AltosMapTileListener.java index 60d92c75..ed47e833 100644 --- a/altoslib/AltosMapTileListener.java +++ b/altoslib/AltosMapTileListener.java @@ -19,4 +19,6 @@ package org.altusmetrum.altoslib_7;  public interface AltosMapTileListener {  	abstract public void notify_tile(AltosMapTile tile, int status); + +	abstract public AltosMapCache cache();  }  | 
