From 81f269ee6951ff4aa86528e48b7a5b99b62de506 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 23 Sep 2016 18:57:19 +0800 Subject: [PATCH] MouseCount and KeyBoardCount, input handling. --- .../Graphics/UserInterface/KeyBoardCount.cs | 30 +++++++++++++++++ osu.Game/Graphics/UserInterface/KeyCounter.cs | 3 ++ osu.Game/Graphics/UserInterface/MouseCount.cs | 33 +++++++++++++++++++ osu.Game/osu.Game.csproj | 2 ++ 4 files changed, 68 insertions(+) create mode 100644 osu.Game/Graphics/UserInterface/KeyBoardCount.cs create mode 100644 osu.Game/Graphics/UserInterface/MouseCount.cs diff --git a/osu.Game/Graphics/UserInterface/KeyBoardCount.cs b/osu.Game/Graphics/UserInterface/KeyBoardCount.cs new file mode 100644 index 0000000000..2f9997feea --- /dev/null +++ b/osu.Game/Graphics/UserInterface/KeyBoardCount.cs @@ -0,0 +1,30 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK.Input; +using osu.Framework.Graphics; +using osu.Framework.Input; + +namespace osu.Game.Graphics.UserInterface +{ + class KeyBoardCount : Count + { + public Key Key { get; } + public KeyBoardCount(string name, Key key) : base(name) + { + Key = key; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (args.Key == this.Key) IsLit = true; + return base.OnKeyDown(state, args); + } + + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + if (args.Key == this.Key) IsLit = false; + return base.OnKeyUp(state, args); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index ecb3b133b4..dad7c84745 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -1,6 +1,7 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using OpenTK; using osu.Framework.Graphics.Containers; namespace osu.Game.Graphics.UserInterface @@ -13,5 +14,7 @@ namespace osu.Game.Graphics.UserInterface } public void AddKey(Count key) => base.Add(key); + + public override bool Contains(Vector2 screenSpacePos) => true; } } diff --git a/osu.Game/Graphics/UserInterface/MouseCount.cs b/osu.Game/Graphics/UserInterface/MouseCount.cs new file mode 100644 index 0000000000..b993ce3a53 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/MouseCount.cs @@ -0,0 +1,33 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Input; +using osu.Framework.Graphics; +using osu.Framework.Input; + +namespace osu.Game.Graphics.UserInterface +{ + class MouseCount : Count + { + public MouseButton Button { get; } + public MouseCount(string name, MouseButton button) : base(name) + { + Button = button; + } + + public override bool Contains(Vector2 screenSpacePos) => true; + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + if (args.Button == this.Button) IsLit = true; + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + if (args.Button == this.Button) IsLit = false; + return base.OnMouseUp(state, args); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 5170aa2d57..16ebc40bc8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -54,7 +54,9 @@ + +