protected override object CreateTileBrush(BaseFrameworkElement element)
        {
            Visual visual1 = element.Visual != null ? element.Visual.PlatformSpecificObject as Visual : (Visual)null;

            if (visual1 == null)
            {
                return((object)null);
            }
            foreach (Visual visual2 in ElementUtilities.GetVisualTree(visual1))
            {
                if (MakeDrawingBrushCommand.IsMediaElementInstance(visual2))
                {
                    this.showDrawingVideoWarning = true;
                    break;
                }
            }
            Drawing      drawing      = MakeDrawingBrushCommand.SimplifyDrawing(MakeDrawingBrushCommand.CreateDrawing(visual1, false), Path.GetDirectoryName(this.SceneViewModel.ProjectContext.ProjectPath));
            DrawingBrush drawingBrush = new DrawingBrush();

            if (drawing != null)
            {
                drawingBrush.Drawing = drawing;
                UIElement uiElement = visual1 as UIElement;
                if (uiElement != null)
                {
                    drawingBrush.Viewbox      = new Rect(uiElement.RenderSize);
                    drawingBrush.ViewboxUnits = BrushMappingMode.Absolute;
                }
            }
            return((object)drawingBrush);
        }
 private static Drawing SimplifyGlyphRunDrawing(GlyphRunDrawing glyphRunDrawing)
 {
     if (glyphRunDrawing.ForegroundBrush == null || glyphRunDrawing.GlyphRun == null)
     {
         return((Drawing)null);
     }
     System.Windows.Media.Geometry geometry = glyphRunDrawing.GlyphRun.BuildGeometry();
     if (geometry == null || geometry.IsEmpty())
     {
         return((Drawing)null);
     }
     return(MakeDrawingBrushCommand.SimplifyGeometryDrawing(new GeometryDrawing(glyphRunDrawing.ForegroundBrush, (Pen)null, geometry)));
 }
 private static Drawing SimplifyDrawingGroup(DrawingGroup drawingGroup, string projectPath)
 {
     for (int index = drawingGroup.Children.Count - 1; index >= 0; --index)
     {
         Drawing drawing = MakeDrawingBrushCommand.SimplifyDrawing(drawingGroup.Children[index], projectPath);
         if (drawing == null)
         {
             drawingGroup.Children.RemoveAt(index);
         }
         else
         {
             drawingGroup.Children[index] = drawing;
         }
     }
     if (drawingGroup.ClipGeometry == null)
     {
         drawingGroup.ClearValue(DrawingGroup.ClipGeometryProperty);
     }
     if (drawingGroup.Transform == null || drawingGroup.Transform.Value.IsIdentity)
     {
         drawingGroup.ClearValue(DrawingGroup.TransformProperty);
     }
     if (drawingGroup.Opacity >= 1.0)
     {
         drawingGroup.ClearValue(DrawingGroup.OpacityProperty);
     }
     if (drawingGroup.OpacityMask == null)
     {
         drawingGroup.ClearValue(DrawingGroup.OpacityMaskProperty);
     }
     if (drawingGroup.BitmapEffect == null)
     {
         drawingGroup.ClearValue(DrawingGroup.BitmapEffectProperty);
     }
     if (drawingGroup.BitmapEffectInput == null || drawingGroup.BitmapEffectInput.AreaToApplyEffect.IsEmpty && drawingGroup.BitmapEffectInput.Input == BitmapEffectInput.ContextInputSource)
     {
         drawingGroup.ClearValue(DrawingGroup.BitmapEffectInputProperty);
     }
     if (drawingGroup.Children.Count == 0 || drawingGroup.Opacity <= 0.0)
     {
         return((Drawing)null);
     }
     if (drawingGroup.Children.Count == 1 && drawingGroup.ClipGeometry == null && (drawingGroup.Transform == null || drawingGroup.Transform.Value.IsIdentity) && (drawingGroup.Opacity == 1.0 && drawingGroup.OpacityMask == null && drawingGroup.BitmapEffect == null))
     {
         return(drawingGroup.Children[0]);
     }
     return((Drawing)drawingGroup);
 }
 private static Drawing SimplifyDrawing(Drawing drawing, string projectPath)
 {
     if (drawing != null)
     {
         if (drawing.IsFrozen)
         {
             drawing = drawing.Clone();
         }
         DrawingGroup drawingGroup;
         if ((drawingGroup = drawing as DrawingGroup) != null)
         {
             drawing = MakeDrawingBrushCommand.SimplifyDrawingGroup(drawingGroup, projectPath);
         }
         else
         {
             GeometryDrawing geometryDrawing;
             if ((geometryDrawing = drawing as GeometryDrawing) != null)
             {
                 drawing = MakeDrawingBrushCommand.SimplifyGeometryDrawing(geometryDrawing);
             }
             else
             {
                 GlyphRunDrawing glyphRunDrawing;
                 if ((glyphRunDrawing = drawing as GlyphRunDrawing) != null)
                 {
                     drawing = MakeDrawingBrushCommand.SimplifyGlyphRunDrawing(glyphRunDrawing);
                 }
                 else
                 {
                     ImageDrawing imageDrawing;
                     if ((imageDrawing = drawing as ImageDrawing) != null)
                     {
                         drawing = MakeDrawingBrushCommand.SimplifyImageDrawing(imageDrawing, projectPath);
                     }
                     else
                     {
                         VideoDrawing videoDrawing;
                         if ((videoDrawing = drawing as VideoDrawing) != null)
                         {
                             drawing = MakeDrawingBrushCommand.SimplifyVideoDrawing(videoDrawing);
                         }
                     }
                 }
             }
         }
     }
     return(drawing);
 }
Beispiel #5
0
        private void AddImageDrawing(ConvertibleDrawing.DrawingStackEntry entry)
        {
            ImageDrawing imageDrawing = entry.Drawing as ImageDrawing;

            if (this.projectPath != null)
            {
                imageDrawing = (ImageDrawing)MakeDrawingBrushCommand.SimplifyImageDrawing(imageDrawing, this.projectPath);
            }
            Image image = new Image();

            ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.HeightProperty, (DependencyObject)image, (object)imageDrawing.Bounds.Height);
            ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.WidthProperty, (DependencyObject)image, (object)imageDrawing.Bounds.Width);
            ConvertibleDrawing.SetValueIfNotDefault(Image.SourceProperty, (DependencyObject)image, (object)imageDrawing.ImageSource);
            ConvertibleDrawing.SetPositionInCanvas((UIElement)image, entry.Offset);
            if (entry.Transform != Transform.Identity)
            {
                ConvertibleDrawing.SetValueIfNotDefault(UIElement.RenderTransformProperty, (DependencyObject)image, (object)entry.Transform);
            }
            entry.Canvas.Children.Add((UIElement)image);
        }
        private static Drawing CreateDrawing(Visual visual, bool includeTransform)
        {
            DrawingGroup drawingGroup = new DrawingGroup();

            System.Windows.Media.Geometry clip = VisualTreeHelper.GetClip(visual);
            if (clip != null)
            {
                drawingGroup.ClipGeometry = clip;
            }
            if (includeTransform)
            {
                Transform transform = VisualTreeHelper.GetTransform(visual);
                Vector    offset    = VisualTreeHelper.GetOffset(visual);
                Matrix    matrix    = transform == null ? Matrix.Identity : transform.Value;
                matrix.Translate(offset.X, offset.Y);
                if (!matrix.IsIdentity)
                {
                    drawingGroup.Transform = (Transform) new MatrixTransform(matrix);
                }
            }
            double opacity = VisualTreeHelper.GetOpacity(visual);

            if (opacity != 1.0)
            {
                drawingGroup.Opacity = opacity;
            }
            Brush opacityMask = VisualTreeHelper.GetOpacityMask(visual);

            if (opacityMask != null)
            {
                drawingGroup.OpacityMask = opacityMask;
            }
            BitmapEffect bitmapEffect = VisualTreeHelper.GetBitmapEffect(visual);

            if (bitmapEffect != null)
            {
                drawingGroup.BitmapEffect = bitmapEffect;
            }
            BitmapEffectInput bitmapEffectInput = VisualTreeHelper.GetBitmapEffectInput(visual);

            if (bitmapEffectInput != null && (!bitmapEffectInput.AreaToApplyEffect.IsEmpty || bitmapEffectInput.Input != BitmapEffectInput.ContextInputSource))
            {
                drawingGroup.BitmapEffectInput = bitmapEffectInput;
            }
            Drawing drawing1;

            if (MakeDrawingBrushCommand.IsMediaElementInstance(visual))
            {
                Rect bounds = VisualTreeHelper.GetDrawing(visual).Bounds;
                drawing1 = (Drawing) new VideoDrawing()
                {
                    Rect = bounds
                };
            }
            else
            {
                drawing1 = (Drawing)VisualTreeHelper.GetDrawing(visual);
            }
            if (drawing1 != null)
            {
                drawingGroup.Children.Add(drawing1);
            }
            for (int childIndex = 0; childIndex < VisualTreeHelper.GetChildrenCount((DependencyObject)visual); ++childIndex)
            {
                Visual visual1 = VisualTreeHelper.GetChild((DependencyObject)visual, childIndex) as Visual;
                if (visual1 != null)
                {
                    Drawing drawing2 = MakeDrawingBrushCommand.CreateDrawing(visual1, true);
                    if (drawing2 != null)
                    {
                        drawingGroup.Children.Add(drawing2);
                    }
                }
            }
            if (drawingGroup.Children.Count == 0)
            {
                return((Drawing)null);
            }
            if (drawingGroup.Children.Count == 1 && drawingGroup.ClipGeometry == null && (drawingGroup.Transform == null || drawingGroup.Transform.Value.IsIdentity) && (drawingGroup.Opacity == 1.0 && drawingGroup.OpacityMask == null && drawingGroup.BitmapEffect == null))
            {
                return(drawingGroup.Children[0]);
            }
            return((Drawing)drawingGroup);
        }