Example #1
0
            protected override void SetButtonState(BindingDescriptor bindingDescriptor, int state)
            {
                var inputId = bindingDescriptor.Index;

                ((IXbox360Controller)target).SetButtonState(buttonIndexes[inputId], state != 0);
                /*SendReport();*/
            }
Example #2
0
        private void InitMouseReports()
        {
            StaticData.MouseAxisBindingReports[0].Blockable = _blockingEnabled;
            StaticData.MouseAxisBindingReports[1].Blockable = _blockingEnabled;
            _mouseReports    = new ConcurrentDictionary <BindingDescriptor, BindingReport>();
            _mouseButtonList = new DeviceReportNode
            {
                Title = "Buttons"
            };
            for (var i = 0; i < 9; i++)
            {
                var bd = new BindingDescriptor
                {
                    Index = i,
                    Type  = BindingType.Button
                };
                var report = BuildMouseBindingReport(bd);
                _mouseReports.TryAdd(bd, report);
                _mouseButtonList.Bindings.Add(report);
            }

            for (var i = 0; i < 2; i++)
            {
                _mouseReports.TryAdd(StaticData.MouseAxisBindingReports[i].BindingDescriptor,
                                     StaticData.MouseAxisBindingReports[i]);
            }
        }
Example #3
0
        public BindingReport BuildMouseBindingReport(BindingDescriptor bindingDescriptor)
        {
            if (bindingDescriptor.Type == BindingType.Axis)
            {
                return(StaticData.MouseAxisBindingReports[bindingDescriptor.Index]);
            }

            var i        = bindingDescriptor.Index;
            var category = i > 4 ? BindingCategory.Event : BindingCategory.Momentary;
            var name     = StaticData.MouseButtonNames[i];
            var path     = category == BindingCategory.Momentary ? $"Button: {name}" : $"Event: {name}";

            return(new BindingReport
            {
                Title = name,
                Path = path,
                Category = category,
                BindingDescriptor = new BindingDescriptor
                {
                    Index = i,
                    Type = BindingType.Button
                },
                Blockable = _blockingEnabled
            });
        }
        public bool SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor bindingDescriptor, int state)
        {
            var devId = _subscriptionToDevice[subReq.SubscriptionDescriptor.SubscriberGuid];

            if (!_vJoyDevices[devId].IsAcquired)
            {
                return(false);
            }
            switch (bindingDescriptor.Type)
            {
            case BindingType.Axis:
                return(vJ.SetAxis((state + 32768) / 2, devId + 1, AxisIdToUsage[bindingDescriptor.Index]));

            case BindingType.Button:
                return(vJ.SetBtn(state == 1, devId + 1, (uint)(bindingDescriptor.Index + 1)));

            case BindingType.POV:
                int pov = (int)(Math.Floor((decimal)(bindingDescriptor.Index / 4)));
                int dir = bindingDescriptor.Index % 4;
                //Log("vJoy POV output requested - POV {0}, Dir {1}, State {2}", pov, dir, state);
                _vJoyDevices[devId].SetPovState(pov, dir, state);
                break;

            default:
                break;
            }
            return(false);
        }
Example #5
0
            protected override void SetPovState(BindingDescriptor bindingDescriptor, int state)
            {
                var inputId = bindingDescriptor.Index;

                report.SetButtonState(povIndexes[inputId], state != 0);
                SendReport();
            }
Example #6
0
 public bool SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor bindingDescriptor, int state)
 {
     if (!isLive)
     {
         return(false);
     }
     return(devicesHandler.SetOutputState(subReq, bindingDescriptor, state));
 }
        public CommandBindingExpression CreateCommandBinding(string expression, params Type[] nestedDataContextTypes)
        {
            var dataContextStack = CreateDataContextStack(DataContextStack, nestedDataContextTypes);

            var descriptor = new BindingDescriptor(expression, typeof(CommandBindingExpression), dataContextStack);

            return((CommandBindingExpression)bindingCache.GetOrAdd(descriptor, bd => CompileCommandBindingExpression(descriptor)));
        }
        public ValueBindingExpression <T> CreateValueBinding <T>(string expression, params Type[] nestedDataContextTypes)
        {
            var dataContextStack = CreateDataContextStack(DataContextStack, nestedDataContextTypes);

            var descriptor = new BindingDescriptor(expression, typeof(ValueBindingExpression <T>), dataContextStack);

            return((ValueBindingExpression <T>)bindingCache.GetOrAdd(descriptor, bd => CompileValueBindingExpression(descriptor)));
        }
Example #9
0
 public bool SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor bindingDescriptor, int state)
 {
     if (_activeOutputDevices.TryGetValue(subReq.DeviceDescriptor, out var deviceHandler))
     {
         deviceHandler.SetOutputState(subReq, bindingDescriptor, state);
         return(true);
     }
     return(false);
 }
Example #10
0
        public static sbyte GetValue(BindingDescriptor bindingDescriptor, int state)
        {
            if (bindingDescriptor.Type == BindingType.Axis)
            {
                return((sbyte)(state / 327.67));
            }

            return((sbyte)(state * 100));
        }
Example #11
0
            protected void SetSliderState(BindingDescriptor bindingDescriptor, int state)
            {
                var inputId = bindingDescriptor.Index;
                //var outState = (short)((state / 256) + 128);              // Xbox Triggers are shorts, but 0..255
                var outState = (byte)(state);              // Xbox Triggers are shorts, but 0..255

                ((IXbox360Controller)target).SetSliderValue(sliderIndexes[inputId], outState);
                /*SendReport();*/
            }
Example #12
0
        /// <summary>
        /// Fires all subscription callbacks for a given Type / Index / SubIndex
        /// </summary>
        /// <param name="bindingDescriptor">A Binding describing the binding</param>
        /// <param name="value">The new value for the input</param>
        public bool FireCallbacks(BindingDescriptor bindingDescriptor, short value)
        {
            if (ContainsKey(bindingDescriptor.Type, bindingDescriptor.Index, bindingDescriptor.SubIndex))
            {
                return(_bindings[bindingDescriptor.Type][bindingDescriptor.Index][bindingDescriptor.SubIndex].FireCallbacks(bindingDescriptor, value));
            }

            return(false);
        }
        private IBinding CompileValueBindingExpression(BindingDescriptor bindingDescriptor)
        {
            var properties = new object[]
            {
                bindingDescriptor.DataContextStack,
                new OriginalStringBindingProperty(bindingDescriptor.Expression)
            };

            return(BindingCompilationService.CreateBinding(bindingDescriptor.BindingType, properties));
        }
Example #14
0
            public bool SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor bindingDescriptor, int state)
            {
                var handler = GetHandler(subReq.DeviceDescriptor);

                if (handler != null)
                {
                    return(handler.SetOutputState(subReq, bindingDescriptor, state));
                }
                return(false);
            }
Example #15
0
            protected override void SetAxisState(BindingDescriptor bindingDescriptor, int state)
            {
                var inputId  = bindingDescriptor.Index;
                var outState = bindingDescriptor.Index > 3      // If Index is 4 or 5 (Triggers)...
                    ? (short)((state / 256) + 128)              // Xbox Triggers are shorts, but 0..255
                    : (short)state;                             // Other axes are regular shorts

                report.SetAxis(axisIndexes[inputId], outState);
                SendReport();
            }
Example #16
0
        private void BuildBindingReports()
        {
            _bindingReports = new ConcurrentDictionary <BindingDescriptor, BindingReport>();
            for (var i = 0; i < 269; i++)
            {
                if (!Enum.IsDefined(typeof(JoystickOffset), i))
                {
                    continue;
                }
                var bindingType       = Utilities.OffsetToType((JoystickOffset)i);
                var bindingDescriptor = new BindingDescriptor
                {
                    Index    = i,
                    SubIndex = 0,
                    Type     = bindingType
                };
                var    category = bindingType == BindingType.Axis ? BindingCategory.Signed : BindingCategory.Momentary;
                string name;
                switch (bindingType)
                {
                case BindingType.Axis:
                    name = ((JoystickOffset)i).ToString();
                    break;

                case BindingType.Button:
                    name = (i - (int)JoystickOffset.Buttons0 + 1).ToString();
                    break;

                case BindingType.POV:
                    for (var j = 0; j < 4; j++)
                    {
                        // POV reports are added here
                        var povNum = (i - (int)JoystickOffset.PointOfViewControllers0) / 4;
                        bindingDescriptor.Index    = povNum;
                        bindingDescriptor.SubIndex = j;
                        _bindingReports.TryAdd(bindingDescriptor, PovBindingInfos[povNum][j]);
                    }
                    continue;

                default:
                    continue;
                }
                var prefix = bindingType.ToString();
                var br     = new BindingReport
                {
                    Title             = name,
                    Path              = $"{prefix}: {name}",
                    Category          = category,
                    BindingDescriptor = bindingDescriptor
                };
                // Button and Axis reports are added here
                _bindingReports.TryAdd(bindingDescriptor, br);
            }
        }
Example #17
0
        private BindingDescriptor BuildControlChangeDescriptor(int channel, int controllerId)
        {
            var bindingDescriptor = new BindingDescriptor
            {
                Type     = BindingType.Axis,
                Index    = channel + (int)MidiCommandCode.ControlChange,
                SubIndex = controllerId
            };

            return(bindingDescriptor);
        }
Example #18
0
        private BindingDescriptor BuildNoteDescriptor(int channel, int octave, int noteIndex)
        {
            var bindingDescriptor = new BindingDescriptor
            {
                Type     = BindingType.Axis,
                Index    = channel + (int)MidiCommandCode.NoteOn,
                SubIndex = ((octave + 2) * 12) + noteIndex
            };

            return(bindingDescriptor);
        }
Example #19
0
        static void Main(string[] args)
        {
            var dev = new DeviceDescriptor {
                DeviceHandle = "TestHandle"
            };
            var subHandler = new SubscriptionHandler(dev, DeviceEmptyHandler);

            var bd1 = new BindingDescriptor {
                Type = BindingType.Button, Index = 1
            };
            var bd2 = new BindingDescriptor {
                Type = BindingType.Button, Index = 2
            };
            var pov1Up = new BindingDescriptor {
                Type = BindingType.POV, Index = 0, SubIndex = 0
            };
            var pov1Right = new BindingDescriptor {
                Type = BindingType.POV, Index = 0, SubIndex = 1
            };

            var b1    = new SubscriptionHelper("Button 1 Subscriber 1", subHandler, dev, bd1);
            var b1a   = new SubscriptionHelper("Button 1 Subscriber 2", subHandler, dev, bd1);
            var b2    = new SubscriptionHelper("Button 2", subHandler, dev, bd2);
            var pov1U = new SubscriptionHelper("POV 1 Up", subHandler, dev, pov1Up);
            var pov1R = new SubscriptionHelper("POV 1 Right", subHandler, dev, pov1Right);

            var tCount = subHandler.Count();

            var buttonsDict = subHandler[BindingType.Button];
            var bCount      = buttonsDict.Count;


            foreach (var item in subHandler)
            {
                Console.WriteLine($"Found Item - Index: {item.Key}");
            }

            var countBefore    = subHandler.Count(BindingType.POV, 0);
            var containsBefore = subHandler.ContainsKey(BindingType.POV, 0);

            subHandler.FireCallbacks(bd1, 100);

            pov1U.Unsubscribe();
            pov1R.Unsubscribe();

            var countAfter    = subHandler.Count(BindingType.POV, 0);
            var containsAfter = subHandler.ContainsKey(BindingType.POV, 0);

            b1.Unsubscribe();
            b1a.Unsubscribe();
            b2.Unsubscribe();

            Console.ReadLine();
        }
        private IBinding CompileCommandBindingExpression(BindingDescriptor descriptor)
        {
            var bindingId = Convert.ToBase64String(Encoding.ASCII.GetBytes(descriptor.DataContextStack.DataContextType.Name + "." + descriptor.Expression));

            var properties = new object[] {
                descriptor.DataContextStack,
                new OriginalStringBindingProperty(descriptor.Expression),
                new IdBindingProperty(bindingId)
            };

            return(BindingCompilationService.CreateBinding(descriptor.BindingType, properties));
        }
Example #21
0
        public void this_Operator_Binds_One_Time()
        {
            Class1            target1 = new Class1();
            Class1            target2 = new Class1();
            BindingDescriptor binding = Class1.FooProperty.Bind().WithMode(BindingMode.OneTime);

            target1.SetValue(Class1.FooProperty, "first");
            target2[binding] = target1[!Class1.FooProperty];
            target1.SetValue(Class1.FooProperty, "second");

            Assert.Equal("first", target2.GetValue(Class1.FooProperty));
        }
Example #22
0
 public IOTester SubscribeOutput(ProviderDescriptor providerDescriptor, DeviceDescriptor deviceDescriptor, BindingDescriptor bindingDescriptor)
 {
     _output = new OutputSubscription()
     {
         ProviderDescriptor = providerDescriptor,
         DeviceDescriptor   = deviceDescriptor
     };
     _bindingDescriptor = bindingDescriptor;
     if (!IOW.Instance.SubscribeOutput(_output))
     {
         throw new Exception("Could not subscribe to output");
     }
     return(this);
 }
Example #23
0
 public bool SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor bindingDescriptor, int state)
 {
     if (outputHandlers.ContainsKey(subReq.DeviceDescriptor.DeviceHandle))
     {
         var slot = outputHandlers[subReq.DeviceDescriptor.DeviceHandle].GetSlot(bindingDescriptor);
         if (slot != null)
         {
             var value = OutputHandler.GetValue(bindingDescriptor, state);
             outputState[(int)slot] = value;
             Write(outputState);
             return(true);
         }
     }
     return(false);
 }
Example #24
0
            protected override void SetAxisState(BindingDescriptor bindingDescriptor, int state)
            {
                var inputId = bindingDescriptor.Index;

                if (bindingDescriptor.Index > 3)
                {
                    SetSliderState(bindingDescriptor, state);
                }
                else
                {
                    var outState = (short)state;                            // Other axes are regular shorts
                    ((IXbox360Controller)target).SetAxisValue(axisIndexes[inputId], outState);
                    /*SendReport();*/
                }
            }
Example #25
0
        protected sealed override BindingDescriptor CreateBindingDescriptor(BindingDescriptor source)
        {
            var result = base.CreateBindingDescriptor(source);

            // If the binding is a template binding, then complete when the Template changes.
            if (source.Priority == BindingPriority.TemplatedParent)
            {
                var templateChanged = GetObservable(TemplateProperty).Skip(1);

                result.SourceObservable = result.Source.GetObservable(result.Property)
                                          .TakeUntil(templateChanged);
            }

            return(result);
        }
Example #26
0
        static void OnBindingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            BindingEditor editor   = (BindingEditor)sender;
            object        newValue = args.NewValue;

            Type      bindingType = null;
            ModelItem item        = newValue as ModelItem;
            string    bindingName = null;

            if (item != null)
            {
                bindingType = item.ItemType;
                bindingName = (string)item.Properties["Name"].ComputedValue;
            }
            else if (newValue != null)
            {
                bindingType = newValue.GetType();
                if (typeof(Binding).IsAssignableFrom(bindingType))
                {
                    bindingName = ((Binding)newValue).Name;
                }
            }

            // Make combo appear empty if the binding is not one of the ones known to us, e.g., has been custom-tweaked in XAML.
            BindingDescriptor toSelect = null;

            Func <BindingDescriptor, bool> where = p => null != p.Value && p.Value.BindingType == bindingType;
            if (editor.bindingElements.Count(where) > 1)
            {
                toSelect = editor.bindingElements.Where(where).Where(p => string.Equals(p.BindingName, bindingName)).FirstOrDefault();
            }
            else
            {
                toSelect = editor.bindingElements.Where(where).FirstOrDefault();
            }
            //prevent OnSelectionChanged now - the binding is set directly to the object, no need to set again through event handler
            editor.isInitializing = true;
            if (null != toSelect)
            {
                editor.SelectedItem = toSelect;
            }
            else
            {
                editor.SelectedIndex = 0;
            }
            //allow selection changed events to be consumed again
            editor.isInitializing = false;
        }
Example #27
0
        public DeviceReport GetInputDeviceReport(DeviceDescriptor deviceDescriptor)
        {
            var deviceReport = new DeviceReport
            {
                DeviceDescriptor = _spaceMouseProDescriptor,
                DeviceName       = "SpaceMouse Pro"
            };

            // ----- Axes -----
            var axisInfo = new DeviceReportNode
            {
                Title = "Axes"
            };

            for (var i = 0; i < 6; i++)
            {
                var bd = new BindingDescriptor
                {
                    Index = i,
                    Type  = BindingType.Axis
                };
                axisInfo.Bindings.Add(GetInputBindingReport(deviceDescriptor, bd));
            }

            deviceReport.Nodes.Add(axisInfo);

            // ----- Buttons -----
            var buttonInfo = new DeviceReportNode
            {
                Title = "Buttons"
            };

            foreach (var button in _buttonNames)
            {
                var bd = new BindingDescriptor
                {
                    Index = button.Key,
                    Type  = BindingType.Button
                };
                buttonInfo.Bindings.Add(GetInputBindingReport(deviceDescriptor, bd));
            }

            deviceReport.Nodes.Add(buttonInfo);

            return(deviceReport);
        }
Example #28
0
        public BindingReport BuildKeyboardBindingReport(BindingDescriptor bindingDescriptor)
        {
            var keyName = KeyNameHelper.GetNameFromScanCode(bindingDescriptor.Index + 1);

            if (keyName == null)
            {
                return(null);
            }
            return(new BindingReport
            {
                Title = keyName,
                Path = $"Key: {keyName}",
                Category = BindingCategory.Momentary,
                BindingDescriptor = bindingDescriptor,
                Blockable = _blockingEnabled
            });
        }
Example #29
0
        public void SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor bindingDescriptor, int state)
        {
            var       channel     = (bindingDescriptor.Index & 0xf) + 1;
            var       commandCode = (MidiCommandCode)(bindingDescriptor.Index & 0xf0);
            MidiEvent evt;

            switch (commandCode)
            {
            case MidiCommandCode.ControlChange:
                var value = (int)((state + 32768) / 516.0236220472441);
                evt = new ControlChangeEvent(0, channel, (MidiController)bindingDescriptor.SubIndex, value);
                break;

            default:
                return;
            }
            _midiOut.Send(evt.GetAsShortMessage());
        }
Example #30
0
            public bool SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor bindingDescriptor, int state)
            {
                switch (bindingDescriptor.Type)
                {
                case BindingType.Axis:
                    SetAxisState(bindingDescriptor, state);
                    break;

                case BindingType.Button:
                    SetButtonState(bindingDescriptor, state);
                    break;

                case BindingType.POV:
                    SetPovState(bindingDescriptor, state);
                    break;
                }
                return(false);
            }
        private BindingDescriptor<EditableColumn> createUserBindingDescriptor()
        {
            BindingDescriptor<EditableColumn> bd = new BindingDescriptor<EditableColumn>();

            EditableColumn column = new EditableColumn();
            column.DataType = typeof(string);
            column.Name = "Username";
            column.ObjectPropertyName = column.Name;
            column.Editable = true;
            column.Widget = typeof(TextBox);
            column.Visible = true;

            EditableColumn column2 = new EditableColumn();
            column2.DataType = typeof(string);
            column2.Name = "Email";
            column2.ObjectPropertyName = column2.Name;
            column2.Editable = true;
            column2.Widget = typeof(TextBox);
            column2.Visible = true;

            EditableColumn column3 = new EditableColumn();
            column3.DataType = typeof(int);
            column3.Name = "Desk";
            column3.ObjectPropertyName = column3.Name;
            column3.Editable = true;
            column3.Widget = typeof(IntegerTextBox);
            column3.Visible = true;

            EditableColumn column4 = new EditableColumn();
            column4.DataType = typeof(bool);
            column4.Name = "Is Active";
            column4.ObjectPropertyName = "IsActive";
            column4.Editable = true;
            column4.Widget = typeof(CheckBox);
            column4.Visible = true;

            bd.BindingColumns.Add(column);
            bd.BindingColumns.Add(column2);
            bd.BindingColumns.Add(column3);
            bd.BindingColumns.Add(column4);

            return bd;
        }
        private void createBindingDescriptorFromTable()
        {
            BindingDescriptor = new BindingDescriptor<EditableColumn>();

            foreach (DataColumn dColumn in _dataTable.Columns)
            {
                Logger.GetInstance().WriteLine("dataTableGrid reading column:" + dColumn.ColumnName);
                EditableColumn editColumn = new EditableColumn();
                editColumn.Editable = true;
                editColumn.DataType = dColumn.DataType;
                editColumn.Name = dColumn.ColumnName;
                editColumn.ObjectPropertyName = dColumn.ColumnName;
                editColumn.Visible = true;
                if (typeof(int).IsAssignableFrom(dColumn.DataType))
                {
                    editColumn.Widget = typeof(IntegerTextBox);
                }
                else if (typeof(bool).IsAssignableFrom(dColumn.DataType))
                {
                    editColumn.Widget = typeof(CheckBox);
                }
                else
                {
                    editColumn.Widget = typeof(TextBox);
                }
                BindingDescriptor.BindingColumns.Add(editColumn);
            }
        }
Example #33
0
        protected sealed override BindingDescriptor CreateBindingDescriptor(BindingDescriptor source)
        {
            var result = base.CreateBindingDescriptor(source);

            // If the binding is a template binding, then complete when the Template changes.
            if (source.Priority == BindingPriority.TemplatedParent)
            {
                var templateChanged = GetObservable(TemplateProperty).Skip(1);

                result.SourceObservable = result.Source.GetObservable(result.Property)
                    .TakeUntil(templateChanged);
            }

            return result;
        }
        public static Binding BuildBinding(string path)
        {
            BindingDescriptor bindingDescriptor;

            if (BindingCache.TryGetValue(path, out bindingDescriptor))
                return bindingDescriptor.ToBinding();

            bindingDescriptor = new BindingDescriptor();

            var match = _bindingPathRegex.Match(path);

            if (match.Groups["propertyPath"].Success)
            {
                bindingDescriptor.PropertyPath = match.Groups["propertyPath"].Value;
            }

            if (!match.Groups["dataContext"].Success &&
                !match.Groups["markupSource"].Success &&
                !match.Groups["xName"].Success)
            {
                throw new System.Windows.Markup.XamlParseException("Could not find source in: " + path);
            }

            if (match.Groups["xName"].Success)
            {
                bindingDescriptor.ElementName = match.Groups["xName"].Value;
            }

            if (match.Groups["markupSource"].Success)
            {
                string markupSourcePath = match.Groups["markupSource"].Value;

                Match selfExtensionMatch = _selfExtensionRegex.Match(markupSourcePath);

                if (selfExtensionMatch.Success)
                {
                    bindingDescriptor.RelativeSource = RelativeSource.Self;
                }
                //DEM Added TemplatedParent and FindAncestor support
                else
                {
                    Match parenttemplateExtensionMatch = _templateParentExtensionRegex.Match(markupSourcePath);
                    if (parenttemplateExtensionMatch.Success)
                    {
                        bindingDescriptor.RelativeSource = RelativeSource.TemplatedParent;
                    }
                    else
                    {
                        Match RelativeAncestorExtensionMatch = _RelativeAncestorExtensionRegex.Match(markupSourcePath);
                        if (RelativeAncestorExtensionMatch.Success)
                        {
                           // RelativeSource nr = new RelativeSource(RelativeSourceMode.FindAncestor);
                            RelativeSource nr = new RelativeSource();
                            nr.AncestorType = TypeFromStringSolver.FromString(RelativeAncestorExtensionMatch.Groups["Type"].Value);
                            if (RelativeAncestorExtensionMatch.Groups["Level"].Success) 
                            {
                                nr.AncestorLevel = int.Parse(RelativeAncestorExtensionMatch.Groups["Level"].Value);
                            }
                            bindingDescriptor.RelativeSource = nr;
                        }
                    }
                }
                //End DEM

            }

            BindingCache.Add(path, bindingDescriptor);

            return bindingDescriptor.ToBinding();
        }