use full window canvas and try to use the real size in pixel...
This commit is contained in:
parent
c002b8a3c3
commit
099ab0e817
@ -1,15 +1,19 @@
|
|||||||
package org.oscim.gdx.client;
|
package org.oscim.gdx.client;
|
||||||
|
|
||||||
// -draftCompile -localWorkers 2
|
// -draftCompile -localWorkers 2
|
||||||
|
import org.oscim.core.Tile;
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||||
|
import com.badlogic.gdx.backends.gwt.GwtGraphics;
|
||||||
|
|
||||||
public class GwtLauncher extends GwtApplication {
|
public class GwtLauncher extends GwtApplication {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GwtApplicationConfiguration getConfig () {
|
public GwtApplicationConfiguration getConfig() {
|
||||||
GwtApplicationConfiguration cfg = new GwtApplicationConfiguration(1400, 800);
|
GwtApplicationConfiguration cfg = new GwtApplicationConfiguration(GwtGraphics.getWindowWidthJSNI(),
|
||||||
|
GwtGraphics.getWindowHeightJSNI() );
|
||||||
cfg.stencil = true;
|
cfg.stencil = true;
|
||||||
cfg.fps = 25;
|
cfg.fps = 25;
|
||||||
|
|
||||||
@ -17,7 +21,11 @@ public class GwtLauncher extends GwtApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApplicationListener getApplicationListener () {
|
public ApplicationListener getApplicationListener() {
|
||||||
|
if (GwtGraphics.getDevicePixelRatioJSNI() > 1)
|
||||||
|
Tile.SIZE = 400;
|
||||||
|
else
|
||||||
|
Tile.SIZE = 360;
|
||||||
|
|
||||||
return new GwtGdxMap();
|
return new GwtGdxMap();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,13 +49,16 @@ import com.google.gwt.user.client.ui.Label;
|
|||||||
import com.google.gwt.user.client.ui.Panel;
|
import com.google.gwt.user.client.ui.Panel;
|
||||||
import com.google.gwt.user.client.ui.RootPanel;
|
import com.google.gwt.user.client.ui.RootPanel;
|
||||||
import com.google.gwt.user.client.ui.SimplePanel;
|
import com.google.gwt.user.client.ui.SimplePanel;
|
||||||
import com.google.gwt.user.client.ui.TextArea;
|
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
/** Implementation of an {@link Application} based on GWT. Clients have to override {@link #getConfig()} and
|
/**
|
||||||
* {@link #getApplicationListener()}. Clients can override the default loading screen via
|
* Implementation of an {@link Application} based on GWT. Clients have to
|
||||||
* {@link #getPreloaderCallback()} and implement any loading screen drawing via GWT widgets.
|
* override {@link #getConfig()} and {@link #getApplicationListener()}. Clients
|
||||||
* @author mzechner */
|
* can override the default loading screen via {@link #getPreloaderCallback()}
|
||||||
|
* and implement any loading screen drawing via GWT widgets.
|
||||||
|
*
|
||||||
|
* @author mzechner
|
||||||
|
*/
|
||||||
public abstract class GwtApplication implements EntryPoint, Application {
|
public abstract class GwtApplication implements EntryPoint, Application {
|
||||||
private ApplicationListener listener;
|
private ApplicationListener listener;
|
||||||
private GwtApplicationConfiguration config;
|
private GwtApplicationConfiguration config;
|
||||||
@ -63,7 +66,6 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
private GwtInput input;
|
private GwtInput input;
|
||||||
private GwtNet net;
|
private GwtNet net;
|
||||||
private Panel root = null;
|
private Panel root = null;
|
||||||
private TextArea log = null;
|
|
||||||
private int logLevel = LOG_ERROR;
|
private int logLevel = LOG_ERROR;
|
||||||
private Array<Runnable> runnables = new Array<Runnable>();
|
private Array<Runnable> runnables = new Array<Runnable>();
|
||||||
private Array<Runnable> runnablesHelper = new Array<Runnable>();
|
private Array<Runnable> runnablesHelper = new Array<Runnable>();
|
||||||
@ -74,15 +76,13 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
private ObjectMap<String, Preferences> prefs = new ObjectMap<String, Preferences>();
|
private ObjectMap<String, Preferences> prefs = new ObjectMap<String, Preferences>();
|
||||||
|
|
||||||
/** @return the configuration for the {@link GwtApplication}. */
|
/** @return the configuration for the {@link GwtApplication}. */
|
||||||
public abstract GwtApplicationConfiguration getConfig ();
|
public abstract GwtApplicationConfiguration getConfig();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModuleLoad () {
|
public void onModuleLoad() {
|
||||||
consoleLog("onModuleLoad");
|
|
||||||
this.agentInfo = computeAgentInfo();
|
this.agentInfo = computeAgentInfo();
|
||||||
this.listener = getApplicationListener();
|
this.listener = getApplicationListener();
|
||||||
this.config = getConfig();
|
this.config = getConfig();
|
||||||
this.log = config.log;
|
|
||||||
|
|
||||||
if (config.rootPanel != null) {
|
if (config.rootPanel != null) {
|
||||||
this.root = config.rootPanel;
|
this.root = config.rootPanel;
|
||||||
@ -117,18 +117,18 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
// called (function instanceof Function fails, wtf JS?).
|
// called (function instanceof Function fails, wtf JS?).
|
||||||
new Timer() {
|
new Timer() {
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run() {
|
||||||
//if (SoundManager.ok()) {
|
//if (SoundManager.ok()) {
|
||||||
final PreloaderCallback callback = getPreloaderCallback();
|
final PreloaderCallback callback = getPreloaderCallback();
|
||||||
preloader = new Preloader();
|
preloader = new Preloader();
|
||||||
preloader.preload("assets.txt", new PreloaderCallback() {
|
preloader.preload("assets.txt", new PreloaderCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void error (String file) {
|
public void error(String file) {
|
||||||
callback.error(file);
|
callback.error(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update (PreloaderState state) {
|
public void update(PreloaderState state) {
|
||||||
callback.update(state);
|
callback.update(state);
|
||||||
if (state.hasEnded()) {
|
if (state.hasEnded()) {
|
||||||
root.clear();
|
root.clear();
|
||||||
@ -142,7 +142,7 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
}.scheduleRepeating(100);
|
}.scheduleRepeating(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLoop () {
|
private void setupLoop() {
|
||||||
// setup modules
|
// setup modules
|
||||||
consoleLog("setupLoop");
|
consoleLog("setupLoop");
|
||||||
try {
|
try {
|
||||||
@ -152,8 +152,10 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
root.add(new Label("Sorry, your browser doesn't seem to support WebGL"));
|
root.add(new Label("Sorry, your browser doesn't seem to support WebGL"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastWidth = graphics.getWidth();
|
lastWidth = graphics.getWidth();
|
||||||
lastHeight = graphics.getHeight();
|
lastHeight = graphics.getHeight();
|
||||||
|
|
||||||
Gdx.app = this;
|
Gdx.app = this;
|
||||||
//Gdx.audio = new GwtAudio();
|
//Gdx.audio = new GwtAudio();
|
||||||
Gdx.graphics = graphics;
|
Gdx.graphics = graphics;
|
||||||
@ -164,11 +166,15 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
Gdx.input = this.input;
|
Gdx.input = this.input;
|
||||||
this.net = new GwtNet();
|
this.net = new GwtNet();
|
||||||
Gdx.net = this.net;
|
Gdx.net = this.net;
|
||||||
|
final double pixelRatio = GwtGraphics.getDevicePixelRatioJSNI();
|
||||||
|
consoleLog(">>>> " + config.width + "x"+ config.height + " ratio " + pixelRatio);
|
||||||
|
|
||||||
// tell listener about app creation
|
// tell listener about app creation
|
||||||
try {
|
try {
|
||||||
listener.create();
|
listener.create();
|
||||||
listener.resize(graphics.getWidth(), graphics.getHeight());
|
listener.resize(
|
||||||
|
(int)(graphics.getWidth()),
|
||||||
|
(int)(graphics.getHeight()));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
error("GwtApplication", "exception: " + t.getMessage(), t);
|
error("GwtApplication", "exception: " + t.getMessage(), t);
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
@ -178,14 +184,17 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
// setup rendering timer
|
// setup rendering timer
|
||||||
new Timer() {
|
new Timer() {
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
graphics.update();
|
graphics.update();
|
||||||
if (Gdx.graphics.getWidth() != lastWidth || Gdx.graphics.getHeight() != lastHeight) {
|
if (Gdx.graphics.getWidth() != lastWidth
|
||||||
GwtApplication.this.listener.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|| Gdx.graphics.getHeight() != lastHeight) {
|
||||||
|
GwtApplication.this.listener.resize(
|
||||||
|
(int)(Gdx.graphics.getWidth()),
|
||||||
|
(int)(Gdx.graphics.getHeight()));
|
||||||
lastWidth = graphics.getWidth();
|
lastWidth = graphics.getWidth();
|
||||||
lastHeight = graphics.getHeight();
|
lastHeight = graphics.getHeight();
|
||||||
Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
|
//Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
|
||||||
}
|
}
|
||||||
runnablesHelper.addAll(runnables);
|
runnablesHelper.addAll(runnables);
|
||||||
runnables.clear();
|
runnables.clear();
|
||||||
@ -200,16 +209,16 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
throw new RuntimeException(t);
|
throw new RuntimeException(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.scheduleRepeating((int)((1f / config.fps) * 1000));
|
}.scheduleRepeating((int) ((1f / config.fps) * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Panel getRootPanel () {
|
public Panel getRootPanel() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
long loadStart = TimeUtils.nanoTime();
|
long loadStart = TimeUtils.nanoTime();
|
||||||
|
|
||||||
public PreloaderCallback getPreloaderCallback () {
|
public PreloaderCallback getPreloaderCallback() {
|
||||||
final Panel preloaderPanel = new VerticalPanel();
|
final Panel preloaderPanel = new VerticalPanel();
|
||||||
preloaderPanel.setStyleName("gdx-preloader");
|
preloaderPanel.setStyleName("gdx-preloader");
|
||||||
final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
|
final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
|
||||||
@ -227,12 +236,12 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
return new PreloaderCallback() {
|
return new PreloaderCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error (String file) {
|
public void error(String file) {
|
||||||
System.out.println("error: " + file);
|
System.out.println("error: " + file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update (PreloaderState state) {
|
public void update(PreloaderState state) {
|
||||||
meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
|
meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,22 +249,22 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Graphics getGraphics () {
|
public Graphics getGraphics() {
|
||||||
return graphics;
|
return graphics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Audio getAudio () {
|
public Audio getAudio() {
|
||||||
return Gdx.audio;
|
return Gdx.audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Input getInput () {
|
public Input getInput() {
|
||||||
return Gdx.input;
|
return Gdx.input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Files getFiles () {
|
public Files getFiles() {
|
||||||
return Gdx.files;
|
return Gdx.files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,79 +273,51 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
return Gdx.net;
|
return Gdx.net;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkLogLabel () {
|
|
||||||
if (log == null) {
|
|
||||||
log = new TextArea();
|
|
||||||
log.setSize(graphics.getWidth() + "px", "200px");
|
|
||||||
log.setReadOnly(true);
|
|
||||||
root.add(log);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log (String tag, String message) {
|
public void log(String tag, String message) {
|
||||||
if (logLevel >= LOG_INFO) {
|
if (logLevel >= LOG_INFO) {
|
||||||
checkLogLabel();
|
consoleLog(tag + ": " + message);
|
||||||
log.setText(log.getText() + "\n" + tag + ": " + message);
|
|
||||||
log.setCursorPos(log.getText().length() - 1);
|
|
||||||
System.out.println(tag + ": " + message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log (String tag, String message, Exception exception) {
|
public void log(String tag, String message, Exception exception) {
|
||||||
if (logLevel >= LOG_INFO) {
|
if (logLevel >= LOG_INFO) {
|
||||||
checkLogLabel();
|
consoleLog(tag + ": " + message + "\n" + exception.getMessage());
|
||||||
log.setText(log.getText() + "\n" + tag + ": " + message + "\n" + exception.getMessage() + "\n");
|
consoleLog(getStackTrace(exception));
|
||||||
log.setCursorPos(log.getText().length() - 1);
|
|
||||||
System.out.println(tag + ": " + message + "\n" + exception.getMessage());
|
|
||||||
System.out.println(getStackTrace(exception));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error (String tag, String message) {
|
public void error(String tag, String message) {
|
||||||
if (logLevel >= LOG_ERROR) {
|
if (logLevel >= LOG_ERROR) {
|
||||||
checkLogLabel();
|
consoleLog(tag + ": " + message);
|
||||||
log.setText(log.getText() + "\n" + tag + ": " + message);
|
|
||||||
log.setCursorPos(log.getText().length() - 1);
|
|
||||||
System.err.println(tag + ": " + message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error (String tag, String message, Throwable exception) {
|
public void error(String tag, String message, Throwable exception) {
|
||||||
if (logLevel >= LOG_ERROR) {
|
if (logLevel >= LOG_ERROR) {
|
||||||
checkLogLabel();
|
consoleLog(getStackTrace(exception));
|
||||||
log.setText(log.getText() + "\n" + tag + ": " + message + "\n" + exception.getMessage());
|
|
||||||
log.setCursorPos(log.getText().length() - 1);
|
|
||||||
System.err.println(tag + ": " + message + "\n" + exception.getMessage() + "\n");
|
|
||||||
System.out.println(getStackTrace(exception));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void debug (String tag, String message) {
|
public void debug(String tag, String message) {
|
||||||
if (logLevel >= LOG_DEBUG) {
|
if (logLevel >= LOG_DEBUG) {
|
||||||
checkLogLabel();
|
consoleLog(tag + ": " + message + "\n");
|
||||||
log.setText(log.getText() + "\n" + tag + ": " + message + "\n");
|
|
||||||
log.setCursorPos(log.getText().length() - 1);
|
|
||||||
System.out.println(tag + ": " + message + "\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void debug (String tag, String message, Throwable exception) {
|
public void debug(String tag, String message, Throwable exception) {
|
||||||
if (logLevel >= LOG_DEBUG) {
|
if (logLevel >= LOG_DEBUG) {
|
||||||
checkLogLabel();
|
consoleLog(tag + ": " + message + "\n" + exception.getMessage());
|
||||||
log.setText(log.getText() + "\n" + tag + ": " + message + "\n" + exception.getMessage() + "\n");
|
consoleLog(getStackTrace(exception));
|
||||||
log.setCursorPos(log.getText().length() - 1);
|
|
||||||
System.out.println(tag + ": " + message + "\n" + exception.getMessage());
|
|
||||||
System.out.println(getStackTrace(exception));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStackTrace (Throwable e) {
|
private String getStackTrace(Throwable e) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
for (StackTraceElement trace : e.getStackTrace()) {
|
for (StackTraceElement trace : e.getStackTrace()) {
|
||||||
buffer.append(trace.toString() + "\n");
|
buffer.append(trace.toString() + "\n");
|
||||||
@ -345,32 +326,32 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLogLevel (int logLevel) {
|
public void setLogLevel(int logLevel) {
|
||||||
this.logLevel = logLevel;
|
this.logLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApplicationType getType () {
|
public ApplicationType getType() {
|
||||||
return ApplicationType.WebGL;
|
return ApplicationType.WebGL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getVersion () {
|
public int getVersion() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getJavaHeap () {
|
public long getJavaHeap() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getNativeHeap () {
|
public long getNativeHeap() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Preferences getPreferences (String name) {
|
public Preferences getPreferences(String name) {
|
||||||
Preferences pref = prefs.get(name);
|
Preferences pref = prefs.get(name);
|
||||||
if (pref == null) {
|
if (pref == null) {
|
||||||
pref = new GwtPreferences(name);
|
pref = new GwtPreferences(name);
|
||||||
@ -383,33 +364,36 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
public Clipboard getClipboard() {
|
public Clipboard getClipboard() {
|
||||||
return new Clipboard() {
|
return new Clipboard() {
|
||||||
@Override
|
@Override
|
||||||
public String getContents () {
|
public String getContents() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContents (String content) {
|
public void setContents(String content) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postRunnable (Runnable runnable) {
|
public void postRunnable(Runnable runnable) {
|
||||||
runnables.add(runnable);
|
runnables.add(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit () {
|
public void exit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Contains precomputed information on the user-agent. Useful for dealing with browser and OS behavioral differences. Kindly
|
/**
|
||||||
* borrowed from PlayN */
|
* Contains precomputed information on the user-agent. Useful for dealing
|
||||||
public static AgentInfo agentInfo () {
|
* with browser and OS behavioral differences. Kindly
|
||||||
|
* borrowed from PlayN
|
||||||
|
*/
|
||||||
|
public static AgentInfo agentInfo() {
|
||||||
return agentInfo;
|
return agentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** kindly borrowed from PlayN **/
|
/** kindly borrowed from PlayN **/
|
||||||
private static native AgentInfo computeAgentInfo () /*-{
|
private static native AgentInfo computeAgentInfo() /*-{
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
return {
|
return {
|
||||||
// browser type flags
|
// browser type flags
|
||||||
@ -427,65 +411,65 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
|
|
||||||
/** Returned by {@link #agentInfo}. Kindly borrowed from PlayN. */
|
/** Returned by {@link #agentInfo}. Kindly borrowed from PlayN. */
|
||||||
public static class AgentInfo extends JavaScriptObject {
|
public static class AgentInfo extends JavaScriptObject {
|
||||||
public final native boolean isFirefox () /*-{
|
public final native boolean isFirefox() /*-{
|
||||||
return this.isFirefox;
|
return this.isFirefox;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
public final native boolean isChrome () /*-{
|
public final native boolean isChrome() /*-{
|
||||||
return this.isChrome;
|
return this.isChrome;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
public final native boolean isSafari () /*-{
|
public final native boolean isSafari() /*-{
|
||||||
return this.isSafari;
|
return this.isSafari;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
public final native boolean isOpera () /*-{
|
public final native boolean isOpera() /*-{
|
||||||
return this.isOpera;
|
return this.isOpera;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
public final native boolean isIE () /*-{
|
public final native boolean isIE() /*-{
|
||||||
return this.isIE;
|
return this.isIE;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
public final native boolean isMacOS () /*-{
|
public final native boolean isMacOS() /*-{
|
||||||
return this.isMacOS;
|
return this.isMacOS;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
public final native boolean isLinux () /*-{
|
public final native boolean isLinux() /*-{
|
||||||
return this.isLinux;
|
return this.isLinux;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
public final native boolean isWindows () /*-{
|
public final native boolean isWindows() /*-{
|
||||||
return this.isWindows;
|
return this.isWindows;
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
protected AgentInfo () {
|
protected AgentInfo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBaseUrl () {
|
public String getBaseUrl() {
|
||||||
return preloader.baseUrl;
|
return preloader.baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Preloader getPreloader () {
|
public Preloader getPreloader() {
|
||||||
return preloader;
|
return preloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLifecycleListener (LifecycleListener listener) {
|
public void addLifecycleListener(LifecycleListener listener) {
|
||||||
synchronized(lifecycleListeners) {
|
synchronized (lifecycleListeners) {
|
||||||
lifecycleListeners.add(listener);
|
lifecycleListeners.add(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeLifecycleListener (LifecycleListener listener) {
|
public void removeLifecycleListener(LifecycleListener listener) {
|
||||||
synchronized(lifecycleListeners) {
|
synchronized (lifecycleListeners) {
|
||||||
lifecycleListeners.removeValue(listener, true);
|
lifecycleListeners.removeValue(listener, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
native void consoleLog(String message) /*-{
|
private native void consoleLog(String message) /*-{
|
||||||
console.log( "GWT:" + message );
|
console.log(message);
|
||||||
}-*/;
|
}-*/;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,346 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 2011 See AUTHORS file.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.badlogic.gdx.backends.gwt;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Graphics;
|
||||||
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
|
import com.badlogic.gdx.graphics.GL11;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.GLCommon;
|
||||||
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
|
import com.google.gwt.canvas.client.Canvas;
|
||||||
|
import com.google.gwt.dom.client.CanvasElement;
|
||||||
|
import com.google.gwt.dom.client.Style.Unit;
|
||||||
|
import com.google.gwt.event.logical.shared.ResizeEvent;
|
||||||
|
import com.google.gwt.event.logical.shared.ResizeHandler;
|
||||||
|
import com.google.gwt.user.client.Window;
|
||||||
|
import com.google.gwt.user.client.ui.Panel;
|
||||||
|
import com.google.gwt.webgl.client.WebGLContextAttributes;
|
||||||
|
import com.google.gwt.webgl.client.WebGLRenderingContext;
|
||||||
|
|
||||||
|
public class GwtGraphics implements Graphics {
|
||||||
|
CanvasElement canvas;
|
||||||
|
WebGLRenderingContext context;
|
||||||
|
GL20 gl;
|
||||||
|
String extensions;
|
||||||
|
float fps = 0;
|
||||||
|
long lastTimeStamp = System.currentTimeMillis();
|
||||||
|
float deltaTime = 0;
|
||||||
|
float time = 0;
|
||||||
|
int frames;
|
||||||
|
GwtApplicationConfiguration config;
|
||||||
|
boolean inFullscreenMode = false;
|
||||||
|
double pixelRatio;
|
||||||
|
|
||||||
|
public GwtGraphics(Panel root, GwtApplicationConfiguration config) {
|
||||||
|
Canvas canvasWidget = Canvas.createIfSupported();
|
||||||
|
if (canvasWidget == null)
|
||||||
|
throw new GdxRuntimeException("Canvas not supported");
|
||||||
|
canvas = canvasWidget.getCanvasElement();
|
||||||
|
root.add(canvasWidget);
|
||||||
|
|
||||||
|
this.pixelRatio = getDevicePixelRatioJSNI();
|
||||||
|
|
||||||
|
canvas.setWidth((int) (config.width * pixelRatio));
|
||||||
|
canvas.setHeight((int) (config.height * pixelRatio));
|
||||||
|
|
||||||
|
canvas.getStyle().setWidth(config.width, Unit.PX);
|
||||||
|
canvas.getStyle().setHeight(config.height, Unit.PX);
|
||||||
|
|
||||||
|
this.config = config;
|
||||||
|
|
||||||
|
WebGLContextAttributes attributes = WebGLContextAttributes.create();
|
||||||
|
attributes.setAntialias(config.antialiasing);
|
||||||
|
attributes.setStencil(config.stencil);
|
||||||
|
attributes.setAlpha(false);
|
||||||
|
attributes.setPremultipliedAlpha(false);
|
||||||
|
|
||||||
|
context = WebGLRenderingContext.getContext(canvas, attributes);
|
||||||
|
context.viewport(0, 0, config.width, config.height);
|
||||||
|
|
||||||
|
this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGL20(context);
|
||||||
|
|
||||||
|
Window.addResizeHandler(new ResizeHandler() {
|
||||||
|
@Override
|
||||||
|
public void onResize(ResizeEvent event) {
|
||||||
|
int w = getWindowWidthJSNI();
|
||||||
|
int h = getWindowHeightJSNI();
|
||||||
|
|
||||||
|
canvas.getStyle().setWidth(w, Unit.PX);
|
||||||
|
canvas.getStyle().setHeight(h, Unit.PX);
|
||||||
|
|
||||||
|
Gdx.app.log("onResize", w + "/" + h);
|
||||||
|
canvas.setWidth((int) (w * pixelRatio));
|
||||||
|
canvas.setHeight((int) (h * pixelRatio));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static native double getDevicePixelRatioJSNI() /*-{
|
||||||
|
return $wnd.devicePixelRatio || 1.0;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
public static native int getWindowWidthJSNI() /*-{
|
||||||
|
return $wnd.innerWidth;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
public static native int getWindowHeightJSNI() /*-{
|
||||||
|
return $wnd.innerHeight;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
public WebGLRenderingContext getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGL11Available() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGL20Available() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GLCommon getGLCommon() {
|
||||||
|
return gl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GL10 getGL10() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GL11 getGL11() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GL20 getGL20() {
|
||||||
|
return gl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return canvas.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHeight() {
|
||||||
|
return canvas.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getDeltaTime() {
|
||||||
|
return deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFramesPerSecond() {
|
||||||
|
return (int) fps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GraphicsType getType() {
|
||||||
|
return GraphicsType.WebGL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getPpiX() {
|
||||||
|
return 96;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getPpiY() {
|
||||||
|
return 96;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getPpcX() {
|
||||||
|
return 96 / 2.54f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getPpcY() {
|
||||||
|
return 96 / 2.54f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsDisplayModeChange() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DisplayMode[] getDisplayModes() {
|
||||||
|
return new DisplayMode[] { new DisplayMode(getScreenWidthJSNI(), getScreenHeightJSNI(), 60,
|
||||||
|
8) {
|
||||||
|
} };
|
||||||
|
}
|
||||||
|
|
||||||
|
private native int getScreenWidthJSNI() /*-{
|
||||||
|
return $wnd.screen.width;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
private native int getScreenHeightJSNI() /*-{
|
||||||
|
return $wnd.screen.height;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
private native boolean isFullscreenJSNI() /*-{
|
||||||
|
if ("webkitIsFullScreen" in $doc) {
|
||||||
|
return $doc.webkitIsFullScreen;
|
||||||
|
}
|
||||||
|
if ("mozFullScreen" in $doc) {
|
||||||
|
return $doc.mozFullScreen;
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
private void fullscreenChanged() {
|
||||||
|
if (!isFullscreen()) {
|
||||||
|
canvas.setWidth(config.width);
|
||||||
|
canvas.setHeight(config.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private native boolean setFullscreenJSNI(GwtGraphics graphics, CanvasElement element) /*-{
|
||||||
|
if (element.webkitRequestFullScreen) {
|
||||||
|
element.width = $wnd.screen.width;
|
||||||
|
element.height = $wnd.screen.height;
|
||||||
|
element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||||
|
$doc.addEventListener(
|
||||||
|
"webkitfullscreenchange",
|
||||||
|
function() {
|
||||||
|
graphics.@com.badlogic.gdx.backends.gwt.GwtGraphics::fullscreenChanged()();
|
||||||
|
}, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (element.mozRequestFullScreen) {
|
||||||
|
element.width = $wnd.screen.width;
|
||||||
|
element.height = $wnd.screen.height;
|
||||||
|
element.mozRequestFullScreen();
|
||||||
|
$doc.addEventListener(
|
||||||
|
"mozfullscreenchange",
|
||||||
|
function() {
|
||||||
|
graphics.@com.badlogic.gdx.backends.gwt.GwtGraphics::fullscreenChanged()();
|
||||||
|
}, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
private native void exitFullscreen() /*-{
|
||||||
|
if ($doc.webkitExitFullscreen)
|
||||||
|
$doc.webkitExitFullscreen();
|
||||||
|
if ($doc.mozExitFullscreen)
|
||||||
|
$doc.mozExitFullscreen();
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DisplayMode getDesktopDisplayMode() {
|
||||||
|
return new DisplayMode(getScreenWidthJSNI(), getScreenHeightJSNI(), 60, 8) {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setDisplayMode(DisplayMode displayMode) {
|
||||||
|
if (displayMode.width != getScreenWidthJSNI()
|
||||||
|
&& displayMode.height != getScreenHeightJSNI())
|
||||||
|
return false;
|
||||||
|
return setFullscreenJSNI(this, canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setDisplayMode(int width, int height, boolean fullscreen) {
|
||||||
|
if (fullscreen) {
|
||||||
|
if (width != getScreenWidthJSNI() && height != getScreenHeightJSNI())
|
||||||
|
return false;
|
||||||
|
return setFullscreenJSNI(this, canvas);
|
||||||
|
} else {
|
||||||
|
if (isFullscreenJSNI())
|
||||||
|
exitFullscreen();
|
||||||
|
canvas.setWidth(width);
|
||||||
|
canvas.setHeight(height);
|
||||||
|
canvas.getStyle().setWidth(width, Unit.PX);
|
||||||
|
canvas.getStyle().setHeight(height, Unit.PX);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BufferFormat getBufferFormat() {
|
||||||
|
return new BufferFormat(8, 8, 8, 0, 16, config.stencil ? 8 : 0, 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsExtension(String extension) {
|
||||||
|
if (extensions == null)
|
||||||
|
extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
|
||||||
|
return extensions.contains(extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
long currTimeStamp = System.currentTimeMillis();
|
||||||
|
deltaTime = (currTimeStamp - lastTimeStamp) / 1000.0f;
|
||||||
|
lastTimeStamp = currTimeStamp;
|
||||||
|
time += deltaTime;
|
||||||
|
frames++;
|
||||||
|
if (time > 1) {
|
||||||
|
this.fps = frames;
|
||||||
|
time = 0;
|
||||||
|
frames = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTitle(String title) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVSync(boolean vsync) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getDensity() {
|
||||||
|
return 96.0f / 160;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContinuousRendering(boolean isContinuous) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isContinuousRendering() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestRendering() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getRawDeltaTime() {
|
||||||
|
return getDeltaTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFullscreen() {
|
||||||
|
return isFullscreenJSNI();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,22 +1,36 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>vtm-gdx</title>
|
<title>vtm-gdx</title>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
<style>
|
|
||||||
canvas {
|
<!-- pixel and dpi are way too simple concepts for web devs, lets also have css-pixels! -->
|
||||||
|
<!-- http://www.html5rocks.com/de/mobile/touch/ -->
|
||||||
|
<!-- http://www.quirksmode.org/mobile/viewports.html -->
|
||||||
|
<!-- http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html -->
|
||||||
|
<!-- devicePixelRatio: http://coding.smashingmagazine.com/2012/08/20/towards-retina-web/ -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
canvas {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
position: fixed;
|
||||||
</style>
|
left: 0;
|
||||||
</head>
|
top: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<script type="text/javascript" src="js/_tessellate.js"></script>
|
||||||
|
<script type="text/javascript" src="js/tessellate.js"></script>
|
||||||
<div align="center" id="embed-org.oscim.gdx.GwtDefinition"></div>
|
<div align="center" id="embed-org.oscim.gdx.GwtDefinition"></div>
|
||||||
<script type="text/javascript" src="org.oscim.gdx.GwtDefinition/org.oscim.gdx.GwtDefinition.nocache.js"></script>
|
<script type="text/javascript"
|
||||||
</body>
|
src="org.oscim.gdx.GwtDefinition/org.oscim.gdx.GwtDefinition.nocache.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function handleMouseDown(evt) {
|
function handleMouseDown(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
@ -29,7 +43,9 @@
|
|||||||
evt.target.style.cursor = '';
|
evt.target.style.cursor = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('embed-org.oscim.gdx.GwtDefinition').addEventListener('mousedown', handleMouseDown, false);
|
document.getElementById('embed-org.oscim.gdx.GwtDefinition')
|
||||||
document.getElementById('embed-org.oscim.gdx.GwtDefinition').addEventListener('mouseup', handleMouseUp, false);
|
.addEventListener('mousedown', handleMouseDown, false);
|
||||||
</script>
|
document.getElementById('embed-org.oscim.gdx.GwtDefinition')
|
||||||
|
.addEventListener('mouseup', handleMouseUp, false);
|
||||||
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user