mirror of
https://github.com/ppy/osu.git
synced 2024-11-14 10:57:30 +08:00
91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using System.Linq;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Lines;
|
|
using osu.Framework.Graphics.Shapes;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
using OpenTK;
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components
|
|
{
|
|
public class ControlPointPiece : CompositeDrawable
|
|
{
|
|
private readonly Slider slider;
|
|
private readonly int index;
|
|
|
|
private readonly Path path;
|
|
private readonly CircularContainer marker;
|
|
|
|
[Resolved]
|
|
private OsuColour colours { get; set; }
|
|
|
|
public ControlPointPiece(Slider slider, int index)
|
|
{
|
|
this.slider = slider;
|
|
this.index = index;
|
|
|
|
Origin = Anchor.Centre;
|
|
Size = new Vector2(10);
|
|
|
|
InternalChildren = new Drawable[]
|
|
{
|
|
path = new SmoothPath
|
|
{
|
|
BypassAutoSizeAxes = Axes.Both,
|
|
Anchor = Anchor.Centre,
|
|
PathWidth = 1
|
|
},
|
|
marker = new CircularContainer
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Masking = true,
|
|
Child = new Box { RelativeSizeAxes = Axes.Both }
|
|
}
|
|
};
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
Position = slider.StackedPosition + slider.ControlPoints[index];
|
|
|
|
marker.Colour = segmentSeparator ? colours.Red : colours.Yellow;
|
|
|
|
path.ClearVertices();
|
|
|
|
if (index != slider.ControlPoints.Length - 1)
|
|
{
|
|
path.AddVertex(Vector2.Zero);
|
|
path.AddVertex(slider.ControlPoints[index + 1] - slider.ControlPoints[index]);
|
|
}
|
|
|
|
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
|
}
|
|
|
|
protected override bool OnDragStart(DragStartEvent e) => true;
|
|
|
|
protected override bool OnDrag(DragEvent e)
|
|
{
|
|
var newControlPoints = slider.ControlPoints.ToArray();
|
|
newControlPoints[index] += e.Delta;
|
|
|
|
slider.ControlPoints = newControlPoints;
|
|
|
|
return true;
|
|
}
|
|
|
|
protected override bool OnDragEnd(DragEndEvent e) => true;
|
|
|
|
private bool segmentSeparator => index != 0 && index != slider.ControlPoints.Length - 1
|
|
&& slider.ControlPoints[index - 1] != slider.ControlPoints[index]
|
|
&& slider.ControlPoints[index + 1] != slider.ControlPoints[index];
|
|
}
|
|
}
|