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.Allocation;
5using osu.Framework.Graphics.Containers;
6using osu.Framework.Graphics.Effects;
7using osu.Framework.Graphics.Shapes;
8using osu.Framework.Input;
9using osu.Framework.Input.Events;
10using osuTK;
11using osuTK.Graphics;
12
13namespace osu.Framework.Graphics.Cursor
14{
15 public class CursorContainer : VisibilityContainer, IRequireHighFrequencyMousePosition
16 {
17 public Drawable ActiveCursor { get; protected set; }
18
19 public CursorContainer()
20 {
21 Depth = float.MinValue;
22 RelativeSizeAxes = Axes.Both;
23
24 State.Value = Visibility.Visible;
25 }
26
27 [BackgroundDependencyLoader]
28 private void load()
29 {
30 Add(ActiveCursor = CreateCursor());
31 }
32
33 protected virtual Drawable CreateCursor() => new Cursor();
34
35 public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
36
37 public override bool PropagatePositionalInputSubTree => IsPresent; // make sure we are still updating position during possible fade out.
38
39 protected override bool OnMouseMove(MouseMoveEvent e)
40 {
41 ActiveCursor.Position = e.MousePosition;
42 return base.OnMouseMove(e);
43 }
44
45 protected override void PopIn()
46 {
47 Alpha = 1;
48 }
49
50 protected override void PopOut()
51 {
52 Alpha = 0;
53 }
54
55 private class Cursor : CircularContainer
56 {
57 public Cursor()
58 {
59 AutoSizeAxes = Axes.Both;
60 Origin = Anchor.Centre;
61
62 BorderThickness = 2;
63 BorderColour = new Color4(247, 99, 164, 255);
64
65 Masking = true;
66 EdgeEffect = new EdgeEffectParameters
67 {
68 Type = EdgeEffectType.Glow,
69 Colour = new Color4(247, 99, 164, 6),
70 Radius = 50
71 };
72
73 Child = new Box
74 {
75 Size = new Vector2(8, 8),
76 Origin = Anchor.Centre,
77 Anchor = Anchor.Centre,
78 };
79 }
80 }
81 }
82}