2021-05-26 12:22:21 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// 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 14:09:00 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-05-26 12:22:21 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Wiki.Markdown
|
|
|
|
{
|
|
|
|
public class WikiMarkdownImageBlock : FillFlowContainer
|
|
|
|
{
|
|
|
|
[Resolved]
|
2021-07-16 09:26:15 +00:00
|
|
|
private IMarkdownTextFlowComponent parentFlowComponent { get; set; }
|
2021-05-26 12:22:21 +00: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 09:26:15 +00:00
|
|
|
MarkdownTextFlowContainer textFlow;
|
|
|
|
|
2021-05-26 12:22:21 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-06-28 13:55:40 +00:00
|
|
|
new BlockMarkdownImage(linkInline),
|
2021-07-16 09:26:15 +00:00
|
|
|
textFlow = parentFlowComponent.CreateTextFlow().With(t =>
|
2021-05-26 12:22:21 +00:00
|
|
|
{
|
|
|
|
t.Anchor = Anchor.TopCentre;
|
|
|
|
t.Origin = Anchor.TopCentre;
|
2021-07-16 09:26:15 +00:00
|
|
|
t.TextAnchor = Anchor.TopCentre;
|
2021-05-26 12:22:21 +00:00
|
|
|
}),
|
|
|
|
};
|
2021-07-16 09:26:15 +00:00
|
|
|
|
|
|
|
textFlow.AddText(linkInline.Title);
|
2021-05-26 12:22:21 +00:00
|
|
|
}
|
2021-06-28 13:55:40 +00:00
|
|
|
|
|
|
|
private class BlockMarkdownImage : WikiMarkdownImage
|
|
|
|
{
|
|
|
|
public BlockMarkdownImage(LinkInline linkInline)
|
|
|
|
: base(linkInline)
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
}
|
2021-06-28 14:04:56 +00:00
|
|
|
|
|
|
|
protected override ImageContainer CreateImageContainer(string url) => new BlockImageContainer(url);
|
|
|
|
|
|
|
|
private class BlockImageContainer : ImageContainer
|
|
|
|
{
|
|
|
|
public BlockImageContainer(string url)
|
|
|
|
: base(url)
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
}
|
2021-06-28 14:09:00 +00:00
|
|
|
|
2021-06-29 12:28:21 +00:00
|
|
|
protected override Sprite CreateImageSprite() => new ImageSprite();
|
2021-06-29 02:49:45 +00:00
|
|
|
|
|
|
|
private class ImageSprite : Sprite
|
2021-06-28 14:09:00 +00:00
|
|
|
{
|
2021-06-29 02:49:45 +00:00
|
|
|
public ImageSprite()
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre;
|
|
|
|
Origin = Anchor.TopCentre;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (Width > Parent.DrawWidth)
|
|
|
|
{
|
|
|
|
float ratio = Height / Width;
|
|
|
|
Width = Parent.DrawWidth;
|
|
|
|
Height = ratio * Width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-28 14:04:56 +00:00
|
|
|
}
|
2021-06-28 13:55:40 +00:00
|
|
|
}
|
2021-05-26 12:22:21 +00:00
|
|
|
}
|
|
|
|
}
|