/// <summary>
        /// Initialize screen capture in the window
        /// </summary>
        private void InitScreenCaptureComposition()
        {
            // Maximal size of the scrreen capture surface
            mScreenCaptureMaxSize = new Vector2(
                System.Windows.Forms.Screen.FromHandle(mWindowHandle).Bounds.Width / 2f,
                System.Windows.Forms.Screen.FromHandle(mWindowHandle).Bounds.Height / 2f
                );

            // Create the compositor.
            mCaptureCompositor = new Compositor();

            // Create a target for the window.
            mCaptureCompositionTarget = mCaptureCompositor.CreateDesktopWindowTarget(mWindowHandle, false);

            // Attach the root visual.
            mCaptureCompositionRootContainer = mCaptureCompositor.CreateContainerVisual();
            mCaptureCompositionRootContainer.RelativeSizeAdjustment   = Vector2.Zero;
            mCaptureCompositionRootContainer.RelativeOffsetAdjustment = Vector3.Zero;
            mCaptureCompositionRootContainer.Size = mScreenCaptureMaxSize;
            UpdateCaptureCompositionOffset(mOverlayData.ScreenCaptureOverlay.PosX, mOverlayData.ScreenCaptureOverlay.PosY);
            UpdateCaptureCompositionScale(mOverlayData.ScreenCaptureOverlay.Scale);
            UpdateCaptureCompositionOpacity(mOverlayData.ScreenCaptureOverlay.Opacity);
            mCaptureCompositionRootContainer.AnchorPoint = new Vector2(0, 0);
            mCaptureCompositionTarget.Root = mCaptureCompositionRootContainer;

            // Setup the rest of the sample application.
            mCaptureHandler = new OverlayScreenCaptureCaptureHandler(mCaptureCompositor);
            mCaptureCompositionRootContainer.Children.InsertAtTop(mCaptureHandler.Visual);
        }
Example #2
0
        void InitializeContainerVisual(Wd.ContainerVisual source, Wc.ContainerVisual target)
        {
            var children = target.Children;

            foreach (var child in source.Children)
            {
                children.InsertAtTop(GetVisual(child));
            }
        }
Example #3
0
        private void CompositionHostControl_Loaded(object sender, RoutedEventArgs e)
        {
            // If the user changes the DPI scale setting for the screen the app is on,
            // the CompositionHostControl is reloaded. Don't redo this set up if it's
            // already been done.
            if (compositionHost is null)
            {
                currentDpi = VisualTreeHelper.GetDpi(this);

                compositionHost = new CompositionHost(CompositionHostElement.ActualHeight, CompositionHostElement.ActualWidth);
                CompositionHostElement.Child = compositionHost;
                compositor            = compositionHost.Compositor;
                containerVisual       = compositor.CreateContainerVisual();
                compositionHost.Child = containerVisual;
            }
        }
Example #4
0
        public BarGraphHostControl()
        {
            InitializeComponent();
            Loaded             += BarGraphHostControl_Loaded;
            DataContextChanged += BarGraphHostControl_DataContextChanged;

            var currentDpi = VisualTreeHelper.GetDpi(this);

            _currentDpiX = currentDpi.PixelsPerInchX;
            _currentDpiY = currentDpi.PixelsPerInchY;

            _compositionHost             = new CompositionHost();
            CompositionHostElement.Child = _compositionHost;
            _compositionHost.RegisterForDispose(this);

            _compositor     = _compositionHost.Compositor;
            _graphContainer = _compositor.CreateContainerVisual();
        }
Example #5
0
        private void BarGraphHostControl_Loaded(object sender, RoutedEventArgs e)
        {
            // If the user changes the DPI scale setting for the screen the app is on,
            // the CompositionHostControl is reloaded. Don't redo this set up if it's
            // already been done.
            if (compositionHost is null)
            {
                var currentDpi = VisualTreeHelper.GetDpi(this);
                currentDpiX = currentDpi.PixelsPerInchX;
                currentDpiY = currentDpi.PixelsPerInchY;

                currentDpi = VisualTreeHelper.GetDpi(this);

                compositionHost = new CompositionHost(CompositionHostElement.ActualWidth, CompositionHostElement.ActualHeight, currentDpiX, currentDpiY);
                CompositionHostElement.Child = compositionHost;
                compositor            = compositionHost.Compositor;
                graphContainer        = compositor.CreateContainerVisual();
                compositionHost.Child = graphContainer;

                compositionHost.MouseMoved        += HostControl_MouseMoved;
                compositionHost.InvalidateDrawing += CompositionHost_InvalidateDrawing;

                // Create properties for render target
                var factory2D = new SharpDX.Direct2D1.Factory();
                var width     = (float)CompositionHostElement.ActualWidth;
                var height    = (float)CompositionHostElement.ActualHeight;

                var properties = new HwndRenderTargetProperties();
                properties.Hwnd           = compositionHost.hwndHost;
                properties.PixelSize      = new SharpDX.Size2((int)(width * currentDpiX / 96.0), (int)(width * currentDpiY / 96.0));
                properties.PresentOptions = PresentOptions.None;

                // Create render target
                windowRenderTarget             = new WindowRenderTarget(factory2D, new RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)), properties);
                windowRenderTarget.DotsPerInch = new Size2F((float)currentDpiX, (float)currentDpiY);
                windowRenderTarget.Resize(new Size2((int)(width * currentDpiX / 96.0), (int)(width * currentDpiY / 96.0)));
            }
        }