// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics.Primitives; using osu.Game.Rulesets.Objects.Drawables; using OpenTK; namespace osu.Game.Rulesets.Edit.Layers.Selection { public class HitObjectCapturer { public event Action HitObjectCaptured; private readonly IEnumerable capturableHitObjects; public HitObjectCapturer(IEnumerable capturableHitObjects) { this.capturableHitObjects = capturableHitObjects; } /// /// Captures all hitobjects that are present within the area of a . /// /// The capture . /// If any s were captured. public bool CaptureQuad(Quad screenSpaceQuad) { bool anyCaptured = false; foreach (var obj in capturableHitObjects.Where(h => h.IsAlive && h.IsPresent && screenSpaceQuad.Contains(h.SelectionPoint))) { HitObjectCaptured?.Invoke(obj); anyCaptured = true; } return anyCaptured; } /// /// Captures the top-most hitobject that is present under a specific point. /// /// The to capture at. /// Whether a was captured. public bool CapturePoint(Vector2 screenSpacePoint) { var captured = capturableHitObjects.Reverse().Where(h => h.IsAlive && h.IsPresent).FirstOrDefault(h => h.ReceiveMouseInputAt(screenSpacePoint)); if (captured == null) return false; HitObjectCaptured?.Invoke(captured); return true; } } }