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 osu.Framework.Graphics.Shapes;
6using osu.Framework.Graphics.Sprites;
7using osu.Framework.Input.Events;
8using osuTK;
9
10namespace osu.Framework.Graphics.Visualisation
11{
12 internal class TitleBar : CompositeDrawable
13 {
14 private readonly Drawable movableTarget;
15
16 public const float HEIGHT = 40;
17
18 public TitleBar(string title, string keyHelpText, Drawable movableTarget)
19 {
20 this.movableTarget = movableTarget;
21
22 RelativeSizeAxes = Axes.X;
23 Size = new Vector2(1, HEIGHT);
24
25 InternalChildren = new Drawable[]
26 {
27 new Box
28 {
29 RelativeSizeAxes = Axes.Both,
30 Colour = FrameworkColour.BlueDark,
31 },
32 new FillFlowContainer
33 {
34 RelativeSizeAxes = Axes.Y,
35 AutoSizeAxes = Axes.X,
36 Direction = FillDirection.Horizontal,
37 Spacing = new Vector2(10),
38 Children = new Drawable[]
39 {
40 new SpriteIcon
41 {
42 Size = new Vector2(20),
43 Margin = new MarginPadding(10) { Right = 0 },
44 Icon = FontAwesome.Regular.Circle,
45 },
46 new SpriteText
47 {
48 Anchor = Anchor.CentreLeft,
49 Origin = Anchor.CentreLeft,
50 Text = title,
51 Font = FrameworkFont.Condensed.With(weight: "Bold"),
52 Colour = FrameworkColour.Yellow,
53 },
54 new SpriteText
55 {
56 Anchor = Anchor.CentreLeft,
57 Origin = Anchor.CentreLeft,
58 Text = keyHelpText,
59 Font = FrameworkFont.Condensed,
60 Colour = FrameworkColour.Yellow,
61 Alpha = 0.5f
62 },
63 }
64 },
65 };
66 }
67
68 protected override bool OnDragStart(DragStartEvent e) => true;
69
70 protected override void OnDrag(DragEvent e)
71 {
72 movableTarget.Position += e.Delta;
73 base.OnDrag(e);
74 }
75
76 protected override bool OnMouseDown(MouseDownEvent e) => true;
77 }
78}