public void PerformLayout(RenderContext localRenderContext) { if (!_performLayout) { return; } _performLayout = false; // Setup background brush if (Background != null) { SizeF actualSize = new SizeF((float)ActualWidth, (float)ActualHeight); RectangleF rect = new RectangleF(ActualPosition.X - 0.5f, ActualPosition.Y - 0.5f, actualSize.Width + 0.5f, actualSize.Height + 0.5f); PositionColoredTextured[] verts = new PositionColoredTextured[6]; verts[0].Position = new Vector3(rect.Left, rect.Top, 1.0f); verts[1].Position = new Vector3(rect.Left, rect.Bottom, 1.0f); verts[2].Position = new Vector3(rect.Right, rect.Bottom, 1.0f); verts[3].Position = new Vector3(rect.Left, rect.Top, 1.0f); verts[4].Position = new Vector3(rect.Right, rect.Top, 1.0f); verts[5].Position = new Vector3(rect.Right, rect.Bottom, 1.0f); Background.SetupBrush(this, ref verts, localRenderContext.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _backgroundContext, ref verts, PrimitiveType.TriangleList); } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _backgroundContext); } }
protected void PerformLayoutBackground(RectangleF innerBorderRect, RenderContext context) { // Setup background brush if (Background != null) { // TODO: Draw background only in the inner rectangle (outer rect minus BorderThickness) using (GraphicsPath path = CreateBorderRectPath(innerBorderRect)) { // Some backgrounds might not be closed (subclasses sometimes create open background shapes, // for example GroupBox). To create a completely filled background, we need a closed figure. path.CloseFigure(); PositionColoredTextured[] verts; float centerX, centerY; PointF[] pathPoints = path.PathPoints; TriangulateHelper.CalcCentroid(pathPoints, out centerX, out centerY); TriangulateHelper.FillPolygon_TriangleList(pathPoints, centerX, centerY, 1, out verts); Background.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _backgroundContext, ref verts, PrimitiveType.TriangleList); } } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _backgroundContext); } }
void DeallocateCursor() { if (_cursorContext != null) { PrimitiveBuffer.DisposePrimitiveBuffer(ref _cursorContext); } }
// Allocate/Deallocate of Children not necessary because UIElement handles all direct children public override void Deallocate() { base.Deallocate(); if (Background != null) { Background.Deallocate(); } PrimitiveBuffer.DisposePrimitiveBuffer(ref _backgroundContext); }
public override void Deallocate() { base.Deallocate(); if (Fill != null) { Fill.Deallocate(); } if (Stroke != null) { Stroke.Deallocate(); } PrimitiveBuffer.DisposePrimitiveBuffer(ref _fillContext); PrimitiveBuffer.DisposePrimitiveBuffer(ref _strokeContext); }
// Allocation/Deallocation of _initializedContent not necessary because UIElement handles all direct children public override void Deallocate() { base.Deallocate(); if (BorderBrush != null) { BorderBrush.Deallocate(); } if (Background != null) { Background.Deallocate(); } _performLayout = true; PrimitiveBuffer.DisposePrimitiveBuffer(ref _backgroundContext); PrimitiveBuffer.DisposePrimitiveBuffer(ref _borderContext); }
protected override void DoPerformLayout(RenderContext context) { base.DoPerformLayout(context); // Setup brushes if (Fill != null || (Stroke != null && StrokeThickness > 0)) { using (GraphicsPath path = CreateRectanglePath(_innerRect)) { if (path.PointCount == 0) { return; } PointF[] pathPoints = path.PathPoints; PositionColoredTextured[] verts; float centerX = _innerRect.Width / 2 + _innerRect.Left; float centerY = _innerRect.Height / 2 + _innerRect.Top; if (Fill != null) { TriangulateHelper.FillPolygon_TriangleList(pathPoints, centerX, centerY, 1, out verts); Fill.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _fillContext, ref verts, PrimitiveType.TriangleList); } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _fillContext); } if (Stroke != null && StrokeThickness > 0) { TriangulateHelper.TriangulateStroke_TriangleList(pathPoints, (float)StrokeThickness, true, 1, StrokeLineJoin, out verts); Stroke.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _strokeContext, ref verts, PrimitiveType.TriangleList); } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _strokeContext); } } } }
protected override void DoPerformLayout(RenderContext context) { base.DoPerformLayout(context); // Setup brushes if (Fill != null || (Stroke != null && StrokeThickness > 0)) { using (GraphicsPath path = GetEllipse(_innerRect.ToDrawingRectF())) { PositionColoredTextured[] verts; float centerX; float centerY; PointF[] pathPoints = path.PathPoints; TriangulateHelper.CalcCentroid(pathPoints, out centerX, out centerY); if (Fill != null) { TriangulateHelper.FillPolygon_TriangleList(pathPoints, centerX, centerY, 1, out verts); Fill.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _fillContext, ref verts, PrimitiveType.TriangleList); } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _fillContext); } if (Stroke != null && StrokeThickness > 0) { TriangulateHelper.TriangulateStroke_TriangleList(pathPoints, (float)StrokeThickness, true, 1, PenLineJoin.Bevel, out verts); Stroke.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _strokeContext, ref verts, PrimitiveType.TriangleList); } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _strokeContext); } } } }
protected void PerformLayoutBorder(RectangleF innerBorderRect, RenderContext context) { // Setup border brush if (BorderBrush != null && BorderThickness > 0) { // TODO: Draw border with thickness BorderThickness - doesn't work yet, the drawn line is only one pixel thick using (GraphicsPath path = CreateBorderRectPath(innerBorderRect)) { using (GraphicsPathIterator gpi = new GraphicsPathIterator(path)) { PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][]; using (GraphicsPath subPath = new GraphicsPath()) { for (int i = 0; i < subPathVerts.Length; i++) { bool isClosed; gpi.NextSubpath(subPath, out isClosed); PointF[] pathPoints = subPath.PathPoints; PenLineJoin lineJoin = Math.Abs(CornerRadius) < DELTA_DOUBLE ? BorderLineJoin : PenLineJoin.Bevel; TriangulateHelper.TriangulateStroke_TriangleList(pathPoints, (float)BorderThickness, isClosed, 1, lineJoin, out subPathVerts[i]); } } PositionColoredTextured[] verts; GraphicsPathHelper.Flatten(subPathVerts, out verts); BorderBrush.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _borderContext, ref verts, PrimitiveType.TriangleList); } } } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _borderContext); } }
protected override void DoPerformLayout(RenderContext context) { base.DoPerformLayout(context); if (Stroke != null && StrokeThickness > 0) { using (GraphicsPath path = GetLine(_innerRect)) { float centerX; float centerY; PointF[] pathPoints = path.PathPoints; TriangulateHelper.CalcCentroid(pathPoints, out centerX, out centerY); PositionColoredTextured[] verts; TriangulateHelper.FillPolygon_TriangleList(pathPoints, centerX, centerY, 1, out verts); Stroke.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _strokeContext, ref verts, PrimitiveType.TriangleList); } } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _strokeContext); } }
public override void Deallocate() { PrimitiveBuffer.DisposePrimitiveBuffer(ref _primitiveBuffer); FreeData(); }
// Allocation/Deallocation of _initializedTemplateControl not necessary because UIElement handles all direct children public override void Deallocate() { base.Deallocate(); PrimitiveBuffer.DisposePrimitiveBuffer(ref _backgroundContext); }
protected override void DoPerformLayout(RenderContext context) { base.DoPerformLayout(context); // Setup brushes if (Fill != null || ((Stroke != null && StrokeThickness > 0))) { using (GraphicsPath path = CalculateTransformedPath(_innerRect)) { if (Fill != null && !_fillDisabled) { using (GraphicsPathIterator gpi = new GraphicsPathIterator(path)) { PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][]; using (GraphicsPath subPath = new GraphicsPath()) { for (int i = 0; i < subPathVerts.Length; i++) { bool isClosed; gpi.NextSubpath(subPath, out isClosed); PointF[] pathPoints = subPath.PathPoints; TriangulateHelper.Triangulate(pathPoints, 1, out subPathVerts[i]); if (subPathVerts[i] == null) { ServiceRegistration.Get <ILogger>().Warn("Failed to triangulate Path \"{0}\"!", Name); } } } PositionColoredTextured[] verts; GraphicsPathHelper.Flatten(subPathVerts, out verts); if (verts != null) { Fill.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _fillContext, ref verts, PrimitiveType.TriangleList); } } } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _fillContext); } if (Stroke != null && StrokeThickness > 0) { using (GraphicsPathIterator gpi = new GraphicsPathIterator(path)) { PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][]; using (GraphicsPath subPath = new GraphicsPath()) { for (int i = 0; i < subPathVerts.Length; i++) { bool isClosed; gpi.NextSubpath(subPath, out isClosed); PointF[] pathPoints = subPath.PathPoints; TriangulateHelper.TriangulateStroke_TriangleList(pathPoints, (float)StrokeThickness, isClosed, 1, StrokeLineJoin, out subPathVerts[i]); } } PositionColoredTextured[] verts; GraphicsPathHelper.Flatten(subPathVerts, out verts); if (verts != null) { Stroke.SetupBrush(this, ref verts, context.ZOrder, true); PrimitiveBuffer.SetPrimitiveBuffer(ref _strokeContext, ref verts, PrimitiveType.TriangleList); } } } else { PrimitiveBuffer.DisposePrimitiveBuffer(ref _strokeContext); } } } }