Пример #1
0
        protected virtual void Enable(IUserInterfaceWindow window)
        {
            var snappingWindow = new SnappingWindow(window.Handle);

            snappingWindow.InitializeComponent(this.Core);
            this.Windows.Add(window, snappingWindow);
        }
Пример #2
0
        protected virtual void Resize(SnappingWindow snappingWindow, Point offset, SnapDirection direction)
        {
            var bounds = snappingWindow.Adapter.Bounds;

            if (this.ResizeDirection.HasFlag(ResizeDirection.Left))
            {
                if (direction.HasFlag(SnapDirection.InsideLeft) && direction.HasFlag(SnapDirection.InsideRight))
                {
                    bounds.X     = snappingWindow.PreviousBounds.X + offset.X;
                    bounds.Width = snappingWindow.PreviousBounds.Width - offset.X;
                }
                else if (direction.HasFlag(SnapDirection.InsideLeft) || direction.HasFlag(SnapDirection.OutsideRight))
                {
                    bounds.X = snappingWindow.PreviousBounds.X + offset.X;
                }
            }

            if (this.ResizeDirection.HasFlag(ResizeDirection.Right))
            {
                if (direction.HasFlag(SnapDirection.InsideLeft) && direction.HasFlag(SnapDirection.InsideRight))
                {
                    bounds.Width = snappingWindow.PreviousBounds.Width + offset.X;
                }
                else if (direction.HasFlag(SnapDirection.OutsideLeft) || direction.HasFlag(SnapDirection.InsideRight))
                {
                    bounds.X = snappingWindow.PreviousBounds.X + offset.X;
                }
            }

            if (this.ResizeDirection.HasFlag(ResizeDirection.Top))
            {
                if (direction.HasFlag(SnapDirection.InsideTop) && direction.HasFlag(SnapDirection.InsideBottom))
                {
                    bounds.Y      = snappingWindow.PreviousBounds.Y + offset.Y;
                    bounds.Height = snappingWindow.PreviousBounds.Height - offset.Y;
                }
                else if (direction.HasFlag(SnapDirection.InsideTop) || direction.HasFlag(SnapDirection.OutsideBottom))
                {
                    bounds.Y = snappingWindow.PreviousBounds.Y + offset.Y;
                }
            }

            if (this.ResizeDirection.HasFlag(ResizeDirection.Bottom))
            {
                if (direction.HasFlag(SnapDirection.InsideTop) && direction.HasFlag(SnapDirection.InsideBottom))
                {
                    bounds.Height = snappingWindow.PreviousBounds.Height + offset.Y;
                }
                else if (direction.HasFlag(SnapDirection.OutsideTop) || direction.HasFlag(SnapDirection.InsideBottom))
                {
                    bounds.Y = snappingWindow.PreviousBounds.Y + offset.Y;
                }
            }

            if (snappingWindow.Adapter.Bounds != bounds)
            {
                snappingWindow.Adapter.Bounds = bounds;
            }
        }
Пример #3
0
 protected static void OnActiveChanged(SnappingWindow sender)
 {
     if (ActiveChanged == null)
     {
         return;
     }
     ActiveChanged(sender, EventArgs.Empty);
 }
Пример #4
0
        protected virtual void Move(SnappingWindow snappingWindow, Point offset, SnapDirection direction)
        {
            var bounds   = snappingWindow.Adapter.Bounds;
            var location = new Point(
                snappingWindow.PreviousBounds.X - offset.X,
                snappingWindow.PreviousBounds.Y - offset.Y
                );

            bounds.Location = location;
            if (snappingWindow.Adapter.Bounds != bounds)
            {
                snappingWindow.Adapter.Bounds = bounds;
            }
        }
Пример #5
0
        public static void ForEachStickyWindow(SnappingWindow snappingWindow, Action <SnappingWindow> action)
        {
            var queue     = new Queue <SnappingWindow>(snappingWindow.StickyWindows.Keys);
            var activated = new HashSet <SnappingWindow>(new[] { snappingWindow });

            while (queue.Count > 0)
            {
                var stickyWindow = queue.Dequeue();
                if (!activated.Add(stickyWindow))
                {
                    continue;
                }
                queue.EnqueueRange(stickyWindow.StickyWindows.Keys);
                action(stickyWindow);
            }
        }
Пример #6
0
 protected virtual bool IsStuck(SnappingWindow snappingWindow, SnapDirection direction)
 {
     if (this.ResizeDirection.HasFlag(ResizeDirection.Left))
     {
         return(direction.HasFlag(SnapDirection.InsideLeft) || direction.HasFlag(SnapDirection.OutsideRight));
     }
     if (this.ResizeDirection.HasFlag(ResizeDirection.Right))
     {
         return(direction.HasFlag(SnapDirection.InsideRight) || direction.HasFlag(SnapDirection.OutsideLeft));
     }
     if (this.ResizeDirection.HasFlag(ResizeDirection.Top))
     {
         return(direction.HasFlag(SnapDirection.InsideTop) || direction.HasFlag(SnapDirection.OutsideBottom));
     }
     if (this.ResizeDirection.HasFlag(ResizeDirection.Bottom))
     {
         return(direction.HasFlag(SnapDirection.InsideBottom) || direction.HasFlag(SnapDirection.OutsideTop));
     }
     return(false);
 }