A game framework written with osu! in mind.
at master 160 lines 4.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 System; 5using System.Collections; 6using System.Collections.Generic; 7using osu.Framework.Audio; 8using osu.Framework.Extensions.EnumExtensions; 9using osu.Framework.Graphics.Audio; 10using osu.Framework.Graphics.Effects; 11using osuTK; 12 13namespace osu.Framework.Graphics.Containers 14{ 15 /// <summary> 16 /// A container which exposes audio adjustments via <see cref="IAggregateAudioAdjustment"/>. 17 /// </summary> 18 /// <remarks> 19 /// This is a bare-minimal implementation of a container, so it may be required to be nested inside a <see cref="Container"/> for some use cases. 20 /// </remarks> 21 /// <typeparam name="T">The type of <see cref="Drawable"/>.</typeparam> 22 public class AudioContainer<T> : DrawableAudioWrapper, IContainerEnumerable<T>, IContainerCollection<T>, ICollection<T>, IReadOnlyList<T> 23 where T : Drawable 24 { 25 private readonly Container<T> container; 26 27 public AudioContainer() 28 : this(new Container<T>()) 29 { 30 } 31 32 private AudioContainer(Container<T> container) 33 : base(container) 34 { 35 this.container = container; 36 } 37 38 public override Vector2 Size 39 { 40 get => container.Size; 41 set 42 { 43 base.Size = new Vector2( 44 RelativeSizeAxes.HasFlagFast(Axes.X) ? 1 : value.X, 45 RelativeSizeAxes.HasFlagFast(Axes.Y) ? 1 : value.Y); 46 47 container.Size = value; 48 } 49 } 50 51 public override Axes RelativeSizeAxes 52 { 53 get => container.RelativeSizeAxes; 54 set 55 { 56 base.RelativeSizeAxes = value; 57 container.RelativeSizeAxes = value; 58 } 59 } 60 61 public new Axes AutoSizeAxes 62 { 63 get => container.AutoSizeAxes; 64 set 65 { 66 base.AutoSizeAxes = value; 67 container.AutoSizeAxes = value; 68 } 69 } 70 71 public new EdgeEffectParameters EdgeEffect 72 { 73 get => base.EdgeEffect; 74 set => base.EdgeEffect = value; 75 } 76 77 public new Vector2 RelativeChildSize 78 { 79 get => container.RelativeChildSize; 80 set => container.RelativeChildSize = value; 81 } 82 83 public new Vector2 RelativeChildOffset 84 { 85 get => container.RelativeChildOffset; 86 set => container.RelativeChildOffset = value; 87 } 88 89 public Container<T>.Enumerator GetEnumerator() => container.GetEnumerator(); 90 91 IEnumerator<T> IEnumerable<T>.GetEnumerator() => GetEnumerator(); 92 93 IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); 94 95 public IReadOnlyList<T> Children 96 { 97 get => container.Children; 98 set => container.Children = value; 99 } 100 101 public int RemoveAll(Predicate<T> match) => container.RemoveAll(match); 102 103 public T Child 104 { 105 get => container.Child; 106 set => container.Child = value; 107 } 108 109 public IEnumerable<T> ChildrenEnumerable 110 { 111 set => container.ChildrenEnumerable = value; 112 } 113 114 public void Add(T drawable) 115 { 116 container.Add(drawable); 117 } 118 119 public void Clear() 120 { 121 container.Clear(); 122 } 123 124 public bool Contains(T item) => container.Contains(item); 125 126 public void CopyTo(T[] array, int arrayIndex) 127 { 128 container.CopyTo(array, arrayIndex); 129 } 130 131 public void AddRange(IEnumerable<T> collection) 132 { 133 container.AddRange(collection); 134 } 135 136 public bool Remove(T drawable) => container.Remove(drawable); 137 int ICollection<T>.Count => container.Count; 138 139 public bool IsReadOnly => container.IsReadOnly; 140 141 public void RemoveRange(IEnumerable<T> range) 142 { 143 container.RemoveRange(range); 144 } 145 146 int IReadOnlyCollection<T>.Count => container.Count; 147 148 public T this[int index] => container[index]; 149 } 150 151 /// <summary> 152 /// A container which exposes audio adjustments via <see cref="IAggregateAudioAdjustment"/>. 153 /// </summary> 154 /// <remarks> 155 /// This is a bare-minimal implementation of a container, so it may be required to be nested inside a <see cref="Container"/> for some use cases. 156 /// </remarks> 157 public class AudioContainer : AudioContainer<Drawable> 158 { 159 } 160}