gdx: add MotionHandler, use common MapEventLayer
This commit is contained in:
parent
26704d3ce5
commit
fed257a1f7
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
199
vtm-gdx/src/org/oscim/gdx/MotionHandler.java
Normal file
199
vtm-gdx/src/org/oscim/gdx/MotionHandler.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user