A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using NUnit.Framework;
5using osu.Framework.Graphics;
6using osu.Framework.Graphics.UserInterface;
7using osu.Framework.Testing;
8using osuTK;
9using osuTK.Input;
10
11namespace osu.Framework.Tests.Visual.UserInterface
12{
13 public class TestSceneButton : ManualInputManagerTestScene
14 {
15 private int clickCount;
16 private readonly BasicButton button;
17
18 public TestSceneButton()
19 {
20 Add(button = new BasicButton
21 {
22 Anchor = Anchor.TopLeft,
23 Origin = Anchor.TopLeft,
24 Text = "this is a button",
25 Size = new Vector2(200, 40),
26 Margin = new MarginPadding(10),
27 FlashColour = FrameworkColour.Green,
28 Action = () => clickCount++
29 });
30 }
31
32 [SetUp]
33 public new void SetUp() => Schedule(() =>
34 {
35 clickCount = 0;
36 button.Enabled.Value = true;
37 });
38
39 [Test]
40 public void Button()
41 {
42 AddStep("click button", () =>
43 {
44 InputManager.MoveMouseTo(button.ScreenSpaceDrawQuad.Centre);
45 InputManager.Click(MouseButton.Left);
46 });
47 AddAssert("action was executed", () => clickCount == 1);
48 }
49
50 [Test]
51 public void DisabledButton()
52 {
53 AddStep("disable button", () => button.Enabled.Value = false);
54 AddStep("click button", () =>
55 {
56 InputManager.MoveMouseTo(button.ScreenSpaceDrawQuad.Centre);
57 InputManager.Click(MouseButton.Left);
58 });
59 AddAssert("action was not executed", () => clickCount == 0);
60 }
61 }
62}