2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2021-05-26 20:22:21 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using Markdig.Syntax.Inlines;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
2021-06-28 22:09:00 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-05-26 20:22:21 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Wiki.Markdown
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class WikiMarkdownImageBlock : FillFlowContainer
|
2021-05-26 20:22:21 +08:00
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
2023-06-23 00:37:25 +08:00
|
|
|
|
private IMarkdownTextFlowComponent parentFlowComponent { get; set; } = null!;
|
2021-05-26 20:22:21 +08:00
|
|
|
|
|
|
|
|
|
private readonly LinkInline linkInline;
|
|
|
|
|
|
|
|
|
|
public WikiMarkdownImageBlock(LinkInline linkInline)
|
|
|
|
|
{
|
|
|
|
|
this.linkInline = linkInline;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
|
Spacing = new Vector2(0, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2021-07-16 17:26:15 +08:00
|
|
|
|
MarkdownTextFlowContainer textFlow;
|
|
|
|
|
|
2021-05-26 20:22:21 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-06-28 21:55:40 +08:00
|
|
|
|
new BlockMarkdownImage(linkInline),
|
2021-07-16 17:26:15 +08:00
|
|
|
|
textFlow = parentFlowComponent.CreateTextFlow().With(t =>
|
2021-05-26 20:22:21 +08:00
|
|
|
|
{
|
|
|
|
|
t.Anchor = Anchor.TopCentre;
|
|
|
|
|
t.Origin = Anchor.TopCentre;
|
2021-07-16 17:26:15 +08:00
|
|
|
|
t.TextAnchor = Anchor.TopCentre;
|
2021-05-26 20:22:21 +08:00
|
|
|
|
}),
|
|
|
|
|
};
|
2021-07-16 17:26:15 +08:00
|
|
|
|
|
|
|
|
|
textFlow.AddText(linkInline.Title);
|
2021-05-26 20:22:21 +08:00
|
|
|
|
}
|
2021-06-28 21:55:40 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class BlockMarkdownImage : WikiMarkdownImage
|
2021-06-28 21:55:40 +08:00
|
|
|
|
{
|
|
|
|
|
public BlockMarkdownImage(LinkInline linkInline)
|
|
|
|
|
: base(linkInline)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
}
|
2021-06-28 22:04:56 +08:00
|
|
|
|
|
|
|
|
|
protected override ImageContainer CreateImageContainer(string url) => new BlockImageContainer(url);
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class BlockImageContainer : ImageContainer
|
2021-06-28 22:04:56 +08:00
|
|
|
|
{
|
|
|
|
|
public BlockImageContainer(string url)
|
|
|
|
|
: base(url)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
}
|
2021-06-28 22:09:00 +08:00
|
|
|
|
|
2021-06-29 20:28:21 +08:00
|
|
|
|
protected override Sprite CreateImageSprite() => new ImageSprite();
|
2021-06-29 10:49:45 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class ImageSprite : Sprite
|
2021-06-28 22:09:00 +08:00
|
|
|
|
{
|
2021-06-29 10:49:45 +08:00
|
|
|
|
public ImageSprite()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre;
|
|
|
|
|
Origin = Anchor.TopCentre;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2023-10-17 16:40:44 +08:00
|
|
|
|
if (Width > Parent!.DrawWidth)
|
2021-06-29 10:49:45 +08:00
|
|
|
|
{
|
|
|
|
|
float ratio = Height / Width;
|
2023-10-17 16:40:44 +08:00
|
|
|
|
Width = Parent!.DrawWidth;
|
2021-06-29 10:49:45 +08:00
|
|
|
|
Height = ratio * Width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-28 22:04:56 +08:00
|
|
|
|
}
|
2021-06-28 21:55:40 +08:00
|
|
|
|
}
|
2021-05-26 20:22:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|