preliminary multi-touch gestures for gdx

This commit is contained in:
Hannes Janetzek 2013-06-30 09:17:56 +02:00
parent f9623e9f22
commit 4d8cf0e62e
2 changed files with 98 additions and 78 deletions

View File

@ -2,17 +2,16 @@ package org.oscim.gdx;
import org.oscim.backend.AssetAdapter; import org.oscim.backend.AssetAdapter;
import org.oscim.backend.Log; import org.oscim.backend.Log;
import org.oscim.backend.input.MotionEvent;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.layers.overlay.GenericOverlay; import org.oscim.layers.labeling.LabelLayer;
import org.oscim.layers.overlay.BuildingOverlay;
import org.oscim.layers.tile.vector.MapTileLayer; import org.oscim.layers.tile.vector.MapTileLayer;
import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer;
import org.oscim.renderer.GLState; import org.oscim.renderer.GLState;
import org.oscim.renderer.layers.GridRenderLayer;
import org.oscim.theme.InternalRenderTheme; import org.oscim.theme.InternalRenderTheme;
import org.oscim.tilesource.TileSource; import org.oscim.tilesource.TileSource;
import org.oscim.tilesource.oscimap2.OSciMap2TileSource; import org.oscim.tilesource.oscimap4.OSciMap4TileSource;
import org.oscim.view.MapRenderCallback; import org.oscim.view.MapRenderCallback;
import org.oscim.view.MapView; import org.oscim.view.MapView;
import org.oscim.view.MapViewPosition; import org.oscim.view.MapViewPosition;
@ -26,7 +25,6 @@ import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.input.GestureDetector; import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener; import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Timer;
public class GdxMap implements ApplicationListener, MapRenderCallback { public class GdxMap implements ApplicationListener, MapRenderCallback {
@ -61,28 +59,35 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
mWidth = w; mWidth = w;
mHeight = h; mHeight = h;
TileSource tileSource = new OSciMap2TileSource(); if (null == null) {
tileSource.setOption("url", //TileSource tileSource = new OSciMap2TileSource();
"http://city.informatik.uni-bremen.de/osci/map-live"); //tileSource.setOption("url",
// "http://city.informatik.uni-bremen.de/osci/map-live");
// TileSource tileSource = new OSciMap4TileSource(); TileSource tileSource = new OSciMap4TileSource();
// tileSource.setOption("url", tileSource.setOption("url",
// "http://city.informatik.uni-bremen.de/osci/testing"); "http://city.informatik.uni-bremen.de/osci/testing");
// TileSource tileSource = new TestTileSource(); // TileSource tileSource = new TestTileSource();
mMapLayer = mMapView.setBaseMap(tileSource); mMapLayer = mMapView.setBaseMap(tileSource);
mMapLayer.setRenderTheme(InternalRenderTheme.DEFAULT); mMapLayer.setRenderTheme(InternalRenderTheme.DEFAULT);
mMapView.getLayerManager().add(new BuildingOverlay(mMapView, mMapLayer.getTileLayer()));
mMapView.getLayerManager().add(new LabelLayer(mMapView, mMapLayer.getTileLayer()));
}
// mMapView.setBaseMap(new BitmapTileLayer(mMapView, // mMapView.setBaseMap(new BitmapTileLayer(mMapView,
// OpenStreetMapMapnik.INSTANCE)); // OpenStreetMapMapnik.INSTANCE));
// mMapView.getLayerManager().add(new GenericOverlay(mMapView, new
// GridRenderLayer(mMapView))); //mMapView.getLayerManager().add(new GenericOverlay(mMapView, new
// GridRenderLayer(mMapView)));
mMapView.getMapViewPosition().setViewport(w, h); mMapView.getMapViewPosition().setViewport(w, h);
MapPosition p = new MapPosition(); MapPosition p = new MapPosition();
p.setZoomLevel(18); p.setZoomLevel(17);
p.setPosition(53.1, 8.8); p.setPosition(53.08, 8.83);
mMapView.setMapPosition(p); mMapView.setMapPosition(p);
mMapRenderer.onSurfaceCreated(); mMapRenderer.onSurfaceCreated();
@ -108,7 +113,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
} }
private int fpsCnt = 0; //private int fpsCnt = 0;
@Override @Override
public void render() { public void render() {
@ -134,6 +139,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
@Override @Override
public void resize(int w, int h) { public void resize(int w, int h) {
Log.d("", "resize " + w + "x" + h);
mWidth = w; mWidth = w;
mHeight = h; mHeight = h;
@ -212,46 +218,6 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
return mHeight; return mHeight;
} }
class GdxMotionEvent extends MotionEvent {
@Override
public int getAction() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getX() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getY() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getX(int idx) {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getY(int idx) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getPointerCount() {
// TODO Auto-generated method stub
return 0;
}
}
class TouchHandler implements InputProcessor { class TouchHandler implements InputProcessor {
private MapViewPosition mMapPosition; private MapViewPosition mMapPosition;
@ -348,11 +314,13 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
public boolean touchDragged(int screenX, int screenY, int pointer) { public boolean touchDragged(int screenX, int screenY, int pointer) {
boolean changed = false; boolean changed = false;
if (!(mActiveScale || mActiveRotate) )
return false;
if (mActiveScale) { if (mActiveScale) {
// changed = mMapPosition.tilt((screenY - mStartY) / 5f); // changed = mMapPosition.tilt((screenY - mStartY) / 5f);
changed = mMapPosition.scaleMap(1 - (screenY - mPosY) / 100f, 0, 0); changed = mMapPosition.scaleMap(1 - (screenY - mPosY) / 100f, 0, 0);
mPosY = screenY; mPosY = screenY;
return true;
} }
if (mActiveRotate) { if (mActiveRotate) {
@ -363,21 +331,21 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
changed = true; changed = true;
} }
if (!(mActiveRotate || mActiveTilt || mActiveScale)) { // if (!(mActiveRotate || mActiveTilt || mActiveScale)) {
int dx = screenX - mPosX; // int dx = screenX - mPosX;
int dy = screenY - mPosY; // int dy = screenY - mPosY;
if (Math.abs(dx) > 0 || Math.abs(dy) > 0) { // if (Math.abs(dx) > 0 || Math.abs(dy) > 0) {
mMapPosition.moveMap(dx, dy); // mMapPosition.moveMap(dx, dy);
mPosX = screenX; // mPosX = screenX;
mPosY = screenY; // mPosY = screenY;
changed = true; // changed = true;
} // }
} // }
if (changed) if (changed){
updateMap(true); updateMap(true);
}
return false; return true;
} }
@Override @Override
@ -408,7 +376,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
class ViewController implements GestureListener { class ViewController implements GestureListener {
private boolean mayFling =true; private boolean mayFling = true;
private boolean mPinch; private boolean mPinch;
@ -445,6 +413,8 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
@Override @Override
public boolean touchDown(float x, float y, int pointer, int button) { public boolean touchDown(float x, float y, int pointer, int button) {
mayFling = true; mayFling = true;
mPinch = false;
return false; return false;
} }
@ -461,10 +431,10 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
@Override @Override
public boolean fling(final float velocityX, final float velocityY, public boolean fling(final float velocityX, final float velocityY,
int button) { int button) {
Log.d("", "fling " + button + " " + velocityX + "/" + velocityY); //Log.d("", "fling " + button + " " + velocityX + "/" + velocityY);
if (mayFling && button == Buttons.LEFT) { if (mayFling && button == Buttons.LEFT) {
int m = Tile.SIZE * 4; int m = Tile.SIZE * 4;
mMapPosition.animateFling((int)velocityX, (int)velocityY, -m, m, -m, m); mMapPosition.animateFling((int) velocityX, (int) velocityY, -m, m, -m, m);
return true; return true;
} }
return false; return false;
@ -472,12 +442,21 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
@Override @Override
public boolean pan(float x, float y, float deltaX, float deltaY) { public boolean pan(float x, float y, float deltaX, float deltaY) {
if (mPinch)
return true;
mMapPosition.moveMap(deltaX, deltaY);
updateMap(true);
return false; return false;
} }
@Override @Override
public boolean zoom(float initialDistance, float distance) { public boolean zoom(float initialDistance, float distance) {
mayFling = false; mayFling = false;
// float fx = mMapView.getWidth() / 2;
// float fy = mMapView.getHeight() / 2;
// mMapPosition.scaleMap(initialDistance / distance, fx, fy);
return false; return false;
} }
@ -499,6 +478,11 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
mPrevPinchWidth = Math.sqrt(dx * dx + dy * dy); mPrevPinchWidth = Math.sqrt(dx * dx + dy * dy);
mPinch = true; mPinch = true;
mBeginTilt = false;
mBeginRotate = false;
mBeginScale= false;
return true; return true;
} }
@ -593,8 +577,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
float x = (float) (mFocusX * rcos + mFocusY * -rsin - mFocusX); float x = (float) (mFocusX * rcos + mFocusY * -rsin - mFocusX);
float y = (float) (mFocusX * rsin + mFocusY * rcos - mFocusY); float y = (float) (mFocusX * rsin + mFocusY * rcos - mFocusY);
mMapPosition mMapPosition.rotateMap(da, x, y);
.rotateMap((float) Math.toDegrees(da), x, y);
changed = true; changed = true;
} }
} }

View File

@ -0,0 +1,37 @@
package org.oscim.gdx;
import org.oscim.backend.input.MotionEvent;
public class GdxMotionEvent extends MotionEvent {
@Override
public int getAction() {
return 0;
}
@Override
public float getX() {
return 0;
}
@Override
public float getY() {
return 0;
}
@Override
public float getX(int idx) {
return 0;
}
@Override
public float getY(int idx) {
return 0;
}
@Override
public int getPointerCount() {
return 0;
}
}