1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs

62 lines
1.8 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2017-01-11 02:44:40 +08:00
using osu.Game.Graphics;
namespace osu.Game.Overlays.Toolbar
{
2017-03-07 09:59:19 +08:00
internal class ToolbarOverlayToggleButton : ToolbarButton
{
private readonly Box stateBackground;
private OverlayContainer stateContainer;
public OverlayContainer StateContainer
{
get { return stateContainer; }
set
{
stateContainer = value;
Action = stateContainer.ToggleVisibility;
stateContainer.StateChanged += stateChanged;
}
}
2016-12-02 20:28:23 +08:00
public ToolbarOverlayToggleButton()
{
2017-02-07 15:15:45 +08:00
Add(stateBackground = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(150).Opacity(180),
BlendingMode = BlendingMode.Additive,
Depth = 2,
Alpha = 0,
});
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (stateContainer != null)
stateContainer.StateChanged -= stateChanged;
}
private void stateChanged(OverlayContainer c, Visibility state)
{
switch (state)
{
case Visibility.Hidden:
2017-02-07 15:15:45 +08:00
stateBackground.FadeOut(200);
break;
case Visibility.Visible:
2017-02-07 15:15:45 +08:00
stateBackground.FadeIn(200);
break;
}
}
}
}