Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧Add resize capture in scenes #968

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Testing/VelaptorTests/Scene/SceneBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ public void UnloadContent_WhenContentHasNotBeenLoaded_DoesNotUnloadContent()
// Assert
sut.IsLoaded.Should().BeFalse();
}

[Fact]
public void Resize_WhenInvoked_UpdatesWindowSize()
{
// Arrange
var sut = CreateSystemUnderTest();

// Act
sut.Resize(new SizeU(10u, 10u));

// Assert
sut.WindowSize.Should().Be(new SizeU(10u, 10u));
}
#endregion

#region Reactable Tests
Expand Down
20 changes: 20 additions & 0 deletions Testing/VelaptorTests/Scene/SceneManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,26 @@ public void SceneExists_WhenSceneDoesNotExist_ReturnsFalse()
actual.Should().BeFalse();
}

[Fact]
public void Resize_WhenInvoked_UpdatesWindowSizeForEachScene()
{
// Arrange
var mockSceneA = Substitute.For<IScene>();
mockSceneA.Id.Returns(Guid.NewGuid());
var mockSceneB = Substitute.For<IScene>();
mockSceneB.Id.Returns(Guid.NewGuid());
var sut = new SceneManager();
sut.AddScene(mockSceneA);
sut.AddScene(mockSceneB);

// Act
sut.Resize(new SizeU(15u, 15u));

// Assert
mockSceneA.Received(1).Resize(new SizeU(15u, 15u));
mockSceneB.Received(1).Resize(new SizeU(15u, 15u));
}

[Fact]
[SuppressMessage("csharpsquid", "S3966", Justification = "Disposing twice is required for testing.")]
public void Dispose_WhenInvokedS_DisposesOfScenes()
Expand Down
6 changes: 6 additions & 0 deletions Velaptor/Scene/IScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ public interface IScene : IUpdatable, IDrawable, IDisposable
/// Unloads the scene's content.
/// </summary>
void UnloadContent();

/// <summary>
/// Updates the <see cref="WindowSize"/>.
/// </summary>
/// <param name="size">The new size.</param>
void Resize(SizeU size);
}
6 changes: 6 additions & 0 deletions Velaptor/Scene/ISceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ public interface ISceneManager : IUpdatable, IDrawable, IDisposable
/// </returns>
[SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Used by library users.")]
bool SceneExists(Guid id);

/// <summary>
/// Updates the size of the window for each scene.
/// </summary>
/// <param name="size">The new size.</param>
void Resize(SizeU size);
}
3 changes: 3 additions & 0 deletions Velaptor/Scene/SceneBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public virtual void UnloadContent()
IsLoaded = false;
}

/// <inheritdoc />
public virtual void Resize(SizeU size) => WindowSize = size;

/// <inheritdoc/>
public virtual void Update(FrameTime frameTime)
{
Expand Down
9 changes: 9 additions & 0 deletions Velaptor/Scene/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ public void UnloadContent()
/// <returns>True if the scene exists.</returns>
public bool SceneExists(Guid id) => this.scenes.Exists(s => s.scene?.Id == id);

/// <inheritdoc />
public void Resize(SizeU size)
{
foreach ((IScene? scene, _) in this.scenes)
{
scene?.Resize(size);
}
}

/// <inheritdoc cref="IDisposable.Dispose"/>
public void Dispose()
{
Expand Down
4 changes: 1 addition & 3 deletions Velaptor/UI/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ protected virtual void OnUnload()
/// <param name="size">The new size.</param>
[ExcludeFromCodeCoverage(Justification = "Not originally intended to have a method body.")]
[SuppressMessage("ReSharper", "VirtualMemberNeverOverridden.Global", Justification = "Used by library users.")]
protected virtual void OnResize(SizeU size)
{
}
protected virtual void OnResize(SizeU size) => this.nativeWindow.SceneManager.Resize(size);

/// <summary>
/// <inheritdoc cref="IDisposable.Dispose"/>
Expand Down
Loading