Sfoglia il codice sorgente

Added econtrol.getChildByType

David Catuhe 8 anni fa
parent
commit
222234565d

+ 15 - 0
dist/preview release/gui/babylon.gui.d.ts

@@ -155,6 +155,7 @@ declare module BABYLON.GUI {
         isPointerBlocker: boolean;
         protected _linkOffsetX: ValueAndUnit;
         protected _linkOffsetY: ValueAndUnit;
+        readonly typeName: string;
         /**
         * An event triggered when the pointer move over the control.
         * @type {BABYLON.Observable}
@@ -212,6 +213,7 @@ declare module BABYLON.GUI {
         readonly centerX: number;
         readonly centerY: number;
         constructor(name?: string);
+        protected _getTypeName(): string;
         linkWithMesh(mesh: AbstractMesh): void;
         _moveToProjectedPosition(projectedPosition: Vector3): void;
         _markMatrixAsDirty(): void;
@@ -272,7 +274,9 @@ declare module BABYLON.GUI {
         background: string;
         readonly children: Control[];
         constructor(name?: string);
+        protected _getTypeName(): string;
         getChildByName(name: string): Control;
+        getChildByType(name: string, type: string): Control;
         containsControl(control: Control): boolean;
         addControl(control: Control): Container;
         removeControl(control: Control): Container;
@@ -296,6 +300,7 @@ declare module BABYLON.GUI {
         private _tempMeasureStore;
         isVertical: boolean;
         constructor(name?: string);
+        protected _getTypeName(): string;
         protected _preMeasure(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
     }
 }
@@ -309,6 +314,7 @@ declare module BABYLON.GUI {
         thickness: number;
         cornerRadius: number;
         constructor(name?: string);
+        protected _getTypeName(): string;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         private _drawRoundedRect(context, offset?);
@@ -323,6 +329,7 @@ declare module BABYLON.GUI {
         private _thickness;
         thickness: number;
         constructor(name?: string);
+        protected _getTypeName(): string;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _clipForChildren(context: CanvasRenderingContext2D): void;
@@ -355,6 +362,7 @@ declare module BABYLON.GUI {
         private readonly _effectiveX2;
         private readonly _effectiveY2;
         constructor(name?: string);
+        protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _measure(): void;
         protected _computeAlignment(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -383,6 +391,7 @@ declare module BABYLON.GUI {
         maximum: number;
         value: number;
         constructor(name?: string);
+        protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         private _pointerIsDown;
         private _updateValueFromPointer(x);
@@ -407,6 +416,7 @@ declare module BABYLON.GUI {
         background: string;
         isChecked: boolean;
         constructor(name?: string);
+        protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _onPointerDown(coordinates: Vector2): boolean;
     }
@@ -428,6 +438,7 @@ declare module BABYLON.GUI {
         background: string;
         isChecked: boolean;
         constructor(name?: string);
+        protected _getTypeName(): string;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _onPointerDown(coordinates: Vector2): boolean;
     }
@@ -449,6 +460,7 @@ declare module BABYLON.GUI {
         textHorizontalAlignment: number;
         textVerticalAlignment: number;
         constructor(name?: string, text?: string);
+        protected _getTypeName(): string;
         private _drawText(text, textWidth, y, context);
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -474,6 +486,7 @@ declare module BABYLON.GUI {
         private _onImageLoaded();
         source: string;
         constructor(name?: string, url?: string);
+        protected _getTypeName(): string;
         synchronizeSizeWithContent(): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         private static _STRETCH_NONE;
@@ -496,6 +509,7 @@ declare module BABYLON.GUI {
         pointerDownAnimation: () => void;
         pointerUpAnimation: () => void;
         constructor(name?: string);
+        protected _getTypeName(): string;
         _processPicking(x: number, y: number, type: number): boolean;
         protected _onPointerEnter(): boolean;
         protected _onPointerOut(): void;
@@ -526,6 +540,7 @@ declare module BABYLON.GUI {
         onValueChangedObservable: Observable<Color3>;
         value: Color3;
         constructor(name?: string);
+        protected _getTypeName(): string;
         private _updateSquareProps();
         private _drawGradientSquare(hueValue, left, top, width, height, context);
         private _drawCircle(centerX, centerY, radius, context);

+ 56 - 1
dist/preview release/gui/babylon.gui.js

@@ -618,7 +618,6 @@ var BABYLON;
                 this.isPointerBlocker = false;
                 this._linkOffsetX = new GUI.ValueAndUnit(0);
                 this._linkOffsetY = new GUI.ValueAndUnit(0);
-                // Properties
                 /**
                 * An event triggered when the pointer move over the control.
                 * @type {BABYLON.Observable}
@@ -650,6 +649,14 @@ var BABYLON;
                 */
                 this.onDirtyObservable = new BABYLON.Observable();
             }
+            Object.defineProperty(Control.prototype, "typeName", {
+                // Properties
+                get: function () {
+                    return this._getTypeName();
+                },
+                enumerable: true,
+                configurable: true
+            });
             Object.defineProperty(Control.prototype, "alpha", {
                 get: function () {
                     return this._alpha;
@@ -989,6 +996,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Control.prototype._getTypeName = function () {
+                return "Control";
+            };
             Control.prototype.linkWithMesh = function (mesh) {
                 if (!this._host || this._root !== this._host._rootContainer) {
                     BABYLON.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
@@ -1475,6 +1485,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Container.prototype._getTypeName = function () {
+                return "Container";
+            };
             Container.prototype.getChildByName = function (name) {
                 for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
                     var child = _a[_i];
@@ -1484,6 +1497,15 @@ var BABYLON;
                 }
                 return null;
             };
+            Container.prototype.getChildByType = function (name, type) {
+                for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
+                    var child = _a[_i];
+                    if (child.typeName === type) {
+                        return child;
+                    }
+                }
+                return null;
+            };
             Container.prototype.containsControl = function (control) {
                 return this._children.indexOf(control) !== -1;
             };
@@ -1622,6 +1644,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            StackPanel.prototype._getTypeName = function () {
+                return "StackPanel";
+            };
             StackPanel.prototype._preMeasure = function (parentMeasure, context) {
                 var stack = 0;
                 for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
@@ -1730,6 +1755,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Rectangle.prototype._getTypeName = function () {
+                return "Rectangle";
+            };
             Rectangle.prototype._localDraw = function (context) {
                 context.save();
                 if (this._background) {
@@ -1834,6 +1862,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Ellipse.prototype._getTypeName = function () {
+                return "Ellipse";
+            };
             Ellipse.prototype._localDraw = function (context) {
                 context.save();
                 context.beginPath();
@@ -2042,6 +2073,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Line.prototype._getTypeName = function () {
+                return "Line";
+            };
             Line.prototype._draw = function (parentMeasure, context) {
                 context.save();
                 this._applyStates(context);
@@ -2217,6 +2251,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Slider.prototype._getTypeName = function () {
+                return "Slider";
+            };
             Slider.prototype._draw = function (parentMeasure, context) {
                 context.save();
                 this._applyStates(context);
@@ -2368,6 +2405,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Checkbox.prototype._getTypeName = function () {
+                return "CheckBox";
+            };
             Checkbox.prototype._draw = function (parentMeasure, context) {
                 context.save();
                 this._applyStates(context);
@@ -2508,6 +2548,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            RadioButton.prototype._getTypeName = function () {
+                return "RadioButton";
+            };
             RadioButton.prototype._draw = function (parentMeasure, context) {
                 context.save();
                 this._applyStates(context);
@@ -2636,6 +2679,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            TextBlock.prototype._getTypeName = function () {
+                return "TextBlock";
+            };
             TextBlock.prototype._drawText = function (text, textWidth, y, context) {
                 var width = this._currentMeasure.width;
                 var x = 0;
@@ -2824,6 +2870,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            Image.prototype._getTypeName = function () {
+                return "Image";
+            };
             Image.prototype.synchronizeSizeWithContent = function () {
                 if (!this._loaded) {
                     return;
@@ -2943,6 +2992,9 @@ var BABYLON;
                 };
                 return _this;
             }
+            Button.prototype._getTypeName = function () {
+                return "Button";
+            };
             // While being a container, the button behaves like a control.
             Button.prototype._processPicking = function (x, y, type) {
                 if (!this.contains(x, y)) {
@@ -3081,6 +3133,9 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            ColorPicker.prototype._getTypeName = function () {
+                return "ColorPicker";
+            };
             ColorPicker.prototype._updateSquareProps = function () {
                 var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
                 var wheelThickness = radius * .2;

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/gui/babylon.gui.min.js


+ 5 - 0
gui/src/controls/button.ts

@@ -9,6 +9,7 @@ module BABYLON.GUI {
 
         constructor(public name?: string) {
             super(name);
+          
             this.thickness = 1;
             this.isPointerBlocker = true;
 
@@ -31,6 +32,10 @@ module BABYLON.GUI {
             }                      
         }
 
+        protected _getTypeName(): string {
+            return "Button";
+        }
+
         // While being a container, the button behaves like a control.
         public _processPicking(x: number, y: number, type: number): boolean {
             if (!this.contains(x, y)) {

+ 4 - 1
gui/src/controls/checkbox.ts

@@ -69,10 +69,13 @@ module BABYLON.GUI {
 
         constructor(public name?: string) {
             super(name);
-
             this.isPointerBlocker = true;
         }
 
+        protected _getTypeName(): string {
+            return "CheckBox";
+        }
+        
         public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
             context.save();
 

+ 4 - 0
gui/src/controls/colorpicker.ts

@@ -51,6 +51,10 @@ module BABYLON.GUI {
             this.value =  Color3.White();
         }
 
+        protected _getTypeName(): string {
+            return "ColorPicker";
+        }        
+
         private _updateSquareProps():void {
             var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height)*.5;
             var wheelThickness = radius*.2;

+ 16 - 2
gui/src/controls/container.ts

@@ -27,7 +27,11 @@ module BABYLON.GUI {
             super(name);
         }
 
-        public getChildByName(name: string) {
+        protected _getTypeName(): string {
+            return "Container";
+        }           
+
+        public getChildByName(name: string): Control {
             for (var child of this._children) {
                 if (child.name === name) {
                     return child;
@@ -35,7 +39,17 @@ module BABYLON.GUI {
             }
 
             return null;
-        }
+        }       
+
+        public getChildByType(name: string, type: string): Control {
+            for (var child of this._children) {
+                if (child.typeName === type) {
+                    return child;
+                }
+            }
+
+            return null;
+        }            
 
         public containsControl(control: Control): boolean {
             return this._children.indexOf(control) !== -1;

+ 8 - 0
gui/src/controls/control.ts

@@ -52,6 +52,10 @@ module BABYLON.GUI {
         
         // Properties
 
+        public get typeName(): string {
+            return this._getTypeName();
+        }
+
         /**
         * An event triggered when the pointer move over the control.
         * @type {BABYLON.Observable}
@@ -391,6 +395,10 @@ module BABYLON.GUI {
         constructor(public name?: string) {
         }
 
+        protected _getTypeName(): string {
+            return "Control";
+        }
+
         public linkWithMesh(mesh: AbstractMesh): void {
             if (!this._host || this._root !== this._host._rootContainer) {
                 Tools.Error("Cannot link a control to a mesh if the control is not at root level");

+ 4 - 0
gui/src/controls/ellipse.ts

@@ -21,6 +21,10 @@ module BABYLON.GUI {
             super(name);
         }
 
+        protected _getTypeName(): string {
+            return "Ellipse";
+        }              
+
         protected _localDraw(context: CanvasRenderingContext2D): void {
             context.save();
 

+ 4 - 0
gui/src/controls/image.ts

@@ -94,6 +94,10 @@ module BABYLON.GUI {
             this.source = url;
         }
 
+        protected _getTypeName(): string {
+            return "Image";
+        }              
+
         public synchronizeSizeWithContent() {
             if (!this._loaded) {
                 return;

+ 4 - 0
gui/src/controls/line.ts

@@ -142,6 +142,10 @@ module BABYLON.GUI {
             this._verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;            
         }
 
+        protected _getTypeName(): string {
+            return "Line";
+        }              
+
         public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
             context.save();
 

+ 4 - 0
gui/src/controls/radioButton.ts

@@ -92,6 +92,10 @@ module BABYLON.GUI {
             this.isPointerBlocker = true;
         }
 
+        protected _getTypeName(): string {
+            return "RadioButton";
+        }              
+
         public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
             context.save();
 

+ 4 - 0
gui/src/controls/rectangle.ts

@@ -39,6 +39,10 @@ module BABYLON.GUI {
             super(name);
         }
 
+        protected _getTypeName(): string {
+            return "Rectangle";
+        }              
+
         protected _localDraw(context: CanvasRenderingContext2D): void {
             context.save();
 

+ 4 - 0
gui/src/controls/slider.ts

@@ -120,6 +120,10 @@ module BABYLON.GUI {
             this.isPointerBlocker = true;
         }
 
+        protected _getTypeName(): string {
+            return "Slider";
+        }              
+
         public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
             context.save();
 

+ 4 - 0
gui/src/controls/stackPanel.ts

@@ -22,6 +22,10 @@ module BABYLON.GUI {
             super(name);
         }
 
+        protected _getTypeName(): string {
+            return "StackPanel";
+        }              
+
         protected _preMeasure(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
             var stack = 0;
             for (var child of this._children) {

+ 4 - 0
gui/src/controls/textBlock.ts

@@ -67,6 +67,10 @@ module BABYLON.GUI {
             this.text = text;
         }
 
+        protected _getTypeName(): string {
+            return "TextBlock";
+        }              
+
         private _drawText(text: string, textWidth: number, y: number, context: CanvasRenderingContext2D): void {
             var width = this._currentMeasure.width;
             var x = 0;