osu/osu.Game/Graphics/UserInterface/OsuButton.cs

89 lines
2.6 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
2017-02-07 04:52:19 +00:00
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
2017-02-07 04:52:19 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
2017-02-25 12:12:39 +00:00
using osu.Framework.Graphics.Transforms;
2017-02-07 04:52:19 +00:00
using osu.Framework.Graphics.UserInterface;
2017-01-31 11:32:36 +00:00
using osu.Framework.Input;
2017-02-07 04:52:19 +00:00
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Graphics.UserInterface
{
public class OsuButton : Button
{
private Box hover;
public OsuButton()
{
Height = 40;
}
protected override SpriteText CreateText() => new OsuSpriteText
{
Depth = -1,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
2017-01-31 10:58:45 +00:00
Font = @"Exo2.0-Bold",
};
public override bool HandleInput => Action != null;
2017-02-07 04:52:19 +00:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (Action == null)
Colour = OsuColour.Gray(0.5f);
BackgroundColour = colours.BlueDark;
2017-01-31 11:32:36 +00:00
2017-02-07 04:52:19 +00:00
Content.Masking = true;
Content.CornerRadius = 5;
2017-01-31 11:32:36 +00:00
Add(new Drawable[]
{
2017-01-31 11:32:36 +00:00
new Triangles
{
RelativeSizeAxes = Axes.Both,
ColourDark = colours.BlueDarker,
ColourLight = colours.Blue,
},
hover = new Box
{
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
Colour = Color4.White.Opacity(0.1f),
Alpha = 0,
},
2017-02-07 04:52:19 +00:00
});
}
2017-01-31 11:32:36 +00:00
protected override bool OnHover(InputState state)
{
hover.FadeIn(200);
return base.OnHover(state);
2017-02-07 04:52:19 +00:00
}
2017-01-31 11:32:36 +00:00
protected override void OnHoverLost(InputState state)
{
hover.FadeOut(200);
base.OnHoverLost(state);
2017-02-07 04:52:19 +00:00
}
2017-01-31 11:32:36 +00:00
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
Content.ScaleTo(0.9f, 4000, EasingTypes.OutQuint);
return base.OnMouseDown(state, args);
2017-02-07 04:52:19 +00:00
}
2017-01-31 11:32:36 +00:00
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
Content.ScaleTo(1, 1000, EasingTypes.OutElastic);
return base.OnMouseUp(state, args);
2017-02-07 04:52:19 +00:00
}
}
2016-11-03 02:27:39 +00:00
}