A game framework written with osu! in mind.
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.Graphics.Containers;
5using osuTK;
6
7namespace osu.Framework.Graphics.Animations
8{
9 /// <summary>
10 /// A drawable which handles sizing in a roughly expected way when wrapping a single direct child.
11 /// </summary>
12 public abstract class CustomisableSizeCompositeDrawable : CompositeDrawable
13 {
14 private bool hasCustomWidth;
15
16 public override float Width
17 {
18 set
19 {
20 base.Width = value;
21 hasCustomWidth = true;
22 }
23 }
24
25 private bool hasCustomHeight;
26
27 public override float Height
28 {
29 set
30 {
31 base.Height = value;
32 hasCustomHeight = true;
33 }
34 }
35
36 public override Vector2 Size
37 {
38 set
39 {
40 Width = value.X;
41 Height = value.Y;
42 }
43 }
44
45 /// <summary>
46 /// Retrieves the size of the target display content.
47 /// </summary>
48 /// <returns>The size of current content.</returns>
49 protected abstract Vector2 GetCurrentDisplaySize();
50
51 protected abstract float GetFillAspectRatio();
52
53 protected virtual void UpdateSizing()
54 {
55 FillAspectRatio = GetFillAspectRatio();
56
57 if (RelativeSizeAxes == Axes.Both) return;
58
59 var frameSize = GetCurrentDisplaySize();
60
61 if ((RelativeSizeAxes & Axes.X) == 0 && !hasCustomWidth)
62 base.Width = frameSize.X;
63
64 if ((RelativeSizeAxes & Axes.Y) == 0 && !hasCustomHeight)
65 base.Height = frameSize.Y;
66 }
67 }
68}