Ejemplo n.º 1
0
        public void Stub03()
        {
            // <SnippetRenderOptionsSnippet3>
            DrawingBrush drawingBrush = new DrawingBrush();

            // Set the caching hint option for the brush.
            RenderOptions.SetCachingHint(drawingBrush, CachingHint.Cache);

            // Set the minimum and maximum relative sizes for regenerating the tiled brush.
            // The tiled brush will be regenerated and re-cached when its size is
            // 0.5x or 2x of the current cached size.
            RenderOptions.SetCacheInvalidationThresholdMinimum(drawingBrush, 0.5);
            RenderOptions.SetCacheInvalidationThresholdMaximum(drawingBrush, 2.0);
            // </SnippetRenderOptionsSnippet3>
        }
Ejemplo n.º 2
0
        void renderVideo()
        {
            DrawingContext context = videoVisual.RenderOpen();

            context.DrawVideo(player, new Rect(0, 0, dispWidth, dispHeight));
            context.Close();

            Brush brush = new VisualBrush(videoVisual);

            rectangle1.Fill = brush;

            RenderOptions.SetCachingHint(brush, CachingHint.Cache);
            RenderOptions.SetCacheInvalidationThresholdMinimum(brush, 0.5);
            RenderOptions.SetCacheInvalidationThresholdMaximum(brush, 2.0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the VisualBrush that will be used to hold the interactive
        /// 2D content.
        /// </summary>
        /// <returns>The VisualBrush to hold the interactive 2D content</returns>
        private VisualBrush CreateVisualBrush()
        {
            VisualBrush vb = new VisualBrush();

            // We don't want the VisualBrush being the InheritanceContext for the Visual it contains.  Rather we want
            // that to be the Viewport2DVisual3D itself.
            vb.CanBeInheritanceContext = false;

            vb.ViewportUnits = BrushMappingMode.Absolute;
            vb.TileMode      = TileMode.None;

            // set any rendering options in the visual brush - we do this to still give access to these caching hints
            // without exposing the visual brush
            RenderOptions.SetCachingHint(vb, (CachingHint)GetValue(CachingHintProperty));
            RenderOptions.SetCacheInvalidationThresholdMinimum(vb, (double)GetValue(CacheInvalidationThresholdMinimumProperty));
            RenderOptions.SetCacheInvalidationThresholdMaximum(vb, (double)GetValue(CacheInvalidationThresholdMaximumProperty));

            return(vb);
        }
Ejemplo n.º 4
0
        public void Stub04()
        {
            DrawingBrush drawingBrush = new DrawingBrush();

            RenderOptions.SetCacheInvalidationThresholdMinimum(drawingBrush, 0.5);
            RenderOptions.SetCacheInvalidationThresholdMaximum(drawingBrush, 2.0);
            RenderOptions.SetCachingHint(drawingBrush, CachingHint.Cache);

            // <SnippetRenderOptionsSnippet4>
            // Get the caching hint option for the brush.
            CachingHint cachingHint = RenderOptions.GetCachingHint(drawingBrush);

            if (cachingHint == CachingHint.Cache)
            {
                // Get the minimum and maximum relative sizes for regenerating the tiled brush.
                double minimum = RenderOptions.GetCacheInvalidationThresholdMinimum(drawingBrush);
                double maximum = RenderOptions.GetCacheInvalidationThresholdMaximum(drawingBrush);

                // Perform action based on cache values...
            }
            // </SnippetRenderOptionsSnippet4>
        }
Ejemplo n.º 5
0
 private void SetCachingForObject(DependencyObject d)
 {
     RenderOptions.SetCachingHint(d, CachingHint.Cache);
     RenderOptions.SetCacheInvalidationThresholdMinimum(d, 0.5);
     RenderOptions.SetCacheInvalidationThresholdMaximum(d, 2.0);
 }
Ejemplo n.º 6
0
        private GeometryModel3D SignLeft(int number)
        {
            string    text      = number.ToString();
            TextBlock textBlock = new TextBlock(new Run(text))
            {
                Foreground = Brushes.White,
                Background = Brushes.Black,
                FontFamily = new FontFamily("Forte")
            };


            VisualBrush visualBrush = new VisualBrush(textBlock);

            RenderOptions.SetCachingHint(visualBrush, CachingHint.Cache);
            RenderOptions.SetCacheInvalidationThresholdMinimum(visualBrush, 0);
            RenderOptions.SetCacheInvalidationThresholdMaximum(visualBrush, double.MaxValue);


            DiffuseMaterial material = new DiffuseMaterial()
            {
                Brush = visualBrush,
            };

            double minDimension = 0;

            minDimension  = PackageLength < PackageHeight ? PackageLength : PackageHeight;
            minDimension /= 1.5;


            Point3DCollection textPointCollection = new Point3DCollection
            {
                new Point3D(-0.005, minDimension, minDimension),
                new Point3D(-0.005, -minDimension, minDimension),
                new Point3D(-0.005, -minDimension, -minDimension),
                new Point3D(-0.005, minDimension, -minDimension)
            };

            Int32Collection triangleIndices = new Int32Collection
            {
                0, 3, 2,
                2, 1, 0
            };

            PointCollection textureCoordinates = new PointCollection
            {
                new Point(1, 0),
                new Point(1, 1),
                new Point(0, 1),
                new Point(0, 0),
            };

            MeshGeometry3D textMesh = new MeshGeometry3D
            {
                Positions          = textPointCollection,
                TriangleIndices    = triangleIndices,
                TextureCoordinates = textureCoordinates
            };

            GeometryModel3D textModel = new GeometryModel3D
            {
                Geometry = textMesh,
                Material = material
            };

            textModel.Transform = new TranslateTransform3D(new Vector3D(-PackageWidth, 0, 0));

            return(textModel);
        }
Ejemplo n.º 7
0
        private Visual3D EnsureChild(Visual3D currentChild, Shape3DMaterial material)
        {
            Visual3D newChild = null;

            if (material != null)
            {
                if (material.HasElement)
                {
                    // We need a Viewport2DVisual3D to display an element.
                    if (currentChild is Viewport2DVisual3D)
                    {
                        newChild = currentChild;
                    }
                    else
                    {
                        //Viewbox viewbox = new Viewbox();
                        //viewbox.StretchDirection = StretchDirection.Both;
                        //viewbox.Stretch = Stretch.Fill;

                        Border border = new Border();
                        border.UseLayoutRounding = true;
                        border.Background        = Brushes.Green;
                        //border.Child = viewbox;

                        Viewport2DVisual3D viewport = new Viewport2DVisual3D();
                        viewport.Visual = border;

                        newChild = viewport;
                    }

                    // Set the appropriate caching strategy.
                    CacheScale cacheScale = CacheScale;
                    if (cacheScale == null)
                    {
                        // Remove any VisualBrush caching.
                        RenderOptions.SetCachingHint(newChild, CachingHint.Unspecified);

                        // Remove any BitmapCache.
                        ((Viewport2DVisual3D)newChild).CacheMode = null;
                    }
                    else if (cacheScale.IsAuto)
                    {
                        // Remove any BitmapCache.
                        ((Viewport2DVisual3D)newChild).CacheMode = null;

                        // Specify VisualBrush caching with 2x min and max
                        // thresholds.
                        RenderOptions.SetCachingHint(newChild, CachingHint.Cache);
                        RenderOptions.SetCacheInvalidationThresholdMinimum(newChild, 0.5);
                        RenderOptions.SetCacheInvalidationThresholdMaximum(newChild, 2.0);
                    }
                    else
                    {
                        // Remove any VisualBrush caching.
                        RenderOptions.SetCachingHint(newChild, CachingHint.Unspecified);

                        // Set a BitmapCache with the appropriate scale.
                        BitmapCache bitmapCache = ((Viewport2DVisual3D)newChild).CacheMode as BitmapCache;
                        if (bitmapCache == null)
                        {
                            ((Viewport2DVisual3D)newChild).CacheMode = new BitmapCache(cacheScale.Scale);
                        }
                        else
                        {
                            bitmapCache.RenderAtScale = cacheScale.Scale;
                        }
                    }
                }
                else
                {
                    Debug.Assert(material.HasMaterial);

                    // We need a ModelVisual3D to display the material.
                    if (currentChild is ModelVisual3D)
                    {
                        Debug.Assert(((ModelVisual3D)currentChild).Content is GeometryModel3D);
                        newChild = currentChild;
                    }
                    else
                    {
                        newChild = new ModelVisual3D();
                        ((ModelVisual3D)newChild).Content = new GeometryModel3D();
                    }
                }
            }

            return(newChild);
        }
Ejemplo n.º 8
0
        private static void OnCacheInvalidationThresholdMaximumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Viewport2DVisual3D viewport2D = (Viewport2DVisual3D)d;

            RenderOptions.SetCacheInvalidationThresholdMaximum(viewport2D._visualBrush, (double)e.NewValue);
        }
        ////public Effect get_effect()
        ////{
        ////   if (container_grid.Effect != null) {
        ////      return container_grid.Effect;
        ////   }
        ////   else {
        ////      return null;
        ////   }

        ////}


        //public void set_effect(Effect e)
        //{
        //   if (container_grid.Effect != null)
        //   {
        //      if (container_grid.Effect.GetType() == e.GetType())
        //      {
        //         container_grid.Effect = null; // if they're the same type, just remove the effect (a toggle)
        //      }
        //      else
        //      {
        //         container_grid.Effect = e;
        //      }
        //   }
        //   else
        //   {
        //      container_grid.Effect = e;
        //   }
        //}

        //public void remove_effect()
        //{
        //   if (container_grid.Effect != null)
        //   {
        //      container_grid.Effect = null;
        //   }
        //}



        public pokeable_mv3d()
        {
            mouse_position = new Point(0.5, 0.5);


            tt3d = new TranslateTransform3D();
            interactive_vp2dv3d = new Viewport2DVisual3D();

            this.Children.Add(interactive_vp2dv3d);
            MeshGeometry3D mg3d = make_plane_meshgeometry3d();


            container_grid            = new Grid();
            container_grid.MouseMove += new System.Windows.Input.MouseEventHandler(container_grid_MouseMove);



            magnify_host   = new effect_host();
            swirl_host     = new effect_host();
            brick_host     = new effect_host();
            ripple_host    = new effect_host();
            color_key_host = new effect_host();
            invert_host    = new effect_host();


            magnify_host.Children.Add(swirl_host);
            swirl_host.Children.Add(brick_host);
            brick_host.Children.Add(ripple_host);
            ripple_host.Children.Add(invert_host);
            invert_host.Children.Add(color_key_host);
            // color_key_host.Children.Add(invert_host);



            //       FileStream fs = File.Open("c:\\border.xaml", FileMode.Open);

            string my_xaml = "		<Grid 	xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" 	xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Margin=\"150,90,150,145\" SnapsToDevicePixels=\"True\" Width=\"1000\" Height=\"500\" > 			<Border Margin=\"0,0,0,0\" BorderThickness=\"10,10,10,10\" Opacity=\"0.675\"> 				<Border.BorderBrush> 					<LinearGradientBrush EndPoint=\"0.982,0.972\" StartPoint=\"0.01,0.025\"> 						<GradientStop Color=\"#4CFFFFFF\" Offset=\"0\"/> 						<GradientStop Color=\"#44FFFFFF\" Offset=\"1\"/> 						<GradientStop Color=\"#FF545454\" Offset=\"0.174\"/> 						<GradientStop Color=\"#ED434343\" Offset=\"0.688\"/> 						<GradientStop Color=\"#FF2A2A2A\" Offset=\"0.808\"/> 						<GradientStop Color=\"#F2999999\" Offset=\"0.397\"/> 						<GradientStop Color=\"#80494949\" Offset=\"0.571\"/> 					</LinearGradientBrush> 				</Border.BorderBrush> 			</Border> 			<Border Width=\"Auto\" Height=\"Auto\" BorderThickness=\"1,1,1,1\"  BorderBrush=\"#59FFFFFF\"/> 			<Border Width=\"Auto\" Height=\"Auto\" BorderThickness=\"1,1,1,1\" BorderBrush=\"#59FFFFFF\" Margin=\"10,10,10,10\" Name=\"inner_border\"> 								<!--Insert Content Here-->  			</Border> 		</Grid>";
            //   string my_xaml = File.Open("c:\\border.xaml", FileMode.Open);



            StringReader  strReader = new StringReader(my_xaml);
            XmlTextReader xmlReader = new XmlTextReader(strReader);

            object obj = XamlReader.Load(xmlReader);

            Grid border_grid = ((Grid)obj);


            Image i = new Image();

            i.Source = make_trasnparent_grid();
            i.HorizontalAlignment = HorizontalAlignment.Stretch;
            i.VerticalAlignment   = VerticalAlignment.Stretch;



            container_grid.Children.Add(i);


            color_key_host.Children.Add(container_grid);



            Viewbox vb = new Viewbox();

            vb.Stretch = Stretch.Fill;
            vb.Child   = magnify_host;



            (border_grid.FindName("inner_border") as Border).Child = vb;

            interactive_vp2dv3d.Visual = border_grid;



            DiffuseMaterial dm = new DiffuseMaterial();

            Viewport2DVisual3D.SetIsVisualHostMaterial(dm, true);

            interactive_vp2dv3d.Geometry = mg3d;
            interactive_vp2dv3d.Material = dm;


            RenderOptions.SetCachingHint(interactive_vp2dv3d, CachingHint.Cache);
            RenderOptions.SetCacheInvalidationThresholdMinimum(interactive_vp2dv3d, 0.001);
            RenderOptions.SetCacheInvalidationThresholdMaximum(interactive_vp2dv3d, 1000);
        }