Browse Source

Moved scaling to per-window.

Always returning a scaling factor of 1 currently.
pull/447/head
Steven Kirk 10 years ago
parent
commit
93b4d810b9
  1. 2
      src/Gtk/Perspex.Gtk/WindowImpl.cs
  2. 5
      src/Perspex.Controls/Platform/ITopLevelImpl.cs
  3. 24
      src/Perspex.Controls/Platform/PlatformManager.cs
  4. 3
      src/Perspex.Controls/TopLevel.cs
  5. 5
      src/Perspex.Layout/ILayoutRoot.cs
  6. 4
      src/Perspex.Layout/Layoutable.cs
  7. 4
      src/Perspex.SceneGraph/Platform/IPlatformSettings.cs
  8. 2
      src/Windows/Perspex.Win32/WindowImpl.cs
  9. 2
      tests/Perspex.Controls.UnitTests/ControlTests.cs
  10. 2
      tests/Perspex.Controls.UnitTests/TestRoot.cs
  11. 7
      tests/Perspex.Controls.UnitTests/TopLevelTests.cs
  12. 4
      tests/Perspex.Controls.UnitTests/WindowingPlatformMock.cs
  13. 1
      tests/Perspex.Layout.UnitTests/FullLayoutTests.cs
  14. 1
      tests/Perspex.Layout.UnitTests/TestLayoutRoot.cs
  15. 4
      tests/Perspex.LeakTests/TestApp.cs
  16. 2
      tests/Perspex.Styling.UnitTests/TestRoot.cs

2
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -75,6 +75,8 @@ namespace Perspex.Gtk
}
}
public double Scaling => 1;
IPlatformHandle ITopLevelImpl.Handle => this;
[DllImport("libgdk-win32-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]

5
src/Perspex.Controls/Platform/ITopLevelImpl.cs

@ -22,6 +22,11 @@ namespace Perspex.Platform
/// </summary>
Size ClientSize { get; set; }
/// <summary>
/// Gets the scaling factor for the window.
/// </summary>
double Scaling { get; }
/// <summary>
/// Gets the platform window handle.
/// </summary>

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

@ -39,9 +39,6 @@ namespace Perspex.Controls.Platform
_designerScalingFactor = factor;
}
static double RenderScalingFactor => (GetSettings()?.RenderScalingFactor ?? 1)*_designerScalingFactor;
static double LayoutScalingFactor => (GetSettings()?.LayoutScalingFactor ?? 1) * _designerScalingFactor;
class RenderTargetDecorator : IRenderTarget
{
private readonly IRenderTarget _target;
@ -62,7 +59,7 @@ namespace Perspex.Controls.Platform
{
var cs = _window.ClientSize;
var ctx = _target.CreateDrawingContext();
var factor = RenderScalingFactor;
var factor = _window.Scaling;
if (factor != 1)
{
ctx.PushPostTransform(Matrix.CreateScale(factor, factor));
@ -79,7 +76,6 @@ namespace Perspex.Controls.Platform
private readonly IPopupImpl _popup;
public ITopLevelImpl TopLevel => _tl;
double ScalingFactor => LayoutScalingFactor;
public WindowDecorator(ITopLevelImpl tl)
{
@ -93,12 +89,12 @@ namespace Perspex.Controls.Platform
private void OnResized(Size size)
{
Resized?.Invoke(size/ScalingFactor);
Resized?.Invoke(size/Scaling);
}
private void OnPaint(Rect rc)
{
var f = ScalingFactor;
var f = Scaling;
Paint?.Invoke(new Rect(rc.X/f, rc.Y/f, rc.Width/f, rc.Height/f));
}
@ -106,31 +102,31 @@ namespace Perspex.Controls.Platform
{
var mouseEvent = obj as RawMouseEventArgs;
if (mouseEvent != null)
mouseEvent.Position /= ScalingFactor;
mouseEvent.Position /= Scaling;
//TODO: Transform event coordinates
Input?.Invoke(obj);
}
public Point PointToScreen(Point point)
{
return _tl.PointToScreen(point*ScalingFactor)/ScalingFactor;
return _tl.PointToScreen(point*Scaling)/Scaling;
}
public void Invalidate(Rect rc)
{
var f = ScalingFactor;
var f = Scaling;
_tl.Invalidate(new Rect(rc.X*f, rc.Y*f, (rc.Width + 1)*f, (rc.Height + 1)*f));
}
public Size ClientSize
{
get { return _tl.ClientSize/ScalingFactor; }
set { _tl.ClientSize = value*ScalingFactor; }
get { return _tl.ClientSize/Scaling; }
set { _tl.ClientSize = value*Scaling; }
}
public Size MaxClientSize => _window.MaxClientSize/ScalingFactor;
public Size MaxClientSize => _window.MaxClientSize/Scaling;
public double Scaling => _tl.Scaling;
public Action<RawInputEventArgs> Input { get; set; }
public Action<Rect> Paint { get; set; }
public Action<Size> Resized { get; set; }

3
src/Perspex.Controls/TopLevel.cs

@ -198,6 +198,9 @@ namespace Perspex.Controls
/// <inheritdoc/>
Size ILayoutRoot.MaxClientSize => Size.Infinity;
/// <inheritdoc/>
double ILayoutRoot.LayoutScaling => PlatformImpl.Scaling;
IStyleHost IStyleHost.StylingParent
{
get { return PerspexLocator.Current.GetService<IGlobalStyles>(); }

5
src/Perspex.Layout/ILayoutRoot.cs

@ -17,5 +17,10 @@ namespace Perspex.Layout
/// The maximum client size available.
/// </summary>
Size MaxClientSize { get; }
/// <summary>
/// The scaling factor to use in layout.
/// </summary>
double LayoutScaling { get; }
}
}

4
src/Perspex.Layout/Layoutable.cs

@ -671,9 +671,9 @@ namespace Perspex.Layout
return new Size(Math.Max(size.Width, 0), Math.Max(size.Height, 0));
}
private static double GetLayoutScale()
private double GetLayoutScale()
{
return PerspexLocator.Current.GetService<IPlatformSettings>()?.LayoutScalingFactor ?? 1.0;
return (VisualRoot as ILayoutRoot)?.LayoutScaling ?? 1.0;
}
}
}

4
src/Perspex.SceneGraph/Platform/IPlatformSettings.cs

@ -10,9 +10,5 @@ namespace Perspex.Platform
Size DoubleClickSize { get; }
TimeSpan DoubleClickTime { get; }
double RenderScalingFactor { get; }
double LayoutScalingFactor { get; }
}
}

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

@ -103,6 +103,8 @@ namespace Perspex.Win32
}
}
public double Scaling => 1;
public IPlatformHandle Handle
{
get;

2
tests/Perspex.Controls.UnitTests/ControlTests.cs

@ -174,6 +174,8 @@ namespace Perspex.Controls.UnitTests
get { throw new NotImplementedException(); }
}
public double LayoutScaling => 1;
public Point TranslatePointToScreen(Point p)
{
throw new NotImplementedException();

2
tests/Perspex.Controls.UnitTests/TestRoot.cs

@ -23,6 +23,8 @@ namespace Perspex.Controls.UnitTests
get { throw new NotImplementedException(); }
}
public double LayoutScaling => 1;
public IRenderQueueManager RenderQueueManager => null;
public Point TranslatePointToScreen(Point p)

7
tests/Perspex.Controls.UnitTests/TopLevelTests.cs

@ -96,6 +96,7 @@ namespace Perspex.Controls.UnitTests
var impl = new Mock<ITopLevelImpl>();
impl.SetupProperty(x => x.ClientSize);
impl.SetupProperty(x => x.Resized);
impl.SetupGet(x => x.Scaling).Returns(1);
var target = new TestTopLevel(impl.Object)
{
@ -121,9 +122,9 @@ namespace Perspex.Controls.UnitTests
RegisterServices();
PerspexLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(new LayoutManager());
var impl = new Mock<ITopLevelImpl>();
var impl = Mock.Of<ITopLevelImpl>(x => x.Scaling == 1);
var target = new TestTopLevel(impl.Object)
var target = new TestTopLevel(impl)
{
Template = CreateTemplate(),
Content = new TextBlock
@ -135,7 +136,7 @@ namespace Perspex.Controls.UnitTests
LayoutManager.Instance.ExecuteInitialLayoutPass(target);
impl.VerifySet(x => x.ClientSize = new Size(321, 432));
Mock.Get(impl).VerifySet(x => x.ClientSize = new Size(321, 432));
}
}

4
tests/Perspex.Controls.UnitTests/WindowingPlatformMock.cs

@ -17,7 +17,7 @@ namespace Perspex.Controls.UnitTests
public IWindowImpl CreateWindow()
{
return _windowImpl?.Invoke() ?? new Mock<IWindowImpl>().Object;
return _windowImpl?.Invoke() ?? Mock.Of<IWindowImpl>(x => x.Scaling == 1);
}
public IWindowImpl CreateEmbeddableWindow()
@ -25,6 +25,6 @@ namespace Perspex.Controls.UnitTests
throw new NotImplementedException();
}
public IPopupImpl CreatePopup() => _popupImpl?.Invoke() ?? new Mock<IPopupImpl>().Object;
public IPopupImpl CreatePopup() => _popupImpl?.Invoke() ?? Mock.Of<IPopupImpl>(x => x.Scaling == 1);
}
}

1
tests/Perspex.Layout.UnitTests/FullLayoutTests.cs

@ -141,6 +141,7 @@ namespace Perspex.Layout.UnitTests
windowImpl.SetupProperty(x => x.ClientSize);
windowImpl.Setup(x => x.MaxClientSize).Returns(new Size(1024, 1024));
windowImpl.SetupGet(x => x.Scaling).Returns(1);
PerspexLocator.CurrentMutable
.Bind<IAssetLoader>().ToConstant(new AssetLoader())

1
tests/Perspex.Layout.UnitTests/TestLayoutRoot.cs

@ -19,5 +19,6 @@ namespace Perspex.Layout.UnitTests
}
public Size MaxClientSize => Size.Infinity;
public double LayoutScaling => 1;
}
}

4
tests/Perspex.LeakTests/TestApp.cs

@ -19,7 +19,7 @@ namespace Perspex.LeakTests
RegisterServices();
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var windowImpl = new Mock<IWindowImpl>();
var windowImpl = Mock.Of<IWindowImpl>(x => x.Scaling == 1);
var renderInterface = fixture.Create<IPlatformRenderInterface>();
var threadingInterface = Mock.Of<IPlatformThreadingInterface>(x =>
x.CurrentThreadIsLoopThread == true);
@ -31,7 +31,7 @@ namespace Perspex.LeakTests
.Bind<IPlatformRenderInterface>().ToConstant(renderInterface)
.Bind<IPlatformThreadingInterface>().ToConstant(threadingInterface)
.Bind<IStandardCursorFactory>().ToConstant(new Mock<IStandardCursorFactory>().Object)
.Bind<IWindowingPlatform>().ToConstant(new WindowingPlatformMock(() => windowImpl.Object));
.Bind<IWindowingPlatform>().ToConstant(new WindowingPlatformMock(() => windowImpl));
Styles = new DefaultTheme();
}

2
tests/Perspex.Styling.UnitTests/TestRoot.cs

@ -26,6 +26,8 @@ namespace Perspex.Styling.UnitTests
get { throw new NotImplementedException(); }
}
public double LayoutScaling => 1;
public Point TranslatePointToScreen(Point p)
{
return new Point();

Loading…
Cancel
Save