Browse Source

add a render info message so dpi can be set.

pull/1975/head
Dan Walmsley 8 years ago
parent
commit
e12a3f91c5
  1. 8
      src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs
  2. 4
      src/Avalonia.DesignerSupport/DesignWindowLoader.cs
  3. 15
      src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
  4. 7
      src/Avalonia.Remote.Protocol/ViewportMessages.cs

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

@ -45,6 +45,13 @@ 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);
}
}
if (obj is ClientSupportedPixelFormatsMessage supportedFormats) if (obj is ClientSupportedPixelFormatsMessage supportedFormats)
{ {
lock (_lock) lock (_lock)
@ -74,7 +81,6 @@ namespace Avalonia.Controls.Remote.Server
allocation = _pendingAllocation; allocation = _pendingAllocation;
_pendingAllocation = null; _pendingAllocation = null;
} }
_dpi = new Vector(allocation.DpiX, allocation.DpiY);
ClientSize = new Size(allocation.Width, allocation.Height); ClientSize = new Size(allocation.Width, allocation.Height);
RenderIfNeeded(); RenderIfNeeded();
}); });

4
src/Avalonia.DesignerSupport/DesignWindowLoader.cs

@ -13,7 +13,7 @@ namespace Avalonia.DesignerSupport
{ {
public class DesignWindowLoader public class DesignWindowLoader
{ {
public static Window LoadDesignerWindow(string xaml, string assemblyPath, Vector dpi) public static Window LoadDesignerWindow(string xaml, string assemblyPath)
{ {
Window window; Window window;
Control control; Control control;
@ -70,8 +70,6 @@ namespace Avalonia.DesignerSupport
if (!window.IsSet(Window.SizeToContentProperty)) if (!window.IsSet(Window.SizeToContentProperty))
window.SizeToContent = SizeToContent.WidthAndHeight; window.SizeToContent = SizeToContent.WidthAndHeight;
} }
(window.PlatformImpl as RemoteServerTopLevelImpl).SetDpi(dpi);
window.Show(); window.Show();
Design.ApplyDesignModeProperties(window, control); Design.ApplyDesignModeProperties(window, control);

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

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
@ -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;
@ -191,8 +199,7 @@ namespace Avalonia.DesignerSupport.Remote
s_currentWindow = null; s_currentWindow = null;
try try
{ {
var dpi = s_viewportAllocatedMessage != null ? new Vector(s_viewportAllocatedMessage.DpiX, s_viewportAllocatedMessage.DpiY) : new Vector(96, 96); s_currentWindow = DesignWindowLoader.LoadDesignerWindow(xaml.Xaml, xaml.AssemblyPath);
s_currentWindow = DesignWindowLoader.LoadDesignerWindow(xaml.Xaml, xaml.AssemblyPath, dpi);
s_transport.Send(new UpdateXamlResultMessage(){Handle = s_currentWindow.PlatformImpl?.Handle?.Handle.ToString()}); s_transport.Send(new UpdateXamlResultMessage(){Handle = s_currentWindow.PlatformImpl?.Handle?.Handle.ToString()});
} }
catch (Exception e) catch (Exception e)

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