Esempio n. 1
0
 public static void DrawTile(TileTexture tiles, TileIndex index, Vector2 position,
                             Color?color = null, TextureMirror mirror = TextureMirror.None)
 {
     Engine.DrawTexture(
         tiles.Texture,
         position: position,
         color: color,
         scaleMode: TextureScaleMode.Nearest,
         source: new Bounds2(index * tiles.SourceSize, tiles.SourceSize),
         size: tiles.DestinationSize,
         mirror: mirror);
 }
Esempio n. 2
0
    /// <summary>
    /// Draws a texture.
    /// </summary>
    /// <param name="texture">The texture to draw.</param>
    /// <param name="position">The position where the texture will be drawn.</param>
    /// <param name="color">The color to multiply with the colors of the texture. If unspecified the colors of the texture will be unchanged.</param>
    /// <param name="size">The destination size of the texture. If unspecified the original texture size will be used.</param>
    /// <param name="rotation">The amount the texture will be rotated clockwise (in degrees). If unspecified the texture will not be rotated.</param>
    /// <param name="pivot">The offset from position to the pivot that the texture will be rotated about. If unspecified the center of the destination bounds will be used.</param>
    /// <param name="mirror">The mirroring to apply to the texture. If unspecified the texture will not be mirrored.</param>
    /// <param name="source">The source bounds of the texture to draw. If unspecified the entire texture will be drawn.</param>
    /// <param name="blendMode">The blend mode to use when drawing the texture. If unspecified the texture will be drawn using the standard alpha-based blend mode.</param>
    /// <param name="scaleMode">The scale mode to use when drawing the texture. If unspecified the texture will be linearly interpolated.</param>
    public static void DrawTexture(Texture texture, Vector2 position, Color?color = null, Vector2?size = null, float rotation = 0, Vector2?pivot = null, TextureMirror mirror = TextureMirror.None, Bounds2?source = null, TextureBlendMode blendMode = TextureBlendMode.Normal, TextureScaleMode scaleMode = TextureScaleMode.Linear)
    {
        DrawTextureSetup(texture.Handle, color, blendMode, scaleMode);

        SDL.SDL_Rect src;
        SDL.SDL_Rect dest;
        if (source.HasValue)
        {
            // Use the specified source coordinates:
            src.x  = (int)source.Value.Position.X;
            src.y  = (int)source.Value.Position.Y;
            src.w  = (int)source.Value.Size.X;
            src.h  = (int)source.Value.Size.Y;
            dest.x = (int)position.X;
            dest.y = (int)position.Y;
            dest.w = src.w;
            dest.h = src.h;
        }
        else
        {
            // Use the full texture as the source:
            src.x  = 0;
            src.y  = 0;
            src.w  = texture.Width;
            src.h  = texture.Height;
            dest.x = (int)position.X;
            dest.y = (int)position.Y;
            dest.w = texture.Width;
            dest.h = texture.Height;
        }

        // Apply the size override, if specified:
        if (size.HasValue)
        {
            dest.w = (int)size.Value.X;
            dest.h = (int)size.Value.Y;
        }

        // Apply the pivot override, if specified:
        SDL.SDL_Point center;
        if (pivot.HasValue)
        {
            center.x = (int)pivot.Value.X;
            center.y = (int)pivot.Value.Y;
        }
        else
        {
            center.x = dest.w / 2;
            center.y = dest.h / 2;
        }

        SDL.SDL_RenderCopyEx(Renderer, texture.Handle, ref src, ref dest, rotation, ref center, (SDL.SDL_RendererFlip)mirror);
    }