Browse Source

Removed RenderTargetDecorator.

Handle scaling in D2D's RenderTarget itself.
pull/488/head
Steven Kirk 11 years ago
parent
commit
553fbb95fc
  1. 36
      src/Perspex.Controls/Platform/PlatformManager.cs
  2. 58
      src/Windows/Perspex.Direct2D1/RenderTarget.cs
  3. 9
      src/Windows/Perspex.Win32/WindowImpl.cs

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

@ -1,7 +1,5 @@
using System; using System;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using Perspex.Input;
using Perspex.Input.Raw;
using Perspex.Media; using Perspex.Media;
using Perspex.Platform; using Perspex.Platform;
@ -9,7 +7,6 @@ namespace Perspex.Controls.Platform
{ {
public static partial class PlatformManager public static partial class PlatformManager
{ {
static IPlatformSettings GetSettings() static IPlatformSettings GetSettings()
=> PerspexLocator.Current.GetService<IPlatformSettings>(); => PerspexLocator.Current.GetService<IPlatformSettings>();
@ -18,9 +15,9 @@ namespace Perspex.Controls.Platform
public static IRenderTarget CreateRenderTarget(ITopLevelImpl window) public static IRenderTarget CreateRenderTarget(ITopLevelImpl window)
{ {
return return PerspexLocator.Current
new RenderTargetDecorator( .GetService<IPlatformRenderInterface>()
PerspexLocator.Current.GetService<IPlatformRenderInterface>().CreateRenderer(window.Handle), window); .CreateRenderer(window.Handle);
} }
public static IDisposable DesignerMode() public static IDisposable DesignerMode()
@ -34,33 +31,6 @@ namespace Perspex.Controls.Platform
_designerScalingFactor = factor; _designerScalingFactor = factor;
} }
class RenderTargetDecorator : IRenderTarget
{
private readonly IRenderTarget _target;
private readonly ITopLevelImpl _window;
public RenderTargetDecorator(IRenderTarget target, ITopLevelImpl window)
{
_target = target;
_window = window;
}
public void Dispose() => _target.Dispose();
public DrawingContext CreateDrawingContext()
{
var cs = _window.ClientSize;
var ctx = _target.CreateDrawingContext();
var factor = _window.Scaling;
if (factor != 1)
{
ctx.PushPostTransform(Matrix.CreateScale(factor, factor));
ctx.PushTransformContainer();
}
return ctx;
}
}
public static IWindowImpl CreateWindow() public static IWindowImpl CreateWindow()
{ {
var platform = PerspexLocator.Current.GetService<IWindowingPlatform>(); var platform = PerspexLocator.Current.GetService<IWindowingPlatform>();

58
src/Windows/Perspex.Direct2D1/RenderTarget.cs

@ -2,10 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using Perspex.Direct2D1.Media;
using Perspex.Media;
using Perspex.Platform; using Perspex.Platform;
using Perspex.Rendering;
using Perspex.Win32.Interop; using Perspex.Win32.Interop;
using SharpDX; using SharpDX;
using SharpDX.Direct2D1; using SharpDX.Direct2D1;
@ -24,8 +21,6 @@ namespace Perspex.Direct2D1
/// </summary> /// </summary>
private readonly SharpDX.Direct2D1.RenderTarget _renderTarget; private readonly SharpDX.Direct2D1.RenderTarget _renderTarget;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RenderTarget"/> class. /// Initializes a new instance of the <see cref="RenderTarget"/> class.
/// </summary> /// </summary>
@ -53,13 +48,6 @@ namespace Perspex.Direct2D1
hwndProperties); hwndProperties);
} }
Size2 GetWindowSize()
{
UnmanagedMethods.RECT rc;
UnmanagedMethods.GetClientRect(_hwnd, out rc);
return new Size2(rc.right - rc.left, rc.bottom - rc.top);
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RenderTarget"/> class. /// Initializes a new instance of the <see cref="RenderTarget"/> class.
/// </summary> /// </summary>
@ -94,19 +82,63 @@ namespace Perspex.Direct2D1
public DrawingContext CreateDrawingContext() public DrawingContext CreateDrawingContext()
{ {
var window = _renderTarget as WindowRenderTarget; var window = _renderTarget as WindowRenderTarget;
var factor = 1.0;
if (window != null) if (window != null)
{ {
var size = GetWindowSize(); var size = GetWindowSize();
factor = GetWindowScaling();
if (size != _savedSize) if (size != _savedSize)
{
window.Resize(_savedSize = size); window.Resize(_savedSize = size);
}
}
var ctx = new DrawingContext(new Media.DrawingContext(_renderTarget, DirectWriteFactory));
if (factor != 1)
{
ctx.PushPostTransform(Matrix.CreateScale(factor, factor));
ctx.PushTransformContainer();
} }
return new DrawingContext(new Media.DrawingContext(_renderTarget, DirectWriteFactory)); return ctx;
} }
public void Dispose() public void Dispose()
{ {
_renderTarget.Dispose(); _renderTarget.Dispose();
} }
private double GetWindowScaling()
{
if (UnmanagedMethods.ShCoreAvailable)
{
uint dpix, dpiy;
var monitor = UnmanagedMethods.MonitorFromWindow(
_hwnd,
UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST);
if (UnmanagedMethods.GetDpiForMonitor(
monitor,
UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI,
out dpix,
out dpiy) == 0)
{
return dpix / 96.0;
}
}
return 1;
}
private Size2 GetWindowSize()
{
UnmanagedMethods.RECT rc;
UnmanagedMethods.GetClientRect(_hwnd, out rc);
return new Size2(rc.right - rc.left, rc.bottom - rc.top);
}
} }
} }

9
src/Windows/Perspex.Win32/WindowImpl.cs

@ -608,13 +608,14 @@ namespace Perspex.Win32
Handle = new PlatformHandle(_hwnd, PlatformConstants.WindowHandleType); Handle = new PlatformHandle(_hwnd, PlatformConstants.WindowHandleType);
var monitor = UnmanagedMethods.MonitorFromWindow(
_hwnd,
UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST);
if (UnmanagedMethods.ShCoreAvailable) if (UnmanagedMethods.ShCoreAvailable)
{ {
uint dpix, dpiy; uint dpix, dpiy;
var monitor = UnmanagedMethods.MonitorFromWindow(
_hwnd,
UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST);
if (UnmanagedMethods.GetDpiForMonitor( if (UnmanagedMethods.GetDpiForMonitor(
monitor, monitor,
UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI,

Loading…
Cancel
Save