Browse Source

Merge pull request #1590 from Temechon/master

Inspector - a lot of bug fixes
Raanan Weber 8 years ago
parent
commit
5a82a21449

File diff suppressed because it is too large
+ 84 - 79
dist/preview release/inspector/babylon.inspector.bundle.js


+ 9 - 3
dist/preview release/inspector/babylon.inspector.css

@@ -19,9 +19,9 @@
  */ }
   .insp-wrapper .gutter {
     background-color: #2c2c2c; }
-    .insp-wrapper .gutter.gutter-vertical {
+    .insp-wrapper .gutter.gutter-vertical:not(.blocked) {
       cursor: ns-resize; }
-    .insp-wrapper .gutter.gutter-horizontal {
+    .insp-wrapper .gutter.gutter-horizontal:not(.blocked) {
       cursor: ew-resize; }
   .insp-wrapper .insp-right-panel {
     width: 750px;
@@ -82,6 +82,8 @@
       color: #5db0d7; }
   .insp-wrapper .tab-panel {
     height: 100%; }
+    .insp-wrapper .tab-panel.searchable {
+      height: calc(100% - 30px - 10px); }
     .insp-wrapper .tab-panel .scene-actions {
       overflow-y: auto; }
       .insp-wrapper .tab-panel .scene-actions .actions-title {
@@ -167,6 +169,9 @@
       margin-bottom: 10px; }
   .insp-wrapper .tab-panel.stats-panel {
     overflow-y: auto; }
+  .insp-wrapper .tab-panel .stats-fps {
+    font-weight: 600;
+    color: #f29766; }
   .insp-wrapper .tab-panel .stat-title1 {
     font-size: 1.1em;
     padding: 10px; }
@@ -266,7 +271,8 @@
     .insp-wrapper .insp-details .header-row {
       background-color: #2c2c2c;
       color: #ccc;
-      width: 100%; }
+      width: 100%;
+      max-width: 100%; }
       .insp-wrapper .insp-details .header-row > * {
         color: #ccc !important;
         padding: 5px 0 5px 5px !important;

+ 15 - 11
dist/preview release/inspector/babylon.inspector.d.ts

@@ -32,8 +32,8 @@ declare module INSPECTOR {
         private _getRelativeParent(elem, lookForAbsoluteOrRelative?);
         /** Build the inspector panel in the given HTML element */
         private _buildInspector(parent);
-        scene: BABYLON.Scene;
-        popupMode: boolean;
+        readonly scene: BABYLON.Scene;
+        readonly popupMode: boolean;
         /**
          * Filter the list of item present in the tree.
          * All item returned should have the given filter contained in the item id.
@@ -170,11 +170,11 @@ declare module INSPECTOR {
         /** Returns the list of properties to be displayed for this adapter */
         abstract getProperties(): Array<PropertyLine>;
         /** Returns the actual object behind this adapter */
-        actualObject: any;
+        readonly actualObject: any;
         /** Returns true if the given object correspond to this  */
         correspondsTo(obj: any): boolean;
         /** Returns the adapter unique name */
-        name: string;
+        readonly name: string;
         /** Returns the list of tools available for this adapter */
         abstract getTools(): Array<AbstractTreeTool>;
         /** Should be overriden in subclasses */
@@ -308,9 +308,9 @@ declare module INSPECTOR {
         /** The obj this property refers to */
         private _obj;
         constructor(prop: string, obj: any);
-        name: string;
+        readonly name: string;
         value: any;
-        type: string;
+        readonly type: string;
         obj: any;
     }
 }
@@ -374,9 +374,9 @@ declare module INSPECTOR {
          * (example : mesh.position = new BABYLON.Vector3 ; the original vector3 object is deleted from the mesh).
         */
         updateObject(): any;
-        name: string;
-        value: any;
-        type: string;
+        readonly name: string;
+        readonly value: any;
+        readonly type: string;
         /**
          * Creates elements that wil be displayed on a property line, depending on the
          * type of the property.
@@ -519,6 +519,10 @@ declare module INSPECTOR {
          */
         private static _CheckIfTypeExists(type);
         /**
+         * Returns true if the user browser is edge.
+         */
+        static IsBrowserEdge(): boolean;
+        /**
          * Returns the name of the type of the given object, where the name
          * is in PROPERTIES constant.
          * Returns 'Undefined' if no type exists for this object
@@ -751,7 +755,7 @@ declare module INSPECTOR {
         switchMeshTab(mesh?: BABYLON.AbstractMesh): void;
         /** Returns the active tab */
         getActiveTab(): Tab;
-        inspector: Inspector;
+        readonly inspector: Inspector;
         /**
          * Returns the total width in pixel of the tabbar,
          * that corresponds to the sum of the width of each visible tab + toolbar width
@@ -853,7 +857,7 @@ declare module INSPECTOR {
         private _lineContent;
         constructor(tab: PropertyTab, obj: Adapter);
         /** Returns the item ID == its adapter ID */
-        id: string;
+        readonly id: string;
         /** Add the given item as a child of this one */
         add(child: TreeItem): void;
         /**

File diff suppressed because it is too large
+ 402 - 351
dist/preview release/inspector/babylon.inspector.js


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


+ 81 - 76
dist/preview release/split.js

@@ -134,6 +134,7 @@ var global = this
         paddingB = 'paddingBottom'
         if (!options.cursor) options.cursor = 'ns-resize'
     }
+    if (options.blockDrag) gutterClass += ' blocked'
 
     // 3. Define the dragging helper functions, and a few helpers to go with them.
     // Each helper is bound to a pair object that contains it's metadata. This
@@ -149,103 +150,107 @@ var global = this
     // startDragging calls `calculateSizes` to store the inital size in the pair object.
     // It also adds event listeners for mouse/touch events,
     // and prevents selection while dragging so avoid the selecting text.
-    var startDragging = function (e) {
-            // Alias frequently used variables to save space. 200 bytes.
-            var self = this
-              , a = self.a
-              , b = self.b
-
-            // Call the onDragStart callback.
-            if (!self.dragging && options.onDragStart) {
-                options.onDragStart()
-            }
+        var startDragging = function (e) {
+            if (!options.blockDrag) {
+                // Alias frequently used variables to save space. 200 bytes.
+                var self = this
+                , a = self.a
+                , b = self.b
+
+                // Call the onDragStart callback.
+                if (!self.dragging && options.onDragStart) {
+                    options.onDragStart()
+                }
 
-            // Don't actually drag the element. We emulate that in the drag function.
-            e.preventDefault()
+                // Don't actually drag the element. We emulate that in the drag function.
+                e.preventDefault()
 
-            // Set the dragging property of the pair object.
-            self.dragging = true
+                // Set the dragging property of the pair object.
+                self.dragging = true
 
-            // Create two event listeners bound to the same pair object and store
-            // them in the pair object.
-            self.move = drag.bind(self)
-            self.stop = stopDragging.bind(self)
+                // Create two event listeners bound to the same pair object and store
+                // them in the pair object.
+                self.move = drag.bind(self)
+                self.stop = stopDragging.bind(self)
 
-            // All the binding. `window` gets the stop events in case we drag out of the elements.
-            global[addEventListener]('mouseup', self.stop)
-            global[addEventListener]('touchend', self.stop)
-            global[addEventListener]('touchcancel', self.stop)
+                // All the binding. `window` gets the stop events in case we drag out of the elements.
+                global[addEventListener]('mouseup', self.stop)
+                global[addEventListener]('touchend', self.stop)
+                global[addEventListener]('touchcancel', self.stop)
 
-            self.parent[addEventListener]('mousemove', self.move)
-            self.parent[addEventListener]('touchmove', self.move)
+                self.parent[addEventListener]('mousemove', self.move)
+                self.parent[addEventListener]('touchmove', self.move)
 
-            // Disable selection. Disable!
-            a[addEventListener]('selectstart', noop)
-            a[addEventListener]('dragstart', noop)
-            b[addEventListener]('selectstart', noop)
-            b[addEventListener]('dragstart', noop)
+                // Disable selection. Disable!
+                a[addEventListener]('selectstart', noop)
+                a[addEventListener]('dragstart', noop)
+                b[addEventListener]('selectstart', noop)
+                b[addEventListener]('dragstart', noop)
 
-            a.style.userSelect = 'none'
-            a.style.webkitUserSelect = 'none'
-            a.style.MozUserSelect = 'none'
-            a.style.pointerEvents = 'none'
+                a.style.userSelect = 'none'
+                a.style.webkitUserSelect = 'none'
+                a.style.MozUserSelect = 'none'
+                a.style.pointerEvents = 'none'
 
-            b.style.userSelect = 'none'
-            b.style.webkitUserSelect = 'none'
-            b.style.MozUserSelect = 'none'
-            b.style.pointerEvents = 'none'
+                b.style.userSelect = 'none'
+                b.style.webkitUserSelect = 'none'
+                b.style.MozUserSelect = 'none'
+                b.style.pointerEvents = 'none'
 
-            // Set the cursor, both on the gutter and the parent element.
-            // Doing only a, b and gutter causes flickering.
-            self.gutter.style.cursor = options.cursor
-            self.parent.style.cursor = options.cursor
+                // Set the cursor, both on the gutter and the parent element.
+                // Doing only a, b and gutter causes flickering.
+                self.gutter.style.cursor = options.cursor
+                self.parent.style.cursor = options.cursor
 
-            // Cache the initial sizes of the pair.
-            calculateSizes.call(self)
+                // Cache the initial sizes of the pair.
+                calculateSizes.call(self)
+            }
         }
 
       // stopDragging is very similar to startDragging in reverse.
-      , stopDragging = function () {
-            var self = this
-              , a = self.a
-              , b = self.b
-
-            if (self.dragging && options.onDragEnd) {
-                options.onDragEnd()
-            }
+      , stopDragging = function () {          
+            if (!options.blockDrag) {
+                var self = this
+                , a = self.a
+                , b = self.b
+
+                if (self.dragging && options.onDragEnd) {
+                    options.onDragEnd()
+                }
 
-            self.dragging = false
+                self.dragging = false
 
-            // Remove the stored event listeners. This is why we store them.
-            global[removeEventListener]('mouseup', self.stop)
-            global[removeEventListener]('touchend', self.stop)
-            global[removeEventListener]('touchcancel', self.stop)
+                // Remove the stored event listeners. This is why we store them.
+                global[removeEventListener]('mouseup', self.stop)
+                global[removeEventListener]('touchend', self.stop)
+                global[removeEventListener]('touchcancel', self.stop)
 
-            self.parent[removeEventListener]('mousemove', self.move)
-            self.parent[removeEventListener]('touchmove', self.move)
+                self.parent[removeEventListener]('mousemove', self.move)
+                self.parent[removeEventListener]('touchmove', self.move)
 
-            // Delete them once they are removed. I think this makes a difference
-            // in memory usage with a lot of splits on one page. But I don't know for sure.
-            delete self.stop
-            delete self.move
+                // Delete them once they are removed. I think this makes a difference
+                // in memory usage with a lot of splits on one page. But I don't know for sure.
+                delete self.stop
+                delete self.move
 
-            a[removeEventListener]('selectstart', noop)
-            a[removeEventListener]('dragstart', noop)
-            b[removeEventListener]('selectstart', noop)
-            b[removeEventListener]('dragstart', noop)
+                a[removeEventListener]('selectstart', noop)
+                a[removeEventListener]('dragstart', noop)
+                b[removeEventListener]('selectstart', noop)
+                b[removeEventListener]('dragstart', noop)
 
-            a.style.userSelect = ''
-            a.style.webkitUserSelect = ''
-            a.style.MozUserSelect = ''
-            a.style.pointerEvents = ''
+                a.style.userSelect = ''
+                a.style.webkitUserSelect = ''
+                a.style.MozUserSelect = ''
+                a.style.pointerEvents = ''
 
-            b.style.userSelect = ''
-            b.style.webkitUserSelect = ''
-            b.style.MozUserSelect = ''
-            b.style.pointerEvents = ''
+                b.style.userSelect = ''
+                b.style.webkitUserSelect = ''
+                b.style.MozUserSelect = ''
+                b.style.pointerEvents = ''
 
-            self.gutter.style.cursor = ''
-            self.parent.style.cursor = ''
+                self.gutter.style.cursor = ''
+                self.parent.style.cursor = ''
+            }
         }
 
       // drag, where all the magic happens. The logic is really quite simple:

+ 1 - 1
inspector/index.html

@@ -42,7 +42,7 @@
         #game-canvas {
             position:absolute;
             width:100%;
-            height:100%; 
+            height:650px; 
             top:0;
             left : 150px;
         }

+ 1 - 1
inspector/sass/_detailPanel.scss

@@ -71,7 +71,7 @@
     background-color: $background-lighter; 
     color           : $color;
     width           : 100%;
-    // Max-width is set in js
+    max-width       : 100%;
     
     // Special definition for text color: the color is the default one
     // All header columns

+ 3 - 0
inspector/sass/_tabPanel.scss

@@ -1,5 +1,8 @@
 .tab-panel {
     height:100%;     
+    &.searchable {
+        height:calc(100% - #{$searchbar-height} - 10px);   
+    }  
     
     .scene-actions {
         overflow-y: auto;

+ 2 - 2
inspector/sass/main.scss

@@ -6,10 +6,10 @@
   // Style for resize bar
   .gutter {
     background-color: $background-lighter;
-    &.gutter-vertical {
+    &.gutter-vertical:not(.blocked) {
       cursor        : ns-resize;
     }
-    &.gutter-horizontal {
+    &.gutter-horizontal:not(.blocked) {
       cursor        : ew-resize;
     }
   }

+ 5 - 0
inspector/sass/tabs/_statsTab.scss

@@ -3,6 +3,11 @@
     &.stats-panel {
         overflow-y      : auto;
     }
+    
+    .stats-fps {
+        font-weight:600;
+        color:$color-top;
+    }
 
     .stat-title1 {        
         font-size       : 1.1em;

+ 53 - 36
inspector/src/Inspector.ts

@@ -35,8 +35,8 @@ module INSPECTOR {
             Inspector.DOCUMENT = window.document;   
             Inspector.WINDOW = window;                       
             
-            // POPUP MODE if parent is defined
-            if (popup) {    
+            // POPUP MODE
+            if (popup) { 
                 // Build the inspector in the given parent
                 this.openPopup(true);// set to true in order to NOT dispose the inspector (done in openPopup), as it's not existing yet
             } else {        
@@ -81,10 +81,20 @@ module INSPECTOR {
                 for (let prop in this._canvasStyle) {
                     this._c2diwrapper.style[prop] = this._canvasStyle[prop];
                 }
+                
                 // Convert wrapper size in % (because getComputedStyle returns px only)
                 let widthPx        = parseFloat(canvasComputedStyle.width.substr(0,canvasComputedStyle.width.length-2)) || 0;
                 let heightPx       = parseFloat(canvasComputedStyle.height.substr(0,canvasComputedStyle.height.length-2)) || 0;
 
+                // If the canvas position is absolute, restrain the wrapper width to the window width + left positionning
+                if (canvasComputedStyle.position === "absolute" || canvasComputedStyle.position === "relative") {
+                    // compute only left as it takes predominance if right is also specified (and it will be for the wrapper)
+                    let leftPx = parseFloat(canvasComputedStyle.left.substr(0,canvasComputedStyle.left.length-2)) || 0;
+                    if (widthPx + leftPx >= Inspector.WINDOW.innerWidth) {
+                        this._c2diwrapper.style.maxWidth = `${widthPx-leftPx}px`;
+                    }
+                }
+                
                 // Check if the parent of the canvas is the body page. If yes, the size ratio is computed
                 let parent = this._getRelativeParent(canvas);
 
@@ -137,8 +147,10 @@ module INSPECTOR {
                 Helpers.SEND_EVENT('resize');
             }
 
-            // Refresh the inspector
-            this.refresh();
+            // Refresh the inspector if the browser is not edge
+            if (!Helpers.IsBrowserEdge()) {
+                this.refresh();
+            }
         }
         
         /**
@@ -249,38 +261,43 @@ module INSPECTOR {
          * Set 'firstTime' to true if there is no inspector created beforehands
          */
         public openPopup(firstTime?:boolean) {    
-            // Create popup
-            let popup = window.open('', 'Babylon.js INSPECTOR', 'toolbar=no,resizable=yes,menubar=no,width=750,height=1000');
-            popup.document.title = 'Babylon.js INSPECTOR';
-            // Get the inspector style      
-            let styles = Inspector.DOCUMENT.querySelectorAll('style');
-            for (let s = 0; s<styles.length; s++) {
-                popup.document.body.appendChild(styles[s].cloneNode(true));              
-            } 
-            let links = document.querySelectorAll('link');
-            for (let l = 0; l<links.length; l++) {
-                let link  = popup.document.createElement("link");
-                link.rel  = "stylesheet";
-                link.href = (links[l] as HTMLLinkElement).href;
-                popup.document.head.appendChild(link);              
-            } 
-            // Dispose the right panel if existing
-            if (!firstTime) {
-                this.dispose();
-            }
-            // set the mode as popup
-            this._popupMode = true;
-            // Save the HTML document
-            Inspector.DOCUMENT = popup.document;
-            Inspector.WINDOW = popup;
-            // Build the inspector wrapper
-            this._c2diwrapper  = Helpers.CreateDiv('insp-wrapper', popup.document.body);
-            // add inspector     
-            let inspector      = Helpers.CreateDiv('insp-right-panel', this._c2diwrapper);
-            // and build it in the popup  
-            this._buildInspector(inspector); 
-            // Rebuild it
-            this.refresh();              
+            
+            if (Helpers.IsBrowserEdge()) {
+                console.warn('Inspector - Popup mode is disabled in Edge, as the popup DOM cannot be updated from the main window for security reasons');
+            } else {
+                // Create popup
+                let popup = window.open('', 'Babylon.js INSPECTOR', 'toolbar=no,resizable=yes,menubar=no,width=750,height=1000');
+                popup.document.title = 'Babylon.js INSPECTOR';
+                // Get the inspector style      
+                let styles = Inspector.DOCUMENT.querySelectorAll('style');
+                for (let s = 0; s<styles.length; s++) {
+                    popup.document.body.appendChild(styles[s].cloneNode(true));              
+                } 
+                let links = document.querySelectorAll('link');
+                for (let l = 0; l<links.length; l++) {
+                    let link  = popup.document.createElement("link");
+                    link.rel  = "stylesheet";
+                    link.href = (links[l] as HTMLLinkElement).href;
+                    popup.document.head.appendChild(link);              
+                } 
+                // Dispose the right panel if existing
+                if (!firstTime) {
+                    this.dispose();
+                }
+                // set the mode as popup
+                this._popupMode = true;
+                // Save the HTML document
+                Inspector.DOCUMENT = popup.document;
+                Inspector.WINDOW = popup;
+                // Build the inspector wrapper
+                this._c2diwrapper  = Helpers.CreateDiv('insp-wrapper', popup.document.body);
+                // add inspector     
+                let inspector      = Helpers.CreateDiv('insp-right-panel', this._c2diwrapper);
+                // and build it in the popup  
+                this._buildInspector(inspector); 
+                // Rebuild it
+                this.refresh(); 
+            }             
         }
     }
 }

+ 0 - 4
inspector/src/details/DetailPanel.ts

@@ -37,10 +37,6 @@
             this._createHeaderRow();
             this._div.appendChild(this._headerRow);
             
-            Inspector.WINDOW.addEventListener('resize', (e) => {
-                // adapt the header row max width according to its parent size;
-                this._headerRow.style.maxWidth = this._headerRow.parentElement.clientWidth+'px';
-            });
         }
         
         /** Updates the HTML of the detail panel */

+ 9 - 0
inspector/src/helpers/Helpers.ts

@@ -36,6 +36,15 @@ module INSPECTOR {
             } 
             return false;
         }
+        
+        /**
+         * Returns true if the user browser is edge.
+         */
+        public static IsBrowserEdge() : boolean {
+            //Detect if we are running on a faulty buggy OS.
+            var regexp = /Edge/
+            return regexp.test(navigator.userAgent);
+        }
 
         /** 
          * Returns the name of the type of the given object, where the name 

+ 2 - 1
inspector/src/lib.d.ts

@@ -9,7 +9,8 @@ interface ISplit {
 
 
 declare function Split (element : Array<HTMLElement> | Array<string>, options:{
-    sizes?      : Array<number>, 
+    sizes?      : Array<number>,
+    blockDrag?  : boolean, 
     minSize?    : number,
     gutterSize? : number,
     snapOffset? : number,

+ 0 - 1
inspector/src/scheduler/Scheduler.ts

@@ -22,7 +22,6 @@ module INSPECTOR {
         public static getInstance() : Scheduler {
             if (!Scheduler._instance) {
                 Scheduler._instance = new Scheduler();
-                console.log('create '); 
             }
             return Scheduler._instance;
         }

+ 5 - 1
inspector/src/tabs/PropertyTab.ts

@@ -23,6 +23,7 @@ module INSPECTOR{
             
             // Build the properties panel : a div that will contains the tree and the detail panel
             this._panel = Helpers.CreateDiv('tab-panel') as HTMLDivElement;
+            this._panel.classList.add('searchable');
             
             // Search bar
             this._searchBar = new SearchBar(this);
@@ -36,7 +37,10 @@ module INSPECTOR{
             this._detailsPanel = new DetailPanel();
             this._panel.appendChild(this._detailsPanel.toHtml());
             
-            Split([this._treePanel, this._detailsPanel.toHtml()], {direction:'vertical'});       
+            Split([this._treePanel, this._detailsPanel.toHtml()], {
+                blockDrag : this._inspector.popupMode,
+                direction:'vertical'
+            });       
             
             this.update();   
         }

+ 1 - 0
inspector/src/tabs/SceneTab.ts

@@ -32,6 +32,7 @@ module INSPECTOR {
             this._detailsPanel.details = details;
             
             Split([this._actions, this._detailsPanel.toHtml()], {  
+                blockDrag : this._inspector.popupMode,
                 sizes:[50, 50],
                 direction:'vertical'
             });  

+ 1 - 0
inspector/src/tabs/ShaderTab.ts

@@ -25,6 +25,7 @@ module INSPECTOR {
             Helpers.LoadScript();
             
             Split([this._vertexPanel, this._fragmentPanel], {
+                blockDrag : this._inspector.popupMode,
                 sizes:[50, 50],
                 direction:'vertical'}
             );  

+ 11 - 2
inspector/src/tabs/StatsTab.ts

@@ -30,8 +30,17 @@ module INSPECTOR {
             this._panel.classList.add("stats-panel")
             
             let title               = Helpers.CreateDiv('stat-title1', this._panel);
-            title.innerHTML         = "Babylon.js v" + BABYLON.Engine.Version + ' - <b>' +BABYLON.Tools.Format(this._inspector.scene.getEngine().getFps(), 0) + " fps</b>";
-            
+            let fpsSpan             = Helpers.CreateElement('span', 'stats-fps');
+            this._updatableProperties.push({ 
+                elem:fpsSpan, 
+                updateFct:() => { return BABYLON.Tools.Format(this._inspector.scene.getEngine().getFps(), 0) + " fps"}
+            });
+                
+            let versionSpan = Helpers.CreateElement('span');
+            versionSpan.textContent = `Babylon.js v${BABYLON.Engine.Version} - `;
+            title.appendChild(versionSpan);
+            title.appendChild(fpsSpan);
+                        
             this._updateLoopHandler = this._update.bind(this);
 
             // Count block

+ 3 - 2
inspector/src/tools/Toolbar.ts

@@ -26,8 +26,9 @@
             // Pick object
             this._tools.push(new PickTool(this._div, this._inspector));
             
-            // Add the popup mode only if the inspector is not in popup mode
-            if (!this._inspector.popupMode) {
+            // Add the popup mode only if the inspector is not in popup mode and if the brower is not edge
+            // Edge is 
+            if (!this._inspector.popupMode && !Helpers.IsBrowserEdge()) {
                 this._tools.push(new PopupTool(this._div, this._inspector));
             }
             // Pause schedule