A game framework written with osu! in mind.
at master 76 lines 2.7 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; 6 7namespace osu.Framework.Graphics.UserInterface 8{ 9 /// <summary> 10 /// A group of controls to be used for selecting a colour. 11 /// Allows both for mouse-interactive input (via <see cref="HSVColourPicker"/>) and textual input (via <see cref="HexColourPicker"/>). 12 /// </summary> 13 public abstract class ColourPicker : 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 private readonly HSVColourPicker hsvColourPicker; 24 private readonly HexColourPicker hexColourPicker; 25 26 protected ColourPicker() 27 { 28 Current.Value = Colour4.White; 29 AutoSizeAxes = Axes.Y; 30 Width = 300; 31 32 InternalChildren = new Drawable[] 33 { 34 new FillFlowContainer 35 { 36 RelativeSizeAxes = Axes.X, 37 AutoSizeAxes = Axes.Y, 38 Direction = FillDirection.Vertical, 39 Children = new Drawable[] 40 { 41 hsvColourPicker = CreateHSVColourPicker().With(d => 42 { 43 d.RelativeSizeAxes = Axes.X; 44 d.Width = 1; 45 }), 46 hexColourPicker = CreateHexColourPicker().With(d => 47 { 48 d.RelativeSizeAxes = Axes.X; 49 d.Width = 1; 50 }) 51 } 52 } 53 }; 54 } 55 56 /// <summary> 57 /// Creates the control that allows for interactively specifying the target colour, using the hue-saturation-value colour model. 58 /// </summary> 59 protected abstract HSVColourPicker CreateHSVColourPicker(); 60 61 /// <summary> 62 /// Creates the control that allows for specifying the target colour using a hex code. 63 /// </summary> 64 protected abstract HexColourPicker CreateHexColourPicker(); 65 66 public override bool IsPresent => base.IsPresent || hsvColourPicker.IsPresent; 67 68 protected override void LoadComplete() 69 { 70 base.LoadComplete(); 71 72 hsvColourPicker.Current = Current; 73 hexColourPicker.Current = Current; 74 } 75 } 76}