Browse Source

Added the ability to use a pointer to represent the background of an SdlWindow.

improved_timing
Ian Burgmyer 6 years ago
parent
commit
c3d78af298
  1. 29
      DotSDL/Graphics/SdlWindow.cs

29
DotSDL/Graphics/SdlWindow.cs

@ -105,6 +105,7 @@ namespace DotSDL.Graphics {
/// <param name="windowHeight">The height of the window.</param>
/// <param name="textureWidth">The width of the window's texture.</param>
/// <param name="textureHeight">The height of the window's texture.</param>
/// <param name="updateType">The method used to update the canvas.</param>
public SdlWindow(string title, Point position, int windowWidth, int windowHeight, int textureWidth, int textureHeight) {
_sdlInit.InitSubsystem(Init.SubsystemFlags.Video);
@ -135,15 +136,10 @@ namespace DotSDL.Graphics {
/// <summary>
/// Handles calling the user draw function and passing the CLR objects to SDL2.
/// </summary>
private unsafe void BaseDraw() {
private void BaseDraw() {
if(IsDestroyed || IsMinimized) return;
OnDraw(ref _canvas); // Call the overridden Draw function.
fixed(void* pixelsPtr = _canvas.Pixels) {
var ptr = (IntPtr)pixelsPtr;
Render.UpdateTexture(_texture, IntPtr.Zero, ptr, TextureWidth * 4);
}
Render.UpdateTexture(_texture, IntPtr.Zero, GetCanvasPointer(), TextureWidth * 4);
Render.RenderCopy(_renderer, _texture, IntPtr.Zero, IntPtr.Zero);
Render.RenderPresent(_renderer);
}
@ -173,6 +169,21 @@ namespace DotSDL.Graphics {
IsDestroyed = true;
}
/// <summary>
/// Gets an <see cref="IntPtr"/> that points to what should be displayed on the window's background. You usually
/// do not need to override this method.
/// </summary>
/// <remarks>If an invalid <see cref="IntPtr"/> is generated by this method, your application may
/// crash with a segmentation fault. When in doubt, override <see cref="OnDraw"/> instead!</remarks>
/// <returns>An <see cref="IntPtr"/> containing the contents of the window's background.</returns>
public unsafe virtual IntPtr GetCanvasPointer() {
OnDraw(ref _canvas); // Call the overridden Draw function.
fixed(void* pixelsPtr = _canvas.Pixels) {
return (IntPtr)pixelsPtr;
}
}
/// <summary>
/// Retrieves the SDL resource ID for this <see cref="SdlWindow"/>.
/// </summary>
@ -254,7 +265,7 @@ namespace DotSDL.Graphics {
/// </summary>
/// <param name="canvas">The active canvas for the window.</param>
protected virtual void OnDraw(ref Canvas canvas) { }
/// <summary>
/// Called before the window is shown.
/// </summary>

Loading…
Cancel
Save