public GlowWindow(PpsWindow ownerWindow, GlowDirection direction) { this.ownerWindow = ownerWindow; this.direction = direction; CreateWindow( caption: String.Empty, style: NativeMethods.WS_POPUP | NativeMethods.WS_CLIPCHILDREN | NativeMethods.WS_CLIPSIBLINGS, exStyle: NativeMethods.WS_EX_TOOLWINDOW | NativeMethods.WS_EX_LAYERED, parentWindow: new WindowInteropHelper(ownerWindow).Owner ); CreateBitmaps(); } // ctor
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); this.IsGlowing = true; this.AllowsTransparency = true; this.Closing += (sender, e) => e.Cancel = !closing; this.Owner = owner; glow.Visibility = Visibility.Collapsed; var b = new Binding("GlowBrush"); b.Source = owner; glow.SetBinding(Glow.GlowBrushProperty, b); b = new Binding("NonActiveGlowBrush"); b.Source = owner; glow.SetBinding(Glow.NonActiveGlowBrushProperty, b); switch (direction) { case GlowDirection.Left: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Right; getLeft = (dpi) => Math.Round((owner.Left - glowSize) * dpi); getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => glowSize * dpi; getHeight = (dpi) => (owner.ActualHeight + glowSize * 2.0) * dpi; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE); }; break; case GlowDirection.Right: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Left; getLeft = (dpi) => Math.Round((owner.Left + owner.ActualWidth) * dpi); getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => glowSize * dpi; getHeight = (dpi) => (owner.ActualHeight + glowSize * 2.0) * dpi; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE); }; break; case GlowDirection.Top: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Bottom; getLeft = (dpi) => owner.Left * dpi; getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => Math.Round(owner.ActualWidth * dpi); getHeight = (dpi) => glowSize * dpi; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS); }; break; case GlowDirection.Bottom: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Top; getLeft = (dpi) => owner.Left * dpi; getTop = (dpi) => Math.Round((owner.Top + owner.ActualHeight) * dpi); getWidth = (dpi) => Math.Round(owner.ActualWidth * dpi); getHeight = (dpi) => glowSize * dpi; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS); }; break; } owner.ContentRendered += (sender, e) => glow.Visibility = Visibility.Visible; owner.Activated += (sender, e) => { Update(); glow.IsGlow = true; }; owner.Deactivated += (sender, e) => glow.IsGlow = false; owner.LocationChanged += (sender, e) => Update(); owner.SizeChanged += (sender, e) => Update(); owner.StateChanged += (sender, e) => Update(); owner.IsVisibleChanged += (sender, e) => Update(); owner.Closed += (sender, e) => { closing = true; Close(); }; }
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); this.Owner = owner; glow.Visibility = Visibility.Collapsed; var b = new Binding("GlowBrush"); b.Source = owner; glow.SetBinding(Glow.GlowBrushProperty, b); switch (direction) { case GlowDirection.Left: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Right; getLeft = (dpi) => Math.Round((owner.Left - glowSize) * dpi); getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => glowSize * dpi; getHeight = (dpi) => (owner.ActualHeight + glowSize * 2.0) * dpi; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; getCursor = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE; break; case GlowDirection.Right: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Left; getLeft = (dpi) => Math.Round((owner.Left + owner.ActualWidth) * dpi); getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => glowSize * dpi; getHeight = (dpi) => (owner.ActualHeight + glowSize * 2.0) * dpi; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; getCursor = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE; break; case GlowDirection.Top: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Bottom; getLeft = (dpi) => owner.Left * dpi; getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => Math.Round(owner.ActualWidth * dpi); getHeight = (dpi) => glowSize * dpi; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; getCursor = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS; break; case GlowDirection.Bottom: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Top; getLeft = (dpi) => owner.Left * dpi; getTop = (dpi) => Math.Round((owner.Top + owner.ActualHeight) * dpi); getWidth = (dpi) => Math.Round(owner.ActualWidth * dpi); getHeight = (dpi) => glowSize * dpi; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; getCursor = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS; break; } owner.ContentRendered += (sender, e) => glow.Visibility = Visibility.Visible; owner.Activated += (sender, e) => { Update(); glow.IsGlow = true; }; owner.Deactivated += (sender, e) => glow.IsGlow = false; owner.LocationChanged += (sender, e) => Update(); owner.SizeChanged += (sender, e) => Update(); owner.StateChanged += (sender, e) => Update(); owner.Closed += (sender, e) => Close(); }
public GlowWindow(Window owner, GlowWindowBehavior behavior, GlowDirection direction) { InitializeComponent(); Title = $"GlowWindow_{direction}"; Name = Title; // We have to set the owner to fix #92 Owner = owner ?? throw new ArgumentNullException(nameof(owner)); this.owner = owner; IsGlowing = true; Closing += (sender, e) => e.Cancel = !closing; glow.Direction = direction; { var b = new Binding { Path = new PropertyPath(nameof(ActualWidth)), Source = this, Mode = BindingMode.OneWay }; glow.SetBinding(WidthProperty, b); } { var b = new Binding { Path = new PropertyPath(nameof(ActualHeight)), Source = this, Mode = BindingMode.OneWay }; glow.SetBinding(HeightProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.GlowBrushProperty), Source = behavior, Mode = BindingMode.OneWay }; glow.SetBinding(Glow.GlowBrushProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.NonActiveGlowBrushProperty), Source = behavior, Mode = BindingMode.OneWay }; glow.SetBinding(Glow.NonActiveGlowBrushProperty, b); } { var b = new Binding { Path = new PropertyPath(BorderThicknessProperty), Source = owner, Mode = BindingMode.OneWay }; glow.SetBinding(BorderThicknessProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.ResizeBorderThicknessProperty), Source = behavior }; SetBinding(ResizeBorderThicknessProperty, b); } switch (direction) { case GlowDirection.Left: glow.HorizontalAlignment = HorizontalAlignment.Right; getLeft = rect => rect.Left - ResizeBorderThickness.Left + 1; getTop = rect => rect.Top - (ResizeBorderThickness.Top / 2); getWidth = rect => ResizeBorderThickness.Left; getHeight = rect => rect.Height + ResizeBorderThickness.Top; getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, ResizeBorderThickness.Top * 2).Contains(p) ? HT.TOPLEFT : new Rect(0, rect.Height - ResizeBorderThickness.Bottom, rect.Width, ResizeBorderThickness.Bottom * 2).Contains(p) ? HT.BOTTOMLEFT : HT.LEFT; break; case GlowDirection.Right: glow.HorizontalAlignment = HorizontalAlignment.Left; getLeft = rect => rect.Right - 1; getTop = rect => rect.Top - (ResizeBorderThickness.Top / 2); getWidth = rect => ResizeBorderThickness.Right; getHeight = rect => rect.Height + ResizeBorderThickness.Top; getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, ResizeBorderThickness.Top * 2).Contains(p) ? HT.TOPRIGHT : new Rect(0, rect.Height - ResizeBorderThickness.Bottom, rect.Width, ResizeBorderThickness.Bottom * 2).Contains(p) ? HT.BOTTOMRIGHT : HT.RIGHT; break; case GlowDirection.Top: glow.VerticalAlignment = VerticalAlignment.Bottom; getLeft = rect => rect.Left - (ResizeBorderThickness.Left / 2); getTop = rect => rect.Top - ResizeBorderThickness.Top + 1; getWidth = rect => rect.Width + ResizeBorderThickness.Left; getHeight = rect => ResizeBorderThickness.Top; getHitTestValue = (p, rect) => new Rect(0, 0, ResizeBorderThickness.Left * 2, rect.Height).Contains(p) ? HT.TOPLEFT : new Rect(rect.Width - ResizeBorderThickness.Right, 0, ResizeBorderThickness.Right * 2, rect.Height).Contains(p) ? HT.TOPRIGHT : HT.TOP; break; case GlowDirection.Bottom: glow.VerticalAlignment = VerticalAlignment.Top; getLeft = rect => rect.Left - (ResizeBorderThickness.Left / 2); getTop = rect => rect.Bottom - 1; getWidth = rect => rect.Width + ResizeBorderThickness.Left; getHeight = rect => ResizeBorderThickness.Bottom; getHitTestValue = (p, rect) => new Rect(0, 0, ResizeBorderThickness.Left * 2, rect.Height).Contains(p) ? HT.BOTTOMLEFT : new Rect(rect.Width - ResizeBorderThickness.Right, 0, ResizeBorderThickness.Right * 2, rect.Height).Contains(p) ? HT.BOTTOMRIGHT : HT.BOTTOM; break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, "Invalid direction."); } owner.Activated += OnOwnerActivated; owner.Deactivated += OnOwnerDeactivated; owner.IsVisibleChanged += OnOwnerIsVisibleChanged; owner.Closed += (sender, e) => InternalClose(); }
public GlowWindow(Window owner, GlowDirection direction) { this.InitializeComponent(); this.Owner = owner; this._owner = owner; this.IsGlowing = true; this.AllowsTransparency = true; this.Closing += (sender, e) => e.Cancel = !this.closing; this.ShowInTaskbar = false; this.glow.Visibility = Visibility.Collapsed; var b = new Binding("GlowBrush"); b.Source = owner; this.glow.SetBinding(Glow.GlowBrushProperty, b); b = new Binding("NonActiveGlowBrush"); b.Source = owner; this.glow.SetBinding(Glow.NonActiveGlowBrushProperty, b); b = new Binding("BorderThickness"); b.Source = owner; this.glow.SetBinding(BorderThicknessProperty, b); this.glow.Direction = direction; switch (direction) { case GlowDirection.Left: this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = HorizontalAlignment.Right; this.getLeft = (rect) => rect.left - glowSize + 1; this.getTop = (rect) => rect.top - 2; this.getWidth = (rect) => glowSize; this.getHeight = (rect) => rect.Height + 4; this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, rect.Height + 4 - edgeSize, rect.Width, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; this.getCursor = (p, rect) => new Rect(0, 0, rect.Width, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, rect.Height + 4 - edgeSize, rect.Width, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE; break; case GlowDirection.Right: this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = HorizontalAlignment.Left; this.getLeft = (rect) => rect.right - 1; this.getTop = (rect) => rect.top - 2; this.getWidth = (rect) => glowSize; this.getHeight = (rect) => rect.Height + 4; this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, rect.Height + 4 - edgeSize, rect.Width, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; this.getCursor = (p, rect) => new Rect(0, 0, rect.Width, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, rect.Height + 4 - edgeSize, rect.Width, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE; break; case GlowDirection.Top: this.PreviewMouseDoubleClick += (sender, e) => { if (this.ownerHandle != IntPtr.Zero) { Standard.NativeMethods.SendMessage(this.ownerHandle, Standard.WM.NCLBUTTONDBLCLK, (IntPtr)Standard.HT.TOP, IntPtr.Zero); } }; this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = VerticalAlignment.Bottom; this.getLeft = (rect) => rect.left - 2; this.getTop = (rect) => rect.top - glowSize + 1; this.getWidth = (rect) => rect.Width + 4; this.getHeight = (rect) => glowSize; this.getHitTestValue = (p, rect) => new Rect(0, 0, edgeSize - glowSize, rect.Height).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(rect.Width + 4 - edgeSize + glowSize, 0, edgeSize - glowSize, rect.Height).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; this.getCursor = (p, rect) => new Rect(0, 0, edgeSize - glowSize, rect.Height).Contains(p) ? Cursors.SizeNWSE : new Rect(rect.Width + 4 - edgeSize + glowSize, 0, edgeSize - glowSize, rect.Height).Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS; break; case GlowDirection.Bottom: this.PreviewMouseDoubleClick += (sender, e) => { if (this.ownerHandle != IntPtr.Zero) { Standard.NativeMethods.SendMessage(this.ownerHandle, Standard.WM.NCLBUTTONDBLCLK, (IntPtr)Standard.HT.BOTTOM, IntPtr.Zero); } }; this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = VerticalAlignment.Top; this.getLeft = (rect) => rect.left - 2; this.getTop = (rect) => rect.bottom - 1; this.getWidth = (rect) => rect.Width + 4; this.getHeight = (rect) => glowSize; this.getHitTestValue = (p, rect) => new Rect(0, 0, edgeSize - glowSize, rect.Height).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(rect.Width + 4 - edgeSize + glowSize, 0, edgeSize - glowSize, rect.Height).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; this.getCursor = (p, rect) => new Rect(0, 0, edgeSize - glowSize, rect.Height).Contains(p) ? Cursors.SizeNESW : new Rect(rect.Width + 4 - edgeSize + glowSize, 0, edgeSize - glowSize, rect.Height).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS; break; } owner.ContentRendered += (sender, e) => this.glow.Visibility = Visibility.Visible; owner.Activated += (sender, e) => { this.Update(); this.glow.IsGlow = true; }; owner.Deactivated += (sender, e) => { this.glow.IsGlow = false; }; owner.StateChanged += (sender, e) => this.Update(); owner.IsVisibleChanged += (sender, e) => this.Update(); owner.Closed += (sender, e) => { this.closing = true; this.Close(); }; }
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); this.IsGlowing = true; this.AllowsTransparency = true; this.Closing += (sender, e) => e.Cancel = !closing; this.Owner = owner; glow.Visibility = Visibility.Collapsed; var b = new Binding("GlowBrush"); b.Source = owner; glow.SetBinding(Glow.GlowBrushProperty, b); b = new Binding("NonActiveGlowBrush"); b.Source = owner; glow.SetBinding(Glow.NonActiveGlowBrushProperty, b); b = new Binding("BorderThickness"); b.Source = owner; glow.SetBinding(Glow.BorderThicknessProperty, b); glow.Direction = direction; switch (direction) { case GlowDirection.Left: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Right; getLeft = (rect) => rect.left - glowSize + 1; getTop = (rect) => rect.top - 2; getWidth = (rect) => glowSize; getHeight = (rect) => rect.Height + 4; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE; }; break; case GlowDirection.Right: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Left; getLeft = (rect) => rect.right - 1; getTop = (rect) => rect.top - 2; getWidth = (rect) => glowSize; getHeight = (rect) => rect.Height + 4; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE; }; break; case GlowDirection.Top: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Bottom; getLeft = (rect) => rect.left - 2; getTop = (rect) => rect.top - glowSize + 1; getWidth = (rect) => rect.Width + 4; getHeight = (rect) => glowSize; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS; }; break; case GlowDirection.Bottom: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Top; getLeft = (rect) => rect.left - 2; getTop = (rect) => rect.bottom - 1; getWidth = (rect) => rect.Width + 4; getHeight = (rect) => glowSize; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS; }; break; } owner.ContentRendered += (sender, e) => glow.Visibility = Visibility.Visible; owner.Activated += (sender, e) => { Update(); glow.IsGlow = true; }; owner.Deactivated += (sender, e) => glow.IsGlow = false; owner.StateChanged += (sender, e) => Update(); owner.IsVisibleChanged += (sender, e) => Update(); owner.Closed += (sender, e) => { closing = true; Close(); }; }
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); this.AllowsTransparency = true; this.Closing += (sender, e) => e.Cancel = !closing; this.Owner = owner; var b = new Binding("GlowBrush") { Source = owner }; glow.SetBinding(Glow.GlowBrushProperty, b); b = new Binding("BorderThickness") { Source = owner }; glow.SetBinding(Glow.BorderThicknessProperty, b); glow.Direction = direction; switch (direction) { case GlowDirection.Left: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Right; getLeft = (rect) => rect.left - glowSize + 1; getTop = (rect) => rect.top - 2; getWidth = (rect) => glowSize; getHeight = (rect) => rect.Height + 4; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE); }; break; case GlowDirection.Right: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Left; getLeft = (rect) => rect.right - 1; getTop = (rect) => rect.top - 2; getWidth = (rect) => glowSize; getHeight = (rect) => rect.Height + 4; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE); }; break; case GlowDirection.Top: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Bottom; getLeft = (rect) => rect.left - 2; getTop = (rect) => rect.top - glowSize + 1; getWidth = (rect) => rect.Width + 4; getHeight = (rect) => glowSize; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS); }; break; case GlowDirection.Bottom: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Top; getLeft = (rect) => rect.left - 2; getTop = (rect) => rect.bottom - 1; getWidth = (rect) => rect.Width + 4; getHeight = (rect) => glowSize; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; getCursor = p => { return((owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS); }; break; } owner.Closed += (sender, e) => { closing = true; Close(); }; }
public GlowWindow(Window owner, GlowWindowBehavior behavior, GlowDirection direction) { this.InitializeComponent(); this.Title = $"GlowWindow_{direction}"; this.Name = this.Title; this.Owner = owner; this.owner = owner; this.IsGlowing = true; this.Closing += (sender, e) => e.Cancel = !this.closing; this.glow.Direction = direction; { var b = new Binding { Path = new PropertyPath(nameof(this.ActualWidth)), Source = this, Mode = BindingMode.OneWay }; this.glow.SetBinding(WidthProperty, b); } { var b = new Binding { Path = new PropertyPath(nameof(this.ActualHeight)), Source = this, Mode = BindingMode.OneWay }; this.glow.SetBinding(HeightProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.GlowBrushProperty), Source = behavior, Mode = BindingMode.OneWay }; this.glow.SetBinding(Glow.GlowBrushProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.NonActiveGlowBrushProperty), Source = behavior, Mode = BindingMode.OneWay }; this.glow.SetBinding(Glow.NonActiveGlowBrushProperty, b); } { var b = new Binding { Path = new PropertyPath(BorderThicknessProperty), Source = owner, Mode = BindingMode.OneWay }; this.glow.SetBinding(BorderThicknessProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.ResizeBorderThicknessProperty), Source = behavior }; this.SetBinding(ResizeBorderThicknessProperty, b); } switch (direction) { case GlowDirection.Left: this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = HorizontalAlignment.Right; this.getLeft = rect => rect.Left - this.ResizeBorderThickness.Left + 1; this.getTop = rect => rect.Top - this.ResizeBorderThickness.Top / 2; this.getWidth = rect => this.ResizeBorderThickness.Left; this.getHeight = rect => rect.Height + this.ResizeBorderThickness.Top; this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p) ? HT.TOPLEFT : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p) ? HT.BOTTOMLEFT : HT.LEFT; break; case GlowDirection.Right: this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = HorizontalAlignment.Left; this.getLeft = rect => rect.Right - 1; this.getTop = rect => rect.Top - this.ResizeBorderThickness.Top / 2; this.getWidth = rect => this.ResizeBorderThickness.Right; this.getHeight = rect => rect.Height + this.ResizeBorderThickness.Top; this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p) ? HT.TOPRIGHT : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p) ? HT.BOTTOMRIGHT : HT.RIGHT; break; case GlowDirection.Top: this.PreviewMouseDoubleClick += (sender, e) => { if (this.IsOwnerHandleValid()) { NativeMethods.SendMessage(this.ownerWindowHandle, WM.NCLBUTTONDBLCLK, (IntPtr)HT.TOP, IntPtr.Zero); } }; this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = VerticalAlignment.Bottom; this.getLeft = rect => rect.Left - this.ResizeBorderThickness.Left / 2; this.getTop = rect => rect.Top - this.ResizeBorderThickness.Top + 1; this.getWidth = rect => rect.Width + this.ResizeBorderThickness.Left; this.getHeight = rect => this.ResizeBorderThickness.Top; this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p) ? HT.TOPLEFT : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p) ? HT.TOPRIGHT : HT.TOP; break; case GlowDirection.Bottom: this.PreviewMouseDoubleClick += (sender, e) => { if (this.IsOwnerHandleValid()) { NativeMethods.SendMessage(this.ownerWindowHandle, WM.NCLBUTTONDBLCLK, (IntPtr)HT.BOTTOM, IntPtr.Zero); } }; this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = VerticalAlignment.Top; this.getLeft = rect => rect.Left - this.ResizeBorderThickness.Left / 2; this.getTop = rect => rect.Bottom - 1; this.getWidth = rect => rect.Width + this.ResizeBorderThickness.Left; this.getHeight = rect => this.ResizeBorderThickness.Bottom; this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p) ? HT.BOTTOMLEFT : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p) ? HT.BOTTOMRIGHT : HT.BOTTOM; break; } owner.Activated += (sender, e) => { this.Update(); this.glow.IsGlow = true; }; owner.Deactivated += (sender, e) => { this.glow.IsGlow = false; }; owner.IsVisibleChanged += (sender, e) => this.Update(); owner.Closed += (sender, e) => this.InternalClose(); }
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); this.Owner = owner; glow.Visibility = Visibility.Collapsed; var b = new Binding("GlowBrush.Color"); b.Source = owner; glow.SetBinding(Glow.GlowColorProperty, b); switch (direction) { case GlowDirection.Left: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Right; getLeft = () => Math.Ceiling(owner.Left - glowSize); getTop = () => owner.Top - glowSize; getWidth = () => glowSize; getHeight = () => owner.ActualHeight + glowSize * 2; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; getCursor = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE; break; case GlowDirection.Right: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Left; getLeft = () => owner.Left + owner.ActualWidth; getTop = () => owner.Top - glowSize; getWidth = () => glowSize; getHeight = () => owner.ActualHeight + glowSize * 2; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; getCursor = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE; break; case GlowDirection.Top: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Bottom; getLeft = () => owner.Left; getTop = () => Math.Ceiling(owner.Top - glowSize); getWidth = () => owner.ActualWidth; getHeight = () => glowSize; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; getCursor = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS; break; case GlowDirection.Bottom: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Top; getLeft = () => owner.Left; getTop = () => owner.Top + owner.ActualHeight; getWidth = () => owner.ActualWidth; getHeight = () => glowSize; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; getCursor = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS; break; } owner.ContentRendered += (sender, e) => glow.Visibility = Visibility.Visible; owner.Activated += (sender, e) => Update(); owner.Activated += (sender, e) => glow.IsGlow = true; owner.Deactivated += (sender, e) => glow.IsGlow = false; owner.LocationChanged += (sender, e) => Update(); owner.SizeChanged += (sender, e) => Update(); owner.StateChanged += (sender, e) => Update(); owner.Closed += (sender, e) => Close(); }
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); this.owner = owner; this.glow.Visibility = Visibility.Collapsed; switch (direction) { case GlowDirection.Left: this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = HorizontalAlignment.Right; this.getLeft = () => owner.Left - this.glowSize; this.getTop = () => owner.Top - this.glowSize; this.getWidth = () => this.glowSize; this.getHeight = () => owner.ActualHeight + this.glowSize * 2; this.getHitTestValue = p => new Rect(0, 0, this.ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, this.ActualHeight - edgeSize, this.ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; this.getCursor = p => new Rect(0, 0, this.ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, this.ActualHeight - edgeSize, this.ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE; break; case GlowDirection.Right: this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = HorizontalAlignment.Left; this.getLeft = () => owner.Left + owner.ActualWidth; this.getTop = () => owner.Top - this.glowSize; this.getWidth = () => this.glowSize; this.getHeight = () => owner.ActualHeight + this.glowSize * 2; this.getHitTestValue = p => new Rect(0, 0, this.ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, this.ActualHeight - edgeSize, this.ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; this.getCursor = p => new Rect(0, 0, this.ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, this.ActualHeight - edgeSize, this.ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE; break; case GlowDirection.Top: this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = VerticalAlignment.Bottom; this.getLeft = () => owner.Left; this.getTop = () => owner.Top - this.glowSize; this.getWidth = () => owner.ActualWidth; this.getHeight = () => this.glowSize; this.getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(this.Width - edgeSize + glowSize, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; this.getCursor = p => new Rect(0, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(this.Width - edgeSize + glowSize, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS; break; case GlowDirection.Bottom: this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = VerticalAlignment.Top; this.getLeft = () => owner.Left; this.getTop = () => owner.Top + owner.ActualHeight; this.getWidth = () => owner.ActualWidth; this.getHeight = () => this.glowSize; this.getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(this.Width - edgeSize + glowSize, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; this.getCursor = p => new Rect(0, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(this.Width - edgeSize + glowSize, 0, edgeSize - glowSize, this.ActualHeight).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS; break; } owner.ContentRendered += (sender, e) => this.glow.Visibility = Visibility.Visible; owner.Activated += (sender, e) => this.Update(); owner.Activated += (sender, e) => this.glow.IsGlow = true; owner.Deactivated += (sender, e) => this.glow.IsGlow = false; owner.LocationChanged += (sender, e) => this.Update(); owner.SizeChanged += (sender, e) => this.Update(); owner.StateChanged += (sender, e) => this.Update(); owner.Closed += (sender, e) => this.Close(); }
public GlowWindow(Window owner, GlowWindowBehavior behavior, GlowDirection direction) { this.InitializeComponent(); this.Title = $"GlowWindow_{direction}"; this.Name = this.Title; // We have to set the owner to fix #92 this.Owner = owner; this.owner = owner; this.IsGlowing = true; this.Closing += (sender, e) => e.Cancel = !this.closing; this.glow.Direction = direction; { var b = new Binding { Path = new PropertyPath(nameof(this.ActualWidth)), Source = this, Mode = BindingMode.OneWay }; this.glow.SetBinding(WidthProperty, b); } { var b = new Binding { Path = new PropertyPath(nameof(this.ActualHeight)), Source = this, Mode = BindingMode.OneWay }; this.glow.SetBinding(HeightProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.GlowBrushProperty), Source = behavior, Mode = BindingMode.OneWay }; this.glow.SetBinding(Glow.GlowBrushProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.NonActiveGlowBrushProperty), Source = behavior, Mode = BindingMode.OneWay }; this.glow.SetBinding(Glow.NonActiveGlowBrushProperty, b); } { var b = new Binding { Path = new PropertyPath(BorderThicknessProperty), Source = owner, Mode = BindingMode.OneWay }; this.glow.SetBinding(BorderThicknessProperty, b); } { var b = new Binding { Path = new PropertyPath(GlowWindowBehavior.ResizeBorderThicknessProperty), Source = behavior }; this.SetBinding(ResizeBorderThicknessProperty, b); } switch (direction) { case GlowDirection.Left: this.glow.HorizontalAlignment = HorizontalAlignment.Right; this.getLeft = rect => rect.Left - this.ResizeBorderThickness.Left + 1; this.getTop = rect => rect.Top - this.ResizeBorderThickness.Top / 2; this.getWidth = rect => this.ResizeBorderThickness.Left; this.getHeight = rect => rect.Height + this.ResizeBorderThickness.Top; this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p) ? HT.TOPLEFT : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p) ? HT.BOTTOMLEFT : HT.LEFT; break; case GlowDirection.Right: this.glow.HorizontalAlignment = HorizontalAlignment.Left; this.getLeft = rect => rect.Right - 1; this.getTop = rect => rect.Top - this.ResizeBorderThickness.Top / 2; this.getWidth = rect => this.ResizeBorderThickness.Right; this.getHeight = rect => rect.Height + this.ResizeBorderThickness.Top; this.getHitTestValue = (p, rect) => new Rect(0, 0, rect.Width, this.ResizeBorderThickness.Top * 2).Contains(p) ? HT.TOPRIGHT : new Rect(0, rect.Height - this.ResizeBorderThickness.Bottom, rect.Width, this.ResizeBorderThickness.Bottom * 2).Contains(p) ? HT.BOTTOMRIGHT : HT.RIGHT; break; case GlowDirection.Top: this.glow.VerticalAlignment = VerticalAlignment.Bottom; this.getLeft = rect => rect.Left - this.ResizeBorderThickness.Left / 2; this.getTop = rect => rect.Top - this.ResizeBorderThickness.Top + 1; this.getWidth = rect => rect.Width + this.ResizeBorderThickness.Left; this.getHeight = rect => this.ResizeBorderThickness.Top; this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p) ? HT.TOPLEFT : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p) ? HT.TOPRIGHT : HT.TOP; break; case GlowDirection.Bottom: this.glow.VerticalAlignment = VerticalAlignment.Top; this.getLeft = rect => rect.Left - this.ResizeBorderThickness.Left / 2; this.getTop = rect => rect.Bottom - 1; this.getWidth = rect => rect.Width + this.ResizeBorderThickness.Left; this.getHeight = rect => this.ResizeBorderThickness.Bottom; this.getHitTestValue = (p, rect) => new Rect(0, 0, this.ResizeBorderThickness.Left * 2, rect.Height).Contains(p) ? HT.BOTTOMLEFT : new Rect(rect.Width - this.ResizeBorderThickness.Right, 0, this.ResizeBorderThickness.Right * 2, rect.Height).Contains(p) ? HT.BOTTOMRIGHT : HT.BOTTOM; break; } owner.Activated += OnOwnerActivated; owner.Deactivated += OnOwnerDeactivated; owner.IsVisibleChanged += OnOwnerIsVisibleChanged; owner.Closed += (sender, e) => this.InternalClose(); }
public GlowWindow(Window owner, GlowDirection direction) { Class6.yDnXvgqzyB5jw(); base(); GlowWindow glowWindow = this; this.InitializeComponent(); this.IsGlowing = true; base.AllowsTransparency = true; base.Closing += new CancelEventHandler((object sender, CancelEventArgs e) => e.Cancel = !this.closing); base.Owner = owner; this.glow.Visibility = System.Windows.Visibility.Collapsed; Binding binding = new Binding("GlowBrush") { Source = owner }; this.glow.SetBinding(Glow.GlowBrushProperty, binding); binding = new Binding("NonActiveGlowBrush") { Source = owner }; this.glow.SetBinding(Glow.NonActiveGlowBrushProperty, binding); binding = new Binding("BorderThickness") { Source = owner }; this.glow.SetBinding(Control.BorderThicknessProperty, binding); this.glow.Direction = direction; switch (direction) { case GlowDirection.Left: { this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; this.getLeft = (RECT rect) => (double)rect.left - 6 + 1; this.getTop = (RECT rect) => (double)(rect.top - 2); this.getWidth = (RECT rect) => 6; this.getHeight = (RECT rect) => (double)(rect.Height + 4); this.getHitTestValue = (Point p) => { if ((new Rect(0, 0, base.ActualWidth, 20)).Contains(p)) { return(HitTestValues.HTTOPLEFT); } if (!(new Rect(0, base.ActualHeight - 20, base.ActualWidth, 20)).Contains(p)) { return(HitTestValues.HTLEFT); } return(HitTestValues.HTBOTTOMLEFT); }; this.getCursor = (Point p) => { if (owner.ResizeMode == System.Windows.ResizeMode.NoResize || owner.ResizeMode == System.Windows.ResizeMode.CanMinimize) { return(owner.Cursor); } if ((new Rect(0, 0, glowWindow.ActualWidth, 20)).Contains(p)) { return(Cursors.SizeNWSE); } if (!(new Rect(0, glowWindow.ActualHeight - 20, glowWindow.ActualWidth, 20)).Contains(p)) { return(Cursors.SizeWE); } return(Cursors.SizeNESW); }; break; } case GlowDirection.Right: { this.glow.Orientation = Orientation.Vertical; this.glow.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; this.getLeft = (RECT rect) => (double)(rect.right - 1); this.getTop = (RECT rect) => (double)(rect.top - 2); this.getWidth = (RECT rect) => 6; this.getHeight = (RECT rect) => (double)(rect.Height + 4); this.getHitTestValue = (Point p) => { if ((new Rect(0, 0, base.ActualWidth, 20)).Contains(p)) { return(HitTestValues.HTTOPRIGHT); } if (!(new Rect(0, base.ActualHeight - 20, base.ActualWidth, 20)).Contains(p)) { return(HitTestValues.HTRIGHT); } return(HitTestValues.HTBOTTOMRIGHT); }; this.getCursor = (Point p) => { if (owner.ResizeMode == System.Windows.ResizeMode.NoResize || owner.ResizeMode == System.Windows.ResizeMode.CanMinimize) { return(owner.Cursor); } if ((new Rect(0, 0, glowWindow.ActualWidth, 20)).Contains(p)) { return(Cursors.SizeNESW); } if (!(new Rect(0, glowWindow.ActualHeight - 20, glowWindow.ActualWidth, 20)).Contains(p)) { return(Cursors.SizeWE); } return(Cursors.SizeNWSE); }; break; } case GlowDirection.Top: { this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; this.getLeft = (RECT rect) => (double)(rect.left - 2); this.getTop = (RECT rect) => (double)rect.top - 6 + 1; this.getWidth = (RECT rect) => (double)(rect.Width + 4); this.getHeight = (RECT rect) => 6; this.getHitTestValue = (Point p) => { if ((new Rect(0, 0, 14, base.ActualHeight)).Contains(p)) { return(HitTestValues.HTTOPLEFT); } if (!(new Rect(base.Width - 20 + 6, 0, 14, base.ActualHeight)).Contains(p)) { return(HitTestValues.HTTOP); } return(HitTestValues.HTTOPRIGHT); }; this.getCursor = (Point p) => { if (owner.ResizeMode == System.Windows.ResizeMode.NoResize || owner.ResizeMode == System.Windows.ResizeMode.CanMinimize) { return(owner.Cursor); } if ((new Rect(0, 0, 14, glowWindow.ActualHeight)).Contains(p)) { return(Cursors.SizeNWSE); } if (!(new Rect(glowWindow.Width - 20 + 6, 0, 14, glowWindow.ActualHeight)).Contains(p)) { return(Cursors.SizeNS); } return(Cursors.SizeNESW); }; break; } case GlowDirection.Bottom: { this.glow.Orientation = Orientation.Horizontal; this.glow.VerticalAlignment = System.Windows.VerticalAlignment.Top; this.getLeft = (RECT rect) => (double)(rect.left - 2); this.getTop = (RECT rect) => (double)(rect.bottom - 1); this.getWidth = (RECT rect) => (double)(rect.Width + 4); this.getHeight = (RECT rect) => 6; this.getHitTestValue = (Point p) => { if ((new Rect(0, 0, 14, base.ActualHeight)).Contains(p)) { return(HitTestValues.HTBOTTOMLEFT); } if (!(new Rect(base.Width - 20 + 6, 0, 14, base.ActualHeight)).Contains(p)) { return(HitTestValues.HTBOTTOM); } return(HitTestValues.HTBOTTOMRIGHT); }; this.getCursor = (Point p) => { if (owner.ResizeMode == System.Windows.ResizeMode.NoResize || owner.ResizeMode == System.Windows.ResizeMode.CanMinimize) { return(owner.Cursor); } if ((new Rect(0, 0, 14, glowWindow.ActualHeight)).Contains(p)) { return(Cursors.SizeNESW); } if (!(new Rect(glowWindow.Width - 20 + 6, 0, 14, glowWindow.ActualHeight)).Contains(p)) { return(Cursors.SizeNS); } return(Cursors.SizeNWSE); }; break; } } owner.ContentRendered += new EventHandler((object sender, EventArgs e) => this.glow.Visibility = System.Windows.Visibility.Visible); owner.Activated += new EventHandler((object sender, EventArgs e) => { this.Update(); this.glow.IsGlow = true; }); owner.Deactivated += new EventHandler((object sender, EventArgs e) => this.glow.IsGlow = false); owner.StateChanged += new EventHandler((object sender, EventArgs e) => this.Update()); owner.IsVisibleChanged += new DependencyPropertyChangedEventHandler((object sender, DependencyPropertyChangedEventArgs e) => this.Update()); owner.Closed += new EventHandler((object sender, EventArgs e) => { this.closing = true; base.Close(); }); }
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); // var windowChrome = new WindowChrome(); // windowChrome.ResizeBorderThickness = new Thickness(0); // windowChrome.CaptionHeight = 0; // windowChrome.CornerRadius = new CornerRadius(0); // windowChrome.GlassFrameThickness = new Thickness(-1); // windowChrome.UseAeroCaptionButtons = false; // this.SetValue(WindowChrome.WindowChromeProperty, windowChrome); this.IsGlowing = true; this.AllowsTransparency = true; this.Owner = owner; glow.Visibility = Visibility.Collapsed; var b = new Binding("GlowBrush"); b.Source = owner; glow.SetBinding(Glow.GlowBrushProperty, b); b = new Binding("NonActiveGlowBrush"); b.Source = owner; glow.SetBinding(Glow.NonActiveGlowBrushProperty, b); switch (direction) { case GlowDirection.Left: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Right; getLeft = (dpi) => Math.Round((owner.Left - glowSize) * dpi); getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => glowSize * dpi; getHeight = (dpi) => (owner.ActualHeight + glowSize * 2.0) * dpi; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE; }; break; case GlowDirection.Right: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Left; getLeft = (dpi) => Math.Round((owner.Left + owner.ActualWidth) * dpi); getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => glowSize * dpi; getHeight = (dpi) => (owner.ActualHeight + glowSize * 2.0) * dpi; getHitTestValue = p => new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTTOPRIGHT : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, ActualHeight - edgeSize, ActualWidth, edgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE; }; break; case GlowDirection.Top: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Bottom; getLeft = (dpi) => owner.Left * dpi; getTop = (dpi) => Math.Round((owner.Top - glowSize) * dpi); getWidth = (dpi) => Math.Round(owner.ActualWidth * dpi); getHeight = (dpi) => glowSize * dpi; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS; }; break; case GlowDirection.Bottom: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Top; getLeft = (dpi) => owner.Left * dpi; getTop = (dpi) => Math.Round((owner.Top + owner.ActualHeight) * dpi); getWidth = (dpi) => Math.Round(owner.ActualWidth * dpi); getHeight = (dpi) => glowSize * dpi; getHitTestValue = p => new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMLEFT : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; getCursor = p => { return (owner.ResizeMode == ResizeMode.NoResize || owner.ResizeMode == ResizeMode.CanMinimize) ? owner.Cursor : new Rect(0, 0, edgeSize - glowSize, ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(Width - edgeSize + glowSize, 0, edgeSize - glowSize, ActualHeight). Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS; }; break; } owner.ContentRendered += (sender, e) => glow.Visibility = Visibility.Visible; owner.Activated += (sender, e) => { Update(); glow.IsGlow = true; }; owner.Deactivated += (sender, e) => glow.IsGlow = false; owner.LocationChanged += (sender, e) => Update(); owner.SizeChanged += (sender, e) => Update(); owner.StateChanged += (sender, e) => Update(); owner.IsVisibleChanged += (sender, e) => Update(); owner.Closed += (sender, e) => { closing = true; Close(); }; }
public GlowWindow(Window owner, GlowDirection direction) { InitializeComponent(); Owner = owner; glow.Visibility = Visibility.Collapsed; glow.IsGlow = false; var b = new Binding("GlowBrush") { Source = owner }; glow.SetBinding(Glow.GlowBrushProperty, b); var b2 = new Binding("InactiveGlowBrush") { Source = owner }; glow.SetBinding(Glow.InactiveGlowBrushProperty, b); switch (direction) { case GlowDirection.Left: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Right; _getLeft = rect => Math.Round(rect.Left - GlowSize); _getTop = rect => Math.Round(rect.Top - GlowSize); _getWidth = rect => GlowSize; _getHeight = rect => rect.Height + GlowSize * 2.0; _getHitTestValue = p => new Rect(0, 0, ActualWidth, EdgeSize).Contains(p) ? HT.TOPLEFT : new Rect(0, ActualHeight - EdgeSize, ActualWidth, EdgeSize).Contains(p) ? HT.BOTTOMLEFT : HT.LEFT; _getCursor = p => new Rect(0, 0, ActualWidth, EdgeSize).Contains(p) ? Cursors.SizeNWSE : new Rect(0, ActualHeight - EdgeSize, ActualWidth, EdgeSize).Contains(p) ? Cursors.SizeNESW : Cursors.SizeWE; break; case GlowDirection.Right: glow.Orientation = Orientation.Vertical; glow.HorizontalAlignment = HorizontalAlignment.Left; _getLeft = rect => rect.Right; _getTop = rect => Math.Round((rect.Top - GlowSize)); _getWidth = rect => GlowSize; _getHeight = rect => (rect.Height + GlowSize * 2.0); _getHitTestValue = p => new Rect(0, 0, ActualWidth, EdgeSize).Contains(p) ? HT.TOPRIGHT : new Rect(0, ActualHeight - EdgeSize, ActualWidth, EdgeSize).Contains(p) ? HT.BOTTOMRIGHT : HT.RIGHT; _getCursor = p => new Rect(0, 0, ActualWidth, EdgeSize).Contains(p) ? Cursors.SizeNESW : new Rect(0, ActualHeight - EdgeSize, ActualWidth, EdgeSize).Contains(p) ? Cursors.SizeNWSE : Cursors.SizeWE; break; case GlowDirection.Top: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Bottom; _getLeft = rect => rect.Left; _getTop = rect => Math.Round(rect.Top - GlowSize); _getWidth = rect => rect.Width; _getHeight = rect => GlowSize; _getHitTestValue = p => new Rect(0, 0, EdgeSize - GlowSize, ActualHeight).Contains(p) ? HT.TOPLEFT : new Rect(Width - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, ActualHeight).Contains(p) ? HT.TOPRIGHT : HT.TOP; _getCursor = p => new Rect(0, 0, EdgeSize - GlowSize, ActualHeight).Contains(p) ? Cursors.SizeNWSE : new Rect(Width - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, ActualHeight). Contains(p) ? Cursors.SizeNESW : Cursors.SizeNS; break; case GlowDirection.Bottom: glow.Orientation = Orientation.Horizontal; glow.VerticalAlignment = VerticalAlignment.Top; _getLeft = rect => rect.Left; _getTop = rect => rect.Bottom; _getWidth = rect => rect.Width; _getHeight = rect => GlowSize; _getHitTestValue = p => new Rect(0, 0, EdgeSize - GlowSize, ActualHeight).Contains(p) ? HT.BOTTOMLEFT : new Rect(Width - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, ActualHeight).Contains(p) ? HT.BOTTOMRIGHT : HT.BOTTOM; _getCursor = p => new Rect(0, 0, EdgeSize - GlowSize, ActualHeight).Contains(p) ? Cursors.SizeNESW : new Rect(Width - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, ActualHeight). Contains(p) ? Cursors.SizeNWSE : Cursors.SizeNS; break; } if (Owner.IsLoaded) { glow.Visibility = Visibility.Visible; glow.IsGlow = Owner.IsActive; } else { Owner.ContentRendered += OwnerOnContentRendered; } Owner.Activated += OwnerOnStateChanged; Owner.Deactivated += OwnerOnStateChanged; Owner.LocationChanged += OwnerOnStateChanged; Owner.SizeChanged += OwnerOnStateChanged; Owner.StateChanged += OwnerOnStateChanged; Owner.Closed += OwnerOnClosed; }