Initial upload
This commit is contained in:
11
html/src/io/anuke/moment/GdxDefinition.gwt.xml
Normal file
11
html/src/io/anuke/moment/GdxDefinition.gwt.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
|
||||
<module rename-to="html">
|
||||
<inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />
|
||||
|
||||
<inherits name='Moment' />
|
||||
<inherits name='uCore' />
|
||||
<entry-point class='io.anuke.moment.client.HtmlLauncher' />
|
||||
<set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>
|
||||
<set-configuration-property name="gdx.assetpath" value="../core/assets" />
|
||||
</module>
|
||||
13
html/src/io/anuke/moment/GdxDefinitionSuperdev.gwt.xml
Normal file
13
html/src/io/anuke/moment/GdxDefinitionSuperdev.gwt.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
|
||||
<module rename-to="html">
|
||||
<inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />
|
||||
|
||||
<inherits name='io.anuke.moment.GdxDefinition' />
|
||||
|
||||
<collapse-all-properties />
|
||||
|
||||
<add-linker name="xsiframe"/>
|
||||
<set-configuration-property name="devModeRedirectEnabled" value="true"/>
|
||||
<set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>
|
||||
</module>
|
||||
100
html/src/io/anuke/moment/client/HtmlLauncher.java
Normal file
100
html/src/io/anuke/moment/client/HtmlLauncher.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package io.anuke.moment.client;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.google.gwt.dom.client.*;
|
||||
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
||||
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
||||
import io.anuke.moment.Moment;
|
||||
|
||||
public class HtmlLauncher extends GwtApplication {
|
||||
static final int WIDTH = 800;
|
||||
static final int HEIGHT = 600;
|
||||
static HtmlLauncher instance;
|
||||
|
||||
@Override
|
||||
public GwtApplicationConfiguration getConfig() {
|
||||
GwtApplicationConfiguration config = new GwtApplicationConfiguration(WIDTH, HEIGHT);
|
||||
|
||||
Element element = Document.get().getElementById("embed-html");
|
||||
VerticalPanel panel = new VerticalPanel();
|
||||
panel.setWidth("100%");
|
||||
panel.setHeight("100%");
|
||||
panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
|
||||
panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
|
||||
element.appendChild(panel.getElement());
|
||||
config.rootPanel = panel;
|
||||
config.width = 2000;
|
||||
config.height = 2000;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationListener createApplicationListener() {
|
||||
instance = this;
|
||||
setLogLevel(LOG_NONE);
|
||||
setLoadingListener(new LoadingListener() {
|
||||
@Override
|
||||
public void beforeSetup() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSetup() {
|
||||
scaleCanvas();
|
||||
setupResizeHook();
|
||||
}
|
||||
});
|
||||
return new Moment();
|
||||
}
|
||||
|
||||
void scaleCanvas() {
|
||||
Element element = Document.get().getElementById("embed-html");
|
||||
int innerWidth = getWindowInnerWidth();
|
||||
int innerHeight = getWindowInnerHeight();
|
||||
int newWidth = innerWidth;
|
||||
int newHeight = innerHeight;
|
||||
float ratio = innerWidth / (float) innerHeight;
|
||||
float viewRatio = WIDTH / (float) HEIGHT;
|
||||
|
||||
if (ratio > viewRatio) {
|
||||
newWidth = (int) (innerHeight * viewRatio);
|
||||
} else {
|
||||
newHeight = (int) (innerWidth / viewRatio);
|
||||
}
|
||||
|
||||
NodeList<Element> nl = element.getElementsByTagName("canvas");
|
||||
|
||||
if (nl != null && nl.getLength() > 0) {
|
||||
Element canvas = nl.getItem(0);
|
||||
canvas.setAttribute("width", "" + newWidth + "px");
|
||||
canvas.setAttribute("height", "" + newHeight + "px");
|
||||
canvas.getStyle().setWidth(newWidth, Style.Unit.PX);
|
||||
canvas.getStyle().setHeight(newHeight, Style.Unit.PX);
|
||||
canvas.getStyle().setTop((int) ((innerHeight - newHeight) * 0.5f), Style.Unit.PX);
|
||||
canvas.getStyle().setLeft((int) ((innerWidth - newWidth) * 0.5f), Style.Unit.PX);
|
||||
canvas.getStyle().setPosition(Style.Position.ABSOLUTE);
|
||||
}
|
||||
}
|
||||
|
||||
native int getWindowInnerWidth() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
native int getWindowInnerHeight() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
native void setupResizeHook() /*-{
|
||||
var htmlLauncher_onWindowResize = $entry(@io.anuke.moment.client.HtmlLauncher::handleResize());
|
||||
$wnd.addEventListener('resize', htmlLauncher_onWindowResize, false);
|
||||
}-*/;
|
||||
|
||||
public static void handleResize() {
|
||||
instance.scaleCanvas();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user