예제 #1
0
        /// <summary>
        /// Gets the resolution in DPI of the target device of a visual.
        /// </summary>
        static public Point GetResolution(Visual visual)
        {
            Point dpi = new Point(120, 120);

            PresentationSource source = PresentationSource.FromVisual(visual);

            if (source == null)
            {
                return(dpi);
            }

            CompositionTarget target = source.CompositionTarget;

            Matrix          m = target.TransformToDevice;
            MatrixTransform t = new MatrixTransform(m);

            Point pt1 = new Point(0, 0);

            pt1 = t.Transform(pt1);

            Point pt2 = new Point(96, 96);

            pt2 = t.Transform(pt2);

            dpi.X = pt2.X - pt1.X;
            dpi.Y = pt2.Y - pt1.Y;
            return(dpi);
        }
        void Reposition()
        {
            _repositionCallback = null;

            Point             offset     = _placementTarget.TranslatePoint(new Point(), _owner);
            Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
            HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(_owner);
            CompositionTarget ct         = hwndSource.CompositionTarget;

            offset = ct.TransformToDevice.Transform(offset);
            size   = ct.TransformToDevice.Transform(size);

            POINT screenLocation = new POINT(offset);

            WinformWin32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            POINT screenSize = new POINT(size);

            try
            {
                WinformWin32.MoveWindow(_form.Handle, screenLocation.x, screenLocation.y, screenSize.x, screenSize.y, true);
            }
            catch
            {
            }
        }
예제 #3
0
        private void InitializeComposition()
        {
            // setup compositor and root visual
            this.compositor = new Compositor();
            this.root = this.compositor.CreateContainerVisual();

            // associate with the CoreWindow
            this.compositionTarget = this.compositor.CreateTargetForCurrentView();
            this.compositionTarget.Root = this.root;

            // add a solid color background
            this.background = this.compositor.CreateSpriteVisual();
            this.background.Brush = this.compositor.CreateColorBrush(Colors.LightGreen);
            this.root.Children.InsertAtBottom(this.background);

            // create green square
            var colorVisual = this.compositor.CreateSpriteVisual();
            colorVisual.Brush = this.compositor.CreateColorBrush(Colors.Green);
            colorVisual.Size = new Vector2(150.0f, 150.0f);
            colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
            this.target = colorVisual;
            this.root.Children.InsertAtTop(this.target);

            // animate square
            Animate(this.target);

            UpdateSize();
        }
예제 #4
0
        public void UpdateWindowPos()
        {
            if (this._isDisposed)
            {
                return;
            }
            PresentationSource presentationSource = null;
            CompositionTarget  compositionTarget  = null;

            if (this.CriticalHandle != IntPtr.Zero && base.IsVisible)
            {
                presentationSource = PresentationSource.CriticalFromVisual(this, false);
                if (presentationSource != null)
                {
                    compositionTarget = presentationSource.CompositionTarget;
                }
            }
            if (compositionTarget != null && compositionTarget.RootVisual != null)
            {
                NativeMethods.RECT rc = this.CalculateAssignedRC(presentationSource);
                Rect rcBoundingBox    = PointUtil.ToRect(rc);
                this.OnWindowPositionChanged(rcBoundingBox);
                UnsafeNativeMethods.ShowWindowAsync(this._hwnd, 5);
                return;
            }
            UnsafeNativeMethods.ShowWindowAsync(this._hwnd, 0);
        }
예제 #5
0
        private static void GetClippedPositionOffsets(TextEditor This, ITextPointer position, LogicalDirection direction, out double horizontalOffset, out double verticalOffset)
        {
            Rect characterRect = position.GetCharacterRect(direction);

            horizontalOffset = characterRect.X;
            verticalOffset   = characterRect.Y + characterRect.Height;
            FrameworkElement frameworkElement = This.TextView.RenderScope as FrameworkElement;

            if (frameworkElement != null)
            {
                GeneralTransform generalTransform = frameworkElement.TransformToAncestor(This.UiScope);
                if (generalTransform != null)
                {
                    TextEditorContextMenu.ClipToElement(frameworkElement, generalTransform, ref horizontalOffset, ref verticalOffset);
                }
            }
            for (Visual visual = This.UiScope; visual != null; visual = (VisualTreeHelper.GetParent(visual) as Visual))
            {
                frameworkElement = (visual as FrameworkElement);
                if (frameworkElement != null)
                {
                    GeneralTransform generalTransform2 = visual.TransformToDescendant(This.UiScope);
                    if (generalTransform2 != null)
                    {
                        TextEditorContextMenu.ClipToElement(frameworkElement, generalTransform2, ref horizontalOffset, ref verticalOffset);
                    }
                }
            }
            PresentationSource presentationSource = PresentationSource.CriticalFromVisual(This.UiScope);
            IWin32Window       win32Window        = presentationSource as IWin32Window;

            if (win32Window != null)
            {
                IntPtr handle = IntPtr.Zero;
                new UIPermission(UIPermissionWindow.AllWindows).Assert();
                try
                {
                    handle = win32Window.Handle;
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
                NativeMethods.RECT rect = new NativeMethods.RECT(0, 0, 0, 0);
                SafeNativeMethods.GetClientRect(new HandleRef(null, handle), ref rect);
                Point             point             = new Point((double)rect.left, (double)rect.top);
                Point             point2            = new Point((double)rect.right, (double)rect.bottom);
                CompositionTarget compositionTarget = presentationSource.CompositionTarget;
                point  = compositionTarget.TransformFromDevice.Transform(point);
                point2 = compositionTarget.TransformFromDevice.Transform(point2);
                GeneralTransform generalTransform3 = compositionTarget.RootVisual.TransformToDescendant(This.UiScope);
                if (generalTransform3 != null)
                {
                    generalTransform3.TryTransform(point, out point);
                    generalTransform3.TryTransform(point2, out point2);
                    horizontalOffset = TextEditorContextMenu.ClipToBounds(point.X, horizontalOffset, point2.X);
                    verticalOffset   = TextEditorContextMenu.ClipToBounds(point.Y, verticalOffset, point2.Y);
                }
            }
        }
예제 #6
0
        private void InitializeComposition()
        {
            // setup compositor and root visual
            this.compositor = new Compositor();
            this.root       = this.compositor.CreateContainerVisual();

            // associate with the CoreWindow
            this.compositionTarget      = this.compositor.CreateTargetForCurrentView();
            this.compositionTarget.Root = this.root;

            // add a solid color background
            this.background       = this.compositor.CreateSpriteVisual();
            this.background.Brush = this.compositor.CreateColorBrush(Colors.LightGreen);
            this.root.Children.InsertAtBottom(this.background);

            // create green square
            var colorVisual = this.compositor.CreateSpriteVisual();

            colorVisual.Brush       = this.compositor.CreateColorBrush(Colors.Green);
            colorVisual.Size        = new Vector2(150.0f, 150.0f);
            colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
            this.target             = colorVisual;
            this.root.Children.InsertAtTop(this.target);

            // animate square
            Animate(this.target);

            UpdateSize();
        }
            private void ShowSystemMenu(object sender, ExecutedRoutedEventArgs e)
            {
                Point point    = _window.PointToScreen(new Point(0, 0));
                var   dipScale = WindowParameters.GetDpi() / 96d;

                if (_window.WindowState == WindowState.Maximized)
                {
                    // 因为不想在最大化时改变标题高度,所以这里的计算方式和标准计算方式不一样
                    point.X += (SystemParameters.WindowNonClientFrameThickness.Left + WindowParameters.PaddedBorderThickness.Left) * dipScale;
                    point.Y += (SystemParameters.WindowNonClientFrameThickness.Top +
                                WindowParameters.PaddedBorderThickness.Top +
                                SystemParameters.WindowResizeBorderThickness.Top -
                                _window.BorderThickness.Top)
                               * dipScale;
                }
                else
                {
                    point.X += _window.BorderThickness.Left * dipScale;
                    point.Y += SystemParameters.WindowNonClientFrameThickness.Top * dipScale;
                }

                CompositionTarget compositionTarget = PresentationSource.FromVisual(_window).CompositionTarget;

                SystemCommands.ShowSystemMenu(_window, compositionTarget.TransformFromDevice.Transform(point));
                e.Handled = true;
            }
예제 #8
0
파일: View.cs 프로젝트: wyepez/VisualApp
        public void SetWindow(CoreWindow window)
        {
            compositor        = new Compositor();
            compositionTarget = compositor.CreateTargetForCurrentView();

            ContainerVisual container = compositor.CreateContainerVisual();

            compositionTarget.Root = container;

            SpriteVisual visual = compositor.CreateSpriteVisual();

            visual.Size   = new Vector2(100, 100);
            visual.Offset = new Vector3(10, 10, 0);
            visual.Brush  = compositor.CreateColorBrush(Colors.Red);

            container.Children.InsertAtTop(visual);

            ScalarKeyFrameAnimation anim = compositor.CreateScalarKeyFrameAnimation();

            anim.InsertKeyFrame(0.0f, 0.0f);
            anim.InsertKeyFrame(1.0f, 360.0f);
            anim.Duration          = TimeSpan.FromSeconds(1);
            anim.IterationBehavior = AnimationIterationBehavior.Forever;
            visual.StartAnimation("RotationAngleInDegrees", anim);
        }
예제 #9
0
        void OnSizeLocationChanged()
        {
            try
            {
                if (this.Visibility == System.Windows.Visibility.Visible)
                {
                    Point             offset     = _placementTarget.TranslatePoint(new Point(), Owner);
                    Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
                    HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
                    CompositionTarget ct         = hwndSource.CompositionTarget;
                    offset = ct.TransformToDevice.Transform(offset);
                    size   = ct.TransformToDevice.Transform(size);

                    Win32.POINT screenLocation = new Win32.POINT(offset);
                    Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
                    Win32.POINT screenSize = new Win32.POINT(size);
                    try
                    {
                        Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }
예제 #10
0
    public void SetWindow(CoreWindow window)
    {
        Compositor      compositor = new Compositor();
        ContainerVisual root       = compositor.CreateContainerVisual();

        m_target      = compositor.CreateTargetForCurrentView();
        m_target.Root = root;

        Uri localUri     = new Uri("ms-appx:///Assets/StoreLogo.png");
        var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(compositor);

        CompositionImageOptions options = new CompositionImageOptions()
        {
            DecodeWidth  = 400,
            DecodeHeight = 400,
        };

        var image  = imageFactory.CreateImageFromUri(localUri, options);
        var visual = compositor.CreateSpriteVisual();

        visual.Size  = new Vector2(400.0f, 400.0f);
        visual.Brush = compositor.CreateSurfaceBrush(image.Surface);
        root.Children.InsertAtTop(visual);

        image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) =>
        {
            if (status != CompositionImageLoadStatus.Success)
            {
                visual.Brush = compositor.CreateColorBrush(Colors.Red);
            }
        };
    }
예제 #11
0
        private static void SystemMenuExecuted(object sender, ExecutedRoutedEventArgs args)
        {
            RibbonWindow rw = sender as RibbonWindow;

            if (rw != null)
            {
                // For right-clicks, display the system menu from the point of the mouse click.
                // For left-clicks, display the system menu in the top-left corner of the client area.
                Point devicePoint;
                MouseButtonEventArgs e = args.Parameter as MouseButtonEventArgs;
                if (e != null)
                {
                    // This is the right-click handler.  The presence of a MouseButtonEventArgs as args.Parameter
                    // indicates we are handling right-click.
                    devicePoint = rw.PointToScreen(e.GetPosition(rw));
                }
                else if (rw._clientAreaBorder != null)
                {
                    // This is the left-click handler.  We can only handle it correctly if the _clientAreaBorder
                    // template part is defined, because that is where we want to position the system menu.
                    devicePoint = rw._clientAreaBorder.PointToScreen(new Point(0, 0));
                }
                else
                {
                    // We can't handle this correctly, so exit.
                    return;
                }

                CompositionTarget compositionTarget = PresentationSource.FromVisual(rw).CompositionTarget;
                SystemCommands.ShowSystemMenu(rw, compositionTarget.TransformFromDevice.Transform(devicePoint));
                args.Handled = true;
            }
        }
예제 #12
0
 public CanvasPresentationSource(ICanvasPresentationSourceHost host, CompositionTarget compositionTarget) : base(compositionTarget)
 {
     Validate.IsNotNull <ICanvasPresentationSourceHost>(host, "host");
     this.host           = host;
     this.mouseDevice    = new CanvasMouseDevice(this);
     this.keyboardDevice = new WinFormsKeyboardDevice(this);
 }
예제 #13
0
        public async void SetWindow(CoreWindow window)
        {
            this.Window = window;

            if (!Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 2))
            {
                var dialog = new MessageDialog("This version of Windows does not support the Composition APIs.");
                await dialog.ShowAsync();

                CoreApplication.Exit();
                return;
            }

            window.PointerPressed += Window_PointerPressed;

            CoreApplication.Suspending += CoreApplication_Suspending;
            DisplayInformation.DisplayContentsInvalidated += DisplayInformation_DisplayContentsInvalidated;

            Compositor = new Compositor();

            CreateDevice();

            SwapChainRenderer = new SwapChainRenderer(Compositor);
            SwapChainRenderer.SetDevice(Device, new Size(window.Bounds.Width, window.Bounds.Height));

            SwapChainRenderer.Visual.Offset = new Vector3((float)window.Bounds.Width, (float)window.Bounds.Height, 0);

            RootVisual = Compositor.CreateContainerVisual();
            RootVisual.Children.InsertAtTop(SwapChainRenderer.Visual);

            CompositionTarget      = Compositor.CreateTargetForCurrentView();
            CompositionTarget.Root = RootVisual;

            var ignoredTask = UpdateVisualsLoop();
        }
예제 #14
0
        // https://docs.microsoft.com/en-us/windows/uwp/composition/visual-layer
        // https://github.com/microsoft/CsWinRT/blob/master/docs/interop.md
        public static void DoVisualLayerStuff(IntPtr hwnd)
        {
            _ = CreateDispatcherQueueControllerForCurrentThread();

            bool rectResult = GetWindowRect(hwnd, out RECT rect);

            if (!rectResult)
            {
                ThrowLoastWin32();
            }

            hwnd = CreateWindow(
                "STATIC",
                "Animation Window",
                WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD,
                rect.left, rect.top,
                rect.right - rect.left, rect.bottom - rect.top,
                hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            Console.WriteLine($"Created new child: 0x{hwnd:X}");

            Compositor compositor = new();
            var        ptr        = compositor.As <ICompositorDesktopInterop>();

            ptr.CreateDesktopWindowTarget(hwnd, false, out IntPtr desktopWindowTargetAbi);

            //DesktopWindowTarget dwt = ABI.Windows.UI.Composition.Desktop.DesktopWindowTarget.FromAbi(desktopWindowTargetAbi);
            CompositionTarget cwt             = ABI.Windows.UI.Composition.CompositionTarget.FromAbi(desktopWindowTargetAbi);
            ContainerVisual   containerVisual = compositor.CreateContainerVisual();

            cwt.Root = containerVisual;

            Console.WriteLine("Press Q to quit");
            PumpMessageUntilQKey(hwnd, (nextValue) => XXX(nextValue, compositor, containerVisual));
        }
예제 #15
0
        private void OnRootSizeChanged(object sender, SizeChangedEventArgs e)
        {
            CompositionTarget ct     = GetCompositionTarget(Root);
            Vector            dips   = new Vector(Root.ActualWidth, Root.ActualHeight);
            Vector            pixels = ct.TransformToDevice.Transform(dips);

            _package.ReflexilWindow.Width  = (int)pixels.X;
            _package.ReflexilWindow.Height = (int)pixels.Y;
        }
예제 #16
0
        /// <summary>
        ///     Converts a rectangle from root visual co-ordinate space to Win32 client
        /// </summary>
        /// <remarks>
        ///     RootToClient takes into account device DPI settings to convert to/from Avalon's assumed 96dpi
        ///     and any "root level" transforms applied to the root such as "right-to-left" inversions.
        /// </remarks>
        /// <param name="rectRoot">
        ///     The rectangle to be converted
        /// </param>
        /// <param name="presentationSource">
        ///     The PresentationSource which hosts the root visual.  This is passed in for performance reasons.
        /// </param>
        /// <returns>
        ///     The rectangle in Win32 client co-ordinate space
        /// </returns>
        internal static Rect RootToClient(Rect rectRoot, PresentationSource presentationSource)
        {
            CompositionTarget target = presentationSource.CompositionTarget;
            Matrix            matrixRootTransform = PointUtil.GetVisualTransform(target.RootVisual);
            Rect   rectRootUntransformed          = Rect.Transform(rectRoot, matrixRootTransform);
            Matrix matrixDPI  = target.TransformToDevice;
            Rect   rectClient = Rect.Transform(rectRootUntransformed, matrixDPI);

            return(rectClient);
        }
        private void InitializeCompositor()
        {
            //Create Compositor, Target, RootVisual, Configure Target
            _compositor = new Compositor();

            _target = _compositor.CreateTargetForCurrentView();

            _rootVisual = _compositor.CreateContainerVisual();

            _target.Root = _rootVisual;
        }
예제 #18
0
 private void on_size_and_location_changing()
 {
     if ((XPorter.Bus.Main_Handle.MainTab.SelectedItem == Item) && (this.IsVisible))
     {
         HwndSource        hwnd_source     = (HwndSource)HwndSource.FromVisual(Owner);
         CompositionTarget compose_target  = hwnd_source.CompositionTarget;
         Point             offset          = compose_target.TransformToDevice.Transform(XPorter.Bus.Global_Offset_Tabs);
         Point             size            = compose_target.TransformToDevice.Transform(XPorter.Bus.Global_Size_Tabs);
         Win32.POINT       screen_location = new Win32.POINT(offset);
         Win32.ClientToScreen(hwnd_source.Handle, ref screen_location);
         Win32.POINT screen_size = new Win32.POINT(size);
         Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screen_location.X, screen_location.Y, screen_size.X, screen_size.Y, true);
     }
 }
예제 #19
0
        private void OnLayoutUpdated(object sender, EventArgs eventArgs)
        {
            CompositionTarget  ct     = null;
            PresentationSource source = PresentationSource.FromVisual(m_elementAttachedTo);

            if (source != null)
            {
                ct = source.CompositionTarget;
            }

            if (ct != null && ct.RootVisual != null)
            {
                UpdateBoundingBox(CalculateAssignedRC(source));
            }
        }
예제 #20
0
            public static void dock_panel_prev_mouse_down(object sender, MouseButtonEventArgs e)
            {
                ContentControl connector_panel = (ContentControl)((DockPanel)sender).TemplatedParent;
                Panel          trgt_panel      = connector_panel.Parent as Panel;
                MainWindow     m_window        = (MainWindow)MainWindow.GetWindow((DockPanel)sender);

                Old_P = e.GetPosition(m_window);
                System.Windows.Point cn_xy = e.GetPosition(connector_panel);

                //------------------------------------------------------------------------------------//
                System.Windows.Point offset     = Target_Panel.TranslatePoint(new System.Windows.Point(), XPorter.Bus.Main_Handle);
                System.Windows.Point size       = new System.Windows.Point(Target_Panel.ActualWidth, Target_Panel.ActualHeight);
                HwndSource           hwndSource = (HwndSource)HwndSource.FromVisual(XPorter.Bus.Main_Handle);
                CompositionTarget    ct         = hwndSource.CompositionTarget;

                offset = ct.TransformToDevice.Transform(offset);
                size   = ct.TransformToDevice.Transform(size);
                Win32.POINT screenLocation = new Win32.POINT(offset);
                Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
                Win32.POINT screenSize = new Win32.POINT(size);

                System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(screenLocation.X + (int)cn_xy.X,
                                                                                screenLocation.Y + (int)cn_xy.Y, screenSize.X - (int)connector_panel.Width + 1,
                                                                                screenSize.Y - (int)connector_panel.Height + 1);
                //if (m_window.WindowState == System.Windows.WindowState.Normal)                                                      //if position is normal we can clip mouse
                //{
                //    System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(
                //        (int)m_window.Left + (int)cn_xy.X + 4,
                //        (int)m_window.Top + (int)cn_xy.Y + 2 + XPorter.Bus.Top,
                //        (int)m_window.Width - (int)connector_panel.Width - 7,
                //        (int)m_window.Height - (int)connector_panel.Height - 4 - XPorter.Bus.Top - XPorter.Bus.Bottom);
                //}
                //else
                //{
                //    System.Drawing.Rectangle MaximizePadding = new System.Drawing.Rectangle(
                //        (int)SystemParameters.WorkArea.Left, (int)SystemParameters.WorkArea.Top,
                //        (int)(SystemParameters.PrimaryScreenWidth - SystemParameters.WorkArea.Right),
                //        (int)(SystemParameters.PrimaryScreenHeight - SystemParameters.WorkArea.Bottom));

                //    System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(
                //       MaximizePadding.Left - 3 + (int)cn_xy.X,
                //       MaximizePadding.Top + (int)cn_xy.Y + XPorter.Bus.Top - 5,
                //       (int)trgt_panel.ActualWidth - MaximizePadding.Width - (int)connector_panel.ActualWidth - 7,
                //       (int)trgt_panel.ActualHeight - MaximizePadding.Height -
                //       (int)connector_panel.ActualHeight - 4 - XPorter.Bus.Top - XPorter.Bus.Bottom);
                //}
                ((DockPanel)sender).CaptureMouse();
            }
예제 #21
0
        private void InitializeComposition()
        {
            // setup compositor and root visual
            this.compositor = new Compositor();
            this.rootVisual = this.compositor.CreateContainerVisual();

            // associate with the CoreWindow
            this.compositionTarget = this.compositor.CreateTargetForCurrentView();
            this.compositionTarget.Root = this.rootVisual;

            // add a solid color background
            this.background = this.compositor.CreateSolidColorVisual();
            this.background.Color = Colors.LightGreen;
            this.rootVisual.Children.InsertAtBottom(this.background);

            UpdateSize();
        }
예제 #22
0
            internal Matrix GetTransformFromDevice()
            {
                CompositionTarget ct = _window.CompositionTarget;

                if (ct != null)
                {
                    try
                    {
                        return(ct.TransformFromDevice);
                    }
                    catch (ObjectDisposedException)
                    {
                    }
                }

                return(Matrix.Identity);
            }
예제 #23
0
        private void InitializeComposition()
        {
            // setup compositor and root visual
            this.compositor = new Compositor();
            this.rootVisual = this.compositor.CreateContainerVisual();

            // associate with the CoreWindow
            this.compositionTarget      = this.compositor.CreateTargetForCurrentView();
            this.compositionTarget.Root = this.rootVisual;

            // add a solid color background
            this.background       = this.compositor.CreateSolidColorVisual();
            this.background.Color = Colors.LightGreen;
            this.rootVisual.Children.InsertAtBottom(this.background);

            UpdateSize();
        }
예제 #24
0
        void DataTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (e.AddedItems.Count > 0)
                {
                    if ((e.AddedItems[0] as TabItem) != null)
                    {
                        if (IsChild((e.AddedItems[0] as TabItem), _placementTarget))
                        {
                            Show();
                            Point _offset = _placementTarget.TranslatePoint(new Point(), Owner);
                            if (offset.X < _offset.X || offset.Y < _offset.Y)
                            {
                                offset = _offset;

                                Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
                                HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
                                CompositionTarget ct         = hwndSource.CompositionTarget;
                                offset = ct.TransformToDevice.Transform(offset);
                                size   = ct.TransformToDevice.Transform(size);

                                Win32.POINT screenLocation = new Win32.POINT(offset);
                                Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
                                Win32.POINT screenSize = new Win32.POINT(size);

                                Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
                            }
                        }
                        else
                        {
                            Hide();
                        }
                    }
                    else
                    {
                        Hide();
                    }
                }
            }
            catch
            {
            }
        }
예제 #25
0
        private void InitComposition(float controlsWidth)
        {
            // Create the compositor.
            compositor = new Compositor();

            // Create a target for the window.
            target = compositor.CreateDesktopWindowTarget(hwnd, true);

            // Attach the root visual.
            root = compositor.CreateContainerVisual();
            root.RelativeSizeAdjustment = Vector2.One;
            root.Size   = new Vector2(-controlsWidth, 0);
            root.Offset = new Vector3(controlsWidth, 0, 0);
            target.Root = root;

            // Setup the rest of the sample application.
            //sample = new BasicSampleApplication(compositor);
            //root.Children.InsertAtTop(sample.Visual);
        }
예제 #26
0
 void on_size_and_location_changing()
 {
     if ((XPorter.Bus.Main_Handle.MainTab.SelectedItem == Item) && (this.Visible))
     {
         System.Windows.Point offset     = Placement_Target.TranslatePoint(new System.Windows.Point(), owner);
         System.Windows.Point size       = new System.Windows.Point(Placement_Target.ActualWidth, Placement_Target.ActualHeight);
         HwndSource           hwndSource = (HwndSource)HwndSource.FromVisual(owner);
         CompositionTarget    ct         = hwndSource.CompositionTarget;
         offset = ct.TransformToDevice.Transform(offset);
         size   = ct.TransformToDevice.Transform(size);
         Win32.POINT screenLocation = new Win32.POINT(offset);
         Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
         Win32.POINT screenSize = new Win32.POINT(size);
         Win32.MoveWindow(Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
     }
     //if (this.Width < 20) Visible = false;
     //else
     //    Visible = true;
 }
        void OnSizeLocationChanged()
        {
            Point             offset     = _placementTarget.TranslatePoint(new Point(), Owner);
            Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
            HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
            CompositionTarget ct         = hwndSource.CompositionTarget;

            offset = ct.TransformToDevice.Transform(offset);
            size   = ct.TransformToDevice.Transform(size);

            Win32.POINT screenLocation = new Win32.POINT(offset);
            Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            Win32.POINT screenSize = new Win32.POINT(size);
            var         hwnsource  = (HwndSource)HwndSource.FromVisual(this);

            if (hwnsource != null)
            {
                Win32.MoveWindow(hwnsource.Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
            }
        }
예제 #28
0
        private void Reposition()
        {
            _repositionCallback = null;

            Point             offset     = _placementTarget.TranslatePoint(new Point(), _owner);
            Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
            HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(_owner);
            CompositionTarget ct         = hwndSource.CompositionTarget;

            offset = ct.TransformToDevice.Transform(offset);
            size   = ct.TransformToDevice.Transform(size);

            Win32.POINT screenLocation = new Win32.POINT(offset);
            Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            Win32.POINT screenSize = new Win32.POINT(size);

            Win32.MoveWindow(_form.Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
            _form.SetBounds(screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y);
            _form.Update();
        }
예제 #29
0
        void Reposition()
        {
            //release DispatcherOperation
            _repositionCallback = null;
            //get WPF Window location
            var translatePoint = _PlacementTarget.TranslatePoint(new Point(), _WpfWindow);
            //get size of placement target
            var translateSize = new Point(_PlacementTarget.ActualWidth, _PlacementTarget.ActualHeight);
            //get HwndSource of WPF Window
            var hwndSource = (HwndSource)PresentationSource.FromVisual(_WpfWindow);

            if (hwndSource == null)
            {
                return;
            }
            //get the visual manager of target window
            CompositionTarget ct = hwndSource.CompositionTarget;

            if (ct == null)
            {
                return;
            }
            //transform location and size
            translatePoint = ct.TransformToDevice.Transform(translatePoint);
            translateSize  = ct.TransformToDevice.Transform(translateSize);

            var screenLocation = new PNInterop.POINTINT(translatePoint);

            PNInterop.ClientToScreen(hwndSource.Handle, ref screenLocation);
            var screenSize = new PNInterop.POINTINT(translateSize);

            //move WinForm
            PNInterop.MoveWindow(_WinForm.Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
            if (EditControlSizeChanged != null)
            {
                //raise EditControlSizeChanged event providing new PNRichEditBox size
                EditControlSizeChanged(this,
                                       new EditControlSizeChangedEventArgs(new Rectangle(new System.Drawing.Point(0, 0),
                                                                                         _EditBox.Size)));
            }
        }
예제 #30
0
        public static void RetrieveDPI(Window wnd)
        {
            try
            {
                if (!wnd.IsVisible)
                {
                    //Первый дефолт
                    dpi = 0;

                    IntPtr ScreenDC = IntPtr.Zero;
                    try
                    {
                        //Когда окна еще нет
                        ScreenDC = GetDC(IntPtr.Zero); //88-x(w), 90-y(h)
                        dpi      = (double)GetDeviceCaps(ScreenDC, 88) / 96.0;
                    }
                    finally
                    {
                        ReleaseDC(IntPtr.Zero, ScreenDC);
                    }
                }
                else
                {
                    //Второй дефолт
                    dpi = 1;

                    //Когда окно уже есть (это вторая попытка)
                    PresentationSource source = PresentationSource.FromVisual(wnd);
                    if (source != null)
                    {
                        CompositionTarget target = source.CompositionTarget; //M11-x(w), M22-y(h)
                        if (target != null)
                        {
                            dpi = source.CompositionTarget.TransformToDevice.M11;
                        }
                    }
                }
            }
            catch (Exception) { }
        }
예제 #31
0
 private static void OnMouseMove(object sender, MouseEventArgs e)
 {
     PaintDotNet.UI.FrameworkElement visual = (PaintDotNet.UI.FrameworkElement)sender;
     if (visual.IsMouseCaptured)
     {
         CompositionTarget compositionTarget = PresentationSource.FromVisual(visual).CompositionTarget;
         PointDouble       position          = e.GetPosition(visual);
         bool flag = visual.HitTestLocal(position);
         SetIsPressed(visual, flag);
         if (GetIsDragging(visual))
         {
             visual.RaiseEvent(new MouseEventArgs(e.InputDevice, DragMoveEvent, visual));
         }
         else if (GetAllowDrag(visual))
         {
             VectorDouble    num8;
             PointDouble     mouseCapturePoint = GetMouseCapturePoint(visual);
             PointDouble     pt             = e.GetPosition(visual);
             Matrix3x2Double matrixToDevice = compositionTarget.MatrixToDevice;
             PointDouble     num5           = matrixToDevice.Transform(mouseCapturePoint);
             VectorDouble    num7           = (VectorDouble)(matrixToDevice.Transform(pt) - num5);
             if (GetAllowClick(visual))
             {
                 num8 = new VectorDouble(PaintDotNet.UI.SystemParameters.MinimumHorizontalDragDistance, PaintDotNet.UI.SystemParameters.MinimumVerticalDragDistance);
             }
             else
             {
                 num8 = new VectorDouble(0.0, 0.0);
             }
             if ((Math.Abs(num7.X) >= num8.X) || (Math.Abs(num7.Y) >= num8.Y))
             {
                 SetIsDragging(visual, true);
                 visual.RaiseEvent(new MouseEventArgs(e.InputDevice, DragBeginEvent, visual));
             }
         }
         e.Handled = true;
     }
 }
예제 #32
0
        void OnSizeLocationChanged()
        {
            Point offset = _placementTarget.TranslatePoint(new Point(), Owner);
            Point size   = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);

            //Modify By mashalin 2014-8-29 修改报错
            if (Owner == null)
            {
                return;
            }

            HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
            CompositionTarget ct         = hwndSource.CompositionTarget;

            offset = ct.TransformToDevice.Transform(offset);
            size   = ct.TransformToDevice.Transform(size);

            Win32.POINT screenLocation = new Win32.POINT(offset);
            Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            Win32.POINT screenSize = new Win32.POINT(size);

            Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
        }
예제 #33
0
        //------------------------------------------------------------------------------
        //
        // VisualProperties.InitNewComposition
        //
        // This method is called by SetWindow(), where we initialize Composition after
        // the CoreWindow has been created.
        //
        //------------------------------------------------------------------------------
        void InitNewComposition()
        {
            //
            // Set up Windows.UI.Composition Compositor, root ContainerVisual, and associate with
            // the CoreWindow.
            //

            _compositor = new Compositor();

            _root = _compositor.CreateContainerVisual();

            #region temp dpi fix
            //temporary: manually correct for DPI
            float dpiScaleFactor = (float)Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
            _root.Scale = new Vector3(dpiScaleFactor, dpiScaleFactor, 1.0f);
            #endregion

            _compositionTarget = _compositor.CreateTargetForCurrentView();
            _compositionTarget.Root = _root;

            //
            // Create a few visuals for our window
            //
            for (int index = 0; index < 20; index++)
            {
                _root.Children.InsertAtTop(CreateChildElement());
            }
        }
        private void InitializeCompositor()
        {
            //Create Compositor, Target, RootVisual, Configure Target
            _compositor = new Compositor();

            _target = _compositor.CreateTargetForCurrentView();

            _rootVisual = _compositor.CreateContainerVisual();

            _target.Root = _rootVisual;
        }