Browse Source

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

fix support for zooming in on previewer and hidpi preview.
danwalmsley 7 years ago
parent
commit
f6fcd5bd1b

+ 20 - 6
src/Avalonia.Controls/Remote/RemoteWidget.cs

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

+ 9 - 0
src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs

@@ -45,6 +45,15 @@ namespace Avalonia.Controls.Remote.Server
                     }
                     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)
                 {
                     lock (_lock)

+ 9 - 1
src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

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

+ 7 - 0
src/Avalonia.Remote.Protocol/ViewportMessages.cs

@@ -37,6 +37,13 @@
         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")]
     public class FrameReceivedMessage
     {