Move new classes for now

This commit is contained in:
Dean Herbert
2019-05-17 19:15:25 +09:00
parent dbc42fd59e
commit 9bc3aa3d46
2 changed files with 0 additions and 0 deletions

View File

@ -1,86 +0,0 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// A simple rounded expandable line. Set its <see cref="Anchor"/>
/// property to the center of the edge it's meant stick with. By default,
/// takes up the full parent's axis defined by <see cref="IsHorizontal"/>.
/// </summary>
public class LineBadge : Circle
{
public float UncollapsedSize;
public float CollapsedSize;
public bool IsCollapsed { get; private set; }
private bool isHorizontal;
/// <summary>
/// Automatically sets the RelativeSizeAxes and switches X and Y size components when changed.
/// </summary>
public bool IsHorizontal
{
get => isHorizontal;
set
{
if (value == isHorizontal)
return;
if (IsLoaded)
{
FinishTransforms();
var height = Height;
var width = Width;
RelativeSizeAxes = value ? Axes.X : Axes.Y;
Width = height;
Height = width;
}
else
RelativeSizeAxes = value ? Axes.X : Axes.Y;
isHorizontal = value;
}
}
/// <param name="startCollapsed">Whether to initialize with the
/// <see cref="CollapsedSize"/> or the <see cref="UncollapsedSize"/>.</param>
public LineBadge(bool startCollapsed = true)
{
IsCollapsed = startCollapsed;
RelativeSizeAxes = Axes.X;
isHorizontal = true;
Origin = Anchor.Centre;
}
protected override void LoadComplete()
{
if (isHorizontal)
Height = IsCollapsed ? CollapsedSize : UncollapsedSize;
else
Width = IsCollapsed ? CollapsedSize : UncollapsedSize;
base.LoadComplete();
}
public void Collapse(float transitionDuration = 400, Easing easing = Easing.Out)
{
IsCollapsed = true;
if (IsHorizontal)
this.ResizeHeightTo(CollapsedSize, transitionDuration, easing);
else
this.ResizeWidthTo(CollapsedSize, transitionDuration, easing);
}
public void Uncollapse(float transitionDuration = 400, Easing easing = Easing.OutElastic)
{
IsCollapsed = false;
if (IsHorizontal)
this.ResizeHeightTo(UncollapsedSize, transitionDuration, easing);
else
this.ResizeWidthTo(UncollapsedSize, transitionDuration, easing);
}
}
}

View File

@ -1,100 +0,0 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using System;
using osu.Framework.Graphics.Sprites;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// An icon with an action upon click that can be disabled.
/// </summary>
public class TooltipIconButton : Container, IHasTooltip
{
private readonly SpriteIcon icon;
private SampleChannel sampleHover;
private SampleChannel sampleClick;
/// <summary>
/// The action to fire upon click if <see cref="IsEnabled"/> is set to true.
/// </summary>
public Action Action;
private bool isEnabled;
/// <summary>
/// If set to true, upon click the <see cref="Action"/> will execute.
/// </summary>
public bool IsEnabled
{
get => isEnabled;
set
{
isEnabled = value;
icon.FadeTo(value ? 1 : 0.5f, 250);
}
}
public IconUsage Icon
{
get => icon.Icon;
set => icon.Icon = value;
}
public TooltipIconButton()
{
isEnabled = true;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
icon = new SpriteIcon
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.8f),
}
};
}
protected override bool OnClick(ClickEvent e)
{
if (isEnabled)
{
sampleClick?.Play();
Action?.Invoke();
}
return base.OnClick(e);
}
protected override bool OnHover(HoverEvent e)
{
if (isEnabled)
sampleHover?.Play();
return base.OnHover(e);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
}
public string TooltipText { get; set; }
}
}