+ /* UI elements */
+
+ AltosPointInt drag_start;
+
+ boolean dragged;
+
+ static final double drag_far = 20;
+
+ private void drag(int x, int y) {
+ if (drag_start == null)
+ return;
+
+ int dx = x - drag_start.x;
+ int dy = y - drag_start.y;
+
+ double distance = Math.hypot(dx, dy);
+
+ if (distance > drag_far)
+ dragged = true;
+
+ if (transform == null) {
+ debug("Transform not set in drag\n");
+ return;
+ }
+
+ 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);
+ dragged = false;
+ }
+
+ private void drag_stop(int x, int y) {
+ if (!dragged)
+ map_interface.select_object (transform.screen_lat_lon(new AltosPointInt(x,y)));
+ }
+
+ private void line_start(int x, int y) {
+ if (line != null) {
+ line.pressed(new AltosPointInt(x, y), transform);
+ repaint();
+ }
+ }
+
+ private void line(int x, int y) {
+ if (line != null) {
+ 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 void touch_stop(int x, int y, boolean is_drag) {
+ notice_user_input();
+ if (is_drag)
+ drag_stop(x, y);
+ }
+