Browse Source

Merge pull request #1975 from AvaloniaUI/fixes/previewer-zooming

fix support for zooming in on previewer and hidpi preview.
pull/1976/head
danwalmsley 8 years ago
committed by GitHub
parent
commit
f6fcd5bd1b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/Avalonia.Controls/Remote/RemoteWidget.cs
  2. 9
      src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs
  3. 10
      src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
  4. 7
      src/Avalonia.Remote.Protocol/ViewportMessages.cs

26
src/Avalonia.Controls/Remote/RemoteWidget.cs

@ -11,11 +11,19 @@ namespace Avalonia.Controls.Remote
{ {
public class RemoteWidget : Control public class RemoteWidget : Control
{ {
public enum SizingMode
{
Local,
Remote
}
private readonly IAvaloniaRemoteTransportConnection _connection; private readonly IAvaloniaRemoteTransportConnection _connection;
private FrameMessage _lastFrame; private FrameMessage _lastFrame;
private WriteableBitmap _bitmap; private WriteableBitmap _bitmap;
public RemoteWidget(IAvaloniaRemoteTransportConnection connection) public RemoteWidget(IAvaloniaRemoteTransportConnection connection)
{ {
Mode = SizingMode.Local;
_connection = connection; _connection = connection;
_connection.OnMessage += (t, msg) => Dispatcher.UIThread.Post(() => OnMessage(msg)); _connection.OnMessage += (t, msg) => Dispatcher.UIThread.Post(() => OnMessage(msg));
_connection.Send(new ClientSupportedPixelFormatsMessage _connection.Send(new ClientSupportedPixelFormatsMessage
@ -28,6 +36,8 @@ namespace Avalonia.Controls.Remote
}); });
} }
public SizingMode Mode { get; set; }
private void OnMessage(object msg) private void OnMessage(object msg)
{ {
if (msg is FrameMessage frame) if (msg is FrameMessage frame)
@ -44,13 +54,17 @@ namespace Avalonia.Controls.Remote
protected override void ArrangeCore(Rect finalRect) protected override void ArrangeCore(Rect finalRect)
{ {
_connection.Send(new ClientViewportAllocatedMessage if (Mode == SizingMode.Local)
{ {
Width = finalRect.Width, _connection.Send(new ClientViewportAllocatedMessage
Height = finalRect.Height, {
DpiX = 96, Width = finalRect.Width,
DpiY = 96 //TODO: Somehow detect the actual DPI Height = finalRect.Height,
}); DpiX = 10 * 96,
DpiY = 10 * 96 //TODO: Somehow detect the actual DPI
});
}
base.ArrangeCore(finalRect); base.ArrangeCore(finalRect);
} }

9
src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs

@ -45,6 +45,15 @@ namespace Avalonia.Controls.Remote.Server
} }
Dispatcher.UIThread.Post(RenderIfNeeded); Dispatcher.UIThread.Post(RenderIfNeeded);
} }
if(obj is ClientRenderInfoMessage renderInfo)
{
lock(_lock)
{
_dpi = new Vector(renderInfo.DpiX, renderInfo.DpiY);
_invalidated = true;
RenderIfNeeded();
}
}
if (obj is ClientSupportedPixelFormatsMessage supportedFormats) if (obj is ClientSupportedPixelFormatsMessage supportedFormats)
{ {
lock (_lock) lock (_lock)

10
src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

@ -15,6 +15,8 @@ namespace Avalonia.DesignerSupport.Remote
{ {
private static ClientSupportedPixelFormatsMessage s_supportedPixelFormats; private static ClientSupportedPixelFormatsMessage s_supportedPixelFormats;
private static ClientViewportAllocatedMessage s_viewportAllocatedMessage; private static ClientViewportAllocatedMessage s_viewportAllocatedMessage;
private static ClientRenderInfoMessage s_renderInfoMessage;
private static IAvaloniaRemoteTransportConnection s_transport; private static IAvaloniaRemoteTransportConnection s_transport;
class CommandLineArgs class CommandLineArgs
{ {
@ -161,7 +163,8 @@ namespace Avalonia.DesignerSupport.Remote
PreviewerWindowingPlatform.PreFlightMessages = new List<object> PreviewerWindowingPlatform.PreFlightMessages = new List<object>
{ {
s_supportedPixelFormats, s_supportedPixelFormats,
s_viewportAllocatedMessage s_viewportAllocatedMessage,
s_renderInfoMessage
}; };
} }
@ -173,6 +176,11 @@ namespace Avalonia.DesignerSupport.Remote
s_supportedPixelFormats = formats; s_supportedPixelFormats = formats;
RebuildPreFlight(); RebuildPreFlight();
} }
if (obj is ClientRenderInfoMessage renderInfo)
{
s_renderInfoMessage = renderInfo;
RebuildPreFlight();
}
if (obj is ClientViewportAllocatedMessage viewport) if (obj is ClientViewportAllocatedMessage viewport)
{ {
s_viewportAllocatedMessage = viewport; s_viewportAllocatedMessage = viewport;

7
src/Avalonia.Remote.Protocol/ViewportMessages.cs

@ -37,6 +37,13 @@
public PixelFormat[] Formats { get; set; } public PixelFormat[] Formats { get; set; }
} }
[AvaloniaRemoteMessageGuid("7A3c25d3-3652-438D-8EF1-86E942CC96C0")]
public class ClientRenderInfoMessage
{
public double DpiX { get; set; }
public double DpiY { get; set; }
}
[AvaloniaRemoteMessageGuid("68014F8A-289D-4851-8D34-5367EDA7F827")] [AvaloniaRemoteMessageGuid("68014F8A-289D-4851-8D34-5367EDA7F827")]
public class FrameReceivedMessage public class FrameReceivedMessage
{ {

Loading…
Cancel
Save