1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:07:23 +08:00

Better masking.

This commit is contained in:
smoogipooo 2017-04-12 14:34:49 +09:00
parent 04baa9eb72
commit 5d5040ee73
2 changed files with 26 additions and 35 deletions

View File

@ -4,6 +4,7 @@
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.MathUtils;
using osu.Framework.Testing;
using osu.Framework.Timing;
@ -63,7 +64,12 @@ namespace osu.Desktop.VisualTests.Tests
Clock = new FramedClock(rateAdjustClock),
Children = new[]
{
playfield = new TaikoPlayfield()
playfield = new TaikoPlayfield
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Height = 0.75f
}
}
});
}

View File

@ -53,6 +53,8 @@ namespace osu.Game.Modes.Taiko.UI
public TaikoPlayfield()
{
Masking = true;
AddInternal(new Drawable[]
{
rightBackgroundContainer = new Container
@ -112,11 +114,9 @@ namespace osu.Game.Modes.Taiko.UI
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
},
hitObjectContainer = new ExternalMaskingRectangleContainer
hitObjectContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
MaskingReference = () => this
},
judgementContainer = new Container<DrawableTaikoJudgement>
{
@ -222,6 +222,22 @@ namespace osu.Game.Modes.Taiko.UI
hitExplosionContainer.Children.FirstOrDefault(e => e.Judgement == judgedObject.Judgement)?.VisualiseSecondHit();
}
protected override void ApplyDrawNode(DrawNode node)
{
base.ApplyDrawNode(node);
var cn = node as ContainerDrawNode;
if (!Masking)
return;
MaskingInfo old = cn.MaskingInfo.Value;
old.MaskingRect = new RectangleF(old.MaskingRect.X, old.MaskingRect.Y - 2000, old.MaskingRect.Width, old.MaskingRect.Height + 4000);
old.ScreenSpaceAABB = new System.Drawing.Rectangle(old.ScreenSpaceAABB.X, old.ScreenSpaceAABB.Y - 2000, old.ScreenSpaceAABB.Width, old.ScreenSpaceAABB.Height + 4000);
cn.MaskingInfo = old;
}
/// <summary>
/// This is a very special type of container. It serves a similar purpose to <see cref="FillMode.Fit"/>, however unlike <see cref="FillMode.Fit"/>,
/// this will only adjust the scale relative to the height of its parent and will maintain the original width relative to its parent.
@ -272,36 +288,5 @@ namespace osu.Game.Modes.Taiko.UI
}
}
}
private class ExternalMaskingRectangleContainer : Container
{
public Func<Drawable> MaskingReference;
protected override void ApplyDrawNode(DrawNode node)
{
base.ApplyDrawNode(node);
Drawable maskingReference = MaskingReference?.Invoke();
if (MaskingReference == null)
return;
var cn = node as ContainerDrawNode;
cn.MaskingInfo = !Masking
? (MaskingInfo?)null
: new MaskingInfo
{
ScreenSpaceAABB = maskingReference.ScreenSpaceDrawQuad.AABB,
MaskingRect = maskingReference.DrawRectangle,
ToMaskingSpace = cn.MaskingInfo.Value.ToMaskingSpace,
CornerRadius = cn.MaskingInfo.Value.CornerRadius,
BorderThickness = cn.MaskingInfo.Value.BorderThickness,
BorderColour = cn.MaskingInfo.Value.BorderColour,
BlendRange = cn.MaskingInfo.Value.BlendRange,
AlphaExponent = cn.MaskingInfo.Value.AlphaExponent
};
}
}
}
}