Browse Source

Removed PointPair.

pull/398/head
Ivan Kochurkin 11 years ago
parent
commit
93e1f0d388
  1. 3
      samples/TestApplicationShared/MainWindow.cs
  2. 29
      src/Perspex.Controls/Shapes/Line.cs
  3. 38
      src/Perspex.SceneGraph/Media/LineGeometry.cs
  4. 20
      src/Perspex.SceneGraph/Media/PathMarkupParser.cs
  5. 1
      src/Perspex.SceneGraph/Perspex.SceneGraph.csproj
  6. 48
      src/Perspex.SceneGraph/PointPair.cs
  7. 9
      tests/Perspex.RenderTests/Shapes/LineTests.cs

3
samples/TestApplicationShared/MainWindow.cs

@ -704,7 +704,8 @@ namespace TestApplication
{
Stroke = Brushes.Red,
StrokeThickness = 2,
PointPair = new PointPair(120, 185, 30, 115)
StartPoint = new Point(120, 185),
EndPoint = new Point(30, 115)
},
new Perspex.Controls.Shapes.Path
{

29
src/Perspex.Controls/Shapes/Line.cs

@ -9,31 +9,42 @@ namespace Perspex.Controls.Shapes
{
public class Line : Shape
{
public static readonly PerspexProperty<PointPair> PointPairProperty =
PerspexProperty.Register<Line, PointPair>("PointPair");
public static readonly PerspexProperty<Point> StartPointProperty =
PerspexProperty.Register<Line, Point>("StartPoint");
public static readonly PerspexProperty<Point> EndPointProperty =
PerspexProperty.Register<Line, Point>("EndPoint");
private LineGeometry _geometry;
private PointPair _pointPair;
private Point _startPoint;
private Point _endPoint;
public Line()
{
StrokeThickness = 1;
}
public PointPair PointPair
public Point StartPoint
{
get { return GetValue(StartPointProperty); }
set { SetValue(StartPointProperty, value); }
}
public Point EndPoint
{
get { return GetValue(PointPairProperty); }
set { SetValue(PointPairProperty, value); }
get { return GetValue(EndPointProperty); }
set { SetValue(EndPointProperty, value); }
}
public override Geometry DefiningGeometry
{
get
{
if (_geometry == null || _pointPair == null || PointPair.P1 != _pointPair.P1 || PointPair.P2 != _pointPair.P2)
if (_geometry == null || StartPoint != _startPoint || EndPoint != _endPoint)
{
_pointPair = PointPair;
_geometry = new LineGeometry(_pointPair);
_startPoint = StartPoint;
_endPoint = EndPoint;
_geometry = new LineGeometry(_startPoint, _endPoint);
}
return _geometry;

38
src/Perspex.SceneGraph/Media/LineGeometry.cs

@ -2,7 +2,6 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Platform;
using System;
namespace Perspex.Media
{
@ -11,22 +10,25 @@ namespace Perspex.Media
/// </summary>
public class LineGeometry : Geometry
{
private PointPair _pointPair;
private Point _startPoint;
private Point _endPoint;
/// <summary>
/// Initializes a new instance of the <see cref="LineGeometry"/> class.
/// </summary>
/// <param name="pointPair">The pointPair.</param>
public LineGeometry(PointPair pointPair)
/// <param name="startPoint">The start point.</param>
/// <param name="endPoint">The end point.</param>
public LineGeometry(Point startPoint, Point endPoint)
{
_pointPair = pointPair;
_startPoint = startPoint;
_endPoint = endPoint;
IPlatformRenderInterface factory = PerspexLocator.Current.GetService<IPlatformRenderInterface>();
IStreamGeometryImpl impl = factory.CreateStreamGeometry();
using (IStreamGeometryContextImpl context = impl.Open())
{
context.BeginFigure(_pointPair.P1, false);
context.LineTo(_pointPair.P2);
context.BeginFigure(_startPoint, false);
context.LineTo(_endPoint);
context.EndFigure(false);
}
@ -39,25 +41,25 @@ namespace Perspex.Media
get
{
double xMin, yMin, xMax, yMax;
if (_pointPair.P1.X <= _pointPair.P2.X)
if (_startPoint.X <= _endPoint.X)
{
xMin = _pointPair.P1.X;
xMax = _pointPair.P2.X;
xMin = _startPoint.X;
xMax = _endPoint.X;
}
else
{
xMin = _pointPair.P2.X;
xMax = _pointPair.P1.X;
xMin = _endPoint.X;
xMax = _startPoint.X;
}
if (_pointPair.P1.Y <= _pointPair.P2.Y)
if (_startPoint.Y <= _endPoint.Y)
{
yMin = _pointPair.P1.Y;
yMax = _pointPair.P2.Y;
yMin = _startPoint.Y;
yMax = _endPoint.Y;
}
else
{
yMin = _pointPair.P2.Y;
yMax = _pointPair.P1.Y;
yMin = _endPoint.Y;
yMax = _startPoint.Y;
}
return new Rect(xMin, yMin, xMax - xMin, yMax - yMin);
@ -67,7 +69,7 @@ namespace Perspex.Media
/// <inheritdoc/>
public override Geometry Clone()
{
return new LineGeometry(new PointPair(_pointPair.P1, _pointPair.P2));
return new LineGeometry(_startPoint, _endPoint);
}
}
}

20
src/Perspex.SceneGraph/Media/PathMarkupParser.cs

@ -147,6 +147,16 @@ namespace Perspex.Media
_context.CubicBezierTo(point1, point2, point);
break;
}
case Command.CubicBezierCurveRelative:
{
Point point1 = ReadRelativePoint(reader, point);
Point point2 = ReadRelativePoint(reader, point);
_context.CubicBezierTo(point, point1, point2);
point = point2;
break;
}
case Command.Arc:
{
//example: A10,10 0 0,0 10,20
@ -164,15 +174,6 @@ namespace Perspex.Media
break;
}
case Command.CubicBezierCurveRelative:
{
Point point1 = ReadRelativePoint(reader, point);
Point point2 = ReadRelativePoint(reader, point);
_context.CubicBezierTo(point, point1, point2);
point = point2;
break;
}
case Command.Close:
_context.EndFigure(true);
openFigure = false;
@ -228,6 +229,7 @@ namespace Perspex.Media
private static double ReadDouble(StringReader reader)
{
ReadWhitespace(reader);
// TODO: Handle Infinity, NaN and scientific notation.
StringBuilder b = new StringBuilder();
bool readSign = false;

1
src/Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -106,7 +106,6 @@
<Compile Include="Media\TileBrush.cs" />
<Compile Include="Media\ImageBush.cs" />
<Compile Include="Media\VisualBrush.cs" />
<Compile Include="PointPair.cs" />
<Compile Include="RelativePoint.cs" />
<Compile Include="Platform\IFormattedTextImpl.cs" />
<Compile Include="Platform\IBitmapImpl.cs" />

48
src/Perspex.SceneGraph/PointPair.cs

@ -1,48 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex
{
/// <summary>
/// Defines a PointPair.
/// </summary>
public class PointPair
{
/// <summary>
/// The first point.
/// </summary>
public Point P1 { get; set; }
/// <summary>
/// The second point.
/// </summary>
public Point P2 { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="PointPair"/> structure.
/// </summary>
/// <param name="p1">The first point.</param>
/// <param name="p2">The second point.</param>
public PointPair(Point p1, Point p2)
{
P1 = p1;
P2 = p2;
}
/// <summary>
/// Initializes a new instance of the <see cref="PointPair"/> structure.
/// </summary>
/// <param name="x1">The x position of first point.</param>
/// <param name="y1">The y position of first point.</param>
/// <param name="x2">The x position of second point.</param>
/// <param name="y2">The y position of second point.</param>
public PointPair(double x1, double y1, double x2, double y2)
{
P1 = new Point(x1, y1);
P2 = new Point(x2, y2);
}
}
}

9
tests/Perspex.RenderTests/Shapes/LineTests.cs

@ -32,7 +32,8 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
{
Stroke = Brushes.Black,
StrokeThickness = 1,
PointPair = new PointPair(0, 0, 200, 200)
StartPoint = new Point(0, 0),
EndPoint = new Point(200, 200)
}
};
@ -51,7 +52,8 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
{
Stroke = Brushes.Black,
StrokeThickness = 1,
PointPair = new PointPair(200, 0, 0, 200)
StartPoint = new Point(200, 0),
EndPoint = new Point(0, 200)
}
};
@ -70,7 +72,8 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
{
Stroke = Brushes.Black,
StrokeThickness = 1,
PointPair = new PointPair(100, 200, 100, 0)
StartPoint = new Point(100, 200),
EndPoint = new Point(100, 0)
}
};

Loading…
Cancel
Save