Переглянути джерело

Merge pull request #5796 from TrevorDev/invalidateRectShadows

expand invalidate rect with shadows
David Catuhe 6 роки тому
батько
коміт
fce3a7cfdc
2 змінених файлів з 27 додано та 7 видалено
  1. 1 1
      dist/preview release/what's new.md
  2. 26 6
      gui/src/2D/controls/control.ts

+ 1 - 1
dist/preview release/what's new.md

@@ -23,7 +23,7 @@
   - Added new [ScrollViewer](https://doc.babylonjs.com/how_to/scrollviewer) with mouse wheel scrolling for larger containers to be viewed using Sliders ([JohnK](https://github.com/BabylonJSGuide/) / [Deltakosh](https://github.com/deltakosh))
   - Moved to a measure / draw mechanism ([Deltakosh](https://github.com/deltakosh))
   - Added support for [nine patch stretch](https://www.babylonjs-playground.com/#G5H9IN#2) mode for images. ([Deltakosh](https://github.com/deltakosh))
-  - InvalidateRect added to AdvancedDynamicTexture to improve perf for heavily populated GUIs ([TrevorDev](https://github.com/TrevorDev))
+  - InvalidateRect added to AdvancedDynamicTexture to improve perf for heavily populated GUIs, works with shadows ([TrevorDev](https://github.com/TrevorDev))
 
 ## Updates
 

+ 26 - 6
gui/src/2D/controls/control.ts

@@ -1118,12 +1118,32 @@ export class Control {
             // the previous measure is used to properly clear a control that is scaled down
             Measure.CombineToRef(this._tmpMeasureA, this._prevCurrentMeasureTransformedIntoGlobalSpace, this._tmpMeasureA);
 
-            this.host.invalidateRect(
-                Math.floor(this._tmpMeasureA.left),
-                Math.floor(this._tmpMeasureA.top),
-                Math.ceil(this._tmpMeasureA.left + this._tmpMeasureA.width),
-                Math.ceil(this._tmpMeasureA.top + this._tmpMeasureA.height),
-            );
+            if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
+                // Expand rect based on shadows
+                var shadowOffsetX = this.shadowOffsetX;
+                var shadowOffsetY = this.shadowOffsetY;
+                var shadowBlur = this.shadowBlur;
+
+                var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
+                var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
+                var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
+                var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
+
+                this.host.invalidateRect(
+                    Math.floor(this._tmpMeasureA.left + leftShadowOffset),
+                    Math.floor(this._tmpMeasureA.top + topShadowOffset),
+                    Math.ceil(this._tmpMeasureA.left + this._tmpMeasureA.width + rightShadowOffset),
+                    Math.ceil(this._tmpMeasureA.top + this._tmpMeasureA.height + bottomShadowOffset),
+                );
+            } else {
+                this.host.invalidateRect(
+                    Math.floor(this._tmpMeasureA.left),
+                    Math.floor(this._tmpMeasureA.top),
+                    Math.ceil(this._tmpMeasureA.left + this._tmpMeasureA.width),
+                    Math.ceil(this._tmpMeasureA.top + this._tmpMeasureA.height),
+                );
+            }
+
         }
     }