|
|
|
@ -20,30 +20,53 @@ namespace Avalonia.Controls |
|
|
|
_iScreenImpl = iScreenImpl; |
|
|
|
} |
|
|
|
|
|
|
|
public Screen ScreenFromBounds(PixelRect bounds){ |
|
|
|
|
|
|
|
Screen currMaxScreen = null; |
|
|
|
double maxAreaSize = 0; |
|
|
|
foreach (Screen screen in All) |
|
|
|
public Screen ScreenFromBounds(PixelRect bounds) |
|
|
|
{ |
|
|
|
Screen currMaxScreen = _iScreenImpl.ScreenFromRect(bounds); |
|
|
|
|
|
|
|
if (currMaxScreen == null) |
|
|
|
{ |
|
|
|
double left = MathUtilities.Clamp(bounds.X, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width); |
|
|
|
double top = MathUtilities.Clamp(bounds.Y, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height); |
|
|
|
double right = MathUtilities.Clamp(bounds.X + bounds.Width, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width); |
|
|
|
double bottom = MathUtilities.Clamp(bounds.Y + bounds.Height, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height); |
|
|
|
double area = (right - left) * (bottom - top); |
|
|
|
if (area > maxAreaSize) |
|
|
|
double maxAreaSize = 0; |
|
|
|
foreach (Screen screen in All) |
|
|
|
{ |
|
|
|
maxAreaSize = area; |
|
|
|
currMaxScreen = screen; |
|
|
|
double left = MathUtilities.Clamp(bounds.X, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width); |
|
|
|
double top = MathUtilities.Clamp(bounds.Y, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height); |
|
|
|
double right = MathUtilities.Clamp(bounds.X + bounds.Width, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width); |
|
|
|
double bottom = MathUtilities.Clamp(bounds.Y + bounds.Height, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height); |
|
|
|
double area = (right - left) * (bottom - top); |
|
|
|
if (area > maxAreaSize) |
|
|
|
{ |
|
|
|
maxAreaSize = area; |
|
|
|
currMaxScreen = screen; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return currMaxScreen; |
|
|
|
} |
|
|
|
|
|
|
|
public Screen ScreenFromWindow(IWindowBaseImpl window) |
|
|
|
{ |
|
|
|
var screen = _iScreenImpl.ScreenFromWindow(window); |
|
|
|
|
|
|
|
if (screen == null && window.Position is { } position) |
|
|
|
{ |
|
|
|
screen = ScreenFromPoint(position); |
|
|
|
} |
|
|
|
|
|
|
|
return screen; |
|
|
|
} |
|
|
|
|
|
|
|
public Screen ScreenFromPoint(PixelPoint point) |
|
|
|
{ |
|
|
|
return All.FirstOrDefault(x => x.Bounds.Contains(point)); |
|
|
|
var screen = _iScreenImpl.ScreenFromPoint(point); |
|
|
|
|
|
|
|
if (screen == null) |
|
|
|
{ |
|
|
|
screen = All.FirstOrDefault(x => x.Bounds.Contains(point)); |
|
|
|
} |
|
|
|
|
|
|
|
return screen; |
|
|
|
} |
|
|
|
|
|
|
|
public Screen ScreenFromVisual(IVisual visual) |
|
|
|
|