1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 07:02:54 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs

62 lines
1.7 KiB
C#
Raw Normal View History

2018-05-22 21:41:10 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-06-19 19:19:52 +08:00
using osu.Framework.Platform;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public class ExternalLinkButton : CompositeDrawable, IHasTooltip
{
public string Link { get; set; }
private Color4 hoverColour;
2018-06-19 19:19:52 +08:00
private GameHost host;
public ExternalLinkButton(string link = null)
{
Link = link;
Size = new Vector2(12);
InternalChild = new SpriteIcon
{
Icon = FontAwesome.fa_external_link,
RelativeSizeAxes = Axes.Both
};
}
[BackgroundDependencyLoader]
2018-06-19 19:19:52 +08:00
private void load(OsuColour colours, GameHost host)
{
hoverColour = colours.Yellow;
2018-06-19 19:19:52 +08:00
this.host = host;
}
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
{
InternalChild.FadeColour(hoverColour, 500, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
return base.OnHover(e);
}
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost(HoverLostEvent e)
{
InternalChild.FadeColour(Color4.White, 500, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
base.OnHoverLost(e);
}
2018-10-02 11:02:47 +08:00
protected override bool OnClick(ClickEvent e)
{
if(Link != null)
2018-06-19 19:19:52 +08:00
host.OpenUrlExternally(Link);
return true;
}
public string TooltipText => "View in browser";
}
}