Browse Source

WIP Rect

pull/4/head
Steven Kirk 12 years ago
parent
commit
6965420e79
  1. 12
      Perspex/Controls/StackPanel.cs
  2. 35
      Perspex/Media/RectangleGeometry.cs
  3. 2
      Perspex/Perspex.csproj
  4. 48
      Perspex/Rect.cs
  5. 8
      Perspex/Shapes/Path.cs
  6. 33
      Perspex/Shapes/Rectangle.cs
  7. 23
      Perspex/Shapes/Shape.cs
  8. 29
      Perspex/Themes/Default/CheckBoxStyle.cs
  9. 13
      TestApplication/Program.cs

12
Perspex/Controls/StackPanel.cs

@ -138,18 +138,8 @@ namespace Perspex.Controls
else
{
childHeight = finalSize.Height;
Rect childFinal = new Rect(arrangedWidth, 0, childWidth, childHeight);
if (childFinal.IsEmpty)
{
child.Arrange(new Rect());
}
else
{
child.Arrange(childFinal);
}
child.Arrange(childFinal);
arrangedWidth += childWidth + gap;
arrangedHeight = Math.Max(arrangedHeight, childHeight);
}

35
Perspex/Media/RectangleGeometry.cs

@ -0,0 +1,35 @@
// -----------------------------------------------------------------------
// <copyright file="RectangleGeometry.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Media
{
using System;
using Splat;
public class RectangleGeometry : Geometry
{
public RectangleGeometry(Rect rect)
{
IStreamGeometryImpl impl = Locator.Current.GetService<IStreamGeometryImpl>();
using (IStreamGeometryContextImpl context = impl.Open())
{
context.BeginFigure(rect.TopLeft, true);
context.LineTo(rect.TopRight);
context.LineTo(rect.BottomRight);
context.LineTo(rect.BottomLeft);
context.EndFigure(true);
}
this.PlatformImpl = impl;
}
public override Rect Bounds
{
get { return this.PlatformImpl.Bounds; }
}
}
}

2
Perspex/Perspex.csproj

@ -87,10 +87,12 @@
<Compile Include="Media\IGeometryImpl.cs" />
<Compile Include="Media\IStreamGeometryImpl.cs" />
<Compile Include="Media\PathMarkupParser.cs" />
<Compile Include="Media\RectangleGeometry.cs" />
<Compile Include="Media\StreamGeometryContext.cs" />
<Compile Include="Media\StreamGeometry.cs" />
<Compile Include="Media\Geometry.cs" />
<Compile Include="Media\Stretch.cs" />
<Compile Include="Shapes\Rectangle.cs" />
<Compile Include="Shapes\Path.cs" />
<Compile Include="Shapes\Shape.cs" />
<Compile Include="Platform\IRenderer.cs" />

48
Perspex/Rect.cs

@ -122,6 +122,54 @@ namespace Perspex
get { return new Size(this.width, this.height); }
}
/// <summary>
/// Gets the right position of the rectangle.
/// </summary>
public double Right
{
get { return this.x + this.width; }
}
/// <summary>
/// Gets the bottom position of the rectangle.
/// </summary>
public double Bottom
{
get { return this.y + this.height; }
}
/// <summary>
/// Gets the top left point of the rectangle.
/// </summary>
public Point TopLeft
{
get { return new Point(this.x, this.y); }
}
/// <summary>
/// Gets the top right point of the rectangle.
/// </summary>
public Point TopRight
{
get { return new Point(this.Right, this.y); }
}
/// <summary>
/// Gets the bottom left point of the rectangle.
/// </summary>
public Point BottomLeft
{
get { return new Point(this.x, this.Bottom); }
}
/// <summary>
/// Gets the bottom right point of the rectangle.
/// </summary>
public Point BottomRight
{
get { return new Point(this.Right, this.Bottom); }
}
/// <summary>
/// Gets a value that indicates whether the rectangle is empty.
/// </summary>

8
Perspex/Shapes/Path.cs

@ -24,13 +24,5 @@ namespace Perspex.Shapes
{
get { return this.Data; }
}
public override void Render(IDrawingContext context)
{
if (this.Data != null && this.Visibility == Visibility.Visible)
{
context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.Data);
}
}
}
}

33
Perspex/Shapes/Rectangle.cs

@ -0,0 +1,33 @@
// -----------------------------------------------------------------------
// <copyright file="Rectangle.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Shapes
{
using System;
using System.Reactive.Linq;
using Perspex.Media;
public class Rectangle : Shape
{
private Size size;
public override Geometry DefiningGeometry
{
get { return new RectangleGeometry(new Rect(size)); }
}
protected override Size MeasureContent(Size availableSize)
{
return new Size(this.Width, this.Height);
}
protected override Size ArrangeContent(Size finalSize)
{
this.size = finalSize;
return base.ArrangeContent(finalSize);
}
}
}

23
Perspex/Shapes/Shape.cs

@ -60,20 +60,14 @@ namespace Perspex.Shapes
protected override Size MeasureContent(Size availableSize)
{
Pen pen = (this.Stroke != null) ? new Pen(this.Stroke, this.StrokeThickness) : null;
Rect shapeBounds = this.RenderedGeometry.Bounds;
double width = this.Width;
double height = this.Height;
double desiredX = availableSize.Width;
double desiredY = availableSize.Height;
double sx = 0.0;
double sy = 0.0;
if (this.Stretch == Stretch.None)
{
return new Size(
shapeBounds.X + shapeBounds.Width,
shapeBounds.Y + shapeBounds.Height);
}
if (double.IsInfinity(availableSize.Width))
{
desiredX = shapeBounds.Width;
@ -125,10 +119,21 @@ namespace Perspex.Shapes
break;
default:
sx = sy = 1;
break;
}
return new Size(shapeBounds.Width * sx, shapeBounds.Height * sy);
double finalX = (width > 0) ? width : shapeBounds.Width * sx;
double finalY = (height > 0) ? height : shapeBounds.Height * sy;
return new Size(finalX, finalY);
}
public override void Render(IDrawingContext context)
{
if (this.RenderedGeometry != null && this.Visibility == Visibility.Visible)
{
context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.RenderedGeometry);
}
}
}
}

29
Perspex/Themes/Default/CheckBoxStyle.cs

@ -53,19 +53,22 @@ namespace Perspex.Themes.Default
Gap = 8,
Children = new PerspexList<Control>
{
new Border
new Rectangle
{
BorderThickness = 2,
BorderBrush = Brushes.Black,
Padding = new Thickness(8),
Content = new Path
{
Id = "checkMark",
Data = StreamGeometry.Parse("M0,0 L10,10 M10,0 L0,10"),
Stroke = Brushes.Black,
StrokeThickness = 2,
VerticalAlignment = VerticalAlignment.Center,
},
Id = "checkBorder",
Stroke = Brushes.Black,
StrokeThickness = 2,
Width = 16,
Height = 16,
VerticalAlignment = VerticalAlignment.Center,
},
new Path
{
Id = "checkMark",
Data = StreamGeometry.Parse("M0,0 L10,10 M10,0 L0,10"),
Stroke = Brushes.Black,
StrokeThickness = 2,
VerticalAlignment = VerticalAlignment.Center,
},
new ContentPresenter
{
@ -76,7 +79,7 @@ namespace Perspex.Themes.Default
result.TemplateBinding(control, Border.BackgroundProperty);
StackPanel stack = (StackPanel)result.Content;
ContentPresenter cp = (ContentPresenter)stack.Children[1];
ContentPresenter cp = (ContentPresenter)stack.Children[2];
cp.TemplateBinding(control, ContentPresenter.ContentProperty);
return result;
}

13
TestApplication/Program.cs

@ -52,19 +52,6 @@ namespace TestApplication
Gap = 6,
Children = new PerspexList<Control>
{
new Border
{
BorderBrush = Brushes.Black,
BorderThickness = 1,
Width = 10,
Height = 10,
},
new Path
{
Data = StreamGeometry.Parse("M0,0 L10,0"),
Stroke = Brushes.Black,
StrokeThickness = 1,
},
new Button
{
Content = "Button",

Loading…
Cancel
Save