<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using OpenTK;

namespace osu.Game.Overlays
{
    public class DragBar : Container
    {
        protected readonly Container Fill;

        public Action<float> SeekRequested;

        public bool IsSeeking { get; private set; }

        private bool enabled = true;
        public bool IsEnabled
        {
            get { return enabled; }
            set
            {
                enabled = value;
                if (!enabled)
                    Fill.Width = 0;
            }
        }

        public DragBar()
        {
            RelativeSizeAxes = Axes.X;

            Children = new Drawable[]
            {
                Fill = new Container
                {
                    Name = "FillContainer",
                    Origin = Anchor.BottomLeft,
                    Anchor = Anchor.BottomLeft,
                    RelativeSizeAxes = Axes.Both,
                    Width = 0,
                    Children = new Drawable[]
                    {
                        new Box
                        {
                            RelativeSizeAxes = Axes.Both
                        }
                    }
                }
            };
        }

        public void UpdatePosition(float position)
        {
            if (IsSeeking || !IsEnabled) return;

            updatePosition(position);
        }

        private void seek(InputState state)
        {
            float seekLocation = state.Mouse.Position.X / DrawWidth;

            if (!IsEnabled) return;

            SeekRequested?.Invoke(seekLocation);
            updatePosition(seekLocation);
        }

        private void updatePosition(float position)
        {
            position = MathHelper.Clamp(position, 0, 1);
            Fill.TransformTo(() => Fill.Width, position, 200, EasingTypes.OutQuint, new TransformSeek());
        }

        protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
        {
            seek(state);
            return true;
        }

        protected override bool OnDrag(InputState state)
        {
            seek(state);
            return true;
        }

        protected override bool OnDragStart(InputState state) => IsSeeking = true;

        protected override bool OnDragEnd(InputState state)
        {
            IsSeeking = false;
            return true;
        }

        private class TransformSeek : TransformFloat
        {<commit_msg>Fix unsynchronised tweening.<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using OpenTK;

namespace osu.Game.Overlays
{
    public class DragBar : Container
    {
        protected readonly Container Fill;

        public Action<float> SeekRequested;

        public bool IsSeeking { get; private set; }

        private bool enabled = true;
        public bool IsEnabled
        {
            get { return enabled; }
            set
            {
                enabled = value;
                if (!enabled)
                    Fill.Width = 0;
            }
        }

        public DragBar()
        {
            RelativeSizeAxes = Axes.X;

            Children = new Drawable[]
            {
                Fill = new Container
                {
                    Name = "FillContainer",
                    Origin = Anchor.BottomLeft,
                    Anchor = Anchor.BottomLeft,
                    RelativeSizeAxes = Axes.Both,
                    Width = 0,
                    Children = new Drawable[]
                    {
                        new Box
                        {
                            RelativeSizeAxes = Axes.Both
                        }
                    }
                }
            };
        }

        public void UpdatePosition(float position)
        {
            if (IsSeeking || !IsEnabled) return;

            updatePosition(position, false);
        }

        private void seek(InputState state)
        {
            float seekLocation = state.Mouse.Position.X / DrawWidth;

            if (!IsEnabled) return;

            SeekRequested?.Invoke(seekLocation);
            updatePosition(seekLocation);
        }

        private void updatePosition(float position, bool easing = true)
        {
            position = MathHelper.Clamp(position, 0, 1);
            Fill.TransformTo(() => Fill.Width, position, easing ? 200 : 0, EasingTypes.OutQuint, new TransformSeek());
        }

        protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
        {
            seek(state);
            return true;
        }

        protected override bool OnDrag(InputState state)
        {
            seek(state);
            return true;
        }

        protected override bool OnDragStart(InputState state) => IsSeeking = true;

        protected override bool OnDragEnd(InputState state)
        {
            IsSeeking = false;
            return true;
        }

        private class TransformSeek : TransformFloat
        {
{'fraction_non_alphanumeric': 0.0762484338643279, 'fraction_numerical': 0.005548594952568463, 'mean_word_length': 1.3829424307036247, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5421896', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1329, 'n_words': 340}