2019-01-24 16:43:03 +08: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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Display an icon that is forced to scale to the size of this container.
|
|
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class ConstrainedIconContainer : CompositeDrawable
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
public Drawable Icon
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => InternalChild;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-02-28 12:58:19 +08:00
|
|
|
|
set => InternalChild = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines an edge effect of this <see cref="Container"/>.
|
|
|
|
|
/// Edge effects are e.g. glow or a shadow.
|
|
|
|
|
/// Only has an effect when <see cref="CompositeDrawable.Masking"/> is true.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public new EdgeEffectParameters EdgeEffect
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => base.EdgeEffect;
|
|
|
|
|
set => base.EdgeEffect = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (InternalChildren.Count > 0 && InternalChild.DrawSize.X > 0)
|
|
|
|
|
{
|
|
|
|
|
// We're modifying scale here for a few reasons
|
|
|
|
|
// - Guarantees correctness if BorderWidth is being used
|
|
|
|
|
// - If we were to use RelativeSize/FillMode, we'd need to set the Icon's RelativeSizeAxes directly.
|
|
|
|
|
// We can't do this because we would need access to AutoSizeAxes to set it to none.
|
|
|
|
|
// Other issues come up along the way too, so it's not a good solution.
|
2021-10-27 12:04:41 +08:00
|
|
|
|
float fitScale = Math.Min(DrawSize.X / InternalChild.DrawSize.X, DrawSize.Y / InternalChild.DrawSize.Y);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
InternalChild.Scale = new Vector2(fitScale);
|
|
|
|
|
InternalChild.Anchor = Anchor.Centre;
|
|
|
|
|
InternalChild.Origin = Anchor.Centre;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ConstrainedIconContainer()
|
|
|
|
|
{
|
|
|
|
|
Masking = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|