Browse Source

Documentation.

pull/81/head
Steven Kirk 11 years ago
parent
commit
09e581abc9
  1. 14
      Perspex.Layout/LayoutHelper.cs
  2. 27
      Perspex.Layout/LayoutManager.cs
  3. 22
      Perspex.SceneGraph/VisualTree/BoundsTracker.cs
  4. 18
      Perspex.SceneGraph/VisualTree/TransformedBounds.cs
  5. 22
      Windows/Perspex.Direct2D1/Media/GeometryImpl.cs
  6. 40
      Windows/Perspex.Direct2D1/Media/Imaging/BitmapImpl.cs
  7. 26
      Windows/Perspex.Direct2D1/Media/StreamGeometryImpl.cs

14
Perspex.Layout/LayoutHelper.cs

@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="LayoutHelper.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
@ -8,8 +8,20 @@ namespace Perspex.Layout
{
using System;
/// <summary>
/// Provides helper methods needed for layout.
/// </summary>
public static class LayoutHelper
{
/// <summary>
/// Calculates a control's size based on its <see cref="ILayoutable.Width"/>,
/// <see cref="ILayoutable.Height"/>, <see cref="ILayoutable.MinWidth"/>,
/// <see cref="ILayoutable.MaxWidth"/>, <see cref="ILayoutable.MinHeight"/> and
/// <see cref="ILayoutable.MaxHeight"/>.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="constraints">The space available for the control.</param>
/// <returns>The control's size.</returns>
public static Size ApplyLayoutConstraints(ILayoutable control, Size constraints)
{
double width = (control.Width > 0) ? control.Width : constraints.Width;

27
Perspex.Layout/LayoutManager.cs

@ -302,18 +302,37 @@ namespace Perspex.Layout
}
}
/// <summary>
/// An item to be layed-out.
/// </summary>
private class Item : IComparable<Item>
{
/// <summary>
/// Initializes a new instance of the <see cref="Item"/> class.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="distance">The control's distance from the layout root.</param>
public Item(ILayoutable control, int distance)
{
this.Control = control;
this.Distance = distance;
}
public ILayoutable Control { get; private set; }
public int Distance { get; private set; }
/// <summary>
/// Gets the control.
/// </summary>
public ILayoutable Control { get; }
/// <summary>
/// Gets the control's distance from the layout root.
/// </summary>
public int Distance { get; }
/// <summary>
/// Compares the distance of two items.
/// </summary>
/// <param name="other">The other item/</param>
/// <returns>The comparison.</returns>
public int CompareTo(Item other)
{
return this.Distance - other.Distance;

22
Perspex.SceneGraph/VisualTree/BoundsTracker.cs

@ -11,13 +11,30 @@ namespace Perspex.VisualTree
using System.Linq;
using System.Reactive.Linq;
/// <summary>
/// Tracks the bounds of a control.
/// </summary>
/// <remarks>
/// This class is used by Adorners to track the control that the adorner is attached to.
/// </remarks>
public class BoundsTracker
{
/// <summary>
/// Starts tracking the specified visual.
/// </summary>
/// <param name="visual">The visual.</param>
/// <returns>An observable that returns the tracked bounds.</returns>
public IObservable<TransformedBounds> Track(Visual visual)
{
return this.Track(visual, (Visual)visual.GetVisualRoot());
}
/// <summary>
/// Starts tracking the specified visual relative to another control.
/// </summary>
/// <param name="visual">The visual.</param>
/// <param name="relativeTo">The control that the tracking should be relative to.</param>
/// <returns>An observable that returns the tracked bounds.</returns>
public IObservable<TransformedBounds> Track(Visual visual, Visual relativeTo)
{
var visuals = visual.GetSelfAndVisualAncestors()
@ -36,6 +53,11 @@ namespace Perspex.VisualTree
return Observable.Select(bounds, x => new TransformedBounds((Rect)x, (Rect)new Rect(), (Matrix)Matrix.Identity));
}
/// <summary>
/// Sums a collection of rectangles.
/// </summary>
/// <param name="rects">The collection of rectangles.</param>
/// <returns>The summed rectangle.</returns>
private static Rect ExtractBounds(IList<Rect> rects)
{
var position = rects.Select(x => x.Position).Aggregate((a, b) => a + b);

18
Perspex.SceneGraph/VisualTree/TransformedBounds.cs

@ -6,8 +6,17 @@
namespace Perspex.VisualTree
{
/// <summary>
/// Holds information about the bounds of a control, together with a transform and a clip/
/// </summary>
public class TransformedBounds
{
/// <summary>
/// Initializes a new instance of the <see cref="TransformedBounds"/> class.
/// </summary>
/// <param name="bounds">The control's bounds.</param>
/// <param name="clip">The control's clip rectangle.</param>
/// <param name="transform">The control's transform.</param>
public TransformedBounds(Rect bounds, Rect clip, Matrix transform)
{
this.Bounds = bounds;
@ -15,10 +24,19 @@ namespace Perspex.VisualTree
this.Transform = transform;
}
/// <summary>
/// Gets the control's bounds.
/// </summary>
public Rect Bounds { get; }
/// <summary>
/// Gets the control's clip rectangle.
/// </summary>
public Rect Clip { get; }
/// <summary>
/// Gets the control's transform.
/// </summary>
public Matrix Transform { get; }
}
}

22
Windows/Perspex.Direct2D1/Media/GeometryImpl.cs

@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="GeometryImpl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
@ -10,25 +10,40 @@ namespace Perspex.Direct2D1.Media
using SharpDX.Direct2D1;
using Splat;
/// <summary>
/// The platform-specific interface for <see cref="Perspex.Media.Geometry"/>.
/// </summary>
public abstract class GeometryImpl : IGeometryImpl
{
private TransformedGeometry transformed;
/// <summary>
/// Gets the geometry's bounding rectangle.
/// </summary>
public abstract Rect Bounds
{
get;
}
/// <summary>
/// Gets the geomentry without any transforms applied.
/// </summary>
public abstract Geometry DefiningGeometry
{
get;
}
/// <summary>
/// Gets the Direct2D <see cref="Geometry"/>.
/// </summary>
public Geometry Geometry
{
get { return this.transformed ?? this.DefiningGeometry; }
}
/// <summary>
/// Gets or sets the transform for the geometry.
/// </summary>
public Matrix Transform
{
get
@ -60,6 +75,11 @@ namespace Perspex.Direct2D1.Media
}
}
/// <summary>
/// Gets the geometry's bounding rectangle with the specified stroke thickness.
/// </summary>
/// <param name="strokeThickness">The stroke thickness.</param>
/// <returns>The bounding rectangle.</returns>
public Rect GetRenderBounds(double strokeThickness)
{
if (this.transformed != null)

40
Windows/Perspex.Direct2D1/Media/Imaging/BitmapImpl.cs

@ -11,12 +11,20 @@ namespace Perspex.Direct2D1.Media
using Perspex.Platform;
using SharpDX.WIC;
/// <summary>
/// A Direct2D implementation of a <see cref="Perspex.Media.Imaging.Bitmap"/>.
/// </summary>
public class BitmapImpl : IBitmapImpl
{
private ImagingFactory factory;
private SharpDX.Direct2D1.Bitmap direct2D;
/// <summary>
/// Initializes a new instance of the <see cref="BitmapImpl"/> class.
/// </summary>
/// <param name="factory">The WIC imaging factory to use.</param>
/// <param name="fileName">The filename of the bitmap to load.</param>
public BitmapImpl(ImagingFactory factory, string fileName)
{
this.factory = factory;
@ -27,6 +35,12 @@ namespace Perspex.Direct2D1.Media
}
}
/// <summary>
/// Initializes a new instance of the <see cref="BitmapImpl"/> class.
/// </summary>
/// <param name="factory">The WIC imaging factory to use.</param>
/// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param>
public BitmapImpl(ImagingFactory factory, int width, int height)
{
this.factory = factory;
@ -38,22 +52,36 @@ namespace Perspex.Direct2D1.Media
BitmapCreateCacheOption.CacheOnLoad);
}
public int PixelHeight
/// <summary>
/// Gets the width of the bitmap, in pixels.
/// </summary>
public int PixelWidth
{
get { return this.WicImpl.Size.Width; }
get { return this.WicImpl.Size.Height; }
}
public int PixelWidth
/// <summary>
/// Gets the height of the bitmap, in pixels.
/// </summary>
public int PixelHeight
{
get { return this.WicImpl.Size.Height; }
get { return this.WicImpl.Size.Width; }
}
/// <summary>
/// Gets the WIC implementation of the bitmap.
/// </summary>
public Bitmap WicImpl
{
get;
private set;
}
/// <summary>
/// Gets a Direct2D bitmap to use on the specified render target.
/// </summary>
/// <param name="renderTarget">The render target.</param>
/// <returns>The Direct2D bitmap.</returns>
public SharpDX.Direct2D1.Bitmap GetDirect2DBitmap(SharpDX.Direct2D1.RenderTarget renderTarget)
{
if (this.direct2D == null)
@ -66,6 +94,10 @@ namespace Perspex.Direct2D1.Media
return this.direct2D;
}
/// <summary>
/// Saves the bitmap to a file.
/// </summary>
/// <param name="fileName">The filename.</param>
public void Save(string fileName)
{
if (Path.GetExtension(fileName) != ".png")

26
Windows/Perspex.Direct2D1/Media/StreamGeometryImpl.cs

@ -1,44 +1,58 @@
// -----------------------------------------------------------------------
// <copyright file="StreamGeometryImpl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
using System;
using Perspex.Media;
using Perspex.Platform;
using SharpDX;
using SharpDX.Direct2D1;
using Splat;
using D2DGeometry = SharpDX.Direct2D1.Geometry;
/// <summary>
/// A Direct2D implementation of a <see cref="StreamGeometry"/>.
/// </summary>
public class StreamGeometryImpl : GeometryImpl, IStreamGeometryImpl
{
private PathGeometry path;
/// <summary>
/// Initializes a new instance of the <see cref="StreamGeometryImpl"/> class.
/// </summary>
public StreamGeometryImpl()
{
Factory factory = Locator.Current.GetService<Factory>();
this.path = new PathGeometry(factory);
}
/// <summary>
/// Initializes a new instance of the <see cref="StreamGeometryImpl"/> class.
/// </summary>
/// <param name="geometry">An existing Direct2D <see cref="PathGeometry"/>.</param>
protected StreamGeometryImpl(PathGeometry geometry)
{
this.path = geometry;
}
/// <inheritdoc/>
public override Rect Bounds
{
get { return this.path.GetBounds().ToPerspex(); }
}
/// <inheritdoc/>
public override D2DGeometry DefiningGeometry
{
get { return this.path; }
}
/// <summary>
/// Clones the geometry.
/// </summary>
/// <returns>A cloned geometry.</returns>
public IStreamGeometryImpl Clone()
{
Factory factory = Locator.Current.GetService<Factory>();
@ -49,6 +63,12 @@ namespace Perspex.Direct2D1.Media
return new StreamGeometryImpl(result);
}
/// <summary>
/// Opens the geometry to start defining it.
/// </summary>
/// <returns>
/// A <see cref="StreamGeometryContext"/> which can be used to define the geometry.
/// </returns>
public IStreamGeometryContextImpl Open()
{
return new StreamGeometryContextImpl(this.path.Open());

Loading…
Cancel
Save