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 System;
5using System.Linq;
6using osu.Framework.Allocation;
7using osu.Framework.Bindables;
8using osu.Framework.Extensions;
9using osu.Framework.Extensions.IEnumerableExtensions;
10using osu.Framework.Graphics.Containers;
11using osu.Framework.Graphics.UserInterface;
12
13namespace osu.Framework.Graphics.Visualisation
14{
15 internal class DrawableInspector : VisibilityContainer
16 {
17 [Cached]
18 public Bindable<Drawable> InspectedDrawable { get; private set; } = new Bindable<Drawable>();
19
20 private const float width = 600;
21
22 private readonly GridContainer content;
23 private readonly TabControl<Tab> inspectorTabControl;
24 private readonly Container tabContentContainer;
25 private readonly PropertyDisplay propertyDisplay;
26 private readonly TransformDisplay transformDisplay;
27
28 public DrawableInspector()
29 {
30 Width = width;
31 RelativeSizeAxes = Axes.Y;
32
33 Child = content = new GridContainer
34 {
35 RelativeSizeAxes = Axes.Both,
36 RowDimensions = new[]
37 {
38 new Dimension(GridSizeMode.AutoSize),
39 new Dimension()
40 },
41 ColumnDimensions = new[] { new Dimension() },
42 Content = new[]
43 {
44 new Drawable[]
45 {
46 inspectorTabControl = new BasicTabControl<Tab>
47 {
48 RelativeSizeAxes = Axes.X,
49 Height = 20,
50 Margin = new MarginPadding
51 {
52 Horizontal = 10,
53 Vertical = 5
54 },
55 Items = Enum.GetValues(typeof(Tab)).Cast<Tab>().ToList()
56 },
57 tabContentContainer = new Container
58 {
59 RelativeSizeAxes = Axes.Both,
60 Children = new Drawable[]
61 {
62 propertyDisplay = new PropertyDisplay(),
63 transformDisplay = new TransformDisplay()
64 }
65 }
66 }
67 }.Invert()
68 };
69 }
70
71 protected override void LoadComplete()
72 {
73 base.LoadComplete();
74 inspectorTabControl.Current.BindValueChanged(showTab, true);
75 }
76
77 private void showTab(ValueChangedEvent<Tab> tabChanged)
78 {
79 tabContentContainer.Children.ForEach(tab => tab.Hide());
80
81 switch (tabChanged.NewValue)
82 {
83 case Tab.Properties:
84 propertyDisplay.Show();
85 break;
86
87 case Tab.Transforms:
88 transformDisplay.Show();
89 break;
90 }
91 }
92
93 protected override void PopIn()
94 {
95 this.ResizeWidthTo(width, 500, Easing.OutQuint);
96
97 inspectorTabControl.Current.Value = Tab.Properties;
98 content.Show();
99 }
100
101 protected override void PopOut()
102 {
103 content.Hide();
104
105 this.ResizeWidthTo(0, 500, Easing.OutQuint);
106 }
107
108 private enum Tab
109 {
110 Properties,
111 Transforms
112 }
113 }
114}