refactor: make MapView abstract, remove MapRenderCallback

This commit is contained in:
Hannes Janetzek
2013-07-26 00:56:17 +02:00
parent 3ab9751128
commit 136db862d2
5 changed files with 124 additions and 203 deletions

View File

@@ -10,9 +10,7 @@ import org.oscim.layers.tile.vector.MapTileLayer;
import org.oscim.renderer.GLRenderer;
import org.oscim.renderer.GLState;
import org.oscim.theme.InternalRenderTheme;
import org.oscim.theme.ThemeLoader;
import org.oscim.tilesource.TileSource;
import org.oscim.view.MapRenderCallback;
import org.oscim.view.MapView;
import org.oscim.view.MapViewPosition;
@@ -27,16 +25,47 @@ import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
public class GdxMap implements ApplicationListener, MapRenderCallback {
public class GdxMap implements ApplicationListener {
protected final MapView mMapView;
private final GLRenderer mMapRenderer;
private final TileSource mTileSource;
boolean mRenderRequest;
public GdxMap(TileSource tileSource) {
AssetAdapter.g = new GdxAssetAdapter();
mTileSource = tileSource;
mMapView = new MapView(this);
mMapView = new MapView() {
@Override
public int getWidth() {
return mWidth;
}
@Override
public int getHeight() {
return mHeight;
}
@Override
public void updateMap(boolean forceRender) {
if (!mWaitRedraw) {
mWaitRedraw = true;
Gdx.app.postRunnable(mRedrawRequest);
}
}
@Override
public void render() {
mRenderRequest = true;
if (mClearMap)
updateMap(false);
else
Gdx.graphics.requestRendering();
}
};
mMapRenderer = new GLRenderer(mMapView);
}
@@ -45,6 +74,8 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
// BitmapFont font;
MapTileLayer mMapLayer;
int mHeight, mWidth;
@Override
public void create() {
@@ -142,8 +173,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
mMapView.getMapViewPosition().setViewport(w, h);
mMapRenderer.onSurfaceChanged(w, h);
renderMap();
mMapView.render();
}
@Override
@@ -163,22 +193,11 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
void redrawMapInternal(boolean forceRedraw) {
GLState.blend(false);
GLState.test(false, false);
// if (forceRedraw && !mClearMap)
// Gdx.graphics.requestRendering();
mMapView.updateLayers();
// if (mClearMap) {
mRenderRequest = true;
Gdx.graphics.requestRendering();
mClearMap = false;
// }
}
private boolean mClearMap;
public void clearMap() {
mClearMap = true;
}
/* private */boolean mWaitRedraw;
@@ -190,39 +209,6 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
}
};
@Override
public void updateMap(boolean forceRender) {
if (!mWaitRedraw) {
mWaitRedraw = true;
Gdx.app.postRunnable(mRedrawRequest);
}
}
private boolean mRenderRequest;
@Override
public void renderMap() {
mRenderRequest = true;
if (mClearMap)
updateMap(false);
else
Gdx.graphics.requestRendering();
}
int mHeight, mWidth;
@Override
public int getWidth() {
return mWidth;
}
@Override
public int getHeight() {
return mHeight;
}
class TouchHandler implements InputProcessor {
private MapViewPosition mMapPosition;
@@ -266,11 +252,6 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
mMapView.updateMap(true);
break;
// case Input.Keys.R:
// mMapLayer.reloadTheme();
// mMapView.updateMap(false);
// break;
case Input.Keys.D:
mMapView.setTheme(InternalRenderTheme.DEFAULT);
mMapView.updateMap(false);
@@ -339,19 +320,19 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
changed = true;
}
// if (!(mActiveRotate || mActiveTilt || mActiveScale)) {
// int dx = screenX - mPosX;
// int dy = screenY - mPosY;
// if (Math.abs(dx) > 0 || Math.abs(dy) > 0) {
// mMapPosition.moveMap(dx, dy);
// mPosX = screenX;
// mPosY = screenY;
// changed = true;
// }
// }
// if (!(mActiveRotate || mActiveTilt || mActiveScale)) {
// int dx = screenX - mPosX;
// int dy = screenY - mPosY;
// if (Math.abs(dx) > 0 || Math.abs(dy) > 0) {
// mMapPosition.moveMap(dx, dy);
// mPosX = screenX;
// mPosY = screenY;
// changed = true;
// }
// }
if (changed) {
updateMap(true);
mMapView.updateMap(true);
}
return true;
}
@@ -375,7 +356,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
mMapPosition.animateZoom(1.1f, 150);
//mMapPosition.scaleMap(1.1f, fx, fy);
}
updateMap(false);
mMapView.updateMap(false);
return true;
}
@@ -454,7 +435,7 @@ public class GdxMap implements ApplicationListener, MapRenderCallback {
return true;
mMapPosition.moveMap(deltaX, deltaY);
updateMap(true);
mMapView.updateMap(true);
return false;
}