Преглед изворни кода

expand invalidate rect with shadows

Trevor Baron пре 6 година
родитељ
комит
17bf06203f
2 измењених фајлова са 15 додато и 5 уклоњено
  1. 1 1
      dist/preview release/what's new.md
  2. 14 4
      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
 

+ 14 - 4
gui/src/2D/controls/control.ts

@@ -1118,11 +1118,21 @@ 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);
 
+            // 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),
-                Math.floor(this._tmpMeasureA.top),
-                Math.ceil(this._tmpMeasureA.left + this._tmpMeasureA.width),
-                Math.ceil(this._tmpMeasureA.top + this._tmpMeasureA.height),
+                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),
             );
         }
     }