@ -9,6 +9,8 @@ namespace DotSDL.Graphics {
/// </summary>
public class Canvas {
private int _ width , _ height ;
private Color _ colorMod = new Color { R = 2 5 5 , G = 2 5 5 , B = 2 5 5 , A = 2 5 5 } ;
private byte _ opacity = 2 5 5 ;
/// <summary>
/// <c>true</c> if this <see cref="Canvas"/> has an SDL texture associated with it, otherwise <c>false</c>.
@ -78,6 +80,9 @@ namespace DotSDL.Graphics {
}
}
/// <summary>
/// Sets the blending mode that should be used for this <see cref="Canvas"/>.
/// </summary>
public BlendMode BlendMode {
get = > BlendModeValue ;
set {
@ -88,6 +93,52 @@ namespace DotSDL.Graphics {
}
}
/// <summary>
/// Gets or sets the color modulation that should be used for this <see cref="Canvas"/>.
/// </summary>
/// <remarks>
/// <para>Each pixel of this <see cref="Canvas"/> will be multiplied by the
/// <see cref="Color"/> set here. This can be used to change the color of any
/// individual element without having to manually draw multiplie textures with
/// different palettes.</para>
///
/// <para>Alpha values will not affect the object in any way. In order to adjust
/// the object's translucency, use the <see cref="Opacity"/> property instead.</para>
///
/// <para>Please note that setting this will impact the entire object. No options
/// for masking are provided.</para>
/// </remarks>
public Color ColorMod {
get = > _ colorMod ;
set {
_ colorMod = value ;
if ( HasTexture )
Render . SetTextureColorMod ( Texture , _ colorMod . R , _ colorMod . G , _ colorMod . B ) ;
}
}
/// <summary>
/// Gets or sets the opacity of this <see cref="Canvas"/>.
/// </summary>
/// <remarks>
/// <para>The alpha value of each pixel of this <see cref="Canvas"/> will be
/// multiplied by the value set here. This can be used to fade an entire object
/// in and out.</para>
///
/// <para>Please note that this setting will impact the entire object. No options
/// for masking are provided.</para>
/// </remarks>
public byte Opacity {
get = > _ opacity ;
set {
_ opacity = value ;
if ( HasTexture )
Render . SetTextureAlphaMod ( Texture , _ opacity ) ;
}
}
/// <summary>
/// Determines the method that will be used to scale this sprite when it is plotted to the
/// screen.
@ -128,14 +179,7 @@ namespace DotSDL.Graphics {
Clipping = clipping ;
GetCanvasPointer = ( ) = > {
unsafe {
fixed ( void * pixelPtr = Pixels ) {
return ( IntPtr ) pixelPtr ;
}
}
} ;
ResetGetCanvasPointer ( ) ;
Resize ( ) ;
}
@ -158,7 +202,9 @@ namespace DotSDL.Graphics {
Texture = Render . CreateTexture ( Renderer , SdlPixels . PixelFormatArgb8888 , textureAccess , Width , Height ) ;
HasTexture = true ;
Render . SetTextureAlphaMod ( Texture , _ opacity ) ;
Render . SetTextureBlendMode ( Texture , BlendModeValue ) ;
Render . SetTextureColorMod ( Texture , _ colorMod . R , _ colorMod . G , _ colorMod . B ) ;
}
/// <summary>
@ -190,6 +236,21 @@ namespace DotSDL.Graphics {
return ( Width * point . Y ) + point . X ;
}
/// <summary>
/// Restores the the <see cref="GetCanvasPointer"/> function pointer back to its normal
/// value. This should be called if the application wishes to give control of the pixel
/// array back to this <see cref="Canvas"/> after previously handling it.
/// </summary>
public void ResetGetCanvasPointer ( ) {
GetCanvasPointer = ( ) = > {
unsafe {
fixed ( void * pixelPtr = Pixels ) {
return ( IntPtr ) pixelPtr ;
}
}
} ;
}
/// <summary>
/// Resizes the <see cref="Canvas"/>. Please note that this will also clear the canvas of
/// its existing contents.