public void UpdateThumbs(int offsetLevel) { CURSORINFO cursorInfo = new CURSORINFO(); cursorInfo.cbSize = Marshal.SizeOf(cursorInfo); User32.GetCursorInfo(out cursorInfo); this.IsCursorOnScreen = Options.AreaSrcBounds.Contains(cursorInfo.ptScreenPos.X, cursorInfo.ptScreenPos.Y); this.UpdateCursorState(); // DebugWindow.Instance.UpdateMessage($"Is3DActive: {this.Is3DActive}{Environment.NewLine}IsCursorOnScreen: {this.IsCursorOnScreen}{ Environment.NewLine}ScreenBounds: { Options.ScreenBounds}{Environment.NewLine}Mouse Position:{cursorInfo.ptScreenPos}"); if (this.ThumbLeft == null || this.ThumbRight == null) { return; } SbSComputedVariables scv = Options.ComputedVariables; this.OffsetLevel = offsetLevel; int screenWidth = Options.ScreenDestBounds.Width; int screenHeight = Options.ScreenDestBounds.Height; double scale = Options.ScreenScale; POINT screenSrcTopLeft = new POINT(Options.AreaSrcBounds.Left, Options.AreaSrcBounds.Top); POINT screenDestTopLeft = new POINT(Options.ScreenDestBounds.Left, Options.ScreenDestBounds.Top); int parallaxDecal = 2 * Options.ParallaxEffect * offsetLevel; this.Position = cursorInfo.ptScreenPos - screenSrcTopLeft; POINT offset = App.Current.Dispatcher.Invoke <POINT>(() => { POINT result = this.ThumbLeft.SetCursor(cursorInfo.hCursor); this.ThumbRight.SetCursor(cursorInfo.hCursor); return(result); }); SWP leftVisible = (this.Position.X + parallaxDecal + arrowStdSize.X < screenWidth) && (Options.ModeSbS || this.Position.Y + arrowStdSize.Y < screenHeight) ? SWP.SWP_SHOWWINDOW : SWP.SWP_HIDEWINDOW; SWP rightVisible = (this.Position.X - parallaxDecal > 0) ? SWP.SWP_SHOWWINDOW : SWP.SWP_HIDEWINDOW; User32.SetWindowPos(this.ThumbLeft.Handle, this.Owner?.ThumbLeft.Handle ?? IntPtr.Zero, scv.DestPositionX + (int)((this.Position.X + parallaxDecal - offset.X * scale) / scv.RatioX), scv.DestPositionY + (int)((this.Position.Y - offset.Y * scale) / scv.RatioY), (int)(32 * scale / scv.RatioX), (int)(32 * scale / scv.RatioY), SWP.SWP_ASYNCWINDOWPOS | leftVisible); User32.SetWindowPos(this.ThumbRight.Handle, this.Owner?.ThumbRight.Handle ?? IntPtr.Zero, scv.DestPositionX + scv.DecalSbSX + (int)((this.Position.X - parallaxDecal - offset.X * scale) / scv.RatioX), scv.DestPositionY + scv.DecalSbSY + (int)((this.Position.Y - offset.Y * scale) / scv.RatioY), (int)(32 * scale / scv.RatioX), (int)(32 * scale / scv.RatioY), SWP.SWP_ASYNCWINDOWPOS | rightVisible); //DebugWindow.Instance.UpdateMessage($"Mouse Left: {this.Position.X} Top: {this.Position.Y}"); }
public void UpdateThumbs(bool isTaskBar = false) { int x, y, cx, cy; SbSComputedVariables scv = Options.ComputedVariables; int screenBottom = Options.ScreenSrcBounds.Bottom; int parallaxDecal = 2 * this.OffsetLevel * Options.ParallaxEffect; if (!isTaskBar && !this.SourceRect.IsMaximized() && this.SourceRect.Top < Options.ScreenSrcWorkspace.Bottom) { screenBottom = Options.ScreenSrcWorkspace.Bottom; } DwmApi.DWM_THUMBNAIL_PROPERTIES props = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); props.fVisible = true; props.dwFlags = DwmApi.DWM_TNP_VISIBLE | DwmApi.DWM_TNP_RECTDESTINATION | DwmApi.DWM_TNP_RECTSOURCE; // Left RECT parallaxSourceRectLeft = new RECT( this.SourceRect.Left + parallaxDecal, this.SourceRect.Top, this.SourceRect.Right + parallaxDecal, this.SourceRect.Bottom); props.rcSource = new RECT { Left = Math.Max(0, -parallaxSourceRectLeft.Left + Options.AreaSrcBounds.Left), Top = Math.Max(0, -parallaxSourceRectLeft.Top + Options.AreaSrcBounds.Top), Right = Math.Min(Options.AreaSrcBounds.Right, parallaxSourceRectLeft.Right) - parallaxSourceRectLeft.Left, Bottom = Math.Min(screenBottom, parallaxSourceRectLeft.Bottom) - parallaxSourceRectLeft.Top }; props.rcDestination = new RECT { Left = 0, Top = 0, Right = (int)Math.Ceiling((props.rcSource.Right - props.rcSource.Left) / scv.RatioX), Bottom = (int)Math.Ceiling((props.rcSource.Bottom - props.rcSource.Top) / scv.RatioY) }; x = scv.DestPositionX + (int)Math.Floor(Math.Max(0, parallaxSourceRectLeft.Left - Options.AreaSrcBounds.Left) / scv.RatioX); y = scv.DestPositionY + (int)Math.Floor(Math.Max(0, parallaxSourceRectLeft.Top - Options.AreaSrcBounds.Top) / scv.RatioY); cx = props.rcDestination.Right; cy = props.rcDestination.Bottom; User32.SetWindowPos(this.ThumbLeft.Handle, this.Owner?.ThumbLeft.Handle ?? IntPtr.Zero, x, y, cx, cy, SWP.SWP_ASYNCWINDOWPOS); DwmApi.DwmUpdateThumbnailProperties(this.ThumbLeft.Thumb, ref props); // Right RECT parallaxSourceRectRight = new RECT( this.SourceRect.Left - parallaxDecal, this.SourceRect.Top, this.SourceRect.Right - parallaxDecal, this.SourceRect.Bottom); props.rcSource = new RECT { Left = Math.Max(0, -parallaxSourceRectRight.Left + Options.AreaSrcBounds.Left), Top = Math.Max(0, -parallaxSourceRectRight.Top + Options.AreaSrcBounds.Top), Right = Math.Min(Options.AreaSrcBounds.Right, parallaxSourceRectRight.Right) - parallaxSourceRectRight.Left, Bottom = Math.Min(screenBottom, parallaxSourceRectRight.Bottom) - parallaxSourceRectRight.Top }; props.rcDestination = new RECT { Left = 0, Top = 0, Right = (int)Math.Ceiling((props.rcSource.Right - props.rcSource.Left) / scv.RatioX), Bottom = (int)Math.Ceiling((props.rcSource.Bottom - props.rcSource.Top) / scv.RatioY) }; x = scv.DestPositionX + scv.DecalSbSX + (int)Math.Floor(Math.Max(0, parallaxSourceRectRight.Left - Options.AreaSrcBounds.Left) / scv.RatioX); y = scv.DestPositionY + scv.DecalSbSY + (int)Math.Floor(Math.Max(0, parallaxSourceRectRight.Top - Options.AreaSrcBounds.Top) / scv.RatioY); cx = props.rcDestination.Right; cy = props.rcDestination.Bottom; User32.SetWindowPos(this.ThumbRight.Handle, this.Owner?.ThumbRight.Handle ?? IntPtr.Zero, x, y, cx, cy, SWP.SWP_ASYNCWINDOWPOS); DwmApi.DwmUpdateThumbnailProperties(this.ThumbRight.Thumb, ref props); #if DEBUG //if (this.Title.Contains("About")) //{ // App.Current.Dispatcher.Invoke(() => // { // DebugWindow.Instance.UpdateMessage($"Source Win {this.SourceRect}{Environment.NewLine}Src Thumb {props.rcSource}{Environment.NewLine}Dst Thumb {props.rcDestination}{Environment.NewLine}Dst Pos Left: {Math.Max(0, this.SourceRect.Left) / 2} Top: {Math.Max(0, this.SourceRect.Top)}"); // }); //} #endif }