浏览代码

ideal size - always take smallest

I added to AdvancedDynamicTexture a boolean useSmallestIdeal, if window width is smaller than height, using idealWidth, otherwise idealHeight. I'm now working on being able to match the game to all possible screen sizes so it should actually be a quite useful feature, it looks good that way.

I had problems compiling the source as you can see in the forum, but it should work.
Royi Bernthal 7 年之前
父节点
当前提交
55fcf45c27
共有 2 个文件被更改,包括 20 次插入7 次删除
  1. 15 0
      gui/src/advancedDynamicTexture.ts
  2. 5 7
      gui/src/valueAndUnit.ts

+ 15 - 0
gui/src/advancedDynamicTexture.ts

@@ -28,6 +28,7 @@ module BABYLON.GUI {
         private _fullscreenViewport = new Viewport(0, 0, 1, 1);
         private _fullscreenViewport = new Viewport(0, 0, 1, 1);
         private _idealWidth = 0;
         private _idealWidth = 0;
         private _idealHeight = 0;
         private _idealHeight = 0;
+        private _useSmallestIdeal: boolean = false;
         private _renderAtIdealSize = false;
         private _renderAtIdealSize = false;
         private _focusedControl: Nullable<IFocusableControl>;
         private _focusedControl: Nullable<IFocusableControl>;
         private _blockNextFocusCheck = false;
         private _blockNextFocusCheck = false;
@@ -88,6 +89,20 @@ module BABYLON.GUI {
             this._rootContainer._markAllAsDirty();
             this._rootContainer._markAllAsDirty();
         }
         }
 
 
+        public get useSmallestIdeal(): boolean {
+            return this._useSmallestIdeal;
+        }
+
+        public set useSmallestIdeal(value: boolean) {
+            if (this._useSmallestIdeal === value) {
+                return;
+            }
+
+            this._useSmallestIdeal = value;
+            this.markAsDirty();
+            this._rootContainer._markAllAsDirty();
+        }
+
         public get renderAtIdealSize(): boolean {
         public get renderAtIdealSize(): boolean {
             return this._renderAtIdealSize;
             return this._renderAtIdealSize;
         }
         }

+ 5 - 7
gui/src/valueAndUnit.ts

@@ -31,14 +31,12 @@ module BABYLON.GUI {
 
 
         public getValue(host: AdvancedDynamicTexture): number {
         public getValue(host: AdvancedDynamicTexture): number {
             if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
             if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
+                var width: number = (this._value * host.getSize().width) / host.idealWidth;
+                var height: number = (this._value * host.getSize().height) / host.idealHeight;
 
 
-                if (host.idealWidth) { // horizontal
-                    return (this._value * host.getSize().width) / host.idealWidth;
-                }
-
-                if (host.idealHeight) { // vertical
-                    return (this._value * host.getSize().height) / host.idealHeight;
-                }
+                if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) return window.innerWidth < window.innerHeight ? width : height;
+                if (host.idealWidth) return width; // horizontal
+                if (host.idealHeight) return height; // vertical
             }
             }
             return this._value;
             return this._value;
         }
         }