Android Open Source - TinyVoxel Html Launcher






From Project

Back to project page TinyVoxel.

License

The source code is released under:

GNU General Public License

If you think the Android project TinyVoxel listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.toet.TinyVoxel.client;
//  w  ww  . j ava 2 s  .  c  om
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.*;
import com.toet.TinyVoxel.Config;
import com.toet.TinyVoxel.Game;

public class HtmlLauncher extends GwtApplication {
    static final int WIDTH = 800;
    static final int HEIGHT = 400;
    static HtmlLauncher instance;

    @Override
    public GwtApplicationConfiguration getConfig () {
        GwtApplicationConfiguration config = new GwtApplicationConfiguration(WIDTH, HEIGHT);
        config.useVsync = true;
        config.fps = 30;

        Element element = Document.get().getElementById("embed-html");
        element.getParentElement().getStyle().setOverflow(Style.Overflow.HIDDEN);
        element.getParentElement().getStyle().setBackgroundColor("#336699");

        HorizontalPanel topPanel = new HorizontalPanel();
        topPanel.setWidth("100%");
        topPanel.setHeight("100%");
        topPanel.getElement().getStyle().setPadding(0, Style.Unit.PX);
        topPanel.getElement().getStyle().setMargin(0, Style.Unit.PX);
        topPanel.getElement().getStyle().setOverflow(Style.Overflow.HIDDEN);

        HorizontalPanel panel = new HorizontalPanel();
        panel.setWidth("100%");
        panel.setHeight("100%");
        panel.getElement().getStyle().setPadding(0, Style.Unit.PX);
        panel.getElement().getStyle().setMargin(0, Style.Unit.PX);
        panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

        topPanel.add(panel);

        element.appendChild(topPanel.getElement());

        config.rootPanel = panel;

        if (!Config.IS_DEBUG) {
            config.log = new TextArea();
            config.log.setVisible(false);
        }
        return config;
    }

    @Override
    public ApplicationListener getApplicationListener() {
        instance = this;
        setLogLevel(LOG_NONE);
       if (!Config.IS_DEBUG) {
            setLoadingListener(new LoadingListener() {
                @Override
                public void beforeSetup() {

                }

                @Override
                public void afterSetup() {
                    scaleCanvas();
                    setupResizeHook();
                }
            });
       }
        Config.set(new GwtConfig());
        return new Game();
    }

    void scaleCanvas() {
        Element element = Document.get().getElementById("embed-html");
        element.getStyle().setTop(0, Style.Unit.PX);
        element.getStyle().setLeft(0, Style.Unit.PX);
        element.getStyle().setPosition(Style.Position.ABSOLUTE);
        element.setAttribute("width", "" + getWindowInnerWidth() + "px");
        element.setAttribute("height", "" + getWindowInnerHeight() + "px");
        element.getStyle().setPadding(0, Style.Unit.PX);
        element.getStyle().setMargin(0, Style.Unit.PX);
        element.getStyle().setOverflow(Style.Overflow.HIDDEN);
        element.getParentElement().getStyle().setOverflow(Style.Overflow.HIDDEN);
        element.getParentElement().getStyle().setBackgroundColor("#336699");

        int innerWidth = getWindowInnerWidth();
        int innerHeight = getWindowInnerHeight();

        NodeList<Element> nl = element.getElementsByTagName("canvas");

        if (nl != null && nl.getLength() > 0) {
            Element canvas = nl.getItem(0);
            canvas.setAttribute("width", "" + innerWidth + "px");
            canvas.setAttribute("height", "" + innerHeight + "px");
            canvas.getStyle().setPadding(0, Style.Unit.PX);
            canvas.getStyle().setMargin(0, Style.Unit.PX);
            canvas.getStyle().setWidth(innerWidth, Style.Unit.PX);
            canvas.getStyle().setHeight(innerHeight, Style.Unit.PX);
        }
    }

    native int getWindowInnerWidth() /*-{
        return $wnd.innerWidth;
    }-*/;

    native int getWindowInnerHeight() /*-{
        return $wnd.innerHeight;
    }-*/;

    native void setupResizeHook() /*-{
        var htmlLauncher_onWindowResize = $entry(@com.toet.TinyVoxel.client.HtmlLauncher::handleResize());
        $wnd.addEventListener('resize', htmlLauncher_onWindowResize, false);
    }-*/;

    public static void handleResize() {
        instance.scaleCanvas();
    }
}




Java Source Code List

com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration.java
com.badlogic.gdx.backends.gwt.GwtApplication.java
com.badlogic.gdx.backends.gwt.GwtGL20.java
com.badlogic.gdx.backends.gwt.GwtInput.java
com.badlogic.gdx.backends.gwt.GwtNet.java
com.badlogic.gdx.graphics.Pixmap.java
com.toet.TinyVoxel.Config.java
com.toet.TinyVoxel.Game.java
com.toet.TinyVoxel.IOSConfig.java
com.toet.TinyVoxel.IOSLauncher.java
com.toet.TinyVoxel.OuyaController.java
com.toet.TinyVoxel.Time.java
com.toet.TinyVoxel.Character.Character.java
com.toet.TinyVoxel.Debug.LogHandler.java
com.toet.TinyVoxel.GameControllers.CharacterController.java
com.toet.TinyVoxel.GameControllers.CustomTouchPad.java
com.toet.TinyVoxel.GameControllers.KeyBoardController.java
com.toet.TinyVoxel.GameControllers.TouchPadController.java
com.toet.TinyVoxel.Importer.BinvoxImporter.java
com.toet.TinyVoxel.Importer.DataInputStream.java
com.toet.TinyVoxel.Importer.MeshImporter.java
com.toet.TinyVoxel.Renderer.BlockBuilder.java
com.toet.TinyVoxel.Renderer.Floor.java
com.toet.TinyVoxel.Renderer.Manager.java
com.toet.TinyVoxel.Renderer.Bundles.ArrayBundle.java
com.toet.TinyVoxel.Renderer.Bundles.Bundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridBundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridInterface.java
com.toet.TinyVoxel.Renderer.Bundles.Grid.java
com.toet.TinyVoxel.Renderer.Bundles.GroundBundle.java
com.toet.TinyVoxel.Renderer.Bundles.SingleBundle.java
com.toet.TinyVoxel.Renderer.Bundles.TinyGrid.java
com.toet.TinyVoxel.Renderer.Tools.BrushUtils.java
com.toet.TinyVoxel.Renderer.Tools.GridUtils.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedBoolean.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedInteger.java
com.toet.TinyVoxel.Screens.GUI.java
com.toet.TinyVoxel.Screens.Menu.java
com.toet.TinyVoxel.Shaders.ShaderManager.java
com.toet.TinyVoxel.Shadow.ShadowManager.java
com.toet.TinyVoxel.Util.Box.java
com.toet.TinyVoxel.Util.FullscreenQuad.java
com.toet.TinyVoxel.Util.JobManager.java
com.toet.TinyVoxel.Util.NonBackedTexture.java
com.toet.TinyVoxel.Util.Position.java
com.toet.TinyVoxel.Util.RLEInputStream.java
com.toet.TinyVoxel.Util.RLEOutputStream.java
com.toet.TinyVoxel.Util.SimpleMath.java
com.toet.TinyVoxel.Util.StreamUtil.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.client.GwtConfig.java
com.toet.TinyVoxel.client.HtmlLauncher.java
com.toet.TinyVoxel.desktop.DesktopConfig.java
com.toet.TinyVoxel.desktop.DesktopLauncher.java