refactor backend Adapter classes
This commit is contained in:
parent
4e4d4270db
commit
4fb3d13404
@ -35,6 +35,10 @@ import android.graphics.drawable.Drawable;
|
|||||||
public final class AndroidGraphics extends CanvasAdapter {
|
public final class AndroidGraphics extends CanvasAdapter {
|
||||||
public static final AndroidGraphics INSTANCE = new AndroidGraphics();
|
public static final AndroidGraphics INSTANCE = new AndroidGraphics();
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
g = INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
// public static android.graphics.Bitmap getAndroidBitmap(Bitmap bitmap) {
|
// public static android.graphics.Bitmap getAndroidBitmap(Bitmap bitmap) {
|
||||||
// return ((AndroidBitmap) bitmap).bitmap;
|
// return ((AndroidBitmap) bitmap).bitmap;
|
||||||
// }
|
// }
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.oscim.gdx;
|
package org.oscim.gdx;
|
||||||
|
|
||||||
import org.oscim.android.canvas.AndroidGraphics;
|
import org.oscim.android.canvas.AndroidGraphics;
|
||||||
import org.oscim.backend.CanvasAdapter;
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
@ -40,8 +39,8 @@ public class MainActivity extends AndroidApplication {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
CanvasAdapter.g = AndroidGraphics.INSTANCE;
|
AndroidGraphics.init();
|
||||||
GLAdapter.g = new AndroidGLAdapter();
|
GLAdapter.init(new AndroidGLAdapter());
|
||||||
|
|
||||||
// TODO make this dpi dependent
|
// TODO make this dpi dependent
|
||||||
Tile.SIZE = 400;
|
Tile.SIZE = 400;
|
||||||
|
@ -23,10 +23,14 @@ import org.oscim.backend.AssetAdapter;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
public class AndroidAssetAdapter extends AssetAdapter {
|
public class AndroidAssets extends AssetAdapter {
|
||||||
Context mContext;
|
Context mContext;
|
||||||
|
|
||||||
public AndroidAssetAdapter(Context ctx) {
|
public static void init(Context ctx) {
|
||||||
|
g = new AndroidAssets(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AndroidAssets(Context ctx) {
|
||||||
mContext = ctx;
|
mContext = ctx;
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,6 @@ package org.oscim.android;
|
|||||||
import org.oscim.android.canvas.AndroidGraphics;
|
import org.oscim.android.canvas.AndroidGraphics;
|
||||||
import org.oscim.android.gl.AndroidGL;
|
import org.oscim.android.gl.AndroidGL;
|
||||||
import org.oscim.android.input.AndroidMotionEvent;
|
import org.oscim.android.input.AndroidMotionEvent;
|
||||||
import org.oscim.backend.AssetAdapter;
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
import org.oscim.backend.CanvasAdapter;
|
||||||
import org.oscim.backend.GLAdapter;
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.event.Gesture;
|
import org.oscim.event.Gesture;
|
||||||
@ -58,9 +57,9 @@ public class MapView extends RelativeLayout {
|
|||||||
public MapView(Context context, AttributeSet attributeSet) {
|
public MapView(Context context, AttributeSet attributeSet) {
|
||||||
super(context, attributeSet);
|
super(context, attributeSet);
|
||||||
|
|
||||||
CanvasAdapter.g = AndroidGraphics.INSTANCE;
|
AndroidGraphics.init();
|
||||||
AssetAdapter.g = new AndroidAssetAdapter(context);
|
AndroidAssets.init(context);
|
||||||
GLAdapter.g = new AndroidGL();
|
GLAdapter.init(new AndroidGL());
|
||||||
|
|
||||||
this.setWillNotDraw(true);
|
this.setWillNotDraw(true);
|
||||||
this.setClickable(true);
|
this.setClickable(true);
|
||||||
|
@ -32,7 +32,10 @@ import android.graphics.drawable.BitmapDrawable;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
public final class AndroidGraphics extends CanvasAdapter {
|
public final class AndroidGraphics extends CanvasAdapter {
|
||||||
public static final AndroidGraphics INSTANCE = new AndroidGraphics();
|
|
||||||
|
public static void init() {
|
||||||
|
g = new AndroidGraphics();
|
||||||
|
}
|
||||||
|
|
||||||
public static android.graphics.Paint getAndroidPaint(Paint paint) {
|
public static android.graphics.Paint getAndroidPaint(Paint paint) {
|
||||||
return ((AndroidPaint) paint).mPaint;
|
return ((AndroidPaint) paint).mPaint;
|
||||||
@ -97,7 +100,6 @@ public final class AndroidGraphics extends CanvasAdapter {
|
|||||||
return new MarkerSymbol(drawableToBitmap(drawable), place);
|
return new MarkerSymbol(drawableToBitmap(drawable), place);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static MarkerSymbol makeMarker(Resources res, int resId, HotspotPlace place) {
|
public static MarkerSymbol makeMarker(Resources res, int resId, HotspotPlace place) {
|
||||||
if (place == null)
|
if (place == null)
|
||||||
place = HotspotPlace.CENTER;
|
place = HotspotPlace.CENTER;
|
||||||
|
@ -32,8 +32,8 @@ import org.oscim.backend.canvas.Paint;
|
|||||||
public class AwtGraphics extends CanvasAdapter {
|
public class AwtGraphics extends CanvasAdapter {
|
||||||
private static final AwtGraphics INSTANCE = new AwtGraphics();
|
private static final AwtGraphics INSTANCE = new AwtGraphics();
|
||||||
|
|
||||||
public static final AwtGraphics get() {
|
public static void init() {
|
||||||
return INSTANCE;
|
g = INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AwtGraphics() {
|
private AwtGraphics() {
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.oscim.gdx;
|
package org.oscim.gdx;
|
||||||
|
|
||||||
import org.oscim.awt.AwtGraphics;
|
import org.oscim.awt.AwtGraphics;
|
||||||
import org.oscim.backend.CanvasAdapter;
|
|
||||||
import org.oscim.backend.GLAdapter;
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.tiling.TileSource;
|
import org.oscim.tiling.TileSource;
|
||||||
@ -33,21 +32,13 @@ public class GdxMapApp extends GdxMap {
|
|||||||
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrap LwjglGL20 to add GL20 interface
|
|
||||||
// static class GdxGL extends GdxGL20 {
|
|
||||||
// @Override
|
|
||||||
// public void glGetShaderSource(int shader, int bufsize, Buffer length, String source) {
|
|
||||||
// throw new IllegalArgumentException("not implemented");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
// load native library
|
// load native library
|
||||||
new SharedLibraryLoader().load("vtm-jni");
|
new SharedLibraryLoader().load("vtm-jni");
|
||||||
// init globals
|
// init globals
|
||||||
CanvasAdapter.g = AwtGraphics.get();
|
AwtGraphics.init();
|
||||||
GLAdapter.g = new GdxGL20();
|
GdxAssets.init("assets/");
|
||||||
|
GLAdapter.init(new GdxGL20());
|
||||||
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +61,6 @@ public class GdxMapApp extends GdxMap {
|
|||||||
static protected LwjglApplicationConfiguration getConfig() {
|
static protected LwjglApplicationConfiguration getConfig() {
|
||||||
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
|
||||||
cfg.title = "vtm-gdx";
|
cfg.title = "vtm-gdx";
|
||||||
//cfg.useGL20 = true;
|
|
||||||
cfg.width = 1280;
|
cfg.width = 1280;
|
||||||
cfg.height = 800;
|
cfg.height = 800;
|
||||||
cfg.stencil = 8;
|
cfg.stencil = 8;
|
||||||
|
@ -24,11 +24,16 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
|
|
||||||
public class GdxAssetAdapter extends AssetAdapter {
|
public class GdxAssets extends AssetAdapter {
|
||||||
|
static String pathPrefix = "";
|
||||||
|
|
||||||
|
private GdxAssets(String path) {
|
||||||
|
pathPrefix = path;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream openFileAsStream(String fileName) {
|
public InputStream openFileAsStream(String fileName) {
|
||||||
FileHandle file = Gdx.files.internal("assets/" + fileName);
|
FileHandle file = Gdx.files.internal(pathPrefix + fileName);
|
||||||
if (file == null)
|
if (file == null)
|
||||||
throw new IllegalArgumentException("missing file " + fileName);
|
throw new IllegalArgumentException("missing file " + fileName);
|
||||||
|
|
||||||
@ -39,4 +44,8 @@ public class GdxAssetAdapter extends AssetAdapter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void init(String path) {
|
||||||
|
g = new GdxAssets(path);
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.gdx;
|
package org.oscim.gdx;
|
||||||
|
|
||||||
import org.oscim.backend.AssetAdapter;
|
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.layers.GenericLayer;
|
import org.oscim.layers.GenericLayer;
|
||||||
import org.oscim.layers.TileGridLayer;
|
import org.oscim.layers.TileGridLayer;
|
||||||
@ -51,7 +50,6 @@ public abstract class GdxMap implements ApplicationListener {
|
|||||||
boolean mRenderRequest;
|
boolean mRenderRequest;
|
||||||
|
|
||||||
public GdxMap() {
|
public GdxMap() {
|
||||||
AssetAdapter.g = new GdxAssetAdapter();
|
|
||||||
|
|
||||||
mMap = new Map() {
|
mMap = new Map() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.oscim.ios;
|
package org.oscim.ios;
|
||||||
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
|
||||||
import org.oscim.backend.GLAdapter;
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.gdx.GdxMap;
|
import org.oscim.gdx.GdxMap;
|
||||||
import org.oscim.ios.backend.IosGLAdapter;
|
import org.oscim.ios.backend.IosGLAdapter;
|
||||||
@ -50,8 +49,8 @@ public class RobovmLauncher extends IOSApplication.Delegate {
|
|||||||
|
|
||||||
NSAutoreleasePool pool = new NSAutoreleasePool();
|
NSAutoreleasePool pool = new NSAutoreleasePool();
|
||||||
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
||||||
CanvasAdapter.g = IosGraphics.get();
|
IosGraphics.init();
|
||||||
GLAdapter.g = new IosGLAdapter();
|
GLAdapter.init(new IosGLAdapter());
|
||||||
|
|
||||||
UIApplication.main(argv, null, RobovmLauncher.class);
|
UIApplication.main(argv, null, RobovmLauncher.class);
|
||||||
pool.drain();
|
pool.drain();
|
||||||
|
@ -16,6 +16,10 @@ public class IosGraphics extends CanvasAdapter {
|
|||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
g = INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Canvas getCanvas() {
|
public Canvas getCanvas() {
|
||||||
return new IosCanvas();
|
return new IosCanvas();
|
||||||
|
@ -22,7 +22,7 @@ public class GLAdapter {
|
|||||||
public final static boolean debugView = false;
|
public final static boolean debugView = false;
|
||||||
|
|
||||||
/** The instance provided by backend */
|
/** The instance provided by backend */
|
||||||
public static GL20 g;
|
private static GL20 g;
|
||||||
|
|
||||||
public static boolean GDX_DESKTOP_QUIRKS;
|
public static boolean GDX_DESKTOP_QUIRKS;
|
||||||
public static boolean GDX_WEBGL_QUIRKS;
|
public static boolean GDX_WEBGL_QUIRKS;
|
||||||
@ -35,4 +35,8 @@ public class GLAdapter {
|
|||||||
|
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void init(GL20 gl20) {
|
||||||
|
g = gl20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user