private void ImageSetPixelSize()
        {
            double dpiScale = 1.0;

            var hwndTarget = PresentationSource.FromVisual(this).CompositionTarget as HwndTarget;

            if (hwndTarget != null)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            int surfWidth  = (int)(Host.ActualWidth < 0 ? 0 : Math.Ceiling(Host.ActualWidth * dpiScale));
            int surfHeight = (int)(Host.ActualHeight < 0 ? 0 : Math.Ceiling(Host.ActualHeight * dpiScale));

            InteropImage.SetPixelSize(surfWidth, surfHeight);

            bool isVisible = (surfWidth != 0 && surfHeight != 0);

            if (lastVisible != isVisible)
            {
                lastVisible = isVisible;
                if (lastVisible)
                {
                    CompositionTarget.Rendering += CompositionTarget_Rendering;
                }
                else
                {
                    CompositionTarget.Rendering -= CompositionTarget_Rendering;
                }
            }
        }
        private void Host_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // TODO: handle non-96 DPI
            int surfWidth  = (int)(host.ActualWidth < 0 ? 0 : Math.Ceiling(host.ActualWidth));
            int surfHeight = (int)(host.ActualHeight < 0 ? 0 : Math.Ceiling(host.ActualHeight));

            InteropImage.SetPixelSize(surfWidth, surfHeight);
        }
示例#3
0
        private void InteropImage_IsFrontBufferAvailableChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue == false)
            {
                // force recreation of lost frontbuffer
                Size size = Utils.WpfSizeToPixels(ImageGrid);

                InteropImage.SetPixelSize((int)size.Width + 1, (int)size.Height + 1);
                InteropImage.SetPixelSize((int)size.Width, (int)size.Height);

                InteropImage.RequestRender();
            }
        }
示例#4
0
        private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Grid g = (Grid)Content;

            if (g.ActualWidth > 0 && g.ActualHeight > 0)
            {
                InteropImage.SetPixelSize((int)g.ActualWidth, (int)g.ActualHeight);
            }
            else
            {
                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action <object, SizeChangedEventArgs>)MainWindow_SizeChanged, null, null);
            }
        }
        void textPropertyChanged(string newText)
        {
            //Debug.WriteLine(newText);

            if (null != _dwTextBlockLib)
            {
                _dwTextBlockLib.setText(newText);
                Size textSize = _dwTextBlockLib.getTextSize();

                // サイズ変更
                grid.Width  = textSize.Width;
                grid.Height = textSize.Height;
                InteropImage.SetPixelSize((int)Math.Ceiling(textSize.Width), (int)Math.Ceiling(textSize.Height));
            }
        }
        private void ImageHostGridSizeChanged(object sender, SizeChangedEventArgs e)
        {
            var dpiScale = 1.0; // default value for 96 dpi

            // determine DPI
            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)
            var hwndTarget = PresentationSource.FromVisual(this)?.CompositionTarget as HwndTarget;

            if (hwndTarget != null)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            var surfWidth  = (int)(ImageHostGrid.ActualWidth < 0 ? 0 : Math.Ceiling(ImageHostGrid.ActualWidth * dpiScale));
            var surfHeight = (int)(ImageHostGrid.ActualHeight < 0 ? 0 : Math.Ceiling(ImageHostGrid.ActualHeight * dpiScale));

            // Notify the D3D11Image of the pixel size desired for the DirectX rendering.
            // The D3DRendering component will determine the size of the new surface it is given, at that point.
            InteropImage.SetPixelSize(surfWidth, surfHeight);

            // Stop rendering if the D3DImage isn't visible - currently just if width or height is 0
            // TODO: more optimizations possible (scrolled off screen, etc...)
            var isVisible = surfWidth != 0 && surfHeight != 0;

            if (lastVisible == isVisible)
            {
                return;
            }

            lastVisible = isVisible;
            if (lastVisible)
            {
                CompositionTarget.Rendering += CompositionTarget_Rendering;
            }
            else
            {
                CompositionTarget.Rendering -= CompositionTarget_Rendering;
            }
        }
示例#7
0
        private void Host_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double dpiScale = 1.0; // default value for 96 dpi

            // determine DPI
            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)
            var hwndTarget = PresentationSource.FromVisual(this).CompositionTarget as HwndTarget;

            if (hwndTarget != null)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            int surfWidth  = (int)(host.ActualWidth < 0 ? 0 : Math.Ceiling(host.ActualWidth * dpiScale));
            int surfHeight = (int)(host.ActualHeight < 0 ? 0 : Math.Ceiling(host.ActualHeight * dpiScale));

            // notify the D3D11Image and the DxRendering component of the pixel size desired for the DirectX rendering.
            InteropImage.SetPixelSize(surfWidth, surfHeight);
            NativeMethods.SetRenderSize(surfWidth, surfHeight);

            // Stop rendering if the D3DImage isn't visible - currently just if width or height is 0
            // TODO: more optimizations possible (scrolled off screen, etc...)
            bool isVisible = (surfWidth != 0 && surfHeight != 0);

            if (lastVisible != isVisible)
            {
                lastVisible = isVisible;
                if (lastVisible)
                {
                    CompositionTarget.Rendering += CompositionTarget_Rendering;
                }
                else
                {
                    CompositionTarget.Rendering -= CompositionTarget_Rendering;
                }
            }
        }
示例#8
0
        private void SetInteropImagePixelSize()
        {
            double dpiScale = 1.0; // default value for 96 dpi

            // determine DPI
            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)
            PresentationSource presentationSource = PresentationSource.FromVisual(this);
            var hwndTarget = presentationSource?.CompositionTarget as HwndTarget;

            if (hwndTarget != null)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            int surfWidth  = (int)(ImageContainer.ActualWidth < 0 ? 0 : Math.Ceiling(ImageContainer.ActualWidth * dpiScale));
            int surfHeight = (int)(ImageContainer.ActualHeight < 0 ? 0 : Math.Ceiling(ImageContainer.ActualHeight * dpiScale));

            // notify the D3D11Image and the DxRendering component of the pixel size desired for the DirectX rendering.
            InteropImage.SetPixelSize(surfWidth, surfHeight);

            //make sure the resources are created
            SyncGeometriesWithShapes();
            SyncBrushesWithShapes();
        }
示例#9
0
        private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Size size = Utils.WpfSizeToPixels(ImageGrid);

            InteropImage.SetPixelSize((int)size.Width, (int)size.Height);
        }