예제 #1
0
        /// <summary>
        /// Adds an entry in the control-setting map, generates a tool-tip for the setting.
        /// </summary>
        /// <param name="setting">The name of the setting.</param>
        /// <param name="control">The control used to edit the setting.</param>
        static public void AddMap <T>(Expression <Func <T, object> > setting, object control)
        {
            // Get the member expression
            var me = setting.Body as MemberExpression ?? ((UnaryExpression)setting.Body).Operand as MemberExpression;
            // Get the property
            var prop = (PropertyInfo)me.Member;
            // Get the setting name by reading the property
            //var keyName = prop.Name;
            // Get the description attribute
            var descAttr = GetCustomAttribute <DescriptionAttribute>(prop);
            var desc     = descAttr?.Description ?? string.Empty;
            // Get the default value attribute
            var dvalAttr = GetCustomAttribute <DefaultValueAttribute>(prop);

            // Display help inside yellow header.
            // We could add settings EnableHelpTooltips=1, EnableHelpHeader=1
            if (control is Control c)
            {
                c.MouseHover += control_MouseEnter;
                c.MouseLeave += control_MouseLeave;
            }
            var item = new SettingsMapItem();

            item.Description = desc;
            //item.IniSection = sectionName;
            //item.MapTo = mapTo;
            //item.IniKey = keyName;
            item.Control      = control;
            item.PropertyName = prop.Name;
            item.DefaultValue = dvalAttr?.Value;
            item.Property     = prop;
            // Add to the map
            Current.SettingsMap.Add(item);
        }
예제 #2
0
        /// <summary>
        /// Adds an entry in the control-setting map and also generates a tool-tip for the setting.
        /// </summary>
        /// <param name="sectionName">
        /// The name of the section.
        /// </param>
        /// <param name="setting">
        /// The name of the setting.
        /// </param>
        /// <param name="control">
        /// The control used to edit the setting.
        /// </param>
        /// <param name="settingsMap">
        /// The settings map to add the entry in.
        /// </param>
        static public void AddMap <T>(string sectionName, Expression <Func <T> > setting, Control control, MapTo mapTo = MapTo.None)
        {
            // Get the member expression
            var me = (MemberExpression)setting.Body;
            // Get the property
            var prop = (PropertyInfo)me.Member;
            // Get the setting name by reading the property
            var keyName = (string)prop.GetValue(null, null);

            if (string.IsNullOrEmpty(keyName))
            {
                keyName = prop.Name;
            }
            // Get the description attribute
            var descAttr = GetCustomAttribute <DescriptionAttribute>(prop);
            var desc     = (descAttr != null ? descAttr.Description : string.Empty);

            // Display help inside yellow header.
            // We could add settings EnableHelpTooltips=1, EnableHelpHeader=1
            control.MouseHover += control_MouseEnter;
            control.MouseLeave += control_MouseLeave;
            var item = new SettingsMapItem();

            item.Description  = desc;
            item.IniSection   = sectionName;
            item.IniKey       = keyName;
            item.Control      = control;
            item.PropertyName = prop.Name;
            item.MapTo        = mapTo;
            // Add to the map
            Current.SettingsMap.Add(item);
        }
예제 #3
0
        static public SettingsMapItem AddMap <T>(Expression <Func <T> > setting, Control control, MapTo mapTo = MapTo.None, MapCode code = default)
        {
            // Get the member expression
            var me = (MemberExpression)setting.Body;
            // Get the property
            var prop = (PropertyInfo)me.Member;
            // Get the description attribute
            var descAttr = GetCustomAttribute <DescriptionAttribute>(prop);
            var desc     = descAttr != null
                                ? descAttr.Description
                                : string.Empty;
            // Get the default value attribute
            var dvalAttr = GetCustomAttribute <DefaultValueAttribute>(prop);
            var dval     = descAttr != null
                                ? (string)dvalAttr.Value
                                : null;

            // Display help inside yellow header.
            // We could add settings EnableHelpTooltips=1, EnableHelpHeader=1
            control.MouseHover += control_MouseEnter;
            control.MouseLeave += control_MouseLeave;
            var item = new SettingsMapItem();

            item.Description  = desc;
            item.Code         = code;
            item.Control      = control;
            item.MapTo        = mapTo;
            item.PropertyName = prop.Name;
            item.DefaultValue = dval;
            item.Property     = prop;
            // Add to the map
            Current.SettingsMap.Add(item);
            return(item);
        }
예제 #4
0
파일: Recorder.cs 프로젝트: ph3na/x360ce
 public void StartRecording(SettingsMapItem map = null)
 {
     lock (recordingLock)
     {
         // If recording is already in progress then return.
         if (Recording)
         {
             return;
         }
         CurrentMap = map;
         // Set time to now to make sure that DrawRecordingImage always shows image immediately.
         RecordingStarted  = DateTime.Now;
         Recording         = true;
         recordingSnapshot = null;
         Global._MainWindow.MainPanel.StatusTimerLabel.Content = (CurrentMap?.Code == MapCode.DPad)
                                  ? "Recording - press any D-Pad button on your direct input device. Press ESC to cancel..."
                                  : "Recording - press button, move axis or slider on your direct input device. Press ESC to cancel...";
     }
 }
예제 #5
0
 public void StartRecording(SettingsMapItem map)
 {
     lock (recordingLock)
     {
         // If recording is already in progress then return.
         if (Recording)
         {
             return;
         }
         _Map = map;
         var pn = map.PropertyName;
         Recording          = true;
         recordingSnapshot  = null;
         drawRecordingImage = true;
         RecordingTimer.Start();
         _Map.Control.ForeColor = SystemColors.GrayText;
         MainForm.Current.StatusTimerLabel.Text = (_Map.PropertyName == SettingName.DPad)
              ? "Recording - press any D-Pad button on your direct input device. Press ESC to cancel..."
              : "Recording - press button, move axis or slider on your direct input device. Press ESC to cancel...";
     }
 }
예제 #6
0
 public SettingChangedEventArgs(SettingsMapItem item)
 {
     _Item = item;
 }
예제 #7
0
파일: Recorder.cs 프로젝트: ph3na/x360ce
        /// <summary>
        /// Called when recording is in progress.
        /// </summary>
        /// <param name="state">Current direct input activity.</param>
        /// <returns>True if recording stopped, otherwise false.</returns>
        public bool StopRecording(CustomDiState state = null)
        {
            lock (recordingLock)
            {
                // If recording is not in progress then return false.
                if (!Recording)
                {
                    recordingSnapshot = null;
                    return(false);
                }
                // Must stop recording if null state passed i.e. probably ESC key was pressed.
                var    stop   = state == null;
                string action = null;
                var    map    = CurrentMap;
                var    code   = map.Code;
                var    box    = (ComboBox)map.Control;
                if (state != null)
                {
                    // If recording snapshot was not created yet then...
                    if (recordingSnapshot == null)
                    {
                        // Make snapshot out of the first state during recording.
                        recordingSnapshot = state;
                        return(false);
                    }
                    var actions = state == null
                                                  ? Array.Empty <string>()
                                  // Get actions by comparing initial snapshot with current state.
                                                  : Recorder.CompareTo(recordingSnapshot, state, map.Code);

                    // if recording and at least one action was recorded then...
                    if (!stop && actions.Length > 0)
                    {
                        MapType type;
                        int     index;
                        SettingsConverter.TryParseTextValue(actions[0], out type, out index);
                        // If this is Thumb Up, Left, Right, Down and axis was mapped.
                        if (SettingsConverter.ThumbDirections.Contains(code) && SettingsConverter.IsAxis(type))
                        {
                            // Make full axis.
                            type = SettingsConverter.ToFull(type);
                            var isUp =
                                code == MapCode.LeftThumbUp ||
                                code == MapCode.RightThumbUp;
                            var isLeft =
                                code == MapCode.LeftThumbLeft ||
                                code == MapCode.RightThumbLeft;
                            var isRight =
                                code == MapCode.LeftThumbRight ||
                                code == MapCode.RightThumbRight;
                            var isDown =
                                code == MapCode.LeftThumbDown ||
                                code == MapCode.RightThumbDown;
                            // Invert.
                            if (isLeft || isDown)
                            {
                                type = SettingsConverter.Invert(type);
                            }
                            var newCode     = code;
                            var isLeftThumb = SettingsConverter.LeftThumbCodes.Contains(code);
                            if (isRight || isLeft)
                            {
                                newCode = isLeftThumb
                                                                        ? MapCode.LeftThumbAxisX
                                                                        : MapCode.RightThumbAxisX;
                            }
                            if (isUp || isDown)
                            {
                                newCode = isLeftThumb
                                                                        ? MapCode.LeftThumbAxisY
                                                                        : MapCode.RightThumbAxisY;
                            }
                            // Change destination control.
                            var rMap = SettingsManager.Current.SettingsMap.First(x => x.MapTo == map.MapTo && x.Code == newCode);
                            box    = (ComboBox)rMap.Control;
                            action = SettingsConverter.ToTextValue(type, index);
                            stop   = true;
                        }
                        // If this is DPad ComboBox then...
                        else if (code == MapCode.DPad)
                        {
                            // Get first action suitable for DPad
                            Regex dPadRx     = new Regex("(POV [0-9]+)");
                            var   dPadAction = actions.FirstOrDefault(x => dPadRx.IsMatch(x));
                            if (dPadAction != null)
                            {
                                action = dPadRx.Match(dPadAction).Groups[0].Value;
                                stop   = true;
                            }
                        }
                        else
                        {
                            // Get first recorded action.
                            action = actions[0];
                            stop   = true;
                        }
                    }
                }
                // If recording must stop then...
                if (stop)
                {
                    Recording  = false;
                    CurrentMap = null;
                    // If stop was initiated before action was recorded then...
                    if (string.IsNullOrEmpty(action))
                    {
                        box.Items.Clear();
                    }
                    else
                    {
                        // If suitable action was recorded then...
                        SettingsManager.Current.SetComboBoxValue(box, action);
                        // Save setting and notify if value changed.
                        SettingsManager.Current.RaiseSettingsChanged(box);
                    }
                    //box.ForeColor = SystemColors.WindowText;
                }
                return(stop);
            }
        }