Exemple #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);
            }
        }
        void UpdateCursorShape(RectangleF cursorBounds, float zPos)
        {
            DeallocateCursor();

            PositionColoredTextured[] verts = PositionColoredTextured.CreateQuad_Fan(
                cursorBounds.Left /*- 0.5f*/, cursorBounds.Top /*- 0.5f*/, cursorBounds.Right /*- 0.5f*/, cursorBounds.Bottom /*- 0.5f*/,
                0, 0, 0, 0, zPos, Color);

            if (_cursorBrushInvalid && _cursorBrush != null)
            {
                _cursorBrush.Deallocate();
                _cursorBrush.Dispose();
                _cursorBrush = null;
            }
            if (_cursorBrush == null)
            {
                _cursorBrush = new SolidColorBrush {
                    Color = Color
                }
            }
            ;
            _cursorBrushInvalid = false;

            _cursorBrush.SetupBrush(this, ref verts, zPos, false);
            PrimitiveBuffer.SetPrimitiveBuffer(ref _cursorContext, ref verts, PrimitiveType.TriangleFan);

            _cursorShapeInvalid = false;
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
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);
                    }
                }
            }
        }
        public override void Setup(RectangleF ownerRect, float zOrder, bool skinNeutralAR)
        {
            PositionColoredTextured[] verts = new PositionColoredTextured[4];

            // Upper left
            verts[0].X     = ownerRect.Left;
            verts[0].Y     = ownerRect.Top;
            verts[0].Color = 0;
            verts[0].Tu1   = 0.0f;
            verts[0].Tv1   = 0.0f;
            verts[0].Z     = zOrder;

            // Bottom left
            verts[1].X     = ownerRect.Left;
            verts[1].Y     = ownerRect.Bottom;
            verts[1].Color = 0;
            verts[1].Tu1   = 0.0f;
            verts[1].Tv1   = 1.0f;
            verts[1].Z     = zOrder;

            // Bottom right
            verts[2].X     = ownerRect.Right;
            verts[2].Y     = ownerRect.Bottom;
            verts[2].Color = 0;
            verts[2].Tu1   = 1.0f;
            verts[2].Tv1   = 1.0f;
            verts[2].Z     = zOrder;

            // Upper right
            verts[3].X     = ownerRect.Right;
            verts[3].Y     = ownerRect.Top;
            verts[3].Color = 0;
            verts[3].Tu1   = 1.0f;
            verts[3].Tv1   = 0.0f;
            verts[3].Z     = zOrder;

            PrimitiveBuffer.SetPrimitiveBuffer(ref _primitiveBuffer, ref verts, PrimitiveType.TriangleFan);

            _frameSize = skinNeutralAR ? ImageContext.AdjustForSkinAR(ownerRect.Size) : ownerRect.Size;
            _imageContext.FrameSize = _frameSize;
        }
Exemple #6
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);
                    }
                }
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
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);
            }
        }
Exemple #9
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);
                    }
                }
            }
        }