// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Input; using osu.Game.Rulesets.Edit.Types; using osu.Game.Rulesets.Objects.Drawables; using OpenTK; namespace osu.Game.Rulesets.Edit { /// /// A mask placed above a adding editing functionality. /// public class HitObjectMask : VisibilityContainer { public event Action Selected; public event Action Deselected; public event Action SingleSelectionRequested; public readonly DrawableHitObject HitObject; protected override bool ShouldBeAlive => HitObject.IsAlive || State == Visibility.Visible; public override bool HandleMouseInput => true; public HitObjectMask(DrawableHitObject hitObject) { HitObject = hitObject; AlwaysPresent = true; State = Visibility.Hidden; } /// /// Selects this , causing it to become visible. /// /// True if the was selected. False if the was already selected. public bool Select() { if (State == Visibility.Visible) return false; Show(); Selected?.Invoke(this); return true; } /// /// Deselects this , causing it to become invisible. /// /// True if the was deselected. False if the was already deselected. public bool Deselect() { if (State == Visibility.Hidden) return false; Hide(); Deselected?.Invoke(this); return true; } protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { if (HitObject.IsPresent) { SingleSelectionRequested?.Invoke(this); Select(); return true; } return false; } protected override bool OnDragStart(InputState state) => true; protected override bool OnDrag(InputState state) { // Todo: Various forms of snapping switch (HitObject.HitObject) { case IHasEditablePosition editablePosition: editablePosition.OffsetPosition(state.Mouse.Delta); break; } return true; } protected override bool OnDragEnd(InputState state) => true; protected override void PopIn() => Alpha = 1; protected override void PopOut() => Alpha = 0; /// /// The screen-space point that causes this to be selected. /// public virtual Vector2 SelectionPoint => ScreenSpaceDrawQuad.Centre; /// /// The screen-space quad that outlines this for selections. /// public virtual Quad SelectionQuad => ScreenSpaceDrawQuad; } }