Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
                    }
                }
            }
        }
Пример #3
0
        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);
                    }
                }
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
                    }
                }
            }
        }