A game framework written with osu! in mind.
at master 84 lines 3.0 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osu.Framework.Bindables; 5using osu.Framework.Graphics.Containers; 6using osu.Framework.Graphics.Shapes; 7 8namespace osu.Framework.Graphics.UserInterface 9{ 10 /// <summary> 11 /// Control that allows for specifying a colour using the hue-saturation-value (HSV) colour model. 12 /// </summary> 13 public abstract partial class HSVColourPicker : CompositeDrawable, IHasCurrentValue<Colour4> 14 { 15 private readonly BindableWithCurrent<Colour4> current = new BindableWithCurrent<Colour4>(); 16 17 public Bindable<Colour4> Current 18 { 19 get => current.Current; 20 set => current.Current = value; 21 } 22 23 /// <summary> 24 /// The background of the control. 25 /// </summary> 26 protected Box Background { get; } 27 28 /// <summary> 29 /// Contains the elements of the colour picker. 30 /// </summary> 31 protected FillFlowContainer Content { get; } 32 33 private readonly SaturationValueSelector saturationValueSelector; 34 private readonly HueSelector hueSelector; 35 36 protected HSVColourPicker() 37 { 38 Width = 300; 39 AutoSizeAxes = Axes.Y; 40 Current.Value = Colour4.White; 41 42 InternalChildren = new Drawable[] 43 { 44 Background = new Box 45 { 46 RelativeSizeAxes = Axes.Both 47 }, 48 Content = new FillFlowContainer 49 { 50 RelativeSizeAxes = Axes.X, 51 AutoSizeAxes = Axes.Y, 52 Direction = FillDirection.Vertical, 53 Children = new Drawable[] 54 { 55 saturationValueSelector = CreateSaturationValueSelector(), 56 hueSelector = CreateHueSelector() 57 } 58 } 59 }; 60 } 61 62 /// <summary> 63 /// Creates the control to be used for interactively selecting the hue of the target colour. 64 /// </summary> 65 protected abstract HueSelector CreateHueSelector(); 66 67 /// <summary> 68 /// Creates the control to be used for interactively selecting the saturation and value of the target colour. 69 /// </summary> 70 protected abstract SaturationValueSelector CreateSaturationValueSelector(); 71 72 public override bool IsPresent => base.IsPresent 73 || saturationValueSelector.Scheduler.HasPendingTasks 74 || hueSelector.Scheduler.HasPendingTasks; 75 76 protected override void LoadComplete() 77 { 78 base.LoadComplete(); 79 80 saturationValueSelector.Current.BindTo(current); 81 hueSelector.Hue.BindTo(saturationValueSelector.Hue); 82 } 83 } 84}