< Summary

Class:Imagini.Drawing.Graphics
Assembly:Imagini.2D
File(s):/home/razer/vscode-projects/project-grove/imagini/Imagini.2D/Drawing/Graphics.cs
Covered lines:169
Uncovered lines:53
Coverable lines:222
Total lines:688
Line coverage:76.1% (169 of 222)
Covered branches:30
Total branches:36
Branch coverage:83.3% (30 of 36)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
CreateTexture(...)2057.14%50%
CreateTextureFromSurface(...)2057.14%50%
GetRenderTarget()10100%100%
SetRenderTarget(...)6083.33%83.33%
ReadPixels(...)6061.11%83.33%
GetPixelBufferSize(...)10100%100%
SetDrawingColor(...)1033.33%100%
GetDrawingColor()1060%100%
SetBlendMode(...)10100%100%
GetBlendMode()1075%100%
SetClipRectangle(...)2075%100%
GetClipRectangle()2054.54%100%
SetViewport(...)2062.5%100%
GetViewport()1044.44%100%
SetScale(...)10100%100%
SetScale(...)10100%100%
GetScale(...)10100%100%
GetScale()10100%100%
SetLogicalSize(...)10100%100%
SetLogicalSize(...)10100%100%
GetLogicalSize(...)10100%100%
GetLogicalSize()10100%100%
Clear()10100%100%
Clear(...)10100%100%
Draw(...)4076.92%100%
Draw(...)6075%100%
Draw(...)100%100%
DrawLine(...)10100%100%
DrawLine(...)10100%100%
DrawLines(...)1062.5%100%
DrawPoint(...)1050%100%
DrawPoint(...)10100%100%
DrawPoints(...)10100%100%
DrawRect(...)1087.5%100%
DrawRects(...)10100%100%
FillRect(...)10100%100%
FillRects(...)10100%100%
Destroy()20100%50%
.cctor()10100%100%
Pin(...)10100%100%

File(s)

/home/razer/vscode-projects/project-grove/imagini/Imagini.2D/Drawing/Graphics.cs

#LineLine coverage
 1using System;
 2using System.Diagnostics.CodeAnalysis;
 3using System.Drawing;
 4using System.Linq;
 5using System.Runtime.CompilerServices;
 6using System.Runtime.InteropServices;
 7using static Imagini.ErrorHandler;
 8using static SDL2.SDL_blendmode;
 9using static SDL2.SDL_error;
 10using static SDL2.SDL_hints;
 11using static SDL2.SDL_rect;
 12using static SDL2.SDL_render;
 13
 14namespace Imagini.Drawing
 15{
 16    public sealed class Graphics : Resource
 17    {
 18        internal IntPtr Handle;
 12619        public RendererInfo Renderer { get; private set; }
 20        /// <summary>
 21        /// Returns the output size of this renderer in pixels.
 22        /// </summary>
 23        public Size OutputSize
 24        {
 25            get
 26            {
 20627                var w = 0; var h = 0;
 10328                Try(() => SDL_GetRendererOutputSize(Handle, out w, out h),
 029                    "SDL_GetRendererOutputSize");
 10330                return new Size(w, h);
 31            }
 32        }
 33
 34        /// <summary>
 35        /// Gets the output pixel count.
 36        /// </summary>
 37        public int PixelCount
 38        {
 39            get
 40            {
 741                var size = OutputSize;
 742                return size.Width * size.Height;
 43            }
 44        }
 45
 46        [ExcludeFromCodeCoverage]
 47        internal Graphics(Window owner, RendererInfo rendererInfo)
 48        {
 49            var fallbackRenderer =
 50                RendererInfo.All.FirstOrDefault(r =>
 6351                    r.IsHardwareAccelerated && r.SupportsRenderingToTexture) ??
 52                RendererInfo.All.FirstOrDefault(r =>
 053                    r.IsHardwareAccelerated) ??
 54                RendererInfo.All.First();
 55
 56            Renderer = rendererInfo ?? fallbackRenderer;
 57            Handle = SDL_CreateRenderer(owner.Handle, Renderer.Index, 0);
 58            if (Handle == IntPtr.Zero)
 59                throw new ImaginiException($"Could not initialize renderer: {SDL_GetError()}");
 60        }
 61
 62        /// <summary>
 63        /// Creates a texture with the specified dimensions, format and access
 64        /// type.
 65        /// </summary>
 66        /// <param name="w">Width in pixels</param>
 67        /// <param name="h">Height in pixels</param>
 68        /// <param name="quality">Filtering quality when texture is scaled</param>
 69        /// <param name="format">Pixel format</param>
 70        /// <param name="access">Texture access type</param>
 71        public Texture CreateTexture(int w, int h,
 72            TextureScalingQuality quality = TextureScalingQuality.Nearest,
 73            PixelFormat format = PixelFormat.Format_ARGB8888,
 74            TextureAccess access = TextureAccess.Static)
 75        {
 076            Try(() =>
 3777                SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, quality.AsHint()),
 078                "SDL_SetHint");
 3779            var texture = SDL_CreateTexture(Handle, (uint)format, (int)access, w, h);
 3780            if (texture == IntPtr.Zero)
 081                throw new ImaginiException($"Could not create texture: {SDL_GetError()}");
 3782            return new Texture(texture, this);
 83        }
 84
 85        /// <summary>
 86        /// Creates a static texture from an existing surface.
 87        /// </summary>
 88        /// <param name="surface">Surface to create texture from</param>
 89        /// <param name="quality">Filtering quality when texture is scaled</param>
 90        /// <remarks>
 91        /// The surface is not modified or disposed by this function.
 92        /// <see cref="TextureAccess" /> is static.
 93        /// The pixel format of the created texture may be different from the
 94        /// pixel format of the surface.
 95        /// </remarks>
 96        public Texture CreateTextureFromSurface(Surface surface,
 97            TextureScalingQuality quality = TextureScalingQuality.Nearest)
 98        {
 099            Try(() =>
 1100                SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, quality.AsHint()),
 0101                "SDL_SetHint");
 1102            var texture = SDL_CreateTextureFromSurface(Handle, surface.Handle);
 1103            if (texture == IntPtr.Zero)
 0104                throw new ImaginiException($"Could not create texture: {SDL_GetError()}");
 1105            return new Texture(texture, this);
 106        }
 107
 108        private Texture _renderTarget = null;
 109        /// <summary>
 110        /// Returns the currently active render target or null if it's not set.
 111        /// </summary>
 3112        public Texture GetRenderTarget() => _renderTarget;
 113        /// <summary>
 114        /// Sets the active render target. If null is specified, sets the
 115        /// default render target.
 116        /// </summary>
 117        public void SetRenderTarget(Texture texture)
 118        {
 2119            if (texture != null && texture.Access != TextureAccess.Target)
 0120                throw new ImaginiException("Texture should have Target access");
 2121            Try(() => SDL_SetRenderTarget(Handle, texture?.Handle ?? IntPtr.Zero),
 2122                "SDL_SetRenderTarget");
 2123            _renderTarget = texture;
 2124        }
 125
 126        /// <summary>
 127        /// Reads the pixel data from current render target to the specified pixel data buffer.
 128        /// </summary>
 129        /// <param name="pixelData"></param>
 130        /// <param name="rect">Rectangle to read data from, or null to read entire texture</param>
 131        /// <remarks>This function is pretty slow and shouldn't be used often.</remarks>
 132        public void ReadPixels(ref ColorRGB888[] pixelData, Rectangle? rectangle = null)
 133        {
 32134            if (pixelData.Length < GetPixelBufferSize(rectangle))
 0135                throw new ArgumentOutOfRangeException("Pixel array is too small");
 32136            SDL_Rect? rect = rectangle?.ToSDL();
 32137            var rectHandle = Pin(rect);
 32138            var pixelHandle = Pin(pixelData);
 32139            var width = rect?.w ?? OutputSize.Width;
 140            try
 141            {
 142                unsafe
 143                {
 32144                    var pitch = width * 4;
 0145                    Try(() => SDL_RenderReadPixels(Handle,
 0146                        rectHandle.AddrOfPinnedObject(),
 0147                        (uint)PixelFormat.Format_RGB888,
 0148                        pixelHandle.AddrOfPinnedObject(),
 0149                        pitch),
 0150                        "SDL_RenderReadPixels");
 151                }
 32152            }
 153            finally
 154            {
 32155                pixelHandle.Free();
 32156                rectHandle.Free();
 32157            }
 32158        }
 159
 160        /// <summary>
 161        /// Calculates the buffer size needed for pixel writing and reading
 162        /// operations.
 163        /// </summary>
 164        /// <param name="rectangle">Rectangle to read the data from, or null to read entire texture</param>
 165        /// <seealso cref="Lock" />
 166        public int GetPixelBufferSize(Rectangle? rectangle = null)
 167        {
 49168            var size = OutputSize;
 49169            return Texture.InternalGetPixelBufferSize(size.Width, size.Height, rectangle);
 170        }
 171
 172        /// <summary>
 173        /// Sets the current drawing color.
 174        /// </summary>
 175        public void SetDrawingColor(Color color) =>
 0176            Try(() =>
 65177                SDL_SetRenderDrawColor(Handle, color.R, color.G, color.B, color.A),
 0178                "SDL_SetRenderDrawColor");
 179
 180        /// <summary>
 181        /// Gets the current drawing color.
 182        /// </summary>
 183        public Color GetDrawingColor()
 184        {
 132185            byte r = 0; byte g = 0; byte b = 0; byte a = 0;
 0186            Try(() =>
 33187                SDL_GetRenderDrawColor(Handle, ref r, ref g, ref b, ref a),
 0188                "SDL_GetRenderDrawColor");
 33189            return Color.FromArgb(a, r, g, b);
 190        }
 191
 192        /// <summary>
 193        /// Sets the blend mode.
 194        /// </summary>
 195        public void SetBlendMode(BlendMode mode) =>
 6196            Try(() => SDL_SetRenderDrawBlendMode(Handle, (SDL_BlendMode)mode),
 6197                "SDL_SetRenderDrawBlendMode");
 198
 199        /// <summary>
 200        /// Gets the blend mode.
 201        /// </summary>
 202        public BlendMode GetBlendMode()
 203        {
 6204            SDL_BlendMode val = SDL_BlendMode.SDL_BLENDMODE_NONE;
 6205            Try(() => SDL_GetRenderDrawBlendMode(Handle, ref val),
 0206                "SDL_GetRenderDrawBlendMode");
 6207            return (BlendMode)val;
 208        }
 209
 210        /// <summary>
 211        /// Sets the clipping rectangle.
 212        /// </summary>
 213        /// <param name="rect">Clipping rectangle. If null, disables clipping</param>
 214        public void SetClipRectangle(Rectangle? rect)
 215        {
 2216            var rectHandle = Pin(rect?.ToSDL());
 217            try
 218            {
 219                unsafe
 220                {
 0221                    Try(() => SDL_RenderSetClipRect(Handle,
 0222                        (SDL_Rect*)rectHandle.AddrOfPinnedObject()),
 2223                        "SDL_RenderSetClipRect");
 224                }
 2225            }
 226            finally
 227            {
 2228                rectHandle.Free();
 2229            }
 2230        }
 231
 232        /// <summary>
 233        /// Gets the clip rectangle, or null if clipping is disabled.
 234        /// </summary>
 235        public Rectangle? GetClipRectangle()
 236        {
 237            unsafe
 238            {
 3239                var p = stackalloc int[4];
 3240                SDL_RenderGetClipRect(Handle, (SDL_Rect*)p);
 3241                var value = new Rectangle(
 0242                    *p,
 0243                    *(p + 1),
 0244                    *(p + 2),
 0245                    *(p + 3)
 0246                );
 3247                if (value.Size == Size.Empty)
 2248                    return null;
 1249                return value;
 250            }
 251        }
 252
 253        /// <summary>
 254        /// Sets the viewport.
 255        /// </summary>
 256        /// <param name="rect">Viewport rectangle. If null, whole target is used</param>
 257        public void SetViewport(Rectangle? rect)
 258        {
 2259            var rectHandle = Pin(rect?.ToSDL());
 260            try
 261            {
 262                unsafe
 263                {
 0264                    Try(() => SDL_RenderSetViewport(Handle,
 0265                        (SDL_Rect*)rectHandle.AddrOfPinnedObject()),
 0266                        "SDL_RenderSetViewport");
 267                }
 2268            }
 269            finally
 270            {
 2271                rectHandle.Free();
 2272            }
 2273        }
 274
 275        /// <summary>
 276        /// Gets the current viewport bounds.
 277        /// </summary>
 278        public Rectangle GetViewport()
 279        {
 280            unsafe
 281            {
 3282                var p = stackalloc int[4];
 3283                SDL_RenderGetViewport(Handle, (SDL_Rect*)p);
 0284                var value = new Rectangle(
 0285                    *p,
 0286                    *(p + 1),
 0287                    *(p + 2),
 0288                    *(p + 3)
 3289                );
 3290                return value;
 291            }
 292        }
 293
 294        /// <summary>
 295        /// Sets the drawing scale factor for the current target.
 296        /// </summary>
 297        public void SetScale(float scaleX, float scaleY) =>
 1298            Try(() => SDL_RenderSetScale(Handle, scaleX, scaleY),
 1299                "SDL_RenderSetScale");
 300
 301        /// <summary>
 302        /// Sets the drawing scale factor for the current target.
 303        /// </summary>
 304        public void SetScale(SizeF scale) =>
 1305            SetScale(scale.Width, scale.Height);
 306
 307        /// <summary>
 308        /// Gets the drawing scale factor for the current target.
 309        /// </summary>
 310        public void GetScale(out float scaleX, out float scaleY)
 311        {
 2312            var sX = 0.0f;
 2313            var sY = 0.0f;
 2314            SDL_RenderGetScale(Handle, ref sX, ref sY);
 4315            scaleX = sX; scaleY = sY;
 2316        }
 317
 318        /// <summary>
 319        /// Gets the drawing scale factor for the current target.
 320        /// </summary>
 321        public SizeF GetScale()
 322        {
 2323            GetScale(out float scaleX, out float scaleY);
 2324            return new SizeF(scaleX, scaleY);
 325        }
 326
 327        /// <summary>
 328        /// Sets a device independent resolution for rendering.
 329        /// </summary>
 330        public void SetLogicalSize(int width, int height) =>
 1331            Try(() => SDL_RenderSetLogicalSize(Handle, width, height),
 1332                "SDL_RenderSetLogicalSize");
 333
 334        /// <summary>
 335        /// Sets a device independent resolution for rendering.
 336        /// </summary>
 337        public void SetLogicalSize(Size size) =>
 1338            SetLogicalSize(size.Width, size.Height);
 339
 340        /// <summary>
 341        /// Gets a device independent resolution for rendering. If it was never
 342        /// set, returns zeros.
 343        /// </summary>
 344        public void GetLogicalSize(out int width, out int height)
 345        {
 4346            var w = 0; var h = 0;
 2347            SDL_RenderGetLogicalSize(Handle, ref w, ref h);
 4348            width = w; height = h;
 2349        }
 350
 351        /// <summary>
 352        /// Gets a device independent resolution for rendering. If it was never
 353        /// set, returns zeros.
 354        /// </summary>
 355        public Size GetLogicalSize()
 356        {
 2357            GetLogicalSize(out int w, out int h);
 2358            return new Size(w, h);
 359        }
 360
 361        /// <summary>
 362        /// Clears the current render target with the drawing color.
 363        /// </summary>
 364        public void Clear() =>
 54365            Try(() => SDL_RenderClear(Handle), "SDL_RenderClear");
 366
 367        /// <summary>
 368        /// Clears the current render target with the specified color.
 369        /// </summary>
 370        public void Clear(Color color)
 371        {
 27372            var oldColor = GetDrawingColor();
 27373            SetDrawingColor(color);
 27374            Clear();
 27375            SetDrawingColor(oldColor);
 27376        }
 377
 378        [ExcludeFromCodeCoverage]
 379        /// <summary>
 380        /// Draws a texture at the specified position.
 381        /// </summary>
 382        public void Draw(Texture texture, Point position)
 383        {
 384            var dstRect = new Rectangle(position, texture.Size);
 385            Draw(texture, null, dstRect);
 386        }
 387
 388        [ExcludeFromCodeCoverage]
 389        /// <summary>
 390        /// Draws a texture at the specified position with applied tint color.
 391        /// </summary>
 392        public void Draw(Texture texture, Point position, Color tint) =>
 393            Draw(texture, null, new Rectangle(position, texture.Size), tint, 0);
 394
 395        [ExcludeFromCodeCoverage]
 396        /// <summary>
 397        /// Draws a texture part at the specified position.
 398        /// </summary>
 399        public void Draw(Texture texture, Point position, Rectangle srcRect) =>
 400            Draw(texture, srcRect, new Rectangle(position, texture.Size));
 401
 402        [ExcludeFromCodeCoverage]
 403        /// <summary>
 404        /// Draws a texture part at the specified position with applied tint color.
 405        /// </summary>
 406        public void Draw(Texture texture, Point position, Rectangle srcRect, Color tint) =>
 407            Draw(texture, srcRect, new Rectangle(position, texture.Size), tint);
 408
 409        /// <summary>
 410        /// Copies a portion of the texture to the current rendering target.
 411        /// </summary>
 412        /// <param name="texture">Texture to copy</param>
 413        /// <param name="srcRect">Source rectangle (null for copying whole texture)</param>
 414        /// <param name="dstRect">Destination rectangle (null to fill the entire render target)</param>
 415        public void Draw(Texture texture, Rectangle? srcRect = null,
 416            Rectangle? dstRect = null)
 417        {
 88418            var srcR = srcRect?.ToSDL();
 88419            var dstR = dstRect?.ToSDL();
 88420            var src = Pin(srcR);
 88421            var dst = Pin(dstR);
 422            try
 423            {
 424                unsafe
 425                {
 0426                    Try(() => SDL_RenderCopy(Handle, texture.Handle,
 0427                        (SDL_Rect*)src.AddrOfPinnedObject(),
 0428                        (SDL_Rect*)dst.AddrOfPinnedObject()),
 88429                        "SDL_RenderCopy");
 430                }
 88431            }
 432            finally
 433            {
 88434                src.Free();
 88435                dst.Free();
 88436            }
 88437        }
 438
 439        /// <summary>
 440        /// Copies a portion of the texture to the current rendering target.
 441        /// </summary>
 442        /// <param name="texture">Texture to copy</param>
 443        /// <param name="srcRect">Source rectangle (null for copying whole texture)</param>
 444        /// <param name="dstRect">Destination rectangle (null to fill the entire render target)</param>
 445        /// <param name="angle">
 446        /// Angle in degrees that indicates the rotation that will be applied
 447        /// to dstRect, rotating it in a clockwise direction
 448        /// </param>
 449        /// <param name="center">
 450        /// Point around which dstRect will be rotated (if null, rotation will be
 451        /// done around dstRect's center)
 452        /// </param>
 453        /// <param name="flip">
 454        /// Flipping actions that should be performed on the texture
 455        /// </param>
 456        public void Draw(Texture texture, Rectangle? srcRect,
 457            Rectangle? dstRect, double angle = 0.0,
 458            Point? center = null, TextureFlip flip = TextureFlip.None)
 459        {
 4460            var srcR = Pin(srcRect?.ToSDL());
 4461            var dstR = Pin(dstRect?.ToSDL());
 4462            var cntr = Pin(center?.ToSDL());
 463            try
 464            {
 465                unsafe
 466                {
 0467                    Try(() => SDL_RenderCopyEx(Handle, texture.Handle,
 4468                        (SDL_Rect*)srcR.AddrOfPinnedObject(),
 4469                        (SDL_Rect*)dstR.AddrOfPinnedObject(),
 0470                        angle,
 4471                        (SDL_Point*)cntr.AddrOfPinnedObject(),
 0472                        (SDL_RendererFlip)flip),
 0473                        "SDL_RenderCopyEx");
 474                }
 4475            }
 476            finally
 477            {
 4478                srcR.Free();
 4479                dstR.Free();
 4480                cntr.Free();
 4481            }
 4482        }
 483
 484        /// <summary>
 485        /// Copies a portion of the texture to the current rendering target.
 486        /// </summary>
 487        /// <param name="texture">Texture to copy</param>
 488        /// <param name="srcRect">Source rectangle (null for copying whole texture)</param>
 489        /// <param name="dstRect">Destination rectangle (null to fill the entire render target)</param>
 490        /// <param name="angle">
 491        /// Angle in degrees that indicates the rotation that will be applied
 492        /// to dstRect, rotating it in a clockwise direction
 493        /// </param>
 494        /// <param name="center">
 495        /// Point around which dstRect will be rotated (if null, rotation will be
 496        /// done around dstRect's center)
 497        /// </param>
 498        /// <param name="flip">
 499        /// Flipping actions that should be performed on the texture
 500        /// </param>
 501        /// <param name="tint">Tint color to be applied on the texture</param>
 502        public void Draw(Texture texture, Rectangle? srcRect,
 503            Rectangle? dstRect, Color tint, double angle = 0.0,
 504            Point? center = null, TextureFlip flip = TextureFlip.None)
 505        {
 0506            var oldTint = texture.Tint;
 0507            texture.Tint = tint;
 0508            Draw(texture, srcRect, dstRect, angle, center, flip);
 0509            texture.Tint = oldTint;
 0510        }
 511
 512        /// <summary>
 513        /// Draws a line between two points with the current color.
 514        /// </summary>
 515        public void DrawLine(int x1, int y1, int x2, int y2) =>
 1516            Try(() =>
 1517                SDL_RenderDrawLine(Handle, x1, y1, x2, y2),
 1518                "SDL_RenderDrawLine");
 519
 520        /// <summary>
 521        /// Draws a line between two points with the current color.
 522        /// </summary>
 523        public void DrawLine(Point from, Point to) =>
 1524            DrawLine(from.X, from.Y, to.X, to.Y);
 525
 526        /// <summary>
 527        /// Draws a series of connected lines between the specified points with
 528        /// the current color.
 529        /// </summary>
 530        public void DrawLines(params Point[] points)
 531        {
 532            unsafe
 533            {
 1534                var p = Pin(points);
 535                try
 536                {
 0537                    Try(() => SDL_RenderDrawLines(Handle,
 0538                        (SDL_Point*)p.AddrOfPinnedObject(), points.Length),
 0539                        "SDL_RenderDrawLines");
 1540                }
 541                finally
 542                {
 1543                    p.Free();
 1544                }
 545            }
 1546        }
 547
 548        /// <summary>
 549        /// Draws a point at the specified coordinates using current color.
 550        /// </summary>
 551        public void DrawPoint(int x, int y) =>
 1552            Try(() => SDL_RenderDrawPoint(Handle, x, y),
 0553                "SDL_RenderDrawPoint");
 554
 555        /// <summary>
 556        /// Draws a point at the specified coordinates using current color.
 557        /// </summary>
 558        public void DrawPoint(Point point) =>
 1559            DrawPoint(point.X, point.Y);
 560
 561        /// <summary>
 562        /// Draws points at the specified coordinates using current color.
 563        /// </summary>
 564        public void DrawPoints(params Point[] points)
 565        {
 566            unsafe
 567            {
 1568                var p = Pin(points);
 569                try
 570                {
 1571                    Try(() => SDL_RenderDrawPoints(Handle,
 1572                        (SDL_Point*)p.AddrOfPinnedObject(), points.Length),
 1573                        "SDL_RenderDrawPoints");
 1574                }
 575                finally
 576                {
 1577                    p.Free();
 1578                }
 579            }
 1580        }
 581
 582        /// <summary>
 583        /// Draws a rectangle outline with the current color.
 584        /// </summary>
 585        /// <param name="rectangle">Rectangle to draw outline for. If null,
 586        /// outlines a whole target.</param>
 587        public void DrawRect(Rectangle? rectangle)
 588        {
 589            unsafe
 590            {
 13591                var p = Pin(rectangle);
 592                try
 593                {
 0594                    Try(() =>
 13595                        SDL_RenderDrawRect(Handle, (SDL_Rect*)p.AddrOfPinnedObject()),
 13596                        "SDL_RenderDrawRect");
 13597                }
 598                finally
 599                {
 13600                    p.Free();
 13601                }
 602            }
 13603        }
 604
 605        /// <summary>
 606        /// Draws a rectangle outline with the current color.
 607        /// </summary>
 608        /// <param name="rectangles">Rectangles to draw outline for</param>
 609        public void DrawRects(params Rectangle[] rectangles)
 610        {
 611            unsafe
 612            {
 1613                var p = Pin(rectangles);
 614                try
 615                {
 1616                    Try(() =>
 1617                        SDL_RenderDrawRects(Handle,
 1618                            (SDL_Rect*)p.AddrOfPinnedObject(), rectangles.Length),
 1619                        "SDL_RenderDrawRects");
 1620                }
 621                finally
 622                {
 1623                    p.Free();
 1624                }
 625            }
 1626        }
 627
 628        /// <summary>
 629        /// Fills a rectangle outline with the current color.
 630        /// </summary>
 631        /// <param name="rectangle">Rectangle to fill. If null,
 632        /// fills a whole target.</param>
 633        public void FillRect(Rectangle? rectangle)
 634        {
 635            unsafe
 636            {
 1637                var p = Pin(rectangle);
 638                try
 639                {
 1640                    Try(() =>
 1641                        SDL_RenderFillRect(Handle, (SDL_Rect*)p.AddrOfPinnedObject()),
 1642                        "SDL_RenderFillRect");
 1643                }
 644                finally
 645                {
 1646                    p.Free();
 1647                }
 648            }
 1649        }
 650
 651        /// <summary>
 652        /// Fills rectangles with the current color.
 653        /// </summary>
 654        /// <param name="rectangles">Rectangles to fill</param>
 655        public void FillRects(params Rectangle[] rectangles)
 656        {
 657            unsafe
 658            {
 1659                var p = Pin(rectangles);
 660                try
 661                {
 1662                    Try(() =>
 1663                        SDL_RenderFillRects(Handle,
 1664                            (SDL_Rect*)p.AddrOfPinnedObject(), rectangles.Length),
 1665                        "SDL_RenderFillRects");
 1666                }
 667                finally
 668                {
 1669                    p.Free();
 1670                }
 671            }
 1672        }
 673
 674        internal override void Destroy()
 675        {
 63676            if (IsDisposed) return;
 63677            base.Destroy();
 63678            SDL_DestroyRenderer(Handle);
 63679        }
 680
 1681        static Graphics() => Lifecycle.TryInitialize();
 682
 683        // TODO Explore possibility of using stackalloc instead of pinning
 684
 685        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 274686        static GCHandle Pin(object obj) => GCHandle.Alloc(obj, GCHandleType.Pinned);
 687    }
 688}

Methods/Properties

Renderer()
OutputSize()
PixelCount()
CreateTexture(System.Int32,System.Int32,Imagini.Drawing.TextureScalingQuality,Imagini.Drawing.PixelFormat,Imagini.Drawing.TextureAccess)
CreateTextureFromSurface(Imagini.Drawing.Surface,Imagini.Drawing.TextureScalingQuality)
GetRenderTarget()
SetRenderTarget(Imagini.Drawing.Texture)
ReadPixels(Imagini.Drawing.ColorRGB888[]&,System.Nullable`1<System.Drawing.Rectangle>)
GetPixelBufferSize(System.Nullable`1<System.Drawing.Rectangle>)
SetDrawingColor(System.Drawing.Color)
GetDrawingColor()
SetBlendMode(Imagini.Drawing.BlendMode)
GetBlendMode()
SetClipRectangle(System.Nullable`1<System.Drawing.Rectangle>)
GetClipRectangle()
SetViewport(System.Nullable`1<System.Drawing.Rectangle>)
GetViewport()
SetScale(System.Single,System.Single)
SetScale(System.Drawing.SizeF)
GetScale(System.Single&,System.Single&)
GetScale()
SetLogicalSize(System.Int32,System.Int32)
SetLogicalSize(System.Drawing.Size)
GetLogicalSize(System.Int32&,System.Int32&)
GetLogicalSize()
Clear()
Clear(System.Drawing.Color)
Draw(Imagini.Drawing.Texture,System.Nullable`1<System.Drawing.Rectangle>,System.Nullable`1<System.Drawing.Rectangle>)
Draw(Imagini.Drawing.Texture,System.Nullable`1<System.Drawing.Rectangle>,System.Nullable`1<System.Drawing.Rectangle>,System.Double,System.Nullable`1<System.Drawing.Point>,Imagini.Drawing.TextureFlip)
Draw(Imagini.Drawing.Texture,System.Nullable`1<System.Drawing.Rectangle>,System.Nullable`1<System.Drawing.Rectangle>,System.Drawing.Color,System.Double,System.Nullable`1<System.Drawing.Point>,Imagini.Drawing.TextureFlip)
DrawLine(System.Int32,System.Int32,System.Int32,System.Int32)
DrawLine(System.Drawing.Point,System.Drawing.Point)
DrawLines(System.Drawing.Point[])
DrawPoint(System.Int32,System.Int32)
DrawPoint(System.Drawing.Point)
DrawPoints(System.Drawing.Point[])
DrawRect(System.Nullable`1<System.Drawing.Rectangle>)
DrawRects(System.Drawing.Rectangle[])
FillRect(System.Nullable`1<System.Drawing.Rectangle>)
FillRects(System.Drawing.Rectangle[])
Destroy()
.cctor()
Pin(System.Object)