A game framework written with osu! in mind.
at master 5.0 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.Linq; 5using osu.Framework.Graphics; 6using osu.Framework.Graphics.Containers; 7using osu.Framework.Graphics.Cursor; 8using osu.Framework.Graphics.Shapes; 9using osu.Framework.Input.Events; 10using osuTK; 11using osuTK.Graphics; 12using osuTK.Input; 13 14namespace osu.Framework.Testing.Input 15{ 16 internal class TestCursorContainer : CursorContainer 17 { 18 protected override Drawable CreateCursor() => new TestCursor(); 19 } 20 21 internal class TestCursor : CompositeDrawable 22 { 23 private readonly Container circle; 24 25 private readonly Container border; 26 27 public readonly Container Left; 28 public readonly Container Right; 29 30 public override bool PropagatePositionalInputSubTree => true; 31 32 public TestCursor() 33 { 34 Size = new Vector2(30); 35 36 Origin = Anchor.Centre; 37 38 InternalChildren = new Drawable[] 39 { 40 Left = new Container 41 { 42 RelativeSizeAxes = Axes.Both, 43 Masking = true, 44 Alpha = 0, 45 Width = 0.5f, 46 Child = new CircularContainer 47 { 48 Size = new Vector2(30), 49 Masking = true, 50 BorderThickness = 5, 51 BorderColour = Color4.Cyan, 52 Child = new Box 53 { 54 Colour = Color4.Black, 55 Alpha = 0.1f, 56 RelativeSizeAxes = Axes.Both, 57 }, 58 }, 59 }, 60 Right = new Container 61 { 62 RelativeSizeAxes = Axes.Both, 63 Masking = true, 64 Alpha = 0, 65 Width = 0.5f, 66 Anchor = Anchor.TopRight, 67 Origin = Anchor.TopRight, 68 Child = new CircularContainer 69 { 70 Size = new Vector2(30), 71 X = -15, 72 Masking = true, 73 BorderThickness = 5, 74 BorderColour = Color4.Cyan, 75 Child = new Box 76 { 77 Colour = Color4.Black, 78 Alpha = 0.1f, 79 RelativeSizeAxes = Axes.Both, 80 }, 81 }, 82 }, 83 border = new CircularContainer 84 { 85 RelativeSizeAxes = Axes.Both, 86 Masking = true, 87 BorderThickness = 2, 88 BorderColour = Color4.Cyan, 89 Child = new Box 90 { 91 Colour = Color4.Black, 92 Alpha = 0.1f, 93 RelativeSizeAxes = Axes.Both, 94 }, 95 }, 96 circle = new CircularContainer 97 { 98 Size = new Vector2(8), 99 Anchor = Anchor.Centre, 100 Origin = Anchor.Centre, 101 Masking = true, 102 BorderThickness = 2, 103 BorderColour = Color4.White, 104 Child = new Box 105 { 106 Colour = Color4.Red, 107 RelativeSizeAxes = Axes.Both, 108 }, 109 }, 110 }; 111 } 112 113 protected override bool OnMouseDown(MouseDownEvent e) 114 { 115 switch (e.Button) 116 { 117 case MouseButton.Left: 118 Left.FadeIn(); 119 break; 120 121 case MouseButton.Right: 122 Right.FadeIn(); 123 break; 124 } 125 126 updateBorder(e); 127 return base.OnMouseDown(e); 128 } 129 130 protected override void OnMouseUp(MouseUpEvent e) 131 { 132 switch (e.Button) 133 { 134 case MouseButton.Left: 135 Left.FadeOut(500); 136 break; 137 138 case MouseButton.Right: 139 Right.FadeOut(500); 140 break; 141 } 142 143 updateBorder(e); 144 base.OnMouseUp(e); 145 } 146 147 protected override bool OnScroll(ScrollEvent e) 148 { 149 var delta = new Vector2(e.ScrollDelta.X, -e.ScrollDelta.Y); 150 circle.MoveTo(circle.Position + delta * 10).MoveTo(Vector2.Zero, 500, Easing.OutQuint); 151 return base.OnScroll(e); 152 } 153 154 private void updateBorder(MouseButtonEvent e) 155 { 156 border.BorderColour = e.CurrentState.Mouse.Buttons.Any() ? Color4.Red : Color4.Cyan; 157 } 158 } 159}