mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 10:22:54 +08:00
Make video sprites flippable and vector-scalable to fix type constraint errors
Stable supports these on videos already from a quick read on code (since videos are generally a subclass of sprites).
This commit is contained in:
parent
4ffeb5b469
commit
6d6f165884
@ -1,11 +1,16 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Graphics.Video;
|
using osu.Framework.Graphics.Video;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Storyboards.Drawables
|
namespace osu.Game.Storyboards.Drawables
|
||||||
{
|
{
|
||||||
@ -13,7 +18,7 @@ namespace osu.Game.Storyboards.Drawables
|
|||||||
{
|
{
|
||||||
public readonly StoryboardVideo Video;
|
public readonly StoryboardVideo Video;
|
||||||
|
|
||||||
private Video? drawableVideo;
|
private DrawableVideo? drawableVideo;
|
||||||
|
|
||||||
public override bool RemoveWhenNotAlive => false;
|
public override bool RemoveWhenNotAlive => false;
|
||||||
|
|
||||||
@ -42,7 +47,7 @@ namespace osu.Game.Storyboards.Drawables
|
|||||||
if (stream == null)
|
if (stream == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
InternalChild = drawableVideo = new Video(stream, false)
|
InternalChild = drawableVideo = new DrawableVideo(stream, false)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = RelativeSizeAxes,
|
RelativeSizeAxes = RelativeSizeAxes,
|
||||||
FillMode = FillMode.Fill,
|
FillMode = FillMode.Fill,
|
||||||
@ -70,5 +75,65 @@ namespace osu.Game.Storyboards.Drawables
|
|||||||
drawableVideo.FadeOut(500);
|
drawableVideo.FadeOut(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private partial class DrawableVideo : Video, IFlippable, IVectorScalable
|
||||||
|
{
|
||||||
|
private bool flipH;
|
||||||
|
|
||||||
|
public bool FlipH
|
||||||
|
{
|
||||||
|
get => flipH;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (flipH == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
flipH = value;
|
||||||
|
Invalidate(Invalidation.MiscGeometry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool flipV;
|
||||||
|
|
||||||
|
public bool FlipV
|
||||||
|
{
|
||||||
|
get => flipV;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (flipV == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
flipV = value;
|
||||||
|
Invalidate(Invalidation.MiscGeometry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector2 vectorScale = Vector2.One;
|
||||||
|
|
||||||
|
public Vector2 VectorScale
|
||||||
|
{
|
||||||
|
get => vectorScale;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (vectorScale == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!Validation.IsFinite(value)) throw new ArgumentException($@"{nameof(VectorScale)} must be finite, but is {value}.");
|
||||||
|
|
||||||
|
vectorScale = value;
|
||||||
|
Invalidate(Invalidation.MiscGeometry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Vector2 DrawScale
|
||||||
|
=> new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y) * VectorScale;
|
||||||
|
|
||||||
|
public override Anchor Origin => StoryboardExtensions.AdjustOrigin(base.Origin, VectorScale, FlipH, FlipV);
|
||||||
|
|
||||||
|
public DrawableVideo(Stream stream, bool startAtCurrentTime = true)
|
||||||
|
: base(stream, startAtCurrentTime)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user