A game framework written with osu! in mind.
at master 117 lines 4.2 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 osu.Framework.Graphics.Containers; 6using osu.Framework.Graphics.Cursor; 7using osu.Framework.Graphics.Shapes; 8using osu.Framework.Graphics.UserInterface; 9using osuTK; 10 11namespace osu.Framework.Graphics.Visualisation 12{ 13 internal abstract class ToolWindow : OverlayContainer 14 { 15 public const float WIDTH = 500; 16 public const float HEIGHT = 600; 17 18 private const float button_width = 140; 19 private const float button_height = 40; 20 21 protected readonly FillFlowContainer ToolbarContent; 22 23 protected readonly ScrollContainer<Drawable> ScrollContent; 24 25 protected readonly FillFlowContainer MainHorizontalContent; 26 27 protected ToolWindow(string title, string keyHelpText) 28 { 29 AutoSizeAxes = Axes.X; 30 Height = HEIGHT; 31 32 Masking = true; // for cursor masking 33 34 AddRangeInternal(new Drawable[] 35 { 36 new Box 37 { 38 Colour = FrameworkColour.GreenDark, 39 RelativeSizeAxes = Axes.Both, 40 Depth = 0 41 }, 42 new FillFlowContainer 43 { 44 RelativeSizeAxes = Axes.X, 45 AutoSizeAxes = Axes.Y, 46 Direction = FillDirection.Vertical, 47 Children = new Drawable[] 48 { 49 new TitleBar(title, keyHelpText, this), 50 new Container //toolbar 51 { 52 RelativeSizeAxes = Axes.X, 53 AutoSizeAxes = Axes.Y, 54 Children = new Drawable[] 55 { 56 new Box 57 { 58 Colour = FrameworkColour.BlueGreenDark, 59 RelativeSizeAxes = Axes.Both, 60 }, 61 ToolbarContent = new FillFlowContainer 62 { 63 RelativeSizeAxes = Axes.X, 64 AutoSizeAxes = Axes.Y, 65 Spacing = new Vector2(5), 66 Padding = new MarginPadding(5), 67 }, 68 }, 69 } 70 } 71 }, 72 new TooltipContainer 73 { 74 RelativeSizeAxes = Axes.Y, 75 AutoSizeAxes = Axes.X, 76 Child = MainHorizontalContent = new FillFlowContainer 77 { 78 RelativeSizeAxes = Axes.Y, 79 AutoSizeAxes = Axes.X, 80 Direction = FillDirection.Horizontal, 81 Children = new Drawable[] 82 { 83 ScrollContent = new BasicScrollContainer<Drawable> 84 { 85 RelativeSizeAxes = Axes.Y, 86 Width = WIDTH 87 } 88 } 89 } 90 }, 91 new CursorContainer() 92 }); 93 } 94 95 protected void AddButton(string text, Action action) 96 { 97 ToolbarContent.Add(new BasicButton 98 { 99 Size = new Vector2(button_width, button_height), 100 Text = text, 101 Action = action 102 }); 103 } 104 105 protected override void LoadComplete() 106 { 107 base.LoadComplete(); 108 109 // Used instead of GridContainer due to grid container's autosize failing to reduce size after increase. 110 MainHorizontalContent.Padding = new MarginPadding { Top = TitleBar.HEIGHT + ToolbarContent.DrawHeight }; 111 } 112 113 protected override void PopIn() => this.FadeIn(100); 114 115 protected override void PopOut() => this.FadeOut(100); 116 } 117}