Exemple #1
0
        public override void Draw(IRenderer renderer, RectangleF space, Color color)
        {
            if (TintColor is not null)
            {
                color = MultiplyColor(color, TintColor.Value);
            }
            if (Math.Abs(_imageSize.Y - space.Height) > .001f || Math.Abs(_imageSize.X - space.Width) > .001f)
            {
                _imageSize = space.Size;
                _destRects = _generatePatches(_imageSize);
            }

            for (var i = 0; i < 9; i++)
            {
                if (_ninePatchRects[i].Width == 0 || _ninePatchRects[i].Height == 0)
                {
                    continue;
                }

                var destRect = _destRects[i];
                destRect.X += space.X;
                destRect.Y += space.Y;
                renderer.Draw(this, destRect, _ninePatchRects[i], color);
            }
        }
Exemple #2
0
        internal static RectangleF[] GetNinePatches(Vector2 size, float leftPatchesWidth,
                                                    float rightPatchesWidth, float topPatchesHeight, float bottomPatchesHeight)
        {
            RectangleF[] ninePatchesArray = new RectangleF[9];

            var centerWidth  = size.X - leftPatchesWidth - rightPatchesWidth;
            var centerHeight = size.Y - topPatchesHeight - bottomPatchesHeight;

            const int leftX   = 0;
            var       middleX = leftPatchesWidth;
            var       rightX  = middleX + centerWidth;

            const int topY    = 0;
            var       middleY = topPatchesHeight;
            var       bottomY = middleY + centerHeight;

            ninePatchesArray[0] = new RectangleF(leftX, topY, leftPatchesWidth, topPatchesHeight);       // top-left
            ninePatchesArray[1] = new RectangleF(middleX, topY, centerWidth, topPatchesHeight);          // top-center
            ninePatchesArray[2] = new RectangleF(rightX, topY, rightPatchesWidth, topPatchesHeight);     // top-right

            ninePatchesArray[3] = new RectangleF(leftX, middleY, leftPatchesWidth, centerHeight);        // middle-left
            ninePatchesArray[4] = new RectangleF(middleX, middleY, centerWidth, centerHeight);           // middle-center
            ninePatchesArray[5] = new RectangleF(rightX, middleY, rightPatchesWidth, centerHeight);      // middle-right

            ninePatchesArray[6] = new RectangleF(leftX, bottomY, leftPatchesWidth, bottomPatchesHeight); // bottom-left
            ninePatchesArray[7] = new RectangleF(middleX, bottomY, centerWidth, bottomPatchesHeight);    // bottom-center
            ninePatchesArray[8] =
                new RectangleF(rightX, bottomY, rightPatchesWidth, bottomPatchesHeight);                 // bottom-right

            return(ninePatchesArray);
        }
Exemple #3
0
 public override void Draw(IRenderer renderer, RectangleF space, Color color)
 {
     if (TintColor is not null)
     {
         color = MultiplyColor(color, TintColor.Value);
     }
     renderer.Draw(this, space, color);
 }
Exemple #4
0
 public abstract void Draw(IRenderer renderer, RectangleF space, Color color);