Skip to content

Commit

Permalink
Merge pull request #6022 from peppy/add-background-fill
Browse files Browse the repository at this point in the history
Add button to randomise test scene background colour
  • Loading branch information
bdach authored Oct 10, 2023
2 parents fe27691 + a89c062 commit 238fa68
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
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 bg 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

0 comments on commit 238fa68

Please sign in to comment.