forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AvaloniaUI#7165 from MarchingCube/platform-screen-api
Add more platform specific screen from Window/Rect/Point methods. # Conflicts: # src/Avalonia.Controls/ApiCompatBaseline.txt # src/Avalonia.Controls/Screens.cs
- Loading branch information
1 parent
160a560
commit e84a13f
Showing
17 changed files
with
239 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
using System.Collections.Generic; | ||
|
||
#nullable enable | ||
|
||
namespace Avalonia.Platform | ||
{ | ||
public interface IScreenImpl | ||
{ | ||
int ScreenCount { get; } | ||
|
||
IReadOnlyList<Screen> AllScreens { get; } | ||
|
||
Screen? ScreenFromWindow(IWindowBaseImpl window); | ||
|
||
Screen? ScreenFromPoint(PixelPoint point); | ||
|
||
Screen? ScreenFromRect(PixelRect rect); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Collections.Generic; | ||
using Avalonia.Utilities; | ||
|
||
#nullable enable | ||
|
||
namespace Avalonia.Platform | ||
{ | ||
public static class ScreenHelper | ||
{ | ||
public static Screen? ScreenFromPoint(PixelPoint point, IReadOnlyList<Screen> screens) | ||
{ | ||
foreach (Screen screen in screens) | ||
{ | ||
if (screen.Bounds.ContainsExclusive(point)) | ||
{ | ||
return screen; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static Screen? ScreenFromRect(PixelRect bounds, IReadOnlyList<Screen> screens) | ||
{ | ||
Screen? currMaxScreen = null; | ||
double maxAreaSize = 0; | ||
|
||
foreach (Screen screen in screens) | ||
{ | ||
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 static Screen? ScreenFromWindow(IWindowBaseImpl window, IReadOnlyList<Screen> screens) | ||
{ | ||
var rect = new PixelRect( | ||
window.Position, | ||
PixelSize.FromSize(window.FrameSize ?? window.ClientSize, window.DesktopScaling)); | ||
|
||
return ScreenFromRect(rect, screens); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.