Browse Source

Rename Scale to Scaling and update more comments

pull/9133/head
robloo 4 years ago
parent
commit
d816726ef0
  1. 2
      samples/ControlCatalog/Pages/ScreenPage.cs
  2. 6
      src/Avalonia.Controls/Platform/IScreenImpl.cs
  3. 19
      src/Avalonia.Controls/Platform/Screen.cs
  4. 13
      src/Avalonia.Controls/Screens.cs
  5. 4
      src/Avalonia.Native/ScreenImpl.cs
  6. 2
      src/Avalonia.Native/WindowImplBase.cs
  7. 4
      src/Avalonia.Native/avn.idl
  8. 24
      src/Avalonia.X11/X11Screens.cs
  9. 8
      src/Avalonia.X11/X11Window.cs
  10. 8
      src/Windows/Avalonia.Win32/TrayIconImpl.cs
  11. 2
      src/Windows/Avalonia.Win32/WindowImpl.cs

2
samples/ControlCatalog/Pages/ScreenPage.cs

@ -65,7 +65,7 @@ namespace ControlCatalog.Pages
formattedText = CreateFormattedText($"Scaling: {screen.Scale * 100}%"); formattedText = CreateFormattedText($"Scaling: {screen.Scale * 100}%");
context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 40)); context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 40));
formattedText = CreateFormattedText($"Primary: {screen.IsPrimary}"); formattedText = CreateFormattedText($"IsPrimary: {screen.IsPrimary}");
context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 60)); context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 60));
formattedText = formattedText =

6
src/Avalonia.Controls/Platform/IScreenImpl.cs

@ -6,8 +6,14 @@ namespace Avalonia.Platform
[Unstable] [Unstable]
public interface IScreenImpl public interface IScreenImpl
{ {
/// <summary>
/// Gets the total number of screens available on the device.
/// </summary>
int ScreenCount { get; } int ScreenCount { get; }
/// <summary>
/// Gets the list of all screens available on the device.
/// </summary>
IReadOnlyList<Screen> AllScreens { get; } IReadOnlyList<Screen> AllScreens { get; }
Screen? ScreenFromWindow(IWindowBaseImpl window); Screen? ScreenFromWindow(IWindowBaseImpl window);

19
src/Avalonia.Controls/Platform/Screen.cs

@ -14,11 +14,11 @@ namespace Avalonia.Platform
/// Multiply this value by 100 to get a percentage. /// Multiply this value by 100 to get a percentage.
/// Both X and Y scaling factors are assumed uniform. /// Both X and Y scaling factors are assumed uniform.
/// </remarks> /// </remarks>
public double Scale { get; } public double Scaling { get; }
/// <inheritdoc cref="Scale"/> /// <inheritdoc cref="Scaling"/>
[Obsolete("Use the Scale property instead.")] [Obsolete("Use the Scaling property instead.")]
public double PixelDensity => Scale; public double PixelDensity => Scaling;
/// <summary> /// <summary>
/// Gets the overall pixel-size of the screen. /// Gets the overall pixel-size of the screen.
@ -46,9 +46,16 @@ namespace Avalonia.Platform
[Obsolete("Use the IsPrimary property instead.")] [Obsolete("Use the IsPrimary property instead.")]
public bool Primary => IsPrimary; public bool Primary => IsPrimary;
public Screen(double scale, PixelRect bounds, PixelRect workingArea, bool isPrimary) /// <summary>
/// Initializes a new instance of the <see cref="Screen"/> class.
/// </summary>
/// <param name="scaling">The scaling factor applied to the screen by the operating system.</param>
/// <param name="bounds">The overall pixel-size of the screen.</param>
/// <param name="workingArea">The actual working-area pixel-size of the screen.</param>
/// <param name="isPrimary">Whether the screen is the primary one.</param>
public Screen(double scaling, PixelRect bounds, PixelRect workingArea, bool isPrimary)
{ {
this.Scale = scale; this.Scaling = scaling;
this.Bounds = bounds; this.Bounds = bounds;
this.WorkingArea = workingArea; this.WorkingArea = workingArea;
this.IsPrimary = isPrimary; this.IsPrimary = isPrimary;

13
src/Avalonia.Controls/Screens.cs

@ -16,20 +16,23 @@ namespace Avalonia.Controls
private readonly IScreenImpl _iScreenImpl; private readonly IScreenImpl _iScreenImpl;
/// <summary> /// <summary>
/// Gets the total number of screens available on this device. /// Gets the total number of screens available on the device.
/// </summary> /// </summary>
public int ScreenCount => _iScreenImpl?.ScreenCount ?? 0; public int ScreenCount => _iScreenImpl?.ScreenCount ?? 0;
/// <summary> /// <summary>
/// Gets the list of all screens available on this device. /// Gets the list of all screens available on the device.
/// </summary> /// </summary>
public IReadOnlyList<Screen> All => _iScreenImpl?.AllScreens ?? Array.Empty<Screen>(); public IReadOnlyList<Screen> All => _iScreenImpl?.AllScreens ?? Array.Empty<Screen>();
/// <summary> /// <summary>
/// Gets the primary screen on this device. /// Gets the primary screen on the device.
/// </summary> /// </summary>
public Screen? Primary => All.FirstOrDefault(x => x.IsPrimary); public Screen? Primary => All.FirstOrDefault(x => x.IsPrimary);
/// <summary>
/// Initializes a new instance of the <see cref="Screens"/> class.
/// </summary>
public Screens(IScreenImpl iScreenImpl) public Screens(IScreenImpl iScreenImpl)
{ {
_iScreenImpl = iScreenImpl; _iScreenImpl = iScreenImpl;
@ -39,14 +42,14 @@ namespace Avalonia.Controls
{ {
return _iScreenImpl.ScreenFromRect(bounds); return _iScreenImpl.ScreenFromRect(bounds);
} }
public Screen? ScreenFromWindow(IWindowBaseImpl window) public Screen? ScreenFromWindow(IWindowBaseImpl window)
{ {
return _iScreenImpl.ScreenFromWindow(window); return _iScreenImpl.ScreenFromWindow(window);
} }
public Screen? ScreenFromPoint(PixelPoint point) public Screen? ScreenFromPoint(PixelPoint point)
{ {
return _iScreenImpl.ScreenFromPoint(point); return _iScreenImpl.ScreenFromPoint(point);
} }

4
src/Avalonia.Native/ScreenImpl.cs

@ -30,10 +30,10 @@ namespace Avalonia.Native
var screen = _native.GetScreen(i); var screen = _native.GetScreen(i);
result[i] = new Screen( result[i] = new Screen(
screen.PixelDensity, screen.Scaling,
screen.Bounds.ToAvaloniaPixelRect(), screen.Bounds.ToAvaloniaPixelRect(),
screen.WorkingArea.ToAvaloniaPixelRect(), screen.WorkingArea.ToAvaloniaPixelRect(),
screen.Primary.FromComBool()); screen.IsPrimary.FromComBool());
} }
return result; return result;

2
src/Avalonia.Native/WindowImplBase.cs

@ -92,7 +92,7 @@ namespace Avalonia.Native
_savedScaling = RenderScaling; _savedScaling = RenderScaling;
_nativeControlHost = new NativeControlHostImpl(_native.CreateNativeControlHost()); _nativeControlHost = new NativeControlHostImpl(_native.CreateNativeControlHost());
var monitor = Screen.AllScreens.OrderBy(x => x.Scale) var monitor = Screen.AllScreens.OrderBy(x => x.Scaling)
.FirstOrDefault(m => m.Bounds.Contains(Position)); .FirstOrDefault(m => m.Bounds.Contains(Position));
Resize(new Size(monitor.WorkingArea.Width * 0.75d, monitor.WorkingArea.Height * 0.7d), PlatformResizeReason.Layout); Resize(new Size(monitor.WorkingArea.Width * 0.75d, monitor.WorkingArea.Height * 0.7d), PlatformResizeReason.Layout);

4
src/Avalonia.Native/avn.idl

@ -256,8 +256,8 @@ struct AvnScreen
{ {
AvnRect Bounds; AvnRect Bounds;
AvnRect WorkingArea; AvnRect WorkingArea;
float PixelDensity; float Scaling;
bool Primary; bool IsPrimary;
} }
enum AvnPixelFormat enum AvnPixelFormat

24
src/Avalonia.X11/X11Screens.cs

@ -218,7 +218,7 @@ namespace Avalonia.X11
public int ScreenCount => _impl.Screens.Length; public int ScreenCount => _impl.Screens.Length;
public IReadOnlyList<Screen> AllScreens => public IReadOnlyList<Screen> AllScreens =>
_impl.Screens.Select(s => new Screen(s.PixelDensity, s.Bounds, s.WorkingArea, s.IsPrimary)).ToArray(); _impl.Screens.Select(s => new Screen(s.Scaling, s.Bounds, s.WorkingArea, s.IsPrimary)).ToArray();
} }
interface IX11Screens interface IX11Screens
@ -285,26 +285,30 @@ namespace Avalonia.X11
public string Name { get; set; } public string Name { get; set; }
public PixelRect Bounds { get; set; } public PixelRect Bounds { get; set; }
public Size? PhysicalSize { get; set; } public Size? PhysicalSize { get; set; }
public double PixelDensity { get; set; } public double Scaling { get; set; }
public PixelRect WorkingArea { get; set; } public PixelRect WorkingArea { get; set; }
public X11Screen(PixelRect bounds, bool primary, public X11Screen(
string name, Size? physicalSize, double? pixelDensity) PixelRect bounds,
bool isPrimary,
string name,
Size? physicalSize,
double? scaling)
{ {
IsPrimary = primary; IsPrimary = isPrimary;
Name = name; Name = name;
Bounds = bounds; Bounds = bounds;
if (physicalSize == null && pixelDensity == null) if (physicalSize == null && scaling == null)
{ {
PixelDensity = 1; Scaling = 1;
} }
else if (pixelDensity == null) else if (scaling == null)
{ {
PixelDensity = GuessPixelDensity(bounds, physicalSize.Value); Scaling = GuessPixelDensity(bounds, physicalSize.Value);
} }
else else
{ {
PixelDensity = pixelDensity.Value; Scaling = scaling.Value;
PhysicalSize = physicalSize; PhysicalSize = physicalSize;
} }
} }

8
src/Avalonia.X11/X11Window.cs

@ -120,7 +120,7 @@ namespace Avalonia.X11
if (!_popup && Screen != null) if (!_popup && Screen != null)
{ {
var monitor = Screen.AllScreens.OrderBy(x => x.Scale) var monitor = Screen.AllScreens.OrderBy(x => x.Scaling)
.FirstOrDefault(m => m.Bounds.Contains(Position)); .FirstOrDefault(m => m.Bounds.Contains(Position));
if (monitor != null) if (monitor != null)
@ -570,9 +570,9 @@ namespace Avalonia.X11
newScaling = _scalingOverride.Value; newScaling = _scalingOverride.Value;
else else
{ {
var monitor = _platform.X11Screens.Screens.OrderBy(x => x.PixelDensity) var monitor = _platform.X11Screens.Screens.OrderBy(x => x.Scaling)
.FirstOrDefault(m => m.Bounds.Contains(Position)); .FirstOrDefault(m => m.Bounds.Contains(Position));
newScaling = monitor?.PixelDensity ?? RenderScaling; newScaling = monitor?.Scaling ?? RenderScaling;
} }
if (RenderScaling != newScaling) if (RenderScaling != newScaling)
@ -994,7 +994,7 @@ namespace Avalonia.X11
public IScreenImpl Screen => _platform.Screens; public IScreenImpl Screen => _platform.Screens;
public Size MaxAutoSizeHint => _platform.X11Screens.Screens.Select(s => s.Bounds.Size.ToSize(s.PixelDensity)) public Size MaxAutoSizeHint => _platform.X11Screens.Screens.Select(s => s.Bounds.Size.ToSize(s.Scaling))
.OrderByDescending(x => x.Width + x.Height).FirstOrDefault(); .OrderByDescending(x => x.Width + x.Height).FirstOrDefault();

8
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@ -216,7 +216,7 @@ namespace Avalonia.Win32
{ {
Anchor = PopupAnchor.TopLeft, Anchor = PopupAnchor.TopLeft,
Gravity = PopupGravity.BottomRight, Gravity = PopupGravity.BottomRight,
AnchorRectangle = new Rect(Position.ToPoint(1) / Screens.Primary.Scale, new Size(1, 1)), AnchorRectangle = new Rect(Position.ToPoint(1) / Screens.Primary.Scaling, new Size(1, 1)),
Size = finalRect.Size, Size = finalRect.Size,
ConstraintAdjustment = PopupPositionerConstraintAdjustment.FlipX | PopupPositionerConstraintAdjustment.FlipY, ConstraintAdjustment = PopupPositionerConstraintAdjustment.FlipX | PopupPositionerConstraintAdjustment.FlipY,
}); });
@ -244,16 +244,16 @@ namespace Avalonia.Win32
{ {
var point = _hiddenWindow.Screens.Primary.Bounds.TopLeft; var point = _hiddenWindow.Screens.Primary.Bounds.TopLeft;
var size = _hiddenWindow.Screens.Primary.Bounds.Size; var size = _hiddenWindow.Screens.Primary.Bounds.Size;
return new Rect(point.X, point.Y, size.Width * _hiddenWindow.Screens.Primary.Scale, size.Height * _hiddenWindow.Screens.Primary.Scale); return new Rect(point.X, point.Y, size.Width * _hiddenWindow.Screens.Primary.Scaling, size.Height * _hiddenWindow.Screens.Primary.Scaling);
} }
} }
public void MoveAndResize(Point devicePoint, Size virtualSize) public void MoveAndResize(Point devicePoint, Size virtualSize)
{ {
_moveResize(new PixelPoint((int)devicePoint.X, (int)devicePoint.Y), virtualSize, _hiddenWindow.Screens.Primary.Scale); _moveResize(new PixelPoint((int)devicePoint.X, (int)devicePoint.Y), virtualSize, _hiddenWindow.Screens.Primary.Scaling);
} }
public double Scaling => _hiddenWindow.Screens.Primary.Scale; public double Scaling => _hiddenWindow.Screens.Primary.Scaling;
} }
} }

2
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -224,7 +224,7 @@ namespace Avalonia.Win32
} }
} }
private double PrimaryScreenRenderScaling => Screen.AllScreens.FirstOrDefault(screen => screen.IsPrimary)?.Scale ?? 1; private double PrimaryScreenRenderScaling => Screen.AllScreens.FirstOrDefault(screen => screen.IsPrimary)?.Scaling ?? 1;
public double RenderScaling => _scaling; public double RenderScaling => _scaling;

Loading…
Cancel
Save