define("gameLayout", ["componentmodelComponentApi", "clientkernelLoaderApi", "displayEngineApi", "gameLayoutApi", "PIXI", "BABYLON", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(componentmodelComponentApi, clientkernelLoaderApi, displayEngineApi, gameLayoutApi, PIXI, BABYLON, clientkernelEventbusApi, clientkernelModulesApi) {
        "use strict";

        function $iterator(o) {
            if (o instanceof Array) return function() {
                return {
                    cur: 0,
                    arr: o,
                    hasNext: function() {
                        return this.cur < this.arr.length;
                    },
                    next: function() {
                        return this.arr[this.cur++];
                    }
                };
            };
            return typeof(o.iterator) == 'function' ? $bind(o, o.iterator) : o.iterator;
        };;
        var $fid = 0;

        function $bind(o, m) {
            if (m == null) return null;
            if (m.__id__ == null) m.__id__ = $fid++;
            var f;
            if (o.hx__closures__ == null) o.hx__closures__ = {};
            else f = o.hx__closures__[m.__id__];
            if (f == null) {
                f = function() {
                    return f.method.apply(f.scope, arguments);
                };
                f.scope = o;
                f.method = m;
                o.hx__closures__[m.__id__] = f;
            }
            return f;
        };
        var $_;
        var $estr = function() {
            return _hcmn_.js_Boot.__string_rec(this, '');
        };
        if (typeof gameLayout == 'undefined') {
            var gameLayout = {};
        };
        gameLayout.Activator = function(context) {};
        gameLayout.Activator = ck_implements(gameLayout.Activator, clientkernelModulesApi.IModuleActivator);
        gameLayout.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        gameLayout.Activator.__name__ = ["gameLayout", "Activator"];
        gameLayout.Activator.prototype.start = function(context) {
            context.getServiceTracker([clientkernelLoaderApi.IAssetRegistry, displayEngineApi.IDisplayProvider]).then(function(context1) {
                context1.registerService(new gameLayout.GameLayoutFactory(context1), gameLayoutApi.GameLayoutDeclaration, null);
            });
        };
        gameLayout.Activator.prototype.stop = function(context) {};
        gameLayout.Activator.main = function() {};
        gameLayout.Activator.prototype.__class__ = gameLayout.Activator;
        gameLayout.CacheControl = function(scenarios_cfg, displayProvider, gameLayoutPort) {
            this.cachedIds = [];
            this.displayProvider = displayProvider;
            this.stage = displayProvider.getDefaultStage();
            this.dpFactory = displayProvider.getFactory();
            this.gameLayoutPort = gameLayoutPort;
            this.scenarios = new _hcmn_.haxe_ds_StringMap();
            this.cachedIds = [];
            var _g = 0;
            var _g1 = _hcmn_.Reflect.fields(scenarios_cfg);
            while (_g < _g1.length) {
                var field = _g1[_g];
                ++_g;
                var value = _hcmn_.Reflect.field(scenarios_cfg, field);
                this.scenarios.set(field, value);
            }
            gameLayoutPort.getCacheLayers().subscribe($bind(this, this.cacheLayers));
            gameLayoutPort.getUncacheLayers().subscribe($bind(this, this.uncacheLayers));
        };
        gameLayout.CacheControl.__name__ = ["gameLayout", "CacheControl"];
        gameLayout.CacheControl.prototype.stage = null;
        gameLayout.CacheControl.prototype.dpFactory = null;
        gameLayout.CacheControl.prototype.cachedIds = null;
        gameLayout.CacheControl.prototype.scenarios = null;
        gameLayout.CacheControl.prototype.gameLayoutPort = null;
        gameLayout.CacheControl.prototype.displayProvider = null;
        gameLayout.CacheControl.prototype.cacheGroups = null;
        gameLayout.CacheControl.prototype.cacheLayers = function(e) {
            this.stage = this.displayProvider.getDefaultStage();
            var scenarioId = e.getPayload();
            this.cacheGroups = [];
            if (scenarioId == null) this.cacheGroups[0] = this.stage.getChildren();
            else {
                var scenarioSet = this.scenarios.get(scenarioId);
                if (scenarioSet == null) return;
                var groupIndex = 0;
                var _g1 = 0;
                var _g = this.stage.getNumChildren();
                while (_g1 < _g) {
                    var i = _g1++;
                    var child = this.stage.getChildAt(i);
                    if ((function($this) {
                            var $r;
                            var x = child.getName();
                            $r = _hcmn_.HxOverrides.indexOf(scenarioSet, x, 0);
                            return $r;
                        }(this)) >= 0) {
                        if (this.cacheGroups[groupIndex] == null) this.cacheGroups[groupIndex] = [];
                        this.cacheGroups[groupIndex].push(child);
                    } else if (this.cacheGroups[groupIndex] != null) groupIndex++;
                }
            }
            var _g2 = 0;
            var _g11 = this.cacheGroups;
            while (_g2 < _g11.length) {
                var group = _g11[_g2];
                ++_g2;
                this.cachedIds.push(this.dpFactory.cache(group));
            }
        };
        gameLayout.CacheControl.prototype.uncacheLayers = function(e) {
            var _g = 0;
            var _g1 = this.cachedIds;
            while (_g < _g1.length) {
                var id = _g1[_g];
                ++_g;
                this.dpFactory.uncache(id);
            }
            this.cachedIds = [];
        };
        gameLayout.CacheControl.prototype.restoreLastCache = function() {
            if (this.cacheGroups == null) return;
            var _g = 0;
            var _g1 = this.cacheGroups;
            while (_g < _g1.length) {
                var group = _g1[_g];
                ++_g;
                this.cachedIds.push(this.dpFactory.cache(group));
            }
        };
        gameLayout.CacheControl.prototype.__class__ = gameLayout.CacheControl;
        gameLayout.GameLayout = function(mcontext, context) {
            this.firstLayoutCompleted = false;
            this.matchToNearestSmaller = false;
            this.modelType = gameLayout.GameLayoutModelsEnum.explicit;
            this.updatingComponents = null;
            this.screenHeight = 0;
            this.screenWidth = 0;
            var _g = this;
            this.oldverify = define.verify;
            var myverify = $bind(this, this.verify);
            define.verify = myverify;
            this.context = context;
            this.mcontext = mcontext;
            this.components = new _hcmn_.haxe_ds_StringMap();
            this.port = context.getImplementedPort(gameLayoutApi.IGameLayoutImplementationPort);
            this.updatingComponents = null;
            this.assetRegistry = mcontext.getAnyService(clientkernelLoaderApi.IAssetRegistry);
            gameLayout.GameLayout.displayProvider = mcontext.getAnyService(displayEngineApi.IDisplayProvider);
            this.variablesRegistry = mcontext.getAnyService(clientkernelLoaderApi.IVariableRegistry);
            this.modelPerAspect = new _hcmn_.haxe_ds_StringMap();
            this.stages = new gameLayout.Stages(gameLayout.GameLayout.displayProvider, this.variablesRegistry);
            this.port.getComponentLayoutUpdated().subscribe($bind(this, this.componentUpdated));
            this.assetRegistry.getAsset("gamelayout-config").getContent().then(function(config) {
                _g.config = config;
                _g.setUpCSSBackground(config.backgroundCSS);
                _g.setUpCanvasProperties(config.canvasProperties);
                var map = context.getReferredComponents("layout");
                var wait = context.getReferredComponents("wait");
                var componentPromises = [];
                var componentNames = [];
                var $it0 = map.keys();
                while ($it0.hasNext()) {
                    var m = $it0.next();
                    componentNames.push(m);
                    componentPromises.push(_hcmn_.__map_reserved[m] != null ? map.getReserved(m) : map.h[m]);
                }
                var $it1 = wait.keys();
                while ($it1.hasNext()) {
                    var w = $it1.next();
                    componentPromises.push(_hcmn_.__map_reserved[w] != null ? wait.getReserved(w) : wait.h[w]);
                }
                Promise.all(componentPromises).then(function(data) {
                    var _g2 = 0;
                    var _g1 = componentNames.length;
                    while (_g2 < _g1) {
                        var i = _g2++;
                        var value = data[i];
                        _g.components.set(componentNames[i], value);
                    }
                    _g.initialize(config.layout);
                    _g.cacheControl = new gameLayout.CacheControl(config.cachescenarios, gameLayout.GameLayout.displayProvider, _g.port);
                    _g.layerControl = new gameLayout.LayerControl(config.layerscenarios, gameLayout.GameLayout.displayProvider, _g.port);
                });
            });
            var bus = mcontext.getAnyService(clientkernelEventbusApi.IEventBus, null);
            var clientService = bus.getChannel("ClientService");
            clientService.subscribe("Game.Init", $bind(this, this.onGameInit));
            this.onStartGameInitialSubscription = clientService.subscribe("StateChange", $bind(this, this.onStateChange));
        };
        gameLayout.GameLayout.__name__ = ["gameLayout", "GameLayout"];
        gameLayout.GameLayout.prototype.mcontext = null;
        gameLayout.GameLayout.prototype.context = null;
        gameLayout.GameLayout.prototype.assetRegistry = null;
        gameLayout.GameLayout.prototype.variablesRegistry = null;
        gameLayout.GameLayout.prototype.modelPerAspect = null;
        gameLayout.GameLayout.prototype.stages = null;
        gameLayout.GameLayout.prototype.screenWidth = null;
        gameLayout.GameLayout.prototype.screenHeight = null;
        gameLayout.GameLayout.prototype.components = null;
        gameLayout.GameLayout.prototype.port = null;
        gameLayout.GameLayout.prototype.updatingComponents = null;
        gameLayout.GameLayout.prototype.relayout = null;
        gameLayout.GameLayout.prototype.oldverify = null;
        gameLayout.GameLayout.prototype.cacheControl = null;
        gameLayout.GameLayout.prototype.layerControl = null;
        gameLayout.GameLayout.prototype.config = null;
        gameLayout.GameLayout.prototype.modelType = null;
        gameLayout.GameLayout.prototype.matchToNearestSmaller = null;
        gameLayout.GameLayout.prototype.firstLayoutCompleted = null;
        gameLayout.GameLayout.prototype.onStartGameInitialSubscription = null;
        gameLayout.GameLayout.prototype.devTools = null;
        gameLayout.GameLayout.prototype.setUpCanvasProperties = function(canvasProps) {
            if (canvasProps == null) return;
            var canvasFit = _hcmn_.Reflect.field(canvasProps, "fit");
            if (canvasProps.fit != null) {
                var fitW = canvasFit.indexOf("width") > -1;
                var fitH = canvasFit.indexOf("height") > -1;
                this.stages.setScreenFit(fitW, fitH);
                this.matchToNearestSmaller = !fitW;
            }
            if (canvasProps.webGL != null) this.stages.setWebGL(canvasProps.webGL);
            if (canvasProps.capWidth != null) {
                var capWidth = _hcmn_.Reflect.field(canvasProps, "capWidth");
                gameLayout.Stages.GC_WIDTH = capWidth;
                gameLayout.Stages.capCanvasSize = true;
            }
        };
        gameLayout.GameLayout.prototype.setUpCSSBackground = function(cssProps) {
            var _g = this;
            this.assetRegistry.getAsset("background").getContent().then(function(bg) {
                window.document.body.style.backgroundImage = "url(" + _g.assetRegistry.getAsset("background").getUrl() + ")";
                if (cssProps != null) {
                    var cssPropsFields = _hcmn_.Reflect.fields(cssProps);
                    var _g1 = 0;
                    while (_g1 < cssPropsFields.length) {
                        var p = cssPropsFields[_g1];
                        ++_g1;
                        window.document.body.style.setProperty(p, _hcmn_.Reflect.field(cssProps, p));
                    }
                }
            });
        };
        gameLayout.GameLayout.prototype.verify = function() {
            var ret = this.oldverify();
            if (ret != null) return ret;
            if (this.updatingComponents == null) return null;
            var $it0 = this.updatingComponents.keys();
            while ($it0.hasNext()) {
                var i = $it0.next();
                var $it1 = this.components.keys();
                while ($it1.hasNext()) {
                    var j = $it1.next();
                    if (this.components.get(j).getId() == i) return "verify error: awaiting gamelayout for " + j;
                }
            }
            return null;
        };
        gameLayout.GameLayout.prototype.initialize = function(config) {
            var _g1 = 0;
            var _g = config.length;
            while (_g1 < _g) {
                var i = _g1++;
                var aspects = config[i].aspects;
                var gameLayoutModel = gameLayout.GameLayoutModelFactory.getModel(config[i].model.type);
                gameLayoutModel.configure(config[i]);
                if (gameLayoutModel.getType() == gameLayout.GameLayoutModelsEnum.relative) this.modelType = gameLayout.GameLayoutModelsEnum.relative;
                var _g2 = 0;
                while (_g2 < aspects.length) {
                    var a = aspects[_g2];
                    ++_g2;
                    this.modelPerAspect.set(a == null ? "null" : "" + a, gameLayoutModel);
                }
            }
            _hcmn_.haxe_Timer.delay($bind(this, this.layout), 0);
            window.addEventListener("resize", $bind(this, this.handleLayoutUpdate));
            window.addEventListener("orientationchange", $bind(this, this.handleLayoutUpdate));
        };
        gameLayout.GameLayout.prototype.onStateChange = function(e) {
            if (e.getPayload().state == "onStartGameInitial" || e.getPayload().state == "onStartGameInProgressStage") {
                this.onStartGameInitialSubscription.unsubscribe();
                var _w = this.stages.get("skgl_0").canvas.width;
                this.stages.get("skgl_0").canvas.width = _w + 1;
                _hcmn_.haxe_Timer.delay($bind(this, this.layout), 0);
            }
        };
        gameLayout.GameLayout.prototype.onGameInit = function(e) {
            this.stages.showStageElements();
        };
        gameLayout.GameLayout.prototype.handleLayoutUpdate = function(e) {
            var screenSizeChanged = this.screenWidth != window.innerWidth || this.screenHeight != window.innerHeight;
            if (screenSizeChanged) {
                this.port.getGameLayoutUpdateStarted().publish(null);
                this.layout();
            }
        };
        gameLayout.GameLayout.prototype.layout = function() {
            this.cacheControl.uncacheLayers(null);
            window.scrollTo(0, 0);
            this.screenWidth = window.innerWidth;
            this.screenHeight = window.innerHeight;
            var devicePixelRatio = window.devicePixelRatio;
            if (devicePixelRatio == null) devicePixelRatio = 1.0;
            var r = 1;
            var screenAspect = this.screenWidth / this.screenHeight;
            var aspectIndex = this.matchAspect(screenAspect);
            var aspect = parseFloat(aspectIndex);
            var model = this.modelPerAspect.get(aspectIndex);
            var cl = model.getComponentLayout(aspect);
            this.stages.adjust(cl, aspect, _hcmn_.Math.floor(this.screenWidth * devicePixelRatio), _hcmn_.Math.floor(this.screenHeight * devicePixelRatio), devicePixelRatio);
            this.updateComponents(cl);
        };
        gameLayout.GameLayout.prototype.updateComponents = function(cl) {
            window.PIXI._redrawRegionComponents = {};
            var $it0 = cl.keys();
            while ($it0.hasNext()) {
                var key = $it0.next();
                var containers;
                containers = (_hcmn_.__map_reserved[key] != null ? cl.getReserved(key) : cl.h[key]).containers;
                var $it1 = containers.keys();
                while ($it1.hasNext()) {
                    var k = $it1.next();
                    window.PIXI._redrawRegionComponents[k] = _hcmn_.__map_reserved[k] != null ? containers.getReserved(k) : containers.h[k];
                }
            }
            if (this.updatingComponents != null) {
                this.relayout = true;
                return;
            }
            this.updatingComponents = new _hcmn_.haxe_ds_StringMap();
            var $it2 = this.components.iterator();
            while ($it2.hasNext()) {
                var comp = $it2.next();
                var key1 = comp.getId();
                this.updatingComponents.set(key1, false);
            }
            this.relayout = false;
            var updatePayload = new haxe.ds.ObjectMap();
            $bind(updatePayload, updatePayload.exists);
            $bind(updatePayload, updatePayload.get);
            var $it3 = cl.keys();
            while ($it3.hasNext()) {
                var i = $it3.next();
                var cmp_u;
                cmp_u = _hcmn_.__map_reserved[i] != null ? cl.getReserved(i) : cl.h[i];
                var cmp = new gameLayoutApi.ComponentLayout(new _hcmn_.haxe_ds_StringMap());
                var $it4 = cmp_u.containers.keys();
                while ($it4.hasNext()) {
                    var i1 = $it4.next();
                    var cont = cmp_u.containers.get(i1);
                    var offsetcont = new gameLayoutApi.ContainerLayout(cont.id, cont.stage, cont.stageZIndex, this.stages.get(cont.stage).offsetLeft(cont.left), this.stages.get(cont.stage).offsetTop(cont.top), cont.width, cont.height, cont.zIndex, cont.configuration);
                    cmp.containers.set(i1, offsetcont);
                }
                if (this.components.exists(i)) updatePayload.set(this.components.get(i), cmp);
            }
            this.port.getUpdateComponentLayout().publish(updatePayload);
        };
        gameLayout.GameLayout.prototype.componentUpdated = function(event) {
            var key = event.getPayload().getId();
            this.updatingComponents.remove(key);
            if (!this.updatingComponents.iterator().hasNext()) {
                this.updatingComponents = null;
                if (this.modelType == gameLayout.GameLayoutModelsEnum.relative && !this.firstLayoutCompleted) {
                    this.firstLayoutCompleted = true;
                    var config = this.config.layout;
                    var $it0 = this.modelPerAspect.iterator();
                    while ($it0.hasNext()) {
                        var gameLayoutModel = $it0.next();
                        var _g1 = 0;
                        var _g = config.length;
                        while (_g1 < _g) {
                            var i = _g1++;
                            gameLayoutModel.configure(config[i]);
                        }
                    }
                    this.layout();
                } else {
                    this.port.getGameLayoutUpdated().publish(null);
                    this.cacheControl.restoreLastCache();
                }
                if (this.relayout) this.handleLayoutUpdate(null);
            }
        };
        gameLayout.GameLayout.prototype.matchAspect = function(aspect) {
            var minAspectDiff = 0;
            var minPositiveAspectDiff = 0;
            var ret = null;
            var retPositive = null;
            var $it0 = this.modelPerAspect.keys();
            while ($it0.hasNext()) {
                var i = $it0.next();
                var a = parseFloat(i);
                if (ret == null) {
                    minAspectDiff = _hcmn_.Math.abs(aspect - a);
                    ret = i;
                } else if (_hcmn_.Math.abs(aspect - a) < minAspectDiff) {
                    minAspectDiff = _hcmn_.Math.abs(aspect - a);
                    ret = i;
                }
                if (retPositive == null) {
                    if (a < aspect) {
                        minPositiveAspectDiff = aspect - a;
                        retPositive = i;
                    }
                } else if (a < aspect && aspect - a < minPositiveAspectDiff) {
                    minPositiveAspectDiff = aspect - a;
                    retPositive = i;
                }
            }
            if (this.matchToNearestSmaller && minPositiveAspectDiff != 0) return retPositive;
            else return ret;
        };
        gameLayout.GameLayout.displayProvider = null;
        gameLayout.GameLayout.prototype.__class__ = gameLayout.GameLayout;
        gameLayout.GameLayoutDevTools = function(bus, stages) {
            this.fpsArray = [];
            this.bus = bus;
            this.stages = stages;
            bus.getChannel("GFBus").subscribe("testable:testcomponent:getfps", $bind(this, this.handleFps));
            bus.getChannel("GFBus").subscribe("testable:testcomponent:measureFps", $bind(this, this.measureFps));
            bus.getChannel("GFBus").subscribe("testable:testcomponent:getfpsarray", $bind(this, this.handleFpsArray));
            var setTextVar;
            setTextVar = this.getUrlParam("settext");
            if (setTextVar == "enabled") {
                bus.getChannel("GFBus").subscribe("testable:testcomponent:settext", $bind(this, this.handleSetText));
                var textDOM;
                var _this = window.document;
                textDOM = _this.createElement("div");
                textDOM.setAttribute("id", "testTextDOM");
                textDOM.setAttribute("style", "position: absolute; top: 23px; left: 130px; font-family: Consolas; color: #fff; text-shadow: rgb(0, 0, 0) 1px 0px 0px, rgb(0, 0, 0) 0.540302px 0.841471px 0px, rgb(0, 0, 0) -0.416147px 0.909297px 0px, rgb(0, 0, 0) -0.989992px 0.14112px 0px, rgb(0, 0, 0) -0.653644px -0.756802px 0px, rgb(0, 0, 0) 0.283662px -0.958924px 0px, rgb(0, 0, 0) 0.96017px -0.279415px 0px; font-size: 15px; font-weight: bold;");
                window.document.body.appendChild(textDOM);
            }
            window.document.body.addEventListener("touchmove", function(e) {
                e.preventDefault();
            });
        };
        gameLayout.GameLayoutDevTools.__name__ = ["gameLayout", "GameLayoutDevTools"];
        gameLayout.GameLayoutDevTools.prototype.fpsArray = null;
        gameLayout.GameLayoutDevTools.prototype.timer = null;
        gameLayout.GameLayoutDevTools.prototype.bus = null;
        gameLayout.GameLayoutDevTools.prototype.stages = null;
        gameLayout.GameLayoutDevTools.prototype.measureFps = function(e) {
            var _g = this;
            var stage = this.stages.get("skgl_0");
            this.timer = new _hcmn_.haxe_Timer(100);
            this.timer.run = function() {
                var currentFps = stage.destage.getFpsInfo().fps;
                _g.fpsArray.push(currentFps);
            };
        };
        gameLayout.GameLayoutDevTools.prototype.handleFpsArray = function(e) {
            this.bus.getChannel("TBus").publish("testable:testcomponent:fpsarray", this.fpsArray);
            this.fpsArray = [];
            if (this.timer != null) this.timer.stop();
        };
        gameLayout.GameLayoutDevTools.prototype.handleFps = function(e) {
            var stage = this.stages.get("skgl_0");
            var currentFps = stage.destage.getFpsInfo().fps;
            this.bus.getChannel("TBus").publish("testable:testcomponent:fps", currentFps);
        };
        gameLayout.GameLayoutDevTools.prototype.handleSetText = function(e) {
            var textToShow = e.getPayload();
            var textDOM = window.document.getElementById("testTextDOM");
            if (textDOM != null) {
                textDOM.innerHTML = textToShow;
                this.bus.getChannel("TBus").publish("testable:testcomponent:settextconfirm", textToShow);
            }
        };
        gameLayout.GameLayoutDevTools.prototype.getUrlParam = function(param) {
            var urlParams;
            if (window.location != window.parent.location) urlParams = window.document.referrer.split("?")[1];
            else urlParams = window.document.location.search.split("?")[1];
            if (urlParams == null) return null;
            var vars = urlParams.split("&");
            var _g1 = 0;
            var _g = vars.length;
            while (_g1 < _g) {
                var i = _g1++;
                var pair = vars[i].split("=");
                if (pair[0] == param) return pair[1];
            }
            return null;
        };
        gameLayout.GameLayoutDevTools.prototype.__class__ = gameLayout.GameLayoutDevTools;
        gameLayout.GameLayoutFactory = function(mcontext) {
            this.mcontext = mcontext;
        };
        gameLayout.GameLayoutFactory = ck_implements(gameLayout.GameLayoutFactory, clientkernelModulesApi.IService);
        gameLayout.GameLayoutFactory = ck_implements(gameLayout.GameLayoutFactory, componentmodelComponentApi.IComponentFactory);
        gameLayout.GameLayoutFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        gameLayout.GameLayoutFactory.__name__ = ["gameLayout", "GameLayoutFactory"];
        gameLayout.GameLayoutFactory.prototype.mcontext = null;
        gameLayout.GameLayoutFactory.prototype.createComponent = function(context) {
            new gameLayout.GameLayout(this.mcontext, context);
        };
        gameLayout.GameLayoutFactory.prototype.getComponentDeclaration = function() {
            return gameLayoutApi.GameLayoutDeclaration;
        };
        gameLayout.GameLayoutFactory.prototype.__class__ = gameLayout.GameLayoutFactory;
        gameLayout.LayerControl = function(scenarios_cfg, displayProvider, gameLayoutPort) {
            this.layerIds = [];
            this.displayProvider = displayProvider;
            this.stage = displayProvider.getDefaultStage();
            this.gameLayoutPort = gameLayoutPort;
            this.scenarios = new _hcmn_.haxe_ds_StringMap();
            var _g = 0;
            var _g1 = _hcmn_.Reflect.fields(scenarios_cfg);
            while (_g < _g1.length) {
                var field = _g1[_g];
                ++_g;
                var value = _hcmn_.Reflect.field(scenarios_cfg, field);
                this.scenarios.set(field, value);
            }
            gameLayoutPort.getHideLayers().subscribe($bind(this, this.hideLayers));
            gameLayoutPort.getUnhideLayers().subscribe($bind(this, this.unhideLayers));
        };
        gameLayout.LayerControl.__name__ = ["gameLayout", "LayerControl"];
        gameLayout.LayerControl.prototype.stage = null;
        gameLayout.LayerControl.prototype.layerIds = null;
        gameLayout.LayerControl.prototype.scenarios = null;
        gameLayout.LayerControl.prototype.gameLayoutPort = null;
        gameLayout.LayerControl.prototype.displayProvider = null;
        gameLayout.LayerControl.prototype.hideLayers = function(e) {
            this.stage = this.displayProvider.getDefaultStage();
            var scenarioId = e.getPayload();
            this.layerIds = [];
            var _g1 = 0;
            var _g = this.stage.getNumChildren();
            while (_g1 < _g) {
                var i = _g1++;
                if (this.scenarios.exists(scenarioId)) {
                    var _g3 = 0;
                    var _g2 = this.scenarios.get(scenarioId).length;
                    while (_g3 < _g2) {
                        var j = _g3++;
                        var child = this.stage.getChildAt(i);
                        var layerId = this.scenarios.get(scenarioId)[j];
                        if (layerId == child.getName()) {
                            this.layerIds.push(layerId);
                            child.setVisible(false);
                        }
                    }
                }
            }
        };
        gameLayout.LayerControl.prototype.unhideLayers = function(e) {
            var _g1 = 0;
            var _g = this.layerIds.length;
            while (_g1 < _g) {
                var i = _g1++;
                var child = this.stage.getChildByID(this.layerIds[i]);
                child.setVisible(true);
            }
            this.layerIds = null;
        };
        gameLayout.LayerControl.prototype.__class__ = gameLayout.LayerControl;
        gameLayout.StageElement = function(stage, stageZIndex, left, top, width, height, maxw, maxh) {
            this.maxH = 1080;
            this.maxW = 1920;
            this.stage = stage;
            this.stageZIndex = stageZIndex;
            this.gcHeight = height;
            this.gcWidth = width;
            this.gcTop = top;
            this.gcLeft = left;
            this.maxW = maxw;
            this.maxH = maxh;
        };
        gameLayout.StageElement.__name__ = ["gameLayout", "StageElement"];
        gameLayout.StageElement.prototype.stage = null;
        gameLayout.StageElement.prototype.stageZIndex = null;
        gameLayout.StageElement.prototype.gcHeight = null;
        gameLayout.StageElement.prototype.gcWidth = null;
        gameLayout.StageElement.prototype.gcTop = null;
        gameLayout.StageElement.prototype.gcLeft = null;
        gameLayout.StageElement.prototype.canvas = null;
        gameLayout.StageElement.prototype.destage = null;
        gameLayout.StageElement.prototype.maxW = null;
        gameLayout.StageElement.prototype.maxH = null;
        gameLayout.StageElement.prototype.expand = function(left, top, width, height) {
            var newleft;
            if (this.gcLeft < left) newleft = this.gcLeft;
            else newleft = left;
            var newright;
            if (this.gcLeft + this.gcWidth > left + width) newright = this.gcLeft + this.gcWidth;
            else newright = left + width;
            var newtop;
            if (this.gcTop < top) newtop = this.gcTop;
            else newtop = top;
            var newbottom;
            if (this.gcTop + this.gcHeight > top + height) newbottom = this.gcTop + this.gcHeight;
            else newbottom = top + height;
            this.gcLeft = newleft;
            this.gcWidth = newright - newleft;
            this.gcTop = newtop;
            this.gcHeight = newbottom - newtop;
            if (this.gcWidth + this.gcLeft > this.maxW) this.gcWidth = this.maxW - this.gcLeft;
            if (this.gcHeight + this.gcTop > this.maxH) this.gcHeight = this.maxH - this.gcTop;
            if (this.gcLeft < 0) {
                this.gcWidth += this.gcLeft;
                this.gcLeft = 0;
            }
            if (this.gcTop < 0) {
                this.gcHeight += this.gcTop;
                this.gcTop = 0;
            }
        };
        gameLayout.StageElement.prototype.createCanvas = function(displayProvider, pcStagesOffsetLeft, pcStagesOffsetTop, pcStagesWidth, pcStagesHeight, gcStagesWidth, gcStagesHeight, r, targetFPS, isWebGL) {
            var _this = window.document;
            this.canvas = _this.createElement("canvas");
            this.canvas.id = this.stage;
            this.canvas.style.visibility = "hidden";
            this.canvas.style.position = "absolute";
            this.canvas.style.display = "initial";
            this.canvas.style.zIndex = "" + this.stageZIndex * 10;
            this.canvas.style.outline = "none";
            this.canvas.tabIndex = 0;
            var stageDef = new displayEngineApi.StageDef();
            stageDef.id = this.canvas.id;
            stageDef.canvas = this.canvas;
            stageDef.dimension = new displayEngineApi.Point(this.canvas.width, this.canvas.height);
            stageDef.targetFPS = targetFPS;
            stageDef.isWebgl = isWebGL;
            this.destage = displayProvider.getFactory().createStage(stageDef);
            this.destage.setScaleX(pcStagesWidth / gcStagesWidth);
            this.destage.setScaleY(pcStagesHeight / gcStagesHeight);
            this.adjust(displayProvider, pcStagesOffsetLeft, pcStagesOffsetTop, pcStagesWidth, pcStagesHeight, gcStagesWidth, gcStagesHeight, null, r);
            window.document.body.appendChild(this.canvas);
            this.canvas.focus();
        };
        gameLayout.StageElement.prototype.adjust = function(displayProvider, pcStagesOffsetLeft, pcStagesOffsetTop, pcStagesWidth, pcStagesHeight, gcStagesWidth, gcStagesHeight, newStage, r) {
            if (newStage != null) {
                this.gcLeft = newStage.gcLeft;
                this.gcWidth = newStage.gcWidth;
                this.gcTop = newStage.gcTop;
                this.gcHeight = newStage.gcHeight;
            }
            this.canvas.style.left = _hcmn_.Math.round(r * (pcStagesOffsetLeft + _hcmn_.Math.round(this.gcLeft * pcStagesWidth / gcStagesWidth))) + "px";
            this.canvas.style.top = _hcmn_.Math.round(r * (pcStagesOffsetTop + _hcmn_.Math.round(this.gcTop * pcStagesHeight / gcStagesHeight))) + "px";
            if (this.destage != null) {
                this.destage.setSize(_hcmn_.Math.round(this.gcWidth * pcStagesWidth / gcStagesWidth), _hcmn_.Math.round(this.gcHeight * pcStagesHeight / gcStagesHeight));
                this.destage.setScaleX(pcStagesWidth / gcStagesWidth);
                this.destage.setScaleY(pcStagesHeight / gcStagesHeight);
            } else {
                this.canvas.width = _hcmn_.Math.round(this.gcWidth * pcStagesWidth / gcStagesWidth);
                this.canvas.height = _hcmn_.Math.round(this.gcHeight * pcStagesHeight / gcStagesHeight);
            }
            var scale = 1;
            if (r != 1) {
                this.canvas.style.width = _hcmn_.Math.round(this.canvas.width * r) + "px";
                this.canvas.style.height = _hcmn_.Math.round(this.canvas.height * r) + "px";
                scale = this.capCanvasSize(1440);
            } else {
                this.canvas.style.width = "";
                this.canvas.style.height = "";
            }
            if (this.destage != null && scale > 1) {
                this.destage.setSize(this.canvas.width, this.canvas.height);
                this.destage.setScaleX(this.destage.getScaleX() / scale);
                this.destage.setScaleY(this.destage.getScaleY() / scale);
            }
            if (this.gcHeight == null && this.gcWidth == null) {
                this.canvas.width = _hcmn_.Math.floor(window.innerWidth / r);
                this.canvas.height = _hcmn_.Math.floor(window.innerHeight / r);
                this.canvas.style.left = "0";
                this.canvas.style.top = "0";
                this.canvas.style.width = window.innerWidth + "px";
                this.canvas.style.height = window.innerHeight + "px";
                if (r != 1) this.capCanvasSize(1440);
            }
        };
        gameLayout.StageElement.prototype.capCanvasSize = function(maxSize) {
            var newW = this.canvas.width;
            var newH = this.canvas.height;
            var scale = 1;
            if (this.canvas.width < this.canvas.height) {
                scale = this.canvas.height / maxSize;
                if (this.canvas.height > maxSize) {
                    newH = maxSize;
                    newW = _hcmn_.Math.round(this.canvas.width / scale);
                }
            } else {
                scale = this.canvas.width / maxSize;
                if (this.canvas.width > maxSize) {
                    newW = maxSize;
                    newH = _hcmn_.Math.round(this.canvas.height / scale);
                }
            }
            this.canvas.width = newW;
            this.canvas.height = newH;
            return scale;
        };
        gameLayout.StageElement.prototype.offsetLeft = function(left) {
            return left - this.gcLeft;
        };
        gameLayout.StageElement.prototype.offsetTop = function(top) {
            return top - this.gcTop;
        };
        gameLayout.StageElement.prototype.__class__ = gameLayout.StageElement;
        gameLayout.Stages = function(displayProvider, variablesRegistry) {
            this.isWebGL = false;
            this.fitHeight = true;
            this.fitWidth = true;
            this.variablesRegistry = variablesRegistry;
            this.displayProvider = displayProvider;
            this.r = 1;
            this.stages = new _hcmn_.haxe_ds_StringMap();
        };
        gameLayout.Stages.__name__ = ["gameLayout", "Stages"];
        gameLayout.Stages.prototype.stages = null;
        gameLayout.Stages.prototype.gcWidth = null;
        gameLayout.Stages.prototype.gcHeight = null;
        gameLayout.Stages.prototype.gcAspect = null;
        gameLayout.Stages.prototype.pcWidth = null;
        gameLayout.Stages.prototype.pcHeight = null;
        gameLayout.Stages.prototype.pcOffsetTop = null;
        gameLayout.Stages.prototype.pcOffsetLeft = null;
        gameLayout.Stages.prototype.fitWidth = null;
        gameLayout.Stages.prototype.fitHeight = null;
        gameLayout.Stages.prototype.isWebGL = null;
        gameLayout.Stages.prototype.r = null;
        gameLayout.Stages.prototype.displayProvider = null;
        gameLayout.Stages.prototype.variablesRegistry = null;
        gameLayout.Stages.prototype.adjust = function(cl, aspect, screenWidth, screenHeight, devicePixelRatio) {
            this.gcAspect = aspect;
            this.gcWidth = gameLayout.Stages.GC_WIDTH;
            this.gcHeight = _hcmn_.Math.round(this.gcWidth / this.gcAspect);
            var pcAspect = screenWidth / screenHeight;
            if (pcAspect <= aspect && this.fitWidth || !this.fitHeight) {
                this.pcWidth = screenWidth;
                if (gameLayout.Stages.capCanvasSize && this.pcWidth > gameLayout.Stages.GC_WIDTH * devicePixelRatio) this.pcWidth = _hcmn_.Math.round(gameLayout.Stages.GC_WIDTH * devicePixelRatio);
                this.pcHeight = _hcmn_.Math.round(this.pcWidth / this.gcAspect);
                this.pcOffsetTop = _hcmn_.Math.round((screenHeight - this.pcHeight) / 2);
                this.pcOffsetLeft = _hcmn_.Math.round((screenWidth - this.pcWidth) / 2);
            } else if (this.fitHeight) {
                this.pcHeight = screenHeight;
                var GC_HEIGHT = _hcmn_.Math.round(gameLayout.Stages.GC_WIDTH / this.gcAspect);
                if (gameLayout.Stages.capCanvasSize && this.pcHeight > GC_HEIGHT * devicePixelRatio) this.pcHeight = _hcmn_.Math.round(GC_HEIGHT * devicePixelRatio);
                this.pcWidth = _hcmn_.Math.round(this.pcHeight * this.gcAspect);
                this.pcOffsetLeft = _hcmn_.Math.round((screenWidth - this.pcWidth) / 2);
                this.pcOffsetTop = _hcmn_.Math.round((screenHeight - this.pcHeight) / 2);
            }
            var newstages = this.calculateStages(cl);
            var $it0 = this.stages.keys();
            while ($it0.hasNext()) {
                var k = $it0.next();
                if (!(_hcmn_.__map_reserved[k] != null ? newstages.existsReserved(k) : newstages.h.hasOwnProperty(k))) this.stages.get(k).canvas.remove();
                else this.stages.get(k).adjust(this.displayProvider, this.pcOffsetLeft, this.pcOffsetTop, this.pcWidth, this.pcHeight, this.gcWidth, this.gcHeight, _hcmn_.__map_reserved[k] != null ? newstages.getReserved(k) : newstages.h[k], this.r / devicePixelRatio);
            }
            var $it1 = newstages.keys();
            while ($it1.hasNext()) {
                var k1 = $it1.next();
                if (!this.stages.exists(k1)) {
                    var newstage;
                    newstage = _hcmn_.__map_reserved[k1] != null ? newstages.getReserved(k1) : newstages.h[k1];
                    var targetFPS = _hcmn_.Std.parseInt(this.variablesRegistry.get("targetFPS", "30"));
                    newstage.createCanvas(this.displayProvider, this.pcOffsetLeft, this.pcOffsetTop, this.pcWidth, this.pcHeight, this.gcWidth, this.gcHeight, this.r / devicePixelRatio, targetFPS, this.isWebGL);
                    this.stages.set(k1, newstage);
                }
            }
        };
        gameLayout.Stages.prototype.get = function(stage) {
            return this.stages.get(stage);
        };
        gameLayout.Stages.prototype.showStageElements = function() {
            var $it0 = this.stages.iterator();
            while ($it0.hasNext()) {
                var stage = $it0.next();
                stage.canvas.style.visibility = "visible";
            }
        };
        gameLayout.Stages.prototype.setScreenFit = function(fitW, fitH) {
            this.fitWidth = fitW;
            this.fitHeight = fitH;
        };
        gameLayout.Stages.prototype.setWebGL = function(webgl) {
            this.isWebGL = webgl;
        };
        gameLayout.Stages.prototype.calculateStages = function(cl) {
            var ret = new _hcmn_.haxe_ds_StringMap();
            var $it0 = new haxe.ds._StringMap.StringMapIterator(cl, cl.arrayKeys());
            while ($it0.hasNext()) {
                var component = $it0.next();
                var $it1 = component.containers.iterator();
                while ($it1.hasNext()) {
                    var container = $it1.next();
                    if (!ret.exists(container.stage)) {
                        var value = new gameLayout.StageElement(container.stage, container.stageZIndex, container.left, container.top, container.width, container.height, this.gcWidth, this.gcHeight);
                        ret.set(container.stage, value);
                    } else ret.get(container.stage).expand(container.left, container.top, container.width, container.height);
                }
            }
            return ret;
        };
        gameLayout.Stages.prototype.__class__ = gameLayout.Stages;
        gameLayout.GameLayoutModelFactory = function() {};
        gameLayout.GameLayoutModelFactory.__name__ = ["gameLayout", "GameLayoutModelFactory"];
        gameLayout.GameLayoutModelFactory.getModel = function(type) {
            switch (type) {
                case "explicit":
                    return new gameLayout.ExplicitGameLayoutModel();
                case "relative":
                    return new gameLayout.RelativeGameLayoutModel();
                default:
                    return new gameLayout.ExplicitGameLayoutModel();
            }
        };
        gameLayout.GameLayoutModelFactory.prototype.__class__ = gameLayout.GameLayoutModelFactory;
        gameLayout.GameLayoutModelsEnum = {
            __ename__: ["gameLayout", "GameLayoutModelsEnum"],
            __constructs__: ["explicit", "relative"]
        };
        gameLayout.GameLayoutModelsEnum.explicit = ["explicit", 0];
        gameLayout.GameLayoutModelsEnum.explicit.toString = $estr;
        gameLayout.GameLayoutModelsEnum.explicit.__enum__ = gameLayout.GameLayoutModelsEnum;
        gameLayout.GameLayoutModelsEnum.relative = ["relative", 1];
        gameLayout.GameLayoutModelsEnum.relative.toString = $estr;
        gameLayout.GameLayoutModelsEnum.relative.__enum__ = gameLayout.GameLayoutModelsEnum;

        gameLayout.IGameLayoutModel = function() {}
        gameLayout.IGameLayoutModel.prototype = {

            configure: function(config) {
                return {
                    arguments: ["*"],
                    returns: "void"
                };
            },
            getComponentLayout: function(exactAspect) {
                return {
                    arguments: ["number"],
                    returns: Map
                };
            },
            getRequiredStages: function() {
                return {
                    arguments: [],
                    returns: "array"
                };
            },
            getType: function() {
                return {
                    arguments: [],
                    returns: "*"
                };
            }
        };
        gameLayout.ExplicitGameLayoutModel = function() {
            this.type = gameLayout.GameLayoutModelsEnum.explicit;
            this.requiredStages = null;
            this.componentLayout = null;
        };
        gameLayout.ExplicitGameLayoutModel = ck_implements(gameLayout.ExplicitGameLayoutModel, gameLayout.IGameLayoutModel);
        gameLayout.ExplicitGameLayoutModel.__interfaces__ = [gameLayout.IGameLayoutModel];
        gameLayout.ExplicitGameLayoutModel.__name__ = ["gameLayout", "ExplicitGameLayoutModel"];
        gameLayout.ExplicitGameLayoutModel.prototype.componentLayout = null;
        gameLayout.ExplicitGameLayoutModel.prototype.requiredStages = null;
        gameLayout.ExplicitGameLayoutModel.prototype.type = null;
        gameLayout.ExplicitGameLayoutModel.prototype.configure = function(cfg) {
            var config = cfg.model.config;
            this.componentLayout = new _hcmn_.haxe_ds_StringMap();
            this.requiredStages = [];
            var _g1 = 0;
            var _g = config.components.length;
            while (_g1 < _g) {
                var i = _g1++;
                if (_hcmn_.HxOverrides.indexOf(this.requiredStages, config.components[i].stage, 0) == -1) this.requiredStages.push(config.components[i].stage);
                var cl = new gameLayoutApi.ComponentLayout(new _hcmn_.haxe_ds_StringMap());
                var _g3 = 0;
                var _g2 = config.components[i].containers.length;
                while (_g3 < _g2) {
                    var j = _g3++;
                    var cn = new gameLayoutApi.ContainerLayout(config.components[i].containers[j].id, this.stageName(config.components[i].containers[j].stage), config.components[i].containers[j].stageZIndex, config.components[i].containers[j].left, config.components[i].containers[j].top, config.components[i].containers[j].width, config.components[i].containers[j].height, config.components[i].containers[j].zindex, config.components[i].containers[j].configuration);
                    cl.containers.set(cn.id, cn);
                }
                this.componentLayout.set(config.components[i].id, cl);
            }
        };
        gameLayout.ExplicitGameLayoutModel.prototype.stageName = function(stageIndex) {
            return "skgl_" + stageIndex;
        };
        gameLayout.ExplicitGameLayoutModel.prototype.getComponentLayout = function(exactAspect) {
            return this.componentLayout;
        };
        gameLayout.ExplicitGameLayoutModel.prototype.getRequiredStages = function() {
            var stages = [];
            return stages;
        };
        gameLayout.ExplicitGameLayoutModel.prototype.getType = function() {
            return this.type;
        };
        gameLayout.ExplicitGameLayoutModel.prototype.__class__ = gameLayout.ExplicitGameLayoutModel;
        gameLayout.RelativeGameLayoutModel = function() {
            this.colors = ["#007700", "#770000", "#000077", "#007777", "444444"];
            this.type = gameLayout.GameLayoutModelsEnum.relative;
            this.requiredStages = null;
            this.sectionsPerAspect = null;
            this.componentLayoutsPerAspect = null;
            this.componentLayoutsPerAspect = new _hcmn_.haxe_ds_StringMap();
            this.sectionsPerAspect = new _hcmn_.haxe_ds_StringMap();
            window.drawLayoutSections = $bind(this, this.drawSections);
            this.requiredStages = [];
            this.sectionColor = new _hcmn_.haxe_ds_StringMap();
        };
        gameLayout.RelativeGameLayoutModel = ck_implements(gameLayout.RelativeGameLayoutModel, gameLayout.IGameLayoutModel);
        gameLayout.RelativeGameLayoutModel.__interfaces__ = [gameLayout.IGameLayoutModel];
        gameLayout.RelativeGameLayoutModel.__name__ = ["gameLayout", "RelativeGameLayoutModel"];
        gameLayout.RelativeGameLayoutModel.prototype.componentLayoutsPerAspect = null;
        gameLayout.RelativeGameLayoutModel.prototype.sectionsPerAspect = null;
        gameLayout.RelativeGameLayoutModel.prototype.requiredStages = null;
        gameLayout.RelativeGameLayoutModel.prototype.type = null;
        gameLayout.RelativeGameLayoutModel.prototype.lastLayoutedAspect = null;
        gameLayout.RelativeGameLayoutModel.prototype.helperCanvas = null;
        gameLayout.RelativeGameLayoutModel.prototype.colors = null;
        gameLayout.RelativeGameLayoutModel.prototype.sectionColor = null;
        gameLayout.RelativeGameLayoutModel.prototype.configure = function(cfg) {
            var config = cfg.model.config;
            var aspects = cfg.aspects;
            var _g = 0;
            while (_g < aspects.length) {
                var aspect = aspects[_g];
                ++_g;
                if (!this.sectionsPerAspect.exists(aspect == null ? "null" : "" + aspect)) this.parseSections(config.sections, aspect);
                var componentLayout = new _hcmn_.haxe_ds_StringMap();
                var _g2 = 0;
                var _g1 = config.components.length;
                while (_g2 < _g1) {
                    var i = _g2++;
                    if (_hcmn_.HxOverrides.indexOf(this.requiredStages, config.components[i].stage, 0) == -1) this.requiredStages.push(config.components[i].stage);
                    var cl = new gameLayoutApi.ComponentLayout(new _hcmn_.haxe_ds_StringMap());
                    var _g4 = 0;
                    var _g3 = config.components[i].containers.length;
                    while (_g4 < _g3) {
                        var j = _g4++;
                        var cn = this.extractExpliciteLayout(config.components[i].containers[j], aspect);
                        cl.containers.set(cn.id, cn);
                    }
                    componentLayout.set(config.components[i].id, cl);
                }
                this.componentLayoutsPerAspect.set(aspect == null ? "null" : "" + aspect, componentLayout);
            }
        };
        gameLayout.RelativeGameLayoutModel.prototype.parseSections = function(sectionsJson, aspect) {
            var sections = new _hcmn_.haxe_ds_StringMap();
            if (sectionsJson == null) return;
            var artW = gameLayout.Stages.GC_WIDTH;
            var artH = _hcmn_.Math.round(artW / aspect);
            var _g = 0;
            while (_g < sectionsJson.length) {
                var section = sectionsJson[_g];
                ++_g;
                var newSection = {};
                newSection.id = section.id;
                newSection.zindex = section.zindex;
                newSection.stage = section.stage;
                newSection.configuration = section.configuration;
                newSection.stageZIndex = section.stageZIndex;
                newSection.width = this.parseInt(_hcmn_.Std.string(section.width), artW);
                newSection.height = this.parseInt(_hcmn_.Std.string(section.height), artH);
                newSection.left = this.parseInt(_hcmn_.Std.string(section.left), artW);
                newSection.top = this.parseInt(_hcmn_.Std.string(section.top), artH);
                newSection.left = this.calculateHorizontalAlignment(section.halign, newSection.left, newSection.width, artW);
                newSection.top = this.calculateVerticalAlignment(section.valign, newSection.top, newSection.height, artH);
                var key = newSection.id;
                var value = newSection;
                sections.set(key, value);
            }
            this.sectionsPerAspect.set(aspect == null ? "null" : "" + aspect, sections);
        };
        gameLayout.RelativeGameLayoutModel.prototype.extractExpliciteLayout = function(config, aspect) {
            var artW = gameLayout.Stages.GC_WIDTH;
            var artH = _hcmn_.Math.round(artW / aspect);
            var artT = 0;
            var artL = 0;
            var dobj = null;
            var vbW = null;
            var vbH = null;
            var stage;
            var this1 = gameLayout.GameLayout.displayProvider.getStages();
            var key = this.stageName(config.stage);
            stage = this1.get(key);
            if (stage != null) {
                dobj = stage.getChildByID(config.id);
                if (dobj != null) {
                    vbW = _hcmn_.Math.round(dobj.getUserData().viewBuilderW);
                    vbH = _hcmn_.Math.round(dobj.getUserData().viewBuilderH);
                }
            }
            var left = this.parseInt(config.left, artW);
            var top = this.parseInt(config.top, artH);
            var width = this.parseInt(config.width, artW);
            var height = this.parseInt(config.height, artH);
            if (config.configuration != null) {
                if (config.configuration.viewBuilderWidth != null) vbW = _hcmn_.Math.round(config.configuration.viewBuilderWidth);
                if (config.configuration.viewBuilderHeight != null) vbH = _hcmn_.Math.round(config.configuration.viewBuilderHeight);
            }
            if (left == 0 && top == 0 && width == 0 && height == 0) {
                var cn1 = new gameLayoutApi.ContainerLayout(config.id, this.stageName(config.stage), config.stageZIndex, null, null, null, null, config.zindex, config.configuration);
                return cn1;
            }
            if (config.relativeTo != null) {
                var sectionConfig;
                var this2 = this.sectionsPerAspect.get(aspect == null ? "null" : "" + aspect);
                var key1 = config.relativeTo;
                sectionConfig = this2.get(key1);
                artW = sectionConfig.width;
                artH = sectionConfig.height;
                artT = sectionConfig.top;
                artL = sectionConfig.left;
                left = this.parseInt(config.left, artW);
                top = this.parseInt(config.top, artH);
                width = this.parseInt(config.width, artW);
                height = this.parseInt(config.height, artH);
            }
            if (vbH != null && vbW != null) {
                if (config.height == "auto" && config.width == "auto" || config.height == null && config.width == null) {
                    width = vbW;
                    height = vbH;
                } else if (config.height == "auto") {
                    var compRatio = vbW / vbH;
                    height = _hcmn_.Math.round(width / compRatio);
                } else if (config.width == "auto") {
                    var compRatio1 = vbW / vbH;
                    width = _hcmn_.Math.round(height * compRatio1);
                }
            }
            left = this.calculateHorizontalAlignment(config.halign, left, width, artW);
            top = this.calculateVerticalAlignment(config.valign, top, height, artH);
            left += artL;
            top += artT;
            var cn = new gameLayoutApi.ContainerLayout(config.id, this.stageName(config.stage), config.stageZIndex, left, top, width, height, config.zindex, config.configuration);
            return cn;
        };
        gameLayout.RelativeGameLayoutModel.prototype.calculateVerticalAlignment = function(valign, top, height, artH) {
            var newTop = top;
            if (valign != null) switch (valign) {
                case "center":
                    newTop += _hcmn_.Math.round((artH - newTop - height) / 2);
                    break;
                case "bottom":
                    newTop += artH - height;
                    break;
                case "top":
                    break;
                default:
            }
            return newTop;
        };
        gameLayout.RelativeGameLayoutModel.prototype.calculateHorizontalAlignment = function(halign, left, width, artW) {
            var newLeft = left;
            if (halign != null) switch (halign) {
                case "center":
                    newLeft += _hcmn_.Math.round((artW - newLeft - width) / 2);
                    break;
                case "right":
                    newLeft += artW - width;
                    break;
                case "left":
                    break;
                default:
            }
            return newLeft;
        };
        gameLayout.RelativeGameLayoutModel.prototype.drawSections = function() {
            var skgl = window.document.getElementById("skgl_0");
            if (skgl == null) return;
            window.removeEventListener("resize", $bind(this, this.handleResize));
            window.addEventListener("resize", $bind(this, this.handleResize));
            if (this.helperCanvas == null) {
                var _this = window.document;
                this.helperCanvas = _this.createElement("canvas");
                this.helperCanvas.setAttribute("id", "sectionHelperCanvas");
                var parentNode = skgl.parentElement;
                parentNode.appendChild(this.helperCanvas);
            }
            this.helperCanvas.width = skgl.width;
            this.helperCanvas.height = skgl.height;
            this.helperCanvas.setAttribute("style", skgl.getAttribute("style"));
            this.helperCanvas.style.zIndex = skgl.style.zIndex + "10";
            var scale = 1920 / this.helperCanvas.width;
            var context2d = this.helperCanvas.getContext("2d", null);
            var $it0 = (function($this) {
                var $r;
                var this1 = $this.sectionsPerAspect.get($this.lastLayoutedAspect);
                $r = this1.iterator();
                return $r;
            }(this));
            while ($it0.hasNext()) {
                var section = $it0.next();
                var realleft = section.left / scale;
                var realtop = section.top / scale;
                var realwidth = section.width / scale;
                var realheight = section.height / scale;
                if (!this.sectionColor.exists(section.id)) {
                    var value = this.getNextColor();
                    this.sectionColor.set(section.id, value);
                }
                context2d.strokeStyle = this.sectionColor.get(section.id);
                context2d.lineWidth = 1;
                context2d.beginPath();
                context2d.rect(realleft, realtop, realwidth, realheight);
                context2d.stroke();
                context2d.closePath();
                var txtwidth = context2d.measureText(section.id).width;
                context2d.fillStyle = context2d.strokeStyle;
                context2d.fillRect(realleft, realtop, txtwidth + 4, 18);
                context2d.fillStyle = "#fff";
                context2d.fillText(section.id, realleft + 2, realtop + 10);
            }
        };
        gameLayout.RelativeGameLayoutModel.prototype.handleResize = function(e) {
            if (this.helperCanvas != null) this.helperCanvas.getContext("2d", null).clearRect(0, 0, this.helperCanvas.width, this.helperCanvas.height);
            _hcmn_.haxe_Timer.delay($bind(this, this.drawSections), 200);
        };
        gameLayout.RelativeGameLayoutModel.prototype.getNextColor = function() {
            var currColor = this.colors.shift();
            this.colors.push(currColor);
            return currColor;
        };
        gameLayout.RelativeGameLayoutModel.prototype.parseInt = function(strval, fullval) {
            if (strval == "auto") return fullval;
            var ret = 0;
            if (strval == null || strval == "") return ret;
            if (strval == null) strval = "null";
            else strval = "" + strval;
            if (strval.indexOf("%") >= 0) {
                var valFloat = _hcmn_.Std.parseFloat(_hcmn_.StringTools.replace(strval, "%", ""));
                valFloat *= fullval / 100;
                ret = _hcmn_.Math.round(valFloat);
            } else {
                var valFloat1 = _hcmn_.Std.parseFloat(_hcmn_.StringTools.replace(strval, "px", ""));
                ret = _hcmn_.Math.round(valFloat1);
            }
            if (isNaN(ret)) return 0;
            else return ret;
        };
        gameLayout.RelativeGameLayoutModel.prototype.stageName = function(stageIndex) {
            return "skgl_" + stageIndex;
        };
        gameLayout.RelativeGameLayoutModel.prototype.getComponentLayout = function(exactAspect) {
            if (exactAspect == null) this.lastLayoutedAspect = "null";
            else this.lastLayoutedAspect = "" + exactAspect;
            return this.componentLayoutsPerAspect.get(this.lastLayoutedAspect);
        };
        gameLayout.RelativeGameLayoutModel.prototype.getRequiredStages = function() {
            var stages = [];
            return stages;
        };
        gameLayout.RelativeGameLayoutModel.prototype.getType = function() {
            return this.type;
        };
        gameLayout.RelativeGameLayoutModel.prototype.__class__ = gameLayout.RelativeGameLayoutModel;
        if (typeof haxe == 'undefined') {
            var haxe = {};
        };

        haxe.IMap = function() {}
        haxe.IMap.prototype = {

            get: function(k) {
                return {
                    arguments: ["*"],
                    returns: "null"
                };
            },
            iterator: function() {
                return {
                    arguments: [],
                    returns: "null"
                };
            }
        };
        if (!haxe.ds) {
            haxe.ds = {};
        };
        haxe.ds.ObjectMap = function() {
            this.h = {};
            this.h.__keys__ = {};
        };
        haxe.ds.ObjectMap.__interfaces__ = [haxe.IMap];
        haxe.ds.ObjectMap.__name__ = ["haxe", "ds", "ObjectMap"];
        haxe.ds.ObjectMap.prototype.h = null;
        haxe.ds.ObjectMap.prototype.set = function(key, value) {
            var id = key.__id__ || (key.__id__ = ++haxe.ds.ObjectMap.count);
            this.h[id] = value;
            this.h.__keys__[id] = key;
        };
        haxe.ds.ObjectMap.prototype.get = function(key) {
            return this.h[key.__id__];
        };
        haxe.ds.ObjectMap.prototype.exists = function(key) {
            return this.h.__keys__[key.__id__] != null;
        };
        haxe.ds.ObjectMap.prototype.keys = function() {
            var a = [];
            for (var key in this.h.__keys__) {
                if (this.h.hasOwnProperty(key)) a.push(this.h.__keys__[key]);
            }
            return _hcmn_.HxOverrides.iter(a);
        };
        haxe.ds.ObjectMap.prototype.iterator = function() {
            return {
                ref: this.h,
                it: this.keys(),
                hasNext: function() {
                    return this.it.hasNext();
                },
                next: function() {
                    var i = this.it.next();
                    return this.ref[i.__id__];
                }
            };
        };
        haxe.ds.ObjectMap.prototype.__class__ = haxe.ds.ObjectMap;
        if (!haxe.ds._StringMap) {
            haxe.ds._StringMap = {};
        };
        haxe.ds._StringMap.StringMapIterator = function(map, keys) {
            this.map = map;
            this.keys = keys;
            this.index = 0;
            this.count = keys.length;
        };
        haxe.ds._StringMap.StringMapIterator.__name__ = ["haxe", "ds", "_StringMap", "StringMapIterator"];
        haxe.ds._StringMap.StringMapIterator.prototype.map = null;
        haxe.ds._StringMap.StringMapIterator.prototype.keys = null;
        haxe.ds._StringMap.StringMapIterator.prototype.index = null;
        haxe.ds._StringMap.StringMapIterator.prototype.count = null;
        haxe.ds._StringMap.StringMapIterator.prototype.hasNext = function() {
            return this.index < this.count;
        };
        haxe.ds._StringMap.StringMapIterator.prototype.next = function() {
            return this.map.get(this.keys[this.index++]);
        };
        haxe.ds._StringMap.StringMapIterator.prototype.__class__ = haxe.ds._StringMap.StringMapIterator;
        gameLayout.GameLayout.DEFAULT_STAGE_ID = "skgl_0";;
        gameLayout.StageElement.CANVAS_CAP_DIMENSION = 1440;;
        gameLayout.Stages.GC_WIDTH = 1920;;
        gameLayout.Stages.capCanvasSize = false;;
        haxe.ds.ObjectMap.count = 0;;
        return {
            exports: gameLayout,
            activator: gameLayout.Activator
        };
    });
//# sourceURL=gameLayout.js