diff --git a/vtm-desktop/src/org/oscim/gdx/GdxMapApp.java b/vtm-desktop/src/org/oscim/gdx/GdxMapApp.java
index adde8ce9..95bc76af 100644
--- a/vtm-desktop/src/org/oscim/gdx/GdxMapApp.java
+++ b/vtm-desktop/src/org/oscim/gdx/GdxMapApp.java
@@ -64,8 +64,8 @@ public class GdxMapApp extends GdxMap {
cfg.width = 1280;
cfg.height = 800;
cfg.stencil = 8;
- cfg.samples = 2;
- cfg.foregroundFPS = 30;
+ //cfg.samples = 2;
+ cfg.foregroundFPS = 60;
return cfg;
}
diff --git a/vtm-gdx/src/org/oscim/gdx/GdxMap.java b/vtm-gdx/src/org/oscim/gdx/GdxMap.java
index b21f23a1..9564b232 100644
--- a/vtm-gdx/src/org/oscim/gdx/GdxMap.java
+++ b/vtm-gdx/src/org/oscim/gdx/GdxMap.java
@@ -25,19 +25,21 @@ import org.oscim.map.Map;
import org.oscim.renderer.MapRenderer;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.TileSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
-import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;
public abstract class GdxMap implements ApplicationListener {
+ final static Logger log = LoggerFactory.getLogger(GdxMap.class);
protected final Map mMap;
- protected final MapAdapter mMapAdapter;
+ private final MapAdapter mMapAdapter;
VectorTileLayer mMapLayer;
private final MapRenderer mMapRenderer;
@@ -81,14 +83,18 @@ public abstract class GdxMap implements ApplicationListener {
InputMultiplexer mux = new InputMultiplexer();
mux.addProcessor(new InputHandler(mMap));
- mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
- new MapController(mMap)));
+ //mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
+ // new MapController(mMap)));
+ mux.addProcessor(new MotionHandler(mMap));
+
Gdx.input.setInputProcessor(mux);
createLayers();
}
- protected abstract void createLayers();
+ protected void createLayers() {
+ mMap.layers().add(new TileGridLayer(mMap));
+ }
@Override
public void dispose() {
@@ -97,9 +103,10 @@ public abstract class GdxMap implements ApplicationListener {
@Override
public void render() {
- if (mMapAdapter.needsRedraw()) {
- mMapRenderer.onDrawFrame();
- }
+ if (!mMapAdapter.needsRedraw())
+ return;
+
+ mMapRenderer.onDrawFrame();
}
@Override
diff --git a/vtm-gdx/src/org/oscim/gdx/GdxMotionEvent.java b/vtm-gdx/src/org/oscim/gdx/GdxMotionEvent.java
deleted file mode 100644
index 6fe329ab..00000000
--- a/vtm-gdx/src/org/oscim/gdx/GdxMotionEvent.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2013 Hannes Janetzek
- *
- * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
- *
- * This program is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along with
- * this program. If not, see .
- */
-package org.oscim.gdx;
-
-import org.oscim.event.MotionEvent;
-
-import com.badlogic.gdx.InputProcessor;
-
-public class GdxMotionEvent extends MotionEvent implements InputProcessor {
-
- @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;
- }
-
- @Override
- public long getTime() {
- return 0;
- }
-
- // -------- InputProcessor ----------
- @Override
- public boolean keyDown(int keycode) {
- return false;
- }
-
- @Override
- public boolean keyUp(int keycode) {
- return false;
- }
-
- @Override
- public boolean keyTyped(char character) {
- return false;
- }
-
- @Override
- public boolean touchDown(int screenX, int screenY, int pointer, int button) {
- return false;
- }
-
- @Override
- public boolean touchUp(int screenX, int screenY, int pointer, int button) {
- return false;
- }
-
- @Override
- public boolean touchDragged(int screenX, int screenY, int pointer) {
- return false;
- }
-
- @Override
- public boolean mouseMoved(int screenX, int screenY) {
- return false;
- }
-
- @Override
- public boolean scrolled(int amount) {
- return false;
- }
-
-}
diff --git a/vtm-gdx/src/org/oscim/gdx/MapController.java b/vtm-gdx/src/org/oscim/gdx/GestureHandler.java
similarity index 98%
rename from vtm-gdx/src/org/oscim/gdx/MapController.java
rename to vtm-gdx/src/org/oscim/gdx/GestureHandler.java
index 405460a1..e4d59225 100644
--- a/vtm-gdx/src/org/oscim/gdx/MapController.java
+++ b/vtm-gdx/src/org/oscim/gdx/GestureHandler.java
@@ -7,7 +7,7 @@ import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
-public class MapController implements GestureListener {
+public class GestureHandler implements GestureListener {
private boolean mayFling = true;
private boolean mPinch;
@@ -39,7 +39,7 @@ public class MapController implements GestureListener {
//private ViewController mViewport;
private final Map mMap;
- public MapController(Map map) {
+ public GestureHandler(Map map) {
//mViewport = mMap.viewport();
mMap = map;
}
diff --git a/vtm-gdx/src/org/oscim/gdx/MotionHandler.java b/vtm-gdx/src/org/oscim/gdx/MotionHandler.java
new file mode 100644
index 00000000..f5e22975
--- /dev/null
+++ b/vtm-gdx/src/org/oscim/gdx/MotionHandler.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2013 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.gdx;
+
+import org.oscim.event.MotionEvent;
+import org.oscim.map.Map;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input.Buttons;
+import com.badlogic.gdx.InputProcessor;
+
+public class MotionHandler extends MotionEvent implements InputProcessor {
+ private final Map mMap;
+
+ public MotionHandler(Map map) {
+ mMap = map;
+ }
+
+ int mPointerDown;
+ long mDownTime;
+
+ int mType;
+
+ int mPointer;
+ int mCurX;
+ int mCurY;
+ int mPointerX[] = new int[10];
+ int mPointerY[] = new int[10];
+
+ @Override
+ public int getAction() {
+ return mType;
+ }
+
+ @Override
+ public float getX() {
+ return mCurX;
+ }
+
+ @Override
+ public float getY() {
+ return mCurY;
+ }
+
+ @Override
+ public float getX(int idx) {
+ if (idx >= 10)
+ return 0;
+
+ return mPointerX[idx];
+ }
+
+ @Override
+ public float getY(int idx) {
+ if (idx >= 10)
+ return 0;
+
+ return mPointerY[idx];
+ }
+
+ @Override
+ public int getPointerCount() {
+ return mPointerDown;
+ }
+
+ @Override
+ public long getTime() {
+ return (long) (mTime / 1000000d);
+ }
+
+ // -------- InputProcessor ----------
+ @Override
+ public boolean keyDown(int keycode) {
+ return false;
+ }
+
+ @Override
+ public boolean keyUp(int keycode) {
+ return false;
+ }
+
+ @Override
+ public boolean keyTyped(char character) {
+ return false;
+ }
+
+ long mTime = System.currentTimeMillis();
+
+ @Override
+ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
+ if (pointer >= 10)
+ return true;
+
+ if (button != Buttons.LEFT)
+ return false;
+
+ mTime = Gdx.input.getCurrentEventTime();
+ if (mPointerDown++ == 0) {
+ mDownTime = getTime();
+ mType = MotionEvent.ACTION_DOWN;
+ } else {
+ mType = MotionEvent.ACTION_POINTER_DOWN;
+ }
+
+ mPointerX[pointer] = mCurX = screenX;
+ mPointerY[pointer] = mCurY = screenY;
+ mPointer = pointer;
+ //GdxMap.log.debug("down " + screenX + ":" + screenY
+ // + " / " + pointer + " " + mPointerDown
+ // + " " + (getTime() - mDownTime));
+
+ mMap.input.fire(null, this);
+ return true;
+ }
+
+ @Override
+ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
+ if (pointer >= 10)
+ return true;
+
+ if (button != Buttons.LEFT)
+ return false;
+
+ if (mPointerDown == 0)
+ return true;
+
+ mTime = Gdx.input.getCurrentEventTime();
+ mType = (--mPointerDown == 0) ?
+ MotionEvent.ACTION_UP :
+ MotionEvent.ACTION_POINTER_UP;
+
+ mPointerX[pointer] = mCurX = screenX;
+ mPointerY[pointer] = mCurY = screenY;
+ mPointer = pointer;
+
+ //GdxMap.log.debug("up " + screenX + ":" + screenY
+ // + " / " + pointer + " " + mPointerDown
+ // + " " + (getTime() - mDownTime));
+
+ mMap.input.fire(null, this);
+ return true;
+ }
+
+ @Override
+ public boolean touchDragged(int screenX, int screenY, int pointer) {
+ if (pointer >= 10)
+ return true;
+
+ mTime = Gdx.input.getCurrentEventTime();
+ mType = MotionEvent.ACTION_MOVE;
+
+ mPointerX[pointer] = mCurX = screenX;
+ mPointerY[pointer] = mCurY = screenY;
+ mPointer = pointer;
+
+ //GdxMap.log.debug("dragged " + screenX + ":" + screenY
+ // + " / " + pointer + " " + (getTime() - mDownTime));
+
+ mMap.input.fire(null, this);
+ return true;
+ }
+
+ @Override
+ public boolean mouseMoved(int screenX, int screenY) {
+ mTime = Gdx.input.getCurrentEventTime();
+ mType = MotionEvent.ACTION_MOVE;
+
+ mPointerX[Buttons.LEFT] = mCurX = screenX;
+ mPointerY[Buttons.LEFT] = mCurY = screenY;
+ mPointer = Buttons.LEFT;
+
+ //GdxMap.log.debug("moved " + screenX + ":" + screenY);
+
+ mMap.input.fire(null, this);
+ return true;
+ }
+
+ @Override
+ public boolean scrolled(int amount) {
+ mTime = Gdx.input.getCurrentEventTime();
+
+ return false;
+ }
+
+}