<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
    public class TimelineHitObjectBlueprint : SelectionBlueprint
    {
        private readonly Circle circle;

        [UsedImplicitly]
        private readonly Bindable<double> startTime;

        public Action<DragEvent> OnDragHandled;

        private readonly DragBar dragBar;

        private readonly List<Container> shadowComponents = new List<Container>();

        private const float thickness = 5;

        private const float shadow_radius = 5;

        private const float circle_size = 16;

        public TimelineHitObjectBlueprint(HitObject hitObject)
            : base(hitObject)
        {
            Anchor = Anchor.CentreLeft;
            Origin = Anchor.CentreLeft;

            startTime = hitObject.StartTimeBindable.GetBoundCopy();
            startTime.BindValueChanged(time => X = (float)time.NewValue, true);

            RelativePositionAxes = Axes.X;

            RelativeSizeAxes = Axes.X;
            AutoSizeAxes = Axes.Y;

            circle = new Circle
            {
                Size = new Vector2(circle_size),
                Anchor = Anchor.CentreLeft,
                Origin = Anchor.Centre,
                RelativePositionAxes = Axes.X,
                AlwaysPresent = true,
                Colour = Color4.White,
                EdgeEffect = new EdgeEffectParameters
                {
                    Type = EdgeEffectType.Shadow,
                    Radius = shadow_radius,
                    Colour = Color4.Black
                },
            };

            shadowComponents.Add(circle);

            if (hitObject is IHasDuration)
            {
                DragBar dragBarUnderlay;
                Container extensionBar;

                AddRangeInternal(new Drawable[]
                {
                    extensionBar = new Container
                    {
                        Masking = true,
                        Size = new Vector2(1, thickness),
                        Anchor = Anchor.CentreLeft,
                        Origin = Anchor.CentreLeft,
                        RelativePositionAxes = Axes.X,
                        RelativeSizeAxes = Axes.X,
                        EdgeEffect = new EdgeEffectParameters
                        {
                            Type = EdgeEffectType.Shadow,
                            Radius = shadow_radius,
                            Colour = Color4.Black
                        },
                        Child = new Box
                        {
                            RelativeSizeAxes = Axes.Both,
                        }
                    },
                    circle,
                    // only used for drawing the shadow
                    dragBarUnderlay = new DragBar(null),
                    // cover up the shadow on the join
                    new Box
                    {
                        Height = thickness,
                        Anchor = Anchor.CentreLeft,
                        Origin = Anchor.CentreLeft,
                        RelativeSizeAxes = Axes.X,
                    },
                    dragBar = new DragBar(hitObject) { OnDragHandled = e => OnDragHandled?.Invoke(e) },
                });

                shadowComponents.Add(dragBarUnderlay);
                shadowComponents.Add(extensionBar);
            }
            else
            {
                AddInternal(circle);
            }

            updateShadows();
        }

        protected override void Update()
        {
            base.Update();

            // no bindable so we perform this every update
            Width = (float)(HitObject.GetEndTime() - HitObject.StartTime);<commit_msg>Add combo colour display support<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
    public class TimelineHitObjectBlueprint : SelectionBlueprint
    {
        private readonly Circle circle;

        [UsedImplicitly]
        private readonly Bindable<double> startTime;

        public Action<DragEvent> OnDragHandled;

        private readonly DragBar dragBar;

        private readonly List<Container> shadowComponents = new List<Container>();

        private DrawableHitObject drawableHitObject;

        private Bindable<Color4> comboColour;

        private const float thickness = 5;

        private const float shadow_radius = 5;

        private const float circle_size = 16;

        public TimelineHitObjectBlueprint(HitObject hitObject)
            : base(hitObject)
        {
            Anchor = Anchor.CentreLeft;
            Origin = Anchor.CentreLeft;

            startTime = hitObject.StartTimeBindable.GetBoundCopy();
            startTime.BindValueChanged(time => X = (float)time.NewValue, true);

            RelativePositionAxes = Axes.X;

            RelativeSizeAxes = Axes.X;
            AutoSizeAxes = Axes.Y;

            circle = new Circle
            {
                Size = new Vector2(circle_size),
                Anchor = Anchor.CentreLeft,
                Origin = Anchor.Centre,
                RelativePositionAxes = Axes.X,
                AlwaysPresent = true,
                Colour = Color4.White,
                EdgeEffect = new EdgeEffectParameters
                {
                    Type = EdgeEffectType.Shadow,
                    Radius = shadow_radius,
                    Colour = Color4.Black
                },
            };

            shadowComponents.Add(circle);

            if (hitObject is IHasDuration)
            {
                DragBar dragBarUnderlay;
                Container extensionBar;

                AddRangeInternal(new Drawable[]
                {
                    extensionBar = new Container
                    {
                        Masking = true,
                        Size = new Vector2(1, thickness),
                        Anchor = Anchor.CentreLeft,
                        Origin = Anchor.CentreLeft,
                        RelativePositionAxes = Axes.X,
                        RelativeSizeAxes = Axes.X,
                        EdgeEffect = new EdgeEffectParameters
                        {
                            Type = EdgeEffectType.Shadow,
                            Radius = shadow_radius,
                            Colour = Color4.Black
                        },
                        Child = new Box
                        {
                            RelativeSizeAxes = Axes.Both,
                        }
                    },
                    circle,
                    // only used for drawing the shadow
                    dragBarUnderlay = new DragBar(null),
                    // cover up the shadow on the join
                    new Box
                    {
                        Height = thickness,
                        Anchor = Anchor.CentreLeft,
                        Origin = Anchor.CentreLeft,
                        RelativeSizeAxes = Axes.X,
                    },
                    dragBar = new DragBar(hitObject) { OnDragHandled = e => OnDragHandled?.Invoke(e) },
                });

                shadowComponents.Add(dragBarUnderlay);
                shadowComponents.Add(extensionBar);
            }
            else
            {
                AddInternal(circle);
            }

            updateShadows();
        }

        [BackgroundDependencyLoader(true)]
        private void load(HitObjectComposer composer)
        {
            if (composer != null)
            {
                // best effort to get the drawable representation for grabbing colour and what not.
                drawableHitObject = composer.HitObjects.FirstOrDefault(d => d.HitObject == HitObject);
            }
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();

            if (drawableHitObject != null)
            {
                comboColour = drawableHitObject.AccentColour.GetBoundCopy();
                comboColour.BindValueChanged(colour =>
                {
                    Colour = drawableHitObject.AccentColour.Value;
                }, true);
            }
        }

        protected override void Update()
        {
            base.Update();

            // no bindable so we perform this every update
            Width = (float)(HitObject.GetEndTime() - HitObject.StartTime);
{'fraction_non_alphanumeric': 0.06975554873683133, 'fraction_numerical': 0.0021478981282602025, 'mean_word_length': 1.3912937148447053, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 22, 'https://': 0, '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': '1568761', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2259, 'n_words': 536}