private void DrawRegion(CanvasVirtualImageSource sender, Rect region)
        {
            var tryPanningOrZoomingLayout = new CanvasTextLayout(sender.Device, "Try panning or zooming.", format, 500, 0);

            var infoLayout = new CanvasTextLayout(sender.Device,
                "In this demo, each time a region is updated, it is cleared to a different background color.  " +
                "This is to make it possible to see which regions get redrawn.",
                format, 500, 0);

            var youMadeIt = new CanvasTextLayout(sender.Device,
                "You made it to the end!", endFormat, 1000, 0);

            using (var ds = sender.CreateDrawingSession(NextColor(), region))
            {
                var left = ((int)(region.X / gridSize) - 1) * gridSize;
                var top = ((int)(region.Y / gridSize) - 1) * gridSize;
                var right = ((int)((region.X + region.Width) / gridSize) + 1) * gridSize;
                var bottom = ((int)((region.Y + region.Height) / gridSize) + 1) * gridSize;

                for (var x = left; x <= right; x += gridSize)
                {
                    for (var y = top; y <= bottom; y += gridSize)
                    {
                        var pos = new Vector2((float)x, (float)y);
                        ds.DrawCircle(pos, 10, Colors.White);

                        ds.DrawText(string.Format("{0}\n{1}", x, y), pos, Colors.DarkBlue, coordFormat);
                    }
                }

                DrawTextWithBackground(ds, tryPanningOrZoomingLayout, gridSize / 2, gridSize / 2);
                DrawTextWithBackground(ds, infoLayout, gridSize * 3.5, gridSize * 5.5);
                DrawTextWithBackground(ds, youMadeIt, width - youMadeIt.RequestedSize.Width, height - youMadeIt.RequestedSize.Height);
            }
        }
Exemple #2
0
 private void RegionsInvalidatedHandler(CanvasVirtualImageSource sender, CanvasRegionsInvalidatedEventArgs args)
 {
     foreach (var region in args.InvalidatedRegions)
     {
         RenderRegion(region);
     }
 }
        private void ImageSource_RegionsInvalidated(CanvasVirtualImageSource sender, CanvasRegionsInvalidatedEventArgs args)
        {
            ++regionsInvalidatedEventCount;

            var invalidatedRegions = args.InvalidatedRegions;

            regionsInvalidatedCount += invalidatedRegions.Count();

            status.Text = string.Format("{0} RegionsInvalidated events, {1} total regions invalidated", regionsInvalidatedEventCount, regionsInvalidatedCount);

            try
            {
                foreach (var region in invalidatedRegions)
                {
                    DrawRegion(sender, region);
                }
            }
            catch (Exception e)
            {
                if (!sender.Device.IsDeviceLost(e.HResult))
                {
                    throw;
                }

                sender.Device.RaiseDeviceLost();
            }
        }
        private void DrawRegion(CanvasVirtualImageSource sender, Rect region)
        {
            var tryPanningOrZoomingLayout = new CanvasTextLayout(sender.Device, "Try panning or zooming.", format, 500, 0);

            var infoLayout = new CanvasTextLayout(sender.Device,
                                                  "In this demo, each time a region is updated, it is cleared to a different background color.  " +
                                                  "This is to make it possible to see which regions get redrawn.",
                                                  format, 500, 0);

            var youMadeIt = new CanvasTextLayout(sender.Device,
                                                 "You made it to the end!", endFormat, 1000, 0);

            using (var ds = sender.CreateDrawingSession(NextColor(), region))
            {
                var left   = ((int)(region.X / gridSize) - 1) * gridSize;
                var top    = ((int)(region.Y / gridSize) - 1) * gridSize;
                var right  = ((int)((region.X + region.Width) / gridSize) + 1) * gridSize;
                var bottom = ((int)((region.Y + region.Height) / gridSize) + 1) * gridSize;

                for (var x = left; x <= right; x += gridSize)
                {
                    for (var y = top; y <= bottom; y += gridSize)
                    {
                        var pos = new Vector2((float)x, (float)y);
                        ds.DrawCircle(pos, 10, Colors.White);

                        ds.DrawText(string.Format("{0}\n{1}", x, y), pos, Colors.DarkBlue, coordFormat);
                    }
                }

                DrawTextWithBackground(ds, tryPanningOrZoomingLayout, gridSize / 2, gridSize / 2);
                DrawTextWithBackground(ds, infoLayout, gridSize * 3.5, gridSize * 5.5);
                DrawTextWithBackground(ds, youMadeIt, width - youMadeIt.RequestedSize.Width, height - youMadeIt.RequestedSize.Height);
            }
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs args)
        {
            CompositionTarget.SurfaceContentsLost += CompositionTarget_SurfaceContentsLost;

            var device = CanvasDevice.GetSharedDevice();

            imageSource = new CanvasVirtualImageSource(device, width, height, dpi);
            imageSource.RegionsInvalidated += ImageSource_RegionsInvalidated;
            image.Source = imageSource.Source;
        }
Exemple #6
0
        private void OnRegionsInvalidated(CanvasVirtualImageSource sender, CanvasRegionsInvalidatedEventArgs e)
        {
            foreach (var region in e.InvalidatedRegions)
            {
                var randomColor = CreateRandomColor();

                using (sender.CreateDrawingSession(randomColor, region))
                {
                    // Just changing colors...
                }
            }
        }
Exemple #7
0
        public void Dispose()
        {
            if (_vsis == null)
            {
                return;
            }

            _vsis.RegionsInvalidated -= RegionsInvalidatedHandler;
            _vsis = null;
            _page = null;

            GC.SuppressFinalize(this);
        }
Exemple #8
0
        public VsisPageRenderer(DjvuPage page, Size pageViewSize)
        {
            _page = page;

            var size = FindBestSize(pageViewSize);

            _vsis = new CanvasVirtualImageSource(
                resourceCreator: CanvasDevice.GetSharedDevice(),
                width: (float)size.Width,
                height: (float)size.Height,
                dpi: DisplayInformation.GetForCurrentView().LogicalDpi,
                alphaMode: CanvasAlphaMode.Ignore);
            _vsis.RegionsInvalidated += RegionsInvalidatedHandler;
        }
Exemple #9
0
        void Canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(LoadCanvasResources(sender).AsAsyncAction());

            imageBrush = new CanvasImageBrush(sender);

            imageSource         = new CanvasImageSource(sender, controlSize, controlSize);
            imageControl.Source = imageSource;

            virtualImageSource         = new CanvasVirtualImageSource(sender, controlSize, controlSize);
            virtualImageControl.Source = virtualImageSource.Source;

            swapChain = new CanvasSwapChain(sender, controlSize, controlSize);
            swapChainPanel.SwapChain = swapChain;
        }
Exemple #10
0
        private void RemoveExistingImage()
        {
            if (_image == null)
            {
                return;
            }

            Container.Children.Remove(_image);

            _source.RegionsInvalidated -= OnRegionsInvalidated;
            _image.Source = null;
            _device.Dispose();

            _image  = null;
            _device = null;
            _source = null;
        }
Exemple #11
0
        private void CreateNewImage()
        {
            const float dpi = 96f * 1;             // 300% dpi scale;

            var device = new CanvasDevice();
            var source = new CanvasVirtualImageSource(device, 10000, 10000, dpi);
            var image  = new Image
            {
                Width   = 10000,
                Height  = 10000,
                Stretch = Stretch.Fill,
                Source  = source.Source,
            };

            source.RegionsInvalidated += OnRegionsInvalidated;

            Container.Children.Add(image);

            _image  = image;
            _device = device;
            _source = source;
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs args)
        {
            CompositionTarget.SurfaceContentsLost += CompositionTarget_SurfaceContentsLost;

            var device = CanvasDevice.GetSharedDevice();
            imageSource = new CanvasVirtualImageSource(device, width, height, dpi);
            imageSource.RegionsInvalidated += ImageSource_RegionsInvalidated;
            image.Source = imageSource.Source;
        }
        private void ImageSource_RegionsInvalidated(CanvasVirtualImageSource sender, CanvasRegionsInvalidatedEventArgs args)
        {
            ++regionsInvalidatedEventCount;

            var invalidatedRegions = args.InvalidatedRegions;
            regionsInvalidatedCount += invalidatedRegions.Count();

            status.Text = string.Format("{0} RegionsInvalidated events, {1} total regions invalidated", regionsInvalidatedEventCount, regionsInvalidatedCount);

            try
            {
                foreach (var region in invalidatedRegions)
                {
                    DrawRegion(sender, region);
                }
            }
            catch (Exception e)
            {
                if (!sender.Device.IsDeviceLost(e.HResult))
                    throw;

                sender.Device.RaiseDeviceLost();
            }
        }
Exemple #14
0
        void Canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(LoadCanvasResources(sender).AsAsyncAction());

            imageBrush = new CanvasImageBrush(sender);

            imageSource = new CanvasImageSource(sender, controlSize, controlSize);
            imageControl.Source = imageSource;

            virtualImageSource = new CanvasVirtualImageSource(sender, controlSize, controlSize);
            virtualImageControl.Source = virtualImageSource.Source;

            swapChain = new CanvasSwapChain(sender, controlSize, controlSize);
            swapChainPanel.SwapChain = swapChain;
        }