- turn off libgdx load screen
- block contextmenu
- add osm attribution
- read initial position from url hash
- disable text stroke for firefox/linux (canvas2d is 10 times slower than chromium..)
This commit is contained in:
Hannes Janetzek
2013-08-05 02:54:21 +02:00
parent 05440542b9
commit dfec023e6e
9 changed files with 299 additions and 129 deletions

View File

@@ -16,6 +16,8 @@
package com.badlogic.gdx.backends.gwt;
import org.oscim.backend.GL20;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Audio;
@@ -43,7 +45,6 @@ import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
@@ -130,7 +131,6 @@ public abstract class GwtApplication implements EntryPoint, Application {
private void setupLoop() {
// setup modules
consoleLog("setupLoop");
try {
graphics = new GwtGraphics(root, config);
} catch (Throwable e) {
@@ -167,10 +167,17 @@ public abstract class GwtApplication implements EntryPoint, Application {
throw new RuntimeException(t);
}
final int frameTime = (int) ((1f / config.fps) * 1000);
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// setup rendering timer
new Timer() {
//long lastRun;
@Override
public void run() {
//long startRender = 0;
try {
graphics.update();
if (graphics.getWidth() != lastWidth
@@ -188,14 +195,26 @@ public abstract class GwtApplication implements EntryPoint, Application {
runnablesHelper.get(i).run();
}
runnablesHelper.clear();
//startRender = System.currentTimeMillis();
listener.render();
input.justTouched = false;
} catch (Throwable t) {
error("GwtApplication", "exception: " + t.getMessage(), t);
throw new RuntimeException(t);
}
long now = System.currentTimeMillis();
int diff = (int)(now - graphics.lastTimeStamp);
//if (diff > 80)
// consoleLog("diff " + diff + " " + (now - startRender) + " " + graphics.getFramesPerSecond() );
diff = frameTime - diff;
//lastRun = now;
this.schedule(diff > 5 ? diff : 5);
}
}.scheduleRepeating((int) ((1f / config.fps) * 1000));
}.schedule(0); //scheduleRepeating((int) ((1f / config.fps) * 1000));
}
public Panel getRootPanel() {
@@ -207,9 +226,11 @@ public abstract class GwtApplication implements EntryPoint, Application {
public PreloaderCallback getPreloaderCallback() {
final Panel preloaderPanel = new VerticalPanel();
preloaderPanel.setStyleName("gdx-preloader");
final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
logo.setStyleName("logo");
preloaderPanel.add(logo);
//final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
//logo.setStyleName("logo");
//preloaderPanel.add(logo);
final Panel meterPanel = new SimplePanel();
meterPanel.setStyleName("gdx-meter");
meterPanel.addStyleName("red");

View File

@@ -47,7 +47,7 @@ public class GwtGraphics implements Graphics {
boolean inFullscreenMode = false;
double pixelRatio;
public GwtGraphics(Panel root, GwtApplicationConfiguration config) {
public GwtGraphics(Panel root, final GwtApplicationConfiguration config) {
Canvas canvasWidget = Canvas.createIfSupported();
if (canvasWidget == null)
throw new GdxRuntimeException("Canvas not supported");
@@ -61,7 +61,6 @@ public class GwtGraphics implements Graphics {
canvas.getStyle().setWidth(config.width, Unit.PX);
canvas.getStyle().setHeight(config.height, Unit.PX);
this.config = config;
WebGLContextAttributes attributes = WebGLContextAttributes.create();
@@ -72,17 +71,18 @@ public class GwtGraphics implements Graphics {
context = WebGLRenderingContext.getContext(canvas, attributes);
context.viewport(0, 0, config.width, config.height);
// this actually *enables* the option to use std derivatives in shader..
// this actually *enables* the option to use std derivatives in shader..
context.getExtension("OES_standard_derivatives");
this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGL20(context);
canvas.setId("gdx-canvas");
Window.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
int w = getWindowWidthJSNI();
int h = getWindowHeightJSNI();
int w = config.rootPanel.getOffsetWidth();
int h = config.rootPanel.getOffsetHeight();
canvas.getStyle().setWidth(w, Unit.PX);
canvas.getStyle().setHeight(h, Unit.PX);

View File

@@ -382,6 +382,10 @@ public class GwtInput implements Input {
.addEventListener(
name,
function(e) {
if (capture){
e.preventDefault();
e.stopPropagation();
}
handler.@com.badlogic.gdx.backends.gwt.GwtInput::handleEvent(Lcom/google/gwt/dom/client/NativeEvent;)(e);
}, capture);
}-*/;
@@ -440,6 +444,7 @@ public class GwtInput implements Input {
private void hookEvents() {
addEventListener(canvas, "mousedown", this, true);
addEventListener(canvas, "contextmenu", this, true);
addEventListener(Document.get(), "mousedown", this, true);
addEventListener(canvas, "mouseup", this, true);
addEventListener(Document.get(), "mouseup", this, true);

View File

@@ -17,14 +17,17 @@ package org.oscim.layers.tile.bitmap;
import java.net.URL;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.gdx.client.GwtBitmap;
import org.oscim.layers.tile.MapTile;
import org.oscim.layers.tile.TileLayer;
import org.oscim.layers.tile.TileLoader;
import org.oscim.layers.tile.TileManager;
import org.oscim.layers.tile.bitmap.TileSource.FadeStep;
import org.oscim.renderer.sublayers.BitmapLayer;
import org.oscim.renderer.sublayers.Layers;
import org.oscim.utils.FastMath;
import org.oscim.view.MapView;
import com.google.gwt.event.dom.client.ErrorEvent;
@@ -37,10 +40,41 @@ import com.google.gwt.user.client.ui.RootPanel;
public class BitmapTileLayer extends TileLayer<TileLoader> {
final TileSource mTileSource;
private final FadeStep[] mFade;
public BitmapTileLayer(MapView mapView, TileSource tileSource) {
super(mapView, tileSource.getZoomLevelMin(), tileSource.getZoomLevelMax(), 100);
mTileSource = tileSource;
mFade = mTileSource.getFadeSteps();
}
@Override
public void onUpdate(MapPosition pos, boolean changed, boolean clear) {
super.onUpdate(pos, changed, clear);
if (mFade == null) {
mRenderLayer.setBitmapAlpha(1);
return;
}
float alpha = 0;
for (FadeStep f : mFade) {
if (pos.scale < f.scaleStart || pos.scale > f.scaleEnd)
continue;
if (f.alphaStart == f.alphaEnd) {
alpha = f.alphaStart;
break;
}
double range = f.scaleEnd / f.scaleStart;
float a = (float)((range - (pos.scale / f.scaleStart)) / range);
a = FastMath.clamp(a, 0, 1);
// interpolate alpha between start and end
alpha = a * f.alphaStart + (1 - a) * f.alphaEnd;
break;
}
mRenderLayer.setBitmapAlpha(alpha);
}
@Override

View File

@@ -16,16 +16,12 @@ package org.oscim.tilesource.common;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.oscim.backend.Log;
import org.oscim.layers.tile.MapTile;
import org.oscim.tilesource.ITileDataSink;
import org.oscim.tilesource.ITileDataSource;
import org.oscim.backend.Log;
/**
*
*
@@ -50,42 +46,15 @@ public abstract class PbfTileDataSource implements ITileDataSource {
mSink = sink;
try {
mConn.sendRequest(tile, this);
//InputStream is;
// if (!mConn.sendRequest(tile, this)) {
// Log.d(TAG, tile + " Request Failed");
// result = QueryResult.FAILED;
// } else if ((is = mConn.readHeader()) != null) {
// boolean win = mTileDecoder.decode(tile, sink, is, mConn.getContentLength());
// if (!win)
// Log.d(TAG, tile + " failed");
// } else {
// Log.d(TAG, tile + " Network Error");
// result = QueryResult.FAILED;
// }
// } catch (SocketException e) {
// Log.d(TAG, tile + " Socket exception: " + e.getMessage());
// result = QueryResult.FAILED;
// } catch (SocketTimeoutException e) {
// Log.d(TAG, tile + " Socket Timeout");
// result = QueryResult.FAILED;
// } catch (UnknownHostException e) {
// Log.d(TAG, tile + " No Network");
// result = QueryResult.FAILED;
} catch (Exception e) {
e.printStackTrace();
result = QueryResult.FAILED;
}
//mConn.requestCompleted();
//if (result != QueryResult.SUCCESS)
// mConn.close();
return result;
}
public void process(InputStream is, int length) {
//Log.d(TAG, mTile + " process " + is + " " + length + " " + mSink);
boolean win = false;
if (length >= 0) {
@@ -100,9 +69,6 @@ public abstract class PbfTileDataSource implements ITileDataSource {
mConn.requestCompleted();
mSink.completed(win);
//mTile = null;
//mSink = null;
}
@Override