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 button to randomise test scene background colour #6022

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 43 additions & 3 deletions osu.Framework/Testing/Drawables/TestBrowserToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing.Drawables.Sections;
using osu.Framework.Utils;
using osuTK.Graphics;

namespace osu.Framework.Testing.Drawables
{
internal partial class TestBrowserToolbar : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load()
private void load(TestBrowser browser)
{
const float section_padding = 10;

Expand Down Expand Up @@ -40,6 +45,7 @@ private void load()
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
Expand All @@ -51,7 +57,7 @@ private void load()
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Margin = new MarginPadding { Left = section_padding },
Margin = new MarginPadding { Horizontal = section_padding },
Children = new Drawable[]
{
new Container //Backdrop of the record section
Expand All @@ -64,9 +70,43 @@ private void load()
Colour = FrameworkColour.GreenDarker,
},
},
new ToolbarRecordSection { RelativeSizeAxes = Axes.Y }
new ToolbarRecordSection { RelativeSizeAxes = Axes.Y },
}
},
new Container
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Margin = new MarginPadding { Left = section_padding },
Children = new Drawable[]
{
new Container //Backdrop of the record section
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(-section_padding),
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = FrameworkColour.GreenDarker.Darken(0.5f),
},
},
new BasicButton
{
Text = "bg",
RelativeSizeAxes = Axes.Y,
Width = 40,
Action = () => browser.CurrentTest.ChangeBackgroundColour(
new ColourInfo
{
TopLeft = new Color4(RNG.NextSingle(1), RNG.NextSingle(1), RNG.NextSingle(1), 1),
TopRight = new Color4(RNG.NextSingle(1), RNG.NextSingle(1), RNG.NextSingle(1), 1),
BottomLeft = new Color4(RNG.NextSingle(1), RNG.NextSingle(1), RNG.NextSingle(1), 1),
BottomRight = new Color4(RNG.NextSingle(1), RNG.NextSingle(1), RNG.NextSingle(1), 1)
}
)
},
}
}
}
},
},
Expand Down
26 changes: 22 additions & 4 deletions osu.Framework/Testing/TestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using osu.Framework.Extensions;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
Expand Down Expand Up @@ -58,6 +59,8 @@ public abstract partial class TestScene : Container
private Task runTask;
private ITestSceneTestRunner runner;

private readonly Box backgroundFill;

/// <summary>
/// A nested game instance, if added via <see cref="AddGame"/>.
/// </summary>
Expand Down Expand Up @@ -166,11 +169,23 @@ protected TestScene()
Bottom = padding,
},
RelativeSizeAxes = Axes.Both,
Child = content = new DrawFrameRecordingContainer
Child = new Container
{
Masking = true,
RelativeSizeAxes = Axes.Both
}
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
backgroundFill = new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
},
content = new DrawFrameRecordingContainer
{
Masking = true,
RelativeSizeAxes = Axes.Both
}
}
},
},
}
});
Expand Down Expand Up @@ -255,6 +270,9 @@ private void runNextStep(Action onCompletion, Action<Exception> onError, Func<St

private bool addStepsAsSetupSteps;

public void ChangeBackgroundColour(ColourInfo colour)
=> backgroundFill.FadeColour(colour, 200, Easing.OutQuint);

public StepButton AddStep(string description, Action action)
{
var step = new SingleStepButton(addStepsAsSetupSteps)
Expand Down