Пример #1
0
        /// <summary>
        /// Updates the value of the <see cref="Gesture"/> property based on the current property values of this binding.
        /// </summary>
        private void UpdateGestureFromBinding()
        {
            if (updating)
            {
                return;
            }

            updating = true;

            Gesture = new GamePadGesture(Button, PlayerIndex);

            updating = false;
        }
        /// <summary>
        /// Converts the string representation of a gesture into an instance of the <see cref="GamePadGesture"/> structure.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="str">A string containing a gesture to convert.</param>
        /// <param name="provider">A format provider that provides culture-specific formatting information.</param>
        /// <param name="gesture">A variable to populate with the converted value.</param>
        /// <returns><see langword="true"/> if <paramref name="str"/> was converted successfully; otherwise, <see langword="false"/>.</returns>
        public static Boolean TryParse(String str, IFormatProvider provider, out GamePadGesture gesture)
        {
            Contract.Require(str, nameof(str));

            gesture = null;

            if (String.IsNullOrWhiteSpace(str))
            {
                return(false);
            }

            var parts     = str.Split(':');
            var partIndex = parts.Length == 1 ? null : parts[0].Trim();
            var partEnum  = parts.Length == 1 ? parts[0].Trim() : parts[1].Trim();

            var index = AnyPlayerIndex;

            if (partIndex != null)
            {
                if (partIndex.StartsWith("P", StringComparison.OrdinalIgnoreCase))
                {
                    if (!Int32.TryParse(partIndex.Substring(1), out index) || index < 0)
                    {
                        return(false);
                    }
                }
                else if (!String.Equals("ANY", partIndex, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            var button = GamePadButton.None;

            if (!Enum.TryParse(partEnum, true, out button))
            {
                return(false);
            }

            gesture = new GamePadGesture(button, index);
            return(true);
        }
 /// <summary>
 /// Converts the string representation of a gesture into an instance of the <see cref="GamePadGesture"/> structure.
 /// A return value indicates whether the conversion succeeded.
 /// </summary>
 /// <param name="str">A string containing a gesture to convert.</param>
 /// <param name="gesture">A variable to populate with the converted value.</param>
 /// <returns><see langword="true"/> if <paramref name="str"/> was converted successfully; otherwise, <see langword="false"/>.</returns>
 public static Boolean TryParse(String str, out GamePadGesture gesture)
 {
     return(TryParse(str, null, out gesture));
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GamePadBinding"/> class.
 /// </summary>
 /// <param name="command">The command associated with the specified gesture.</param>
 /// <param name="gesture">The gesture associated with the specified command.</param>
 public GamePadBinding(ICommand command, GamePadGesture gesture)
     : base(command, gesture)
 {
 }