Browse Source

Implemented designer scaling

pull/332/head
Nikita Tsukanov 11 years ago
parent
commit
a961498420
  1. 9
      src/Perspex.Application/Designer/Designer.cs
  2. 5
      src/Perspex.Application/Designer/DesignerApi.cs
  3. 13
      src/Perspex.Controls/Platform/PlatformManager.cs
  4. 20
      src/Windows/Perspex.Designer/AppHost/HostedAppModel.cs
  5. 3
      src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs
  6. 2
      src/Windows/Perspex.Designer/Comm/CommChannel.cs
  7. 24
      src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml

9
src/Perspex.Application/Designer/Designer.cs

@ -29,10 +29,17 @@ namespace Perspex.Designer
public static void Init(Dictionary<string, object> shared) public static void Init(Dictionary<string, object> shared)
{ {
Api = new DesignerApi(shared) {UpdateXaml = UpdateXaml}; Api = new DesignerApi(shared) {UpdateXaml = UpdateXaml, SetScalingFactor = SetScalingFactor};
new DesignerApp(); new DesignerApp();
} }
private static void SetScalingFactor(double factor)
{
PlatformManager.SetDesignerScalingFactor(factor);
if (s_currentWindow != null)
s_currentWindow.PlatformImpl.ClientSize = s_currentWindow.ClientSize;
}
static Window s_currentWindow; static Window s_currentWindow;
private static void UpdateXaml(string xaml) private static void UpdateXaml(string xaml)

5
src/Perspex.Application/Designer/DesignerApi.cs

@ -46,6 +46,11 @@ namespace Perspex.Designer
get { return (Action<IntPtr>) Get(); } get { return (Action<IntPtr>) Get(); }
} }
public Action<double> SetScalingFactor
{
set { Set(value);}
get { return (Action<double>) Get(); }
}
} }
} }

13
src/Perspex.Controls/Platform/PlatformManager.cs

@ -19,6 +19,7 @@ namespace Perspex.Controls.Platform
=> PerspexLocator.Current.GetService<IPlatformSettings>(); => PerspexLocator.Current.GetService<IPlatformSettings>();
static bool s_designerMode; static bool s_designerMode;
private static double _designerScalingFactor = 1;
public static IRenderTarget CreateRenderTarget(ITopLevelImpl window) public static IRenderTarget CreateRenderTarget(ITopLevelImpl window)
{ {
@ -33,6 +34,14 @@ namespace Perspex.Controls.Platform
return Disposable.Create(() => s_designerMode = false); return Disposable.Create(() => s_designerMode = false);
} }
public static void SetDesignerScalingFactor(double factor)
{
_designerScalingFactor = factor;
}
static double RenderScalingFactor => (GetSettings()?.RenderScalingFactor ?? 1)*_designerScalingFactor;
static double LayoutScalingFactor => (GetSettings()?.LayoutScalingFactor ?? 1) * _designerScalingFactor;
class RenderTargetDecorator : IRenderTarget class RenderTargetDecorator : IRenderTarget
{ {
private readonly IRenderTarget _target; private readonly IRenderTarget _target;
@ -53,7 +62,7 @@ namespace Perspex.Controls.Platform
{ {
var cs = _window.ClientSize; var cs = _window.ClientSize;
var ctx = _target.CreateDrawingContext(); var ctx = _target.CreateDrawingContext();
var factor = GetSettings()?.RenderScalingFactor ?? 1; var factor = RenderScalingFactor;
if (factor != 1) if (factor != 1)
{ {
ctx.PushPostTransform(Matrix.CreateScale(factor, factor)); ctx.PushPostTransform(Matrix.CreateScale(factor, factor));
@ -70,7 +79,7 @@ namespace Perspex.Controls.Platform
private readonly IPopupImpl _popup; private readonly IPopupImpl _popup;
public ITopLevelImpl TopLevel => _tl; public ITopLevelImpl TopLevel => _tl;
double ScalingFactor => GetSettings()?.LayoutScalingFactor ?? 1; double ScalingFactor => LayoutScalingFactor;
public WindowDecorator(ITopLevelImpl tl) public WindowDecorator(ITopLevelImpl tl)
{ {

20
src/Windows/Perspex.Designer/AppHost/HostedAppModel.cs

@ -11,10 +11,16 @@ namespace Perspex.Designer.AppHost
{ {
public class HostedAppModel : INotifyPropertyChanged public class HostedAppModel : INotifyPropertyChanged
{ {
private readonly PerspexAppHost _host;
private IntPtr _nativeWindowHandle; private IntPtr _nativeWindowHandle;
private string _error; private string _error;
private string _errorDetails; private string _errorDetails;
internal HostedAppModel(PerspexAppHost host)
{
_host = host;
}
public IntPtr NativeWindowHandle public IntPtr NativeWindowHandle
{ {
get { return _nativeWindowHandle; } get { return _nativeWindowHandle; }
@ -48,12 +54,26 @@ namespace Perspex.Designer.AppHost
} }
} }
public IReadOnlyList<double> AvailableScalingFactors => new List<double>() {1, 2, 4, 8};
public double CurrentScalingFactor
{
get { return _currentScalingFactor; }
set
{
_currentScalingFactor = value;
_host.Api.SetScalingFactor(value);
}
}
public void SetError(string error, string details = null) public void SetError(string error, string details = null)
{ {
Error = error; Error = error;
ErrorDetails = details; ErrorDetails = details;
} }
double _currentScalingFactor = 1;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator] [NotifyPropertyChangedInvocator]

3
src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs

@ -22,12 +22,13 @@ namespace Perspex.Designer.AppHost
private string _lastXaml; private string _lastXaml;
private string _currentXaml; private string _currentXaml;
private bool _initSuccess; private bool _initSuccess;
private readonly HostedAppModel _appModel = new HostedAppModel(); private HostedAppModel _appModel;
private Control _window; private Control _window;
public PerspexAppHost(CommChannel channel) public PerspexAppHost(CommChannel channel)
{ {
_comm = channel; _comm = channel;
_appModel = new HostedAppModel(this);
} }
public void Start() public void Start()

2
src/Windows/Perspex.Designer/Comm/CommChannel.cs

@ -13,7 +13,7 @@ using System.Windows.Threading;
namespace Perspex.Designer.Comm namespace Perspex.Designer.Comm
{ {
internal class CommChannel : IDisposable class CommChannel : IDisposable
{ {
private readonly BinaryReader _input; private readonly BinaryReader _input;
private readonly BinaryWriter _output; private readonly BinaryWriter _output;

24
src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml

@ -4,17 +4,27 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:appHost="clr-namespace:Perspex.Designer.AppHost" xmlns:appHost="clr-namespace:Perspex.Designer.AppHost"
xmlns:system="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance appHost:HostedAppModel}"> d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance appHost:HostedAppModel}">
<DockPanel> <DockPanel>
<Border x:Name="ErrorPanel" DockPanel.Dock="Bottom" BorderBrush="Red" BorderThickness="3" Padding="3"> <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
<StackPanel Orientation="Horizontal"> <ComboBox ItemsSource="{Binding AvailableScalingFactors}" SelectedItem="{Binding CurrentScalingFactor, Mode=TwoWay}">
<TextBlock Text="{Binding Error}" FontSize="16"/> <ComboBox.ItemTemplate>
<TextBlock x:Name="DetailsBlock" FontSize="16"> <DataTemplate DataType="{x:Type system:Double}">
<TextBlock><Run Text="{Binding .}"/>00%</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Border x:Name="ErrorPanel" BorderBrush="Red" BorderThickness="3" Padding="3">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Error}" FontSize="16"/>
<TextBlock x:Name="DetailsBlock" FontSize="16">
<Run> (</Run><Hyperlink Click="Hyperlink_OnClick">View details</Hyperlink><Run>)</Run> <Run> (</Run><Hyperlink Click="Hyperlink_OnClick">View details</Hyperlink><Run>)</Run>
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</Border> </Border>
</StackPanel>
<WindowsFormsHost x:Name="WindowHostControl"/> <WindowsFormsHost x:Name="WindowHostControl"/>
</DockPanel> </DockPanel>
</UserControl> </UserControl>

Loading…
Cancel
Save