-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2612 from jorolf/open-external
Add icon next to beatmap title/username to open in browser
- Loading branch information
Showing
4 changed files
with
125 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. | ||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using osu.Game.Graphics.UserInterface; | ||
using OpenTK; | ||
|
||
namespace osu.Game.Tests.Visual | ||
{ | ||
public class TestCaseExternalLinkButton : OsuTestCase | ||
{ | ||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(ExternalLinkButton) }; | ||
|
||
public TestCaseExternalLinkButton() | ||
{ | ||
Child = new ExternalLinkButton("https://osu.ppy.sh/home") | ||
{ | ||
Size = new Vector2(50) | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. | ||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE | ||
|
||
using System.Diagnostics; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Cursor; | ||
using osu.Framework.Input; | ||
using OpenTK; | ||
using OpenTK.Graphics; | ||
|
||
namespace osu.Game.Graphics.UserInterface | ||
{ | ||
public class ExternalLinkButton : CompositeDrawable, IHasTooltip | ||
{ | ||
public string Link { get; set; } | ||
|
||
private Color4 hoverColour; | ||
|
||
public ExternalLinkButton(string link = null) | ||
{ | ||
Link = link; | ||
Size = new Vector2(12); | ||
InternalChild = new SpriteIcon | ||
{ | ||
Icon = FontAwesome.fa_external_link, | ||
RelativeSizeAxes = Axes.Both | ||
}; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(OsuColour colours) | ||
{ | ||
hoverColour = colours.Yellow; | ||
} | ||
|
||
protected override bool OnHover(InputState state) | ||
{ | ||
InternalChild.FadeColour(hoverColour, 500, Easing.OutQuint); | ||
return base.OnHover(state); | ||
} | ||
|
||
protected override void OnHoverLost(InputState state) | ||
{ | ||
InternalChild.FadeColour(Color4.White, 500, Easing.OutQuint); | ||
base.OnHoverLost(state); | ||
} | ||
|
||
protected override bool OnClick(InputState state) | ||
{ | ||
if(Link != null) | ||
Process.Start(new ProcessStartInfo | ||
{ | ||
FileName = Link, | ||
UseShellExecute = true //see https://github.com/dotnet/corefx/issues/10361 | ||
}); | ||
return true; | ||
} | ||
|
||
public string TooltipText => "View in browser"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters