Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix screen clamping logic #3255

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions GUI/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using log4net;

namespace CKAN
{
Expand Down Expand Up @@ -174,19 +175,22 @@ public static Point ClampedLocation(Point location, Size size, Screen screen = n
{
if (screen == null)
{
log.DebugFormat("Looking for screen of {0}, {1}", location, size);
screen = FindScreen(location, size);
}
if (screen != null)
{
log.DebugFormat("Found screen: {0}", screen.WorkingArea);
// Slide the whole rectangle fully onto the screen
if (location.X < screen.WorkingArea.Top)
location.X = screen.WorkingArea.Top;
if (location.Y < screen.WorkingArea.Left)
location.Y = screen.WorkingArea.Left;
if (location.X < screen.WorkingArea.Left)
location.X = screen.WorkingArea.Left;
if (location.Y < screen.WorkingArea.Top)
location.Y = screen.WorkingArea.Top;
if (location.X + size.Width > screen.WorkingArea.Right)
location.X = screen.WorkingArea.Right - size.Width;
if (location.Y + size.Height > screen.WorkingArea.Bottom)
location.Y = screen.WorkingArea.Bottom - size.Height;
log.DebugFormat("Clamped location: {0}", location);
}
return location;
}
Expand All @@ -209,5 +213,7 @@ public static Point ClampedLocationWithMargins(Point location, Size size, Size t
// then place our window at an offset within the box
return ClampedLocation(location - topLeftMargin, size + topLeftMargin + bottomRightMargin, screen) + topLeftMargin;
}

private static readonly ILog log = LogManager.GetLogger(typeof(Util));
}
}