Example #1
0
 private void SetLayoutOffset(Vector offset, Size oldRenderSize)
 {
     if (!this.AreTransformsClean || !DoubleUtil.AreClose(this.RenderSize, oldRenderSize))
       {
     Transform directionTransform = this.GetFlowDirectionTransform();
     Transform transform = this.RenderTransform;
     if (transform == Transform.Identity)
       transform = (Transform) null;
     FrameworkElement.LayoutTransformData layoutTransformData = FrameworkElement.LayoutTransformDataField.GetValue((DependencyObject) this);
     TransformGroup transformGroup = (TransformGroup) null;
     if (directionTransform != null || transform != null || layoutTransformData != null)
     {
       transformGroup = new TransformGroup();
       transformGroup.CanBeInheritanceContext = false;
       transformGroup.Children.CanBeInheritanceContext = false;
       if (directionTransform != null)
     transformGroup.Children.Add(directionTransform);
       if (layoutTransformData != null)
       {
     transformGroup.Children.Add(layoutTransformData.Transform);
     FrameworkElement.MinMax minMax = new FrameworkElement.MinMax(this);
     Size renderSize = this.RenderSize;
     if (double.IsPositiveInfinity(minMax.maxWidth))
     {
       double width = renderSize.Width;
     }
     if (double.IsPositiveInfinity(minMax.maxHeight))
     {
       double height = renderSize.Height;
     }
     renderSize.Width = Math.Min(renderSize.Width, minMax.maxWidth);
     renderSize.Height = Math.Min(renderSize.Height, minMax.maxHeight);
     Rect rect = Rect.Transform(new Rect(renderSize), layoutTransformData.Transform.Value);
     transformGroup.Children.Add((Transform) new TranslateTransform(-rect.X, -rect.Y));
       }
       if (transform != null)
       {
     Point renderTransformOrigin = this.GetRenderTransformOrigin();
     bool flag = renderTransformOrigin.X != 0.0 || renderTransformOrigin.Y != 0.0;
     if (flag)
     {
       TranslateTransform translateTransform = new TranslateTransform(-renderTransformOrigin.X, -renderTransformOrigin.Y);
       translateTransform.Freeze();
       transformGroup.Children.Add((Transform) translateTransform);
     }
     transformGroup.Children.Add(transform);
     if (flag)
     {
       TranslateTransform translateTransform = new TranslateTransform(renderTransformOrigin.X, renderTransformOrigin.Y);
       translateTransform.Freeze();
       transformGroup.Children.Add((Transform) translateTransform);
     }
       }
     }
     this.VisualTransform = (Transform) transformGroup;
     this.AreTransformsClean = true;
       }
       Vector visualOffset = this.VisualOffset;
       if (DoubleUtil.AreClose(visualOffset.X, offset.X) && DoubleUtil.AreClose(visualOffset.Y, offset.Y))
     return;
       this.VisualOffset = offset;
 }
Example #2
0
 protected override Geometry GetLayoutClip(Size layoutSlotSize)
 {
     bool useLayoutRounding = this.UseLayoutRounding;
       if (useLayoutRounding && !this.CheckFlagsAnd(VisualFlags.UseLayoutRounding))
     this.SetFlags(true, VisualFlags.UseLayoutRounding);
       if (!this.NeedsClipBounds && !this.ClipToBounds)
     return base.GetLayoutClip(layoutSlotSize);
       FrameworkElement.MinMax minMax = new FrameworkElement.MinMax(this);
       Size renderSize = this.RenderSize;
       double width = double.IsPositiveInfinity(minMax.maxWidth) ? renderSize.Width : minMax.maxWidth;
       double height = double.IsPositiveInfinity(minMax.maxHeight) ? renderSize.Height : minMax.maxHeight;
       bool flag1 = this.ClipToBounds || (DoubleUtil.LessThan(width, renderSize.Width) || DoubleUtil.LessThan(height, renderSize.Height));
       renderSize.Width = Math.Min(renderSize.Width, minMax.maxWidth);
       renderSize.Height = Math.Min(renderSize.Height, minMax.maxHeight);
       FrameworkElement.LayoutTransformData layoutTransformData = FrameworkElement.LayoutTransformDataField.GetValue((DependencyObject) this);
       Rect rect1 = new Rect();
       if (layoutTransformData != null)
       {
     rect1 = Rect.Transform(new Rect(0.0, 0.0, renderSize.Width, renderSize.Height), layoutTransformData.Transform.Value);
     renderSize.Width = rect1.Width;
     renderSize.Height = rect1.Height;
       }
       Thickness margin = this.Margin;
       double num1 = margin.Left + margin.Right;
       double num2 = margin.Top + margin.Bottom;
       Size clientSize = new Size(Math.Max(0.0, layoutSlotSize.Width - num1), Math.Max(0.0, layoutSlotSize.Height - num2));
       bool flag2 = this.ClipToBounds || DoubleUtil.LessThan(clientSize.Width, renderSize.Width) || DoubleUtil.LessThan(clientSize.Height, renderSize.Height);
       Transform directionTransform = this.GetFlowDirectionTransform();
       if (flag1 && !flag2)
       {
     Rect rect2 = new Rect(0.0, 0.0, width, height);
     if (useLayoutRounding)
       rect2 = UIElement.RoundLayoutRect(rect2, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     RectangleGeometry rectangleGeometry = new RectangleGeometry(rect2);
     if (directionTransform != null)
       rectangleGeometry.Transform = directionTransform;
     return (Geometry) rectangleGeometry;
       }
       else
       {
     if (!flag2)
       return (Geometry) null;
     Vector alignmentOffset = this.ComputeAlignmentOffset(clientSize, renderSize);
     if (layoutTransformData != null)
     {
       Rect rect2 = new Rect(-alignmentOffset.X + rect1.X, -alignmentOffset.Y + rect1.Y, clientSize.Width, clientSize.Height);
       if (useLayoutRounding)
     rect2 = UIElement.RoundLayoutRect(rect2, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
       RectangleGeometry rectangleGeometry = new RectangleGeometry(rect2);
       Matrix matrix = layoutTransformData.Transform.Value;
       if (matrix.HasInverse)
       {
     matrix.Invert();
     rectangleGeometry.Transform = (Transform) new MatrixTransform(matrix);
       }
       if (flag1)
       {
     Rect rect3 = new Rect(0.0, 0.0, width, height);
     if (useLayoutRounding)
       rect3 = UIElement.RoundLayoutRect(rect3, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     PathGeometry pathGeometry = Geometry.Combine((Geometry) new RectangleGeometry(rect3), (Geometry) rectangleGeometry, GeometryCombineMode.Intersect, (Transform) null);
     if (directionTransform != null)
       pathGeometry.Transform = directionTransform;
     return (Geometry) pathGeometry;
       }
       else
       {
     if (directionTransform != null)
     {
       if (rectangleGeometry.Transform != null)
         rectangleGeometry.Transform = (Transform) new MatrixTransform(rectangleGeometry.Transform.Value * directionTransform.Value);
       else
         rectangleGeometry.Transform = directionTransform;
     }
     return (Geometry) rectangleGeometry;
       }
     }
     else
     {
       Rect rect2 = new Rect(-alignmentOffset.X + rect1.X, -alignmentOffset.Y + rect1.Y, clientSize.Width, clientSize.Height);
       if (useLayoutRounding)
     rect2 = UIElement.RoundLayoutRect(rect2, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
       if (flag1)
       {
     Rect rect3 = new Rect(0.0, 0.0, width, height);
     if (useLayoutRounding)
       rect3 = UIElement.RoundLayoutRect(rect3, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     rect2.Intersect(rect3);
       }
       RectangleGeometry rectangleGeometry = new RectangleGeometry(rect2);
       if (directionTransform != null)
     rectangleGeometry.Transform = directionTransform;
       return (Geometry) rectangleGeometry;
     }
       }
 }
Example #3
0
 protected override sealed Size MeasureCore(Size availableSize)
 {
     bool useLayoutRounding = this.UseLayoutRounding;
       if (useLayoutRounding && !this.CheckFlagsAnd(VisualFlags.UseLayoutRounding))
     this.SetFlags(true, VisualFlags.UseLayoutRounding);
       this.ApplyTemplate();
       if (this.BypassLayoutPolicies)
     return this.MeasureOverride(availableSize);
       Thickness margin = this.Margin;
       double num1 = margin.Left + margin.Right;
       double num2 = margin.Top + margin.Bottom;
       if (useLayoutRounding && this is ScrollContentPresenter)
       {
     num1 = UIElement.RoundLayoutValue(num1, FrameworkElement.DpiScaleX);
     num2 = UIElement.RoundLayoutValue(num2, FrameworkElement.DpiScaleY);
       }
       Size size1 = new Size(Math.Max(availableSize.Width - num1, 0.0), Math.Max(availableSize.Height - num2, 0.0));
       FrameworkElement.MinMax minMax = new FrameworkElement.MinMax(this);
       FrameworkElement.LayoutTransformData layoutTransformData = FrameworkElement.LayoutTransformDataField.GetValue((DependencyObject) this);
       Transform layoutTransform = this.LayoutTransform;
       if (layoutTransform != null && !layoutTransform.IsIdentity)
       {
     if (layoutTransformData == null)
     {
       layoutTransformData = new FrameworkElement.LayoutTransformData();
       FrameworkElement.LayoutTransformDataField.SetValue((DependencyObject) this, layoutTransformData);
     }
     layoutTransformData.CreateTransformSnapshot(layoutTransform);
     layoutTransformData.UntransformedDS = new Size();
     if (useLayoutRounding)
       layoutTransformData.TransformedUnroundedDS = new Size();
       }
       else if (layoutTransformData != null)
       {
     layoutTransformData = (FrameworkElement.LayoutTransformData) null;
     FrameworkElement.LayoutTransformDataField.ClearValue((DependencyObject) this);
       }
       if (layoutTransformData != null)
     size1 = this.FindMaximalAreaLocalSpaceRect(layoutTransformData.Transform, size1);
       size1.Width = Math.Max(minMax.minWidth, Math.Min(size1.Width, minMax.maxWidth));
       size1.Height = Math.Max(minMax.minHeight, Math.Min(size1.Height, minMax.maxHeight));
       if (useLayoutRounding)
     size1 = UIElement.RoundLayoutSize(size1, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
       Size size2 = this.MeasureOverride(size1);
       size2 = new Size(Math.Max(size2.Width, minMax.minWidth), Math.Max(size2.Height, minMax.minHeight));
       Size size3 = size2;
       if (layoutTransformData != null)
       {
     layoutTransformData.UntransformedDS = size3;
     Rect rect = Rect.Transform(new Rect(0.0, 0.0, size3.Width, size3.Height), layoutTransformData.Transform.Value);
     size3.Width = rect.Width;
     size3.Height = rect.Height;
       }
       bool flag = false;
       if (size2.Width > minMax.maxWidth)
       {
     size2.Width = minMax.maxWidth;
     flag = true;
       }
       if (size2.Height > minMax.maxHeight)
       {
     size2.Height = minMax.maxHeight;
     flag = true;
       }
       if (layoutTransformData != null)
       {
     Rect rect = Rect.Transform(new Rect(0.0, 0.0, size2.Width, size2.Height), layoutTransformData.Transform.Value);
     size2.Width = rect.Width;
     size2.Height = rect.Height;
       }
       double val2_1 = size2.Width + num1;
       double val2_2 = size2.Height + num2;
       if (val2_1 > availableSize.Width)
       {
     val2_1 = availableSize.Width;
     flag = true;
       }
       if (val2_2 > availableSize.Height)
       {
     val2_2 = availableSize.Height;
     flag = true;
       }
       if (layoutTransformData != null)
     layoutTransformData.TransformedUnroundedDS = new Size(Math.Max(0.0, val2_1), Math.Max(0.0, val2_2));
       if (useLayoutRounding)
       {
     val2_1 = UIElement.RoundLayoutValue(val2_1, FrameworkElement.DpiScaleX);
     val2_2 = UIElement.RoundLayoutValue(val2_2, FrameworkElement.DpiScaleY);
       }
       SizeBox sizeBox1 = FrameworkElement.UnclippedDesiredSizeField.GetValue((DependencyObject) this);
       if (flag || val2_1 < 0.0 || val2_2 < 0.0)
       {
     if (sizeBox1 == null)
     {
       SizeBox sizeBox2 = new SizeBox(size3);
       FrameworkElement.UnclippedDesiredSizeField.SetValue((DependencyObject) this, sizeBox2);
     }
     else
     {
       sizeBox1.Width = size3.Width;
       sizeBox1.Height = size3.Height;
     }
       }
       else if (sizeBox1 != null)
     FrameworkElement.UnclippedDesiredSizeField.ClearValue((DependencyObject) this);
       return new Size(Math.Max(0.0, val2_1), Math.Max(0.0, val2_2));
 }
Example #4
0
 protected override sealed void ArrangeCore(Rect finalRect)
 {
     bool useLayoutRounding = this.UseLayoutRounding;
       FrameworkElement.LayoutTransformData layoutTransformData = FrameworkElement.LayoutTransformDataField.GetValue((DependencyObject) this);
       Size size1 = Size.Empty;
       if (useLayoutRounding && !this.CheckFlagsAnd(VisualFlags.UseLayoutRounding))
     this.SetFlags(true, VisualFlags.UseLayoutRounding);
       if (this.BypassLayoutPolicies)
       {
     Size renderSize = this.RenderSize;
     this.RenderSize = this.ArrangeOverride(finalRect.Size);
     this.SetLayoutOffset(new Vector(finalRect.X, finalRect.Y), renderSize);
       }
       else
       {
     this.NeedsClipBounds = false;
     Size size2 = finalRect.Size;
     Thickness margin = this.Margin;
     double num1 = margin.Left + margin.Right;
     double num2 = margin.Top + margin.Bottom;
     size2.Width = Math.Max(0.0, size2.Width - num1);
     size2.Height = Math.Max(0.0, size2.Height - num2);
     if (useLayoutRounding && layoutTransformData != null)
     {
       Size size3 = layoutTransformData.TransformedUnroundedDS;
       size1 = layoutTransformData.TransformedUnroundedDS;
       size1.Width = Math.Max(0.0, size1.Width - num1);
       size1.Height = Math.Max(0.0, size1.Height - num2);
     }
     SizeBox sizeBox = FrameworkElement.UnclippedDesiredSizeField.GetValue((DependencyObject) this);
     Size size4;
     if (sizeBox == null)
     {
       size4 = new Size(Math.Max(0.0, this.DesiredSize.Width - num1), Math.Max(0.0, this.DesiredSize.Height - num2));
       if (size1 != Size.Empty)
       {
     size4.Width = Math.Max(size1.Width, size4.Width);
     size4.Height = Math.Max(size1.Height, size4.Height);
       }
     }
     else
       size4 = new Size(sizeBox.Width, sizeBox.Height);
     if (DoubleUtil.LessThan(size2.Width, size4.Width))
     {
       this.NeedsClipBounds = true;
       size2.Width = size4.Width;
     }
     if (DoubleUtil.LessThan(size2.Height, size4.Height))
     {
       this.NeedsClipBounds = true;
       size2.Height = size4.Height;
     }
     if (this.HorizontalAlignment != HorizontalAlignment.Stretch)
       size2.Width = size4.Width;
     if (this.VerticalAlignment != VerticalAlignment.Stretch)
       size2.Height = size4.Height;
     if (layoutTransformData != null)
     {
       Size areaLocalSpaceRect = this.FindMaximalAreaLocalSpaceRect(layoutTransformData.Transform, size2);
       size2 = areaLocalSpaceRect;
       size4 = layoutTransformData.UntransformedDS;
       if (!DoubleUtil.IsZero(areaLocalSpaceRect.Width) && !DoubleUtil.IsZero(areaLocalSpaceRect.Height) && (LayoutDoubleUtil.LessThan(areaLocalSpaceRect.Width, size4.Width) || LayoutDoubleUtil.LessThan(areaLocalSpaceRect.Height, size4.Height)))
     size2 = size4;
       if (DoubleUtil.LessThan(size2.Width, size4.Width))
       {
     this.NeedsClipBounds = true;
     size2.Width = size4.Width;
       }
       if (DoubleUtil.LessThan(size2.Height, size4.Height))
       {
     this.NeedsClipBounds = true;
     size2.Height = size4.Height;
       }
     }
     FrameworkElement.MinMax minMax = new FrameworkElement.MinMax(this);
     double num3 = Math.Max(size4.Width, minMax.maxWidth);
     if (DoubleUtil.LessThan(num3, size2.Width))
     {
       this.NeedsClipBounds = true;
       size2.Width = num3;
     }
     double num4 = Math.Max(size4.Height, minMax.maxHeight);
     if (DoubleUtil.LessThan(num4, size2.Height))
     {
       this.NeedsClipBounds = true;
       size2.Height = num4;
     }
     if (useLayoutRounding)
       size2 = UIElement.RoundLayoutSize(size2, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     Size renderSize = this.RenderSize;
     Size size5 = this.ArrangeOverride(size2);
     this.RenderSize = size5;
     if (useLayoutRounding)
       this.RenderSize = UIElement.RoundLayoutSize(this.RenderSize, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     Size size6 = new Size(Math.Min(size5.Width, minMax.maxWidth), Math.Min(size5.Height, minMax.maxHeight));
     if (useLayoutRounding)
       size6 = UIElement.RoundLayoutSize(size6, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     FrameworkElement frameworkElement1 = this;
     int num5 = (frameworkElement1.NeedsClipBounds ? 1 : 0) | (DoubleUtil.LessThan(size6.Width, size5.Width) ? 1 : (DoubleUtil.LessThan(size6.Height, size5.Height) ? 1 : 0));
     frameworkElement1.NeedsClipBounds = num5 != 0;
     if (layoutTransformData != null)
     {
       Rect rect = Rect.Transform(new Rect(0.0, 0.0, size6.Width, size6.Height), layoutTransformData.Transform.Value);
       size6.Width = rect.Width;
       size6.Height = rect.Height;
       if (useLayoutRounding)
     size6 = UIElement.RoundLayoutSize(size6, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     }
     Size size7 = new Size(Math.Max(0.0, finalRect.Width - num1), Math.Max(0.0, finalRect.Height - num2));
     if (useLayoutRounding)
       size7 = UIElement.RoundLayoutSize(size7, FrameworkElement.DpiScaleX, FrameworkElement.DpiScaleY);
     FrameworkElement frameworkElement2 = this;
     int num6 = (frameworkElement2.NeedsClipBounds ? 1 : 0) | (DoubleUtil.LessThan(size7.Width, size6.Width) ? 1 : (DoubleUtil.LessThan(size7.Height, size6.Height) ? 1 : 0));
     frameworkElement2.NeedsClipBounds = num6 != 0;
     Vector alignmentOffset = this.ComputeAlignmentOffset(size7, size6);
     alignmentOffset.X += finalRect.X + margin.Left;
     alignmentOffset.Y += finalRect.Y + margin.Top;
     if (useLayoutRounding)
     {
       alignmentOffset.X = UIElement.RoundLayoutValue(alignmentOffset.X, FrameworkElement.DpiScaleX);
       alignmentOffset.Y = UIElement.RoundLayoutValue(alignmentOffset.Y, FrameworkElement.DpiScaleY);
     }
     this.SetLayoutOffset(alignmentOffset, renderSize);
       }
 }