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.Collections.Generic;
5using osu.Framework.Input;
6using osu.Framework.Input.Events;
7
8namespace osu.Framework.Graphics.Containers
9{
10 /// <summary>
11 /// An element which starts hidden and can be toggled to visible.
12 /// </summary>
13 public abstract class OverlayContainer : VisibilityContainer
14 {
15 /// <summary>
16 /// Whether we should block any positional input from interacting with things behind us.
17 /// </summary>
18 protected virtual bool BlockPositionalInput => true;
19
20 /// <summary>
21 /// Scroll events are sometimes required to be handled differently to general positional input.
22 /// This covers whether scroll events that occur within this overlay's bounds are blocked or not.
23 /// Defaults to the same value as <see cref="BlockPositionalInput"/>
24 /// </summary>
25 protected virtual bool BlockScrollInput => BlockPositionalInput;
26
27 /// <summary>
28 /// Whether we should block any non-positional input from interacting with things behind us.
29 /// </summary>
30 protected virtual bool BlockNonPositionalInput => false;
31
32 internal override bool BuildNonPositionalInputQueue(List<Drawable> queue, bool allowBlocking = true)
33 {
34 if (PropagateNonPositionalInputSubTree && HandleNonPositionalInput && BlockNonPositionalInput)
35 {
36 // when blocking non-positional input behind us, we still want to make sure the global handlers receive events
37 // but we don't want other drawables behind us handling them.
38 queue.RemoveAll(d => !(d is IHandleGlobalKeyboardInput));
39 }
40
41 return base.BuildNonPositionalInputQueue(queue, allowBlocking);
42 }
43
44 public override bool DragBlocksClick => false;
45
46 protected override bool Handle(UIEvent e)
47 {
48 switch (e)
49 {
50 case ScrollEvent _:
51 if (BlockScrollInput && base.ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
52 return true;
53
54 break;
55
56 case MouseEvent _:
57 if (BlockPositionalInput)
58 return true;
59
60 break;
61 }
62
63 return base.Handle(e);
64 }
65 }
66}