/// <summary> /// Creates a new instance of the <see cref="Cursor"/> class. /// </summary> /// <param name="surface">The <see cref="Surface2D"/> that contains the cursor image.</param> /// <returns>The instance of <see cref="Cursor"/> that was created.</returns> public static Cursor Create(Surface2D surface) { Contract.Require(surface, nameof(surface)); var uv = UltravioletContext.DemandCurrent(); return uv.GetFactoryMethod<CursorFactory>()(uv, surface, 0, 0); }
/// <summary> /// Saves the specified surface as an image with the specified format. /// </summary> /// <param name="surface">The surface to save.</param> /// <param name="stream">The stream to which to save the surface data.</param> /// <param name="format">The format with which to save the image.</param> private void Save(Surface2D surface, Stream stream, ImageFormat format) { var data = new Color[surface.Width * surface.Height]; surface.GetData(data); Save(data, surface.Width, surface.Height, stream, format); }
/// <summary> /// Creates a new instance of the <see cref="Cursor"/> class. /// </summary> /// <param name="surface">The <see cref="Surface2D"/> that contains the cursor image.</param> /// <param name="hx">The x-coordinate of the cursor's hotspot.</param> /// <param name="hy">The y-coordinate of the cursor's hotspot.</param> /// <returns>The instance of <see cref="Cursor"/> that was created.</returns> public static Cursor Create(Surface2D surface, Int32 hx, Int32 hy) { Contract.Require(surface, "surface"); var uv = UltravioletContext.DemandCurrent(); return uv.GetFactoryMethod<CursorFactory>()(uv, surface, hx, hy); }
/// <inheritdoc/> public override void SaveAsJpeg(Surface2D surface, Stream stream) { Contract.Require(surface, "surface"); Contract.Require(stream, "stream"); Save(surface, stream, ImageFormat.Jpeg); }
/// <summary> /// Initializes a new instance of the OpenGLCursor class. /// </summary> /// <param name="uv">The UltravioletContext class.</param> /// <param name="surface">The surface that contains the cursor image.</param> /// <param name="hx">The x-coordinate of the cursor's hotspot.</param> /// <param name="hy">The y-coordinate of the cursor's hotspot.</param> public OpenGLCursor(UltravioletContext uv, Surface2D surface, Int32 hx, Int32 hy) : base(uv) { Contract.Require(surface, "surface"); uv.ValidateResource(surface); if (AreCursorsSupported(uv)) { this.cursor = SDL.CreateColorCursor(((OpenGLSurface2D)surface).Native, hx, hy); this.width = surface.Width; this.height = surface.Height; if (this.cursor == null) { this.width = 0; this.height = 0; } } else { this.cursor = null; this.width = 0; this.height = 0; } }
/// <inheritdoc/> public override void SaveAsPng(Surface2D surface, Stream stream) { Contract.Require(surface, nameof(surface)); Contract.Require(stream, nameof(stream)); Save(surface, stream, Bitmap.CompressFormat.Png); }
/// <inheritdoc/> public override void SaveAsPng(Surface2D surface, Stream stream) { Contract.Require(surface, nameof(surface)); Contract.Require(stream, nameof(stream)); var data = new Color[surface.Width * surface.Height]; surface.GetData(data); Save(data, surface.Width, surface.Height, stream, img => img.AsPNG()); }
/// <inheritdoc/> public override void SaveAsPng(Surface2D surface, Stream stream) { Contract.Require(surface, "surface"); Contract.Require(stream, "stream"); var data = new Color[surface.Width * surface.Height]; surface.GetData(data); Save(data, surface.Width, surface.Height, stream, asPng: true); }
/// <summary> /// Creates the output surface for a texture atlas. /// </summary> private static Surface2D CreateOutputSurface(TextureAtlasDescription atlasDesc, IEnumerable <TextureAtlasImage> atlasImages, ContentManager content, Int32 width, Int32 height, Dictionary <String, Rectangle> images) { var output = Surface2D.Create(width, height); foreach (var image in atlasImages) { var imageArea = images[image.Name]; using (var imageSurface = content.Load <Surface2D>(image.Path, false)) { var areaWithoutPadding = new Rectangle( imageArea.X, imageArea.Y, imageArea.Width - atlasDesc.Metadata.Padding, imageArea.Height - atlasDesc.Metadata.Padding); imageSurface.Blit(output, areaWithoutPadding); } } return(output); }
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="srcRect">The area of this surface that will be copied to the destination surface.</param> /// <param name="dst">The destination surface.</param> /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param> public abstract void Blit(Rectangle srcRect, Surface2D dst, Rectangle dstRect);
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="dst">The destination surface.</param> /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param> public abstract void Blit(Surface2D dst, Rectangle dstRect);
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="dst">The destination surface.</param> public abstract void Blit(Surface2D dst);
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="dst">The destination surface.</param> public abstract void Blit(Surface2D dst);
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="srcRect">The area of this surface that will be copied to the destination surface.</param> /// <param name="dst">The destination surface.</param> /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param> public abstract void Blit(Rectangle srcRect, Surface2D dst, Rectangle dstRect);
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="dst">The destination surface.</param> /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param> public abstract void Blit(Surface2D dst, Rectangle dstRect);
/// <summary> /// Saves the specified surface as a JPEG image. /// </summary> /// <param name="surface">The surface to save.</param> /// <param name="stream">The stream to which to save the surface data.</param> public abstract void SaveAsJpeg(Surface2D surface, Stream stream);
/// <summary> /// Saves the specified surface as a JPEG image. /// </summary> /// <param name="surface">The surface to save.</param> /// <param name="stream">The stream to which to save the surface data.</param> public abstract void SaveAsJpeg(Surface2D surface, Stream stream);
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="srcRect">The area of this surface that will be copied to the destination surface.</param> /// <param name="dst">The destination surface.</param> /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param> public override void Blit(Rectangle srcRect, Surface2D dst, Rectangle dstRect) { Contract.EnsureNotDisposed(this, Disposed); Contract.Require(dst, "dst"); Ultraviolet.ValidateResource(dst); BlitInternal(this, srcRect, (OpenGLSurface2D)dst, dstRect); }
/// <summary> /// Blits the surface onto the specified destination surface. /// </summary> /// <param name="dst">The destination surface.</param> /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param> public override void Blit(Surface2D dst, Rectangle dstRect) { Contract.EnsureNotDisposed(this, Disposed); Contract.Require(dst, "dst"); Ultraviolet.ValidateResource(dst); BlitInternal(this, new Rectangle(0, 0, Width, Height), (OpenGLSurface2D)dst, dstRect); }