public void TestGetBounds() { var displayInfo = DisplayInfo.AllDisplayInfos.First(); var displayBounds = DisplayInfo.GetBounds(displayInfo.Bounds.Location); Assert.Equal(displayInfo.Bounds, displayBounds); }
/// <summary> /// Returns the height, this is needed to know how many toasts are visible /// </summary> /// <returns></returns> public double GetHeight() { var taskbarBounds = Shell32Api.TaskbarPosition.Bounds; var displayBounds = DisplayInfo.GetBounds(taskbarBounds.Location); return(displayBounds.Height); }
/// <summary> /// Checks if the Zoom area can move there where it wants to go, change direction if not. /// </summary> /// <param name="pos">preferred destination location for the zoom area</param> /// <param name="allowZoomOverCaptureRect"> /// false to try to find a location which is neither out of screen bounds nor /// intersects with the selected rectangle /// </param> private void VerifyZoomAnimation(NativePoint pos, bool allowZoomOverCaptureRect) { var screenBounds = DisplayInfo.GetBounds(MousePosition); // convert to be relative to top left corner of all screen bounds screenBounds = screenBounds.MoveTo(WindowCapture.GetLocationRelativeToScreenBounds(screenBounds.Location)); var relativeZoomSize = Math.Min(screenBounds.Width, screenBounds.Height) / 5; // Make sure the final size is a plural of 4, this makes it look better relativeZoomSize = relativeZoomSize - relativeZoomSize % 4; var zoomSize = new NativeSize(relativeZoomSize, relativeZoomSize); var zoomOffset = new NativePoint(20, 20); var targetRectangle = _zoomAnimator.Final.Offset(pos); if (screenBounds.Contains(targetRectangle) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(targetRectangle))) { return; } var destinationLocation = NativePoint.Empty; var tl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); var tr = new NativeRect(pos.X + zoomOffset.X, pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); var bl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); var br = new NativeRect(pos.X + zoomOffset.X, pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); if (screenBounds.Contains(br) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(br))) { destinationLocation = new NativePoint(zoomOffset.X, zoomOffset.Y); } else if (screenBounds.Contains(bl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(bl))) { destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, zoomOffset.Y); } else if (screenBounds.Contains(tr) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tr))) { destinationLocation = new NativePoint(zoomOffset.X, -zoomOffset.Y - zoomSize.Width); } else if (screenBounds.Contains(tl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tl))) { destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, -zoomOffset.Y - zoomSize.Width); } if (destinationLocation == NativePoint.Empty && !allowZoomOverCaptureRect) { VerifyZoomAnimation(pos, true); } else { _zoomAnimator.ChangeDestination(new NativeRect(destinationLocation, zoomSize)); } }
/// <summary> /// Create an animation for the zoomer, depending on if it's active or not. /// </summary> private void InitializeZoomer(bool isOn) { if (isOn) { var screenBounds = DisplayInfo.GetBounds(MousePosition); var zoomerSize = CalculateZoomSize(screenBounds); var initialPosition = new NativePoint(20, 20); // Initialize the zoom with an initial position _zoomAnimator = new RectangleAnimator(new NativeRect(initialPosition, NativeSize.Empty), new NativeRect(initialPosition, zoomerSize), FramesForMillis(1000), EasingTypes.Quintic, EasingModes.EaseOut); VerifyZoomAnimation(_cursorPos, false); } else { _zoomAnimator?.ChangeDestination(new NativeRect(NativePoint.Empty, NativeSize.Empty), FramesForMillis(1000)); } }
/// <summary> /// Checks if the Zoom area can move there where it wants to go, change direction if not. /// </summary> /// <param name="pos">preferred destination location for the zoom area</param> /// <param name="allowZoomOverCaptureRect"> /// false to try to find a location which is neither out of screen bounds nor /// intersects with the selected rectangle /// </param> private void VerifyZoomAnimation(NativePoint pos, bool allowZoomOverCaptureRect) { var screenBounds = DisplayInfo.GetBounds(MousePosition); var zoomSize = CalculateZoomSize(screenBounds); var zoomOffset = new NativePoint(20, 20); var targetRectangle = _zoomAnimator.Final.Offset(pos); if (screenBounds.Contains(targetRectangle) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(targetRectangle))) { return; } var destinationLocation = NativePoint.Empty; var tl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); var tr = new NativeRect(pos.X + zoomOffset.X, pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); var bl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); var br = new NativeRect(pos.X + zoomOffset.X, pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); if (screenBounds.Contains(br) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(br))) { destinationLocation = new NativePoint(zoomOffset.X, zoomOffset.Y); } else if (screenBounds.Contains(bl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(bl))) { destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, zoomOffset.Y); } else if (screenBounds.Contains(tr) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tr))) { destinationLocation = new NativePoint(zoomOffset.X, -zoomOffset.Y - zoomSize.Width); } else if (screenBounds.Contains(tl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tl))) { destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, -zoomOffset.Y - zoomSize.Width); } if (destinationLocation == NativePoint.Empty && !allowZoomOverCaptureRect) { VerifyZoomAnimation(pos, true); } else { _zoomAnimator.ChangeDestination(new NativeRect(destinationLocation, zoomSize)); } }