// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Input.Bindings; using osu.Framework.Threading; namespace osu.Game.Extensions { public static class DrawableExtensions { public const double REPEAT_INTERVAL = 70; public const double INITIAL_DELAY = 250; /// /// Helper method that is used while doesn't support repetitions of . /// Simulates repetitions by continually invoking a delegate according to the default key repeat rate. /// /// /// The returned delegate can be cancelled to stop repeat events from firing (usually in ). /// /// The which is handling the repeat. /// The to schedule repetitions on. /// The to be invoked once immediately and with every repetition. /// The delay imposed on the first repeat. Defaults to . /// A which can be cancelled to stop the repeat events from firing. public static ScheduledDelegate BeginKeyRepeat(this IKeyBindingHandler handler, Scheduler scheduler, Action action, double initialRepeatDelay = INITIAL_DELAY) { action(); ScheduledDelegate repeatDelegate = new ScheduledDelegate(action, handler.Time.Current + initialRepeatDelay, REPEAT_INTERVAL); scheduler.Add(repeatDelegate); return repeatDelegate; } } }