From: Jean-Philippe Bruyère Date: Mon, 14 Dec 2020 01:12:53 +0000 (+0100) Subject: code clean and comments X-Git-Tag: v0.9.5-beta~108 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=aa5e4dafbd6807a846e2694925d9d26482d0afc1;p=jp%2Fcrow.git code clean and comments --- diff --git a/Crow/src/Input/Buttons.cs b/Crow/src/Input/Buttons.cs deleted file mode 100644 index ebf3bc42..00000000 --- a/Crow/src/Input/Buttons.cs +++ /dev/null @@ -1,166 +0,0 @@ -// -// GamePadButton.cs -// -// Author: -// robert <${AuthorEmail}> -// -// Copyright (c) 2012 robert -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace Crow -{ - /// - /// Enumerates available buttons for a GamePad device. - /// - [Flags] - public enum Buttons - { - /// - /// DPad up direction button - /// - DPadUp = 1 << 0, - - /// - /// DPad down direction button - /// - DPadDown = 1 << 1, - - /// - /// DPad left direction button - /// - DPadLeft = 1 << 2, - - /// - /// DPad right direction button - /// - DPadRight = 1 << 3, - - /// - /// Start button - /// - Start = 1 << 4, - - /// - /// Back button - /// - Back = 1 << 5, - - /// - /// Left stick button - /// - LeftStick = 1 << 6, - - /// - /// Right stick button - /// - RightStick = 1 << 7, - - /// - /// Left shoulder button - /// - LeftShoulder = 1 << 8, - - /// - /// Right shoulder button - /// - RightShoulder = 1 << 9, - - /// - /// Home button - /// - Home = 1 << 11, - - /// - /// Home button - /// - BigButton = Home, - - /// - /// A button - /// - A = 1 << 12, - - /// - /// B button - /// - B = 1 << 13, - - /// - /// X button - /// - X = 1 << 14, - - /// - /// Y button - /// - Y = 1 << 15, - - /// - /// Left thumbstick left direction button - /// - LeftThumbstickLeft = 1 << 21, - - /// - /// Right trigger button - /// - RightTrigger = 1 << 22, - - /// - /// Left trigger button - /// - LeftTrigger = 1 << 23, - - /// - /// Right thumbstick up direction button - /// - RightThumbstickUp = 1 << 24, - - /// - /// Right thumbstick down direction button - /// - RightThumbstickDown = 1 << 25, - - /// - /// Right stick right direction button - /// - RightThumbstickRight = 1 << 26, - - /// - /// Right stick left direction button - /// - RightThumbstickLeft = 1 << 27, - - /// - /// Left stick up direction button - /// - LeftThumbstickUp = 1 << 28, - - /// - /// Left stick down direction button - /// - LeftThumbstickDown = 1 << 29, - - /// - /// Left stick right direction button - /// - LeftThumbstickRight = 1 << 30, - } -} diff --git a/Crow/src/Input/CrowEventArgs.cs b/Crow/src/Input/CrowEventArgs.cs new file mode 100644 index 00000000..0686349d --- /dev/null +++ b/Crow/src/Input/CrowEventArgs.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2014-2020 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; + +namespace Crow +{ + /// + /// Base class for Crow interface events. + /// + /// + /// By default, device (mouse, keyboard) events are bubbled through the logical tree unless the `Handled` field + /// of the `CrowEventArgs` is set to `true`, or if an event handler is registered for the Event. + /// For example if you have a templated button that received a mouse + /// event in a `Label` widget inside its tempate, the event may be bubbled to the `Button` widget where a + /// `MouseClick` event may be registered which will cause the bubbling to stop at that level. + /// + public class CrowEventArgs : EventArgs + { + /// + /// If `true`, bubbling of the event through the logical widget tree is stopped + /// + public bool Handled; + } +} diff --git a/Crow/src/Input/KeyEventArgs.cs b/Crow/src/Input/KeyEventArgs.cs index 6444f853..23f8559d 100644 --- a/Crow/src/Input/KeyEventArgs.cs +++ b/Crow/src/Input/KeyEventArgs.cs @@ -1,38 +1,13 @@ -#region License +// Copyright (c) 2006 - 2009 the Open Toolkit library. +// Copyright (c) 2014-2020 Jean-Philippe Bruyère // -// The Open Toolkit Library License -// -// Copyright (c) 2006 - 2009 the Open Toolkit library. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -#endregion +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; -using System.Text; using Glfw; namespace Crow { - public class KeyEventArgs : CrowEventArgs + public class KeyEventArgs : CrowEventArgs { int keyCode=0; Key key; diff --git a/Crow/src/Input/KeyPressEventArgs.cs b/Crow/src/Input/KeyPressEventArgs.cs index 7ff9565b..cb4e534c 100644 --- a/Crow/src/Input/KeyPressEventArgs.cs +++ b/Crow/src/Input/KeyPressEventArgs.cs @@ -1,30 +1,7 @@ -// #region License -// // -// // The Open Toolkit Library License -// // -// // Copyright (c) 2006 - 2009 the Open Toolkit library. -// // -// // Permission is hereby granted, free of charge, to any person obtaining a copy -// // of this software and associated documentation files (the "Software"), to deal -// // in the Software without restriction, including without limitation the rights to -// // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// // the Software, and to permit persons to whom the Software is furnished to do -// // so, subject to the following conditions: -// // -// // The above copyright notice and this permission notice shall be included in all -// // copies or substantial portions of the Software. -// // -// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// // OTHER DEALINGS IN THE SOFTWARE. -// // -// #endregion - +// Copyright (c) 2006 - 2009 the Open Toolkit library. +// Copyright (c) 2014-2020 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; namespace Crow diff --git a/Crow/src/Input/MouseEventArgs.cs b/Crow/src/Input/MouseEventArgs.cs index 53a5e867..e64e9a1b 100644 --- a/Crow/src/Input/MouseEventArgs.cs +++ b/Crow/src/Input/MouseEventArgs.cs @@ -1,41 +1,11 @@ -#region License +// Copyright (c) 2006-2014 Stefanos Apostolopoulos +// Copyright (c) 2014-2020 Jean-Philippe Bruyère // -// MouseEventArgs.cs -// -// Author: -// Stefanos A. -// -// Copyright (c) 2006-2014 Stefanos Apostolopoulos -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -#endregion - -using System; +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using Glfw; namespace Crow { - public class CrowEventArgs : EventArgs - { - public bool Handled; - } public class MouseEventArgs : CrowEventArgs { public readonly int X, Y; diff --git a/Crow/src/Input/MouseScroll.cs b/Crow/src/Input/MouseScroll.cs deleted file mode 100644 index a04e9d69..00000000 --- a/Crow/src/Input/MouseScroll.cs +++ /dev/null @@ -1,118 +0,0 @@ -#region License -// -// MouseWheel.cs -// -// Author: -// Stefanos A. -// -// Copyright (c) 2006-2014 Stefanos Apostolopoulos -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -#endregion - -using System; - -namespace Crow -{ - /// - /// Represents the state of a mouse wheel. - /// - public struct MouseScroll : IEquatable - { - #region Public Members - - /// - /// Gets the absolute horizontal offset of the wheel, - /// or 0 if no horizontal scroll wheel exists. - /// - /// The x. - public float X { get; internal set; } - - /// - /// Gets the absolute vertical offset of the wheel, - /// or 0 if no vertical scroll wheel exists. - /// - /// The y. - public float Y { get; internal set; } - - /// A instance to test for equality. - /// A instance to test for equality. - public static bool operator ==(MouseScroll left, MouseScroll right) - { - return left.Equals(right); - } - - /// A instance to test for inequality. - /// A instance to test for inequality. - public static bool operator !=(MouseScroll left, MouseScroll right) - { - return !left.Equals(right); - } - - /// - /// Returns a that represents the current . - /// - /// A that represents the current . - public override string ToString() - { - return string.Format("[X={0:0.00}, Y={1:0.00}]", X, Y); - } - - /// - /// Serves as a hash function for a object. - /// - /// A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a - /// hash table. - public override int GetHashCode() - { - return X.GetHashCode() ^ Y.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current - /// ; otherwise, false. - public override bool Equals(object obj) - { - return - obj is MouseScroll && - Equals((MouseScroll)obj); - } - - #endregion - - #region IEquatable Members - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current - /// ; otherwise, false. - public bool Equals(MouseScroll other) - { - return X == other.X && Y == other.Y; - } - - #endregion - } -} diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index 84e91c56..4a99e2da 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -432,9 +432,9 @@ namespace Crow public event EventHandler MouseDoubleClick; /// Occurs when mouse mouve in this object. It bubbles to the root public event EventHandler MouseMove; - /// Occurs when mouse enter this object + /// Occurs when mouse enter the bounding rectangle of this object public event EventHandler MouseEnter; - /// Occurs when mouse leave this object + /// Occurs when mouse leave the bounds of this object public event EventHandler MouseLeave; /// Occurs when key is pressed when this object is active public event EventHandler KeyDown; @@ -1968,6 +1968,14 @@ namespace Crow } + /// + /// Default mouse button press method. The `MouseDown` event is raised from withing it. + /// + /// + /// See `CrowEventArgs` for details on interface event handling. + /// + /// Sender of the event + /// mouse button pressed event arguments public virtual void onMouseDown(object sender, MouseButtonEventArgs e){ if (Focusable) { IFace.FocusedWidget = this; @@ -1984,6 +1992,14 @@ namespace Crow else if (!e.Handled) FocusParent?.onMouseDown (sender, e); } + /// + /// Default mouse button release method. The `MouseUp` event is raised from withing it. + /// + /// + /// See `CrowEventArgs` for details on interface event handling. + /// + /// Sender of the event + /// mouse button release event arguments public virtual void onMouseUp(object sender, MouseButtonEventArgs e){ if (IFace.DragAndDropOperation != null){ @@ -2000,12 +2016,23 @@ namespace Crow else if (!e.Handled) FocusParent?.onMouseUp (sender, e); } + /// + /// Default mouse click method. A click is a press and release without mouving combination. + /// + /// The Sender of the event + /// event arguments public virtual void onMouseClick(object sender, MouseButtonEventArgs e){ if (MouseClick != null) MouseClick.Invoke (this, e); else if (!e.Handled) FocusParent?.onMouseClick (sender, e); } + /// + /// Default mouse double click method. A double click is two consecutive press and release without mouving combination. + /// within a delay defined by `Interface.DOUBLECLICK_TRESHOLD` + /// + /// The Sender of the event + /// event arguments public virtual void onMouseDoubleClick(object sender, MouseButtonEventArgs e){ if (MouseDoubleClick != null) MouseDoubleClick.Invoke (this, e);