From 9cb9151811526690b5c6b31391cb4e7f728f8f0c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Oct 2017 16:00:11 +0900 Subject: [PATCH 1/7] Move origin + anchor outside of ctor --- osu.Game/Graphics/UserInterface/IconButton.cs | 3 --- osu.Game/Overlays/MusicController.cs | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/IconButton.cs b/osu.Game/Graphics/UserInterface/IconButton.cs index 1808dc4b6c..956fac279f 100644 --- a/osu.Game/Graphics/UserInterface/IconButton.cs +++ b/osu.Game/Graphics/UserInterface/IconButton.cs @@ -38,9 +38,6 @@ namespace osu.Game.Graphics.UserInterface { AutoSizeAxes = Axes.Both; - Origin = Anchor.Centre; - Anchor = Anchor.Centre; - Children = new Drawable[] { content = new Container diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 64d0d628f0..a99ce89a36 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -161,11 +161,15 @@ namespace osu.Game.Overlays { prevButton = new IconButton { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, Action = prev, Icon = FontAwesome.fa_step_backward, }, playButton = new IconButton { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, Scale = new Vector2(1.4f), IconScale = new Vector2(1.4f), Action = play, @@ -173,6 +177,8 @@ namespace osu.Game.Overlays }, nextButton = new IconButton { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, Action = next, Icon = FontAwesome.fa_step_forward, }, From d7fb59ee0e84c8583b6808b1ae3e1824ffbea624 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Oct 2017 17:20:23 +0900 Subject: [PATCH 2/7] Expose colours of IconButton --- osu.Game/Graphics/UserInterface/IconButton.cs | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/IconButton.cs b/osu.Game/Graphics/UserInterface/IconButton.cs index 956fac279f..9f3f5096a2 100644 --- a/osu.Game/Graphics/UserInterface/IconButton.cs +++ b/osu.Game/Graphics/UserInterface/IconButton.cs @@ -15,9 +15,10 @@ namespace osu.Game.Graphics.UserInterface { public class IconButton : OsuClickableContainer { - private readonly SpriteIcon icon; - private readonly Box hover; - private readonly Container content; + private const float button_size = 30; + + public Color4 FlashColour; + public Color4 NormalColour; public FontAwesome Icon { @@ -25,15 +26,28 @@ namespace osu.Game.Graphics.UserInterface set { icon.Icon = value; } } - private const float button_size = 30; - private Color4 flashColour; - public Vector2 IconScale { get { return icon.Scale; } set { icon.Scale = value; } } + public Vector2 ButtonSize + { + get { return content.Size; } + set { content.Size = value; } + } + + public Color4 HoverColour + { + get { return hover.Colour; } + set { hover.Colour = value; } + } + + private readonly Container content; + private readonly SpriteIcon icon; + private readonly Box hover; + public IconButton() { AutoSizeAxes = Axes.Both; @@ -45,7 +59,6 @@ namespace osu.Game.Graphics.UserInterface Origin = Anchor.Centre, Anchor = Anchor.Centre, Size = new Vector2(button_size), - CornerRadius = 5, Masking = true, EdgeEffect = new EdgeEffectParameters @@ -75,8 +88,8 @@ namespace osu.Game.Graphics.UserInterface [BackgroundDependencyLoader] private void load(OsuColour colours) { - hover.Colour = colours.Yellow.Opacity(0.6f); - flashColour = colours.Yellow; + HoverColour = colours.Yellow.Opacity(0.6f); + FlashColour = colours.Yellow; Enabled.ValueChanged += enabled => this.FadeColour(enabled ? Color4.White : colours.Gray9, 200, Easing.OutQuint); } @@ -95,7 +108,7 @@ namespace osu.Game.Graphics.UserInterface protected override bool OnClick(InputState state) { - hover.FlashColour(flashColour, 800, Easing.OutQuint); + hover.FlashColour(FlashColour, 800, Easing.OutQuint); return base.OnClick(state); } From bbd1a7059e0785b5693cce921205fcbec4c5ae6a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Oct 2017 17:25:39 +0900 Subject: [PATCH 3/7] xmldoc + hook up IconColour --- osu.Game/Graphics/UserInterface/IconButton.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/IconButton.cs b/osu.Game/Graphics/UserInterface/IconButton.cs index 9f3f5096a2..5e5bfad662 100644 --- a/osu.Game/Graphics/UserInterface/IconButton.cs +++ b/osu.Game/Graphics/UserInterface/IconButton.cs @@ -17,27 +17,51 @@ namespace osu.Game.Graphics.UserInterface { private const float button_size = 30; + /// + /// The colour that should be flashed when the is clicked. + /// public Color4 FlashColour; - public Color4 NormalColour; + /// + /// The icon colour. This does not affect . + /// + public Color4 IconColour + { + get { return icon.Colour; } + set { icon.Colour = value; } + } + + /// + /// The icon. + /// public FontAwesome Icon { get { return icon.Icon; } set { icon.Icon = value; } } + /// + /// The icon scale. This does not affect . + /// public Vector2 IconScale { get { return icon.Scale; } set { icon.Scale = value; } } + /// + /// The size of the while it is not being pressed. + /// public Vector2 ButtonSize { get { return content.Size; } set { content.Size = value; } } + /// + /// The background colour of the while it is hovered. + /// + /// public Color4 HoverColour { get { return hover.Colour; } From 44141a38b8579cc0e5a9571ad60dac1bf8ba6ff5 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Oct 2017 18:04:41 +0900 Subject: [PATCH 4/7] Make it possible to change colours before load() --- osu.Game/Graphics/UserInterface/IconButton.cs | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/IconButton.cs b/osu.Game/Graphics/UserInterface/IconButton.cs index 5e5bfad662..099423938a 100644 --- a/osu.Game/Graphics/UserInterface/IconButton.cs +++ b/osu.Game/Graphics/UserInterface/IconButton.cs @@ -17,10 +17,15 @@ namespace osu.Game.Graphics.UserInterface { private const float button_size = 30; + private Color4? flashColour; /// /// The colour that should be flashed when the is clicked. /// - public Color4 FlashColour; + public Color4 FlashColour + { + get { return flashColour ?? Color4.White; } + set { flashColour = value; } + } /// /// The icon colour. This does not affect . @@ -31,6 +36,20 @@ namespace osu.Game.Graphics.UserInterface set { icon.Colour = value; } } + private Color4? hoverColour; + /// + /// The background colour of the while it is hovered. + /// + public Color4 HoverColour + { + get { return hoverColour ?? Color4.White; } + set + { + hoverColour = value; + hover.Colour = value; + } + } + /// /// The icon. /// @@ -58,16 +77,6 @@ namespace osu.Game.Graphics.UserInterface set { content.Size = value; } } - /// - /// The background colour of the while it is hovered. - /// - /// - public Color4 HoverColour - { - get { return hover.Colour; } - set { hover.Colour = value; } - } - private readonly Container content; private readonly SpriteIcon icon; private readonly Box hover; @@ -112,8 +121,11 @@ namespace osu.Game.Graphics.UserInterface [BackgroundDependencyLoader] private void load(OsuColour colours) { - HoverColour = colours.Yellow.Opacity(0.6f); - FlashColour = colours.Yellow; + if (hoverColour == null) + hoverColour = colours.Yellow.Opacity(0.6f); + + if (flashColour == null) + flashColour = colours.Yellow; Enabled.ValueChanged += enabled => this.FadeColour(enabled ? Color4.White : colours.Gray9, 200, Easing.OutQuint); } From 071b1b049cebedee6844a97d37cf7e150c6a5989 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Oct 2017 18:31:56 +0900 Subject: [PATCH 5/7] Fix properties not being set leading to colours not being set --- osu.Game/Graphics/UserInterface/IconButton.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/IconButton.cs b/osu.Game/Graphics/UserInterface/IconButton.cs index 099423938a..d58f5797a3 100644 --- a/osu.Game/Graphics/UserInterface/IconButton.cs +++ b/osu.Game/Graphics/UserInterface/IconButton.cs @@ -122,10 +122,10 @@ namespace osu.Game.Graphics.UserInterface private void load(OsuColour colours) { if (hoverColour == null) - hoverColour = colours.Yellow.Opacity(0.6f); + HoverColour = colours.Yellow.Opacity(0.6f); if (flashColour == null) - flashColour = colours.Yellow; + FlashColour = colours.Yellow; Enabled.ValueChanged += enabled => this.FadeColour(enabled ? Color4.White : colours.Gray9, 200, Easing.OutQuint); } From c2f3c0e6df60ef5579867d631cef16996eba467a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Oct 2017 18:32:09 +0900 Subject: [PATCH 6/7] Add TestCaseIconButton to demonstrate IconButton usages --- osu.Game/Tests/Visual/TestCaseIconButton.cs | 110 ++++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 2 files changed, 111 insertions(+) create mode 100644 osu.Game/Tests/Visual/TestCaseIconButton.cs diff --git a/osu.Game/Tests/Visual/TestCaseIconButton.cs b/osu.Game/Tests/Visual/TestCaseIconButton.cs new file mode 100644 index 0000000000..7fe2eb01f0 --- /dev/null +++ b/osu.Game/Tests/Visual/TestCaseIconButton.cs @@ -0,0 +1,110 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Testing; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Tests.Visual +{ + public class TestCaseIconButton : OsuTestCase + { + public override string Description => "Various display modes of icon buttons"; + + public TestCaseIconButton() + { + Child = new FillFlowContainer + { + RelativeSizeAxes = Axes.Both, + Spacing = new Vector2(10, 10), + Children = new[] + { + new NamedIconButton("No change", new IconButton()), + new NamedIconButton("Green colours", new IconButton + { + IconColour = Color4.LightGreen, + FlashColour = Color4.DarkGreen, + HoverColour = Color4.Green + }), + new NamedIconButton("Full-width", new IconButton { ButtonSize = new Vector2(200, 30) }), + new NamedIconButton("Unchanging size", new IconButton(), false) + } + }; + } + + private class NamedIconButton : Container + { + public NamedIconButton(string name, IconButton button, bool allowSizeChange = true) + { + AutoSizeAxes = Axes.Y; + Width = 200; + + Container iconContainer; + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + Alpha = 0.5f, + }, + new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 10), + Children = new Drawable[] + { + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = name + }, + new Container + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.1f, + }, + iconContainer = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Child = button + } + } + } + } + } + }; + + if (allowSizeChange) + iconContainer.AutoSizeAxes = Axes.Both; + else + { + iconContainer.RelativeSizeAxes = Axes.X; + iconContainer.Height = 30; + } + + button.Anchor = Anchor.Centre; + button.Origin = Anchor.Centre; + button.Icon = FontAwesome.fa_osu_osu_o; + } + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index ff5c492fc7..81f360f640 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -759,6 +759,7 @@ + From 8cea875f5fe830f654462d9ce24f057af8d04494 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Oct 2017 18:35:30 +0900 Subject: [PATCH 7/7] Remove unused using --- osu.Game/Tests/Visual/TestCaseIconButton.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Tests/Visual/TestCaseIconButton.cs b/osu.Game/Tests/Visual/TestCaseIconButton.cs index 7fe2eb01f0..bec8f8314b 100644 --- a/osu.Game/Tests/Visual/TestCaseIconButton.cs +++ b/osu.Game/Tests/Visual/TestCaseIconButton.cs @@ -6,7 +6,6 @@ using OpenTK.Graphics; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Framework.Testing; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface;