public override void ReadXml(XmlReader reader)
        {
            string name = reader.GetAttribute("Name");
            string guid = reader.GetAttribute("GUID");

            reader.ReadStartElement("Controller");
            name         = reader.ReadElementString("Name");
            guid         = reader.ReadElementString("GUID");
            ControllerId = new DirectXControllerGuid(name, new Guid(guid));
            if (_device == null)
            {
                if (!reader.IsEmptyElement)
                {
                    reader.ReadStartElement("Functions");
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        reader.ReadStartElement("Function");
                        string functionName = reader.ReadElementString("Type");
                        int    objectNumber = int.Parse(reader.ReadElementString("Number"), CultureInfo.InvariantCulture);
                        reader.ReadEndElement();
                        AddFunction(DirectXControllerFunction.CreateDummy(this, functionName, objectNumber));
                    }
                    reader.ReadEndElement();
                }
                else
                {
                    reader.Read();
                }
            }
            else
            {
                reader.Skip();
            }
            reader.ReadEndElement();
        }
        private void AddFunction(DirectXControllerFunction function)
        {
            if (function != null)
            {
                Values.Add(function.Value);
                foreach (IBindingTrigger trigger in function.Triggers)
                {
                    Triggers.Add(trigger);
                }

                _functions.Add(function);
            }
        }
Пример #3
0
        public static DirectXControllerFunction CreateDummy(DirectXControllerInterface controllerInterface, string type, int objectNumber)
        {
            DirectXControllerFunction function = null;
            JoystickState             state    = new JoystickState();

            switch (type)
            {
            case "X Axis":
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.X, objectNumber, state);
                break;

            case "Y Axis":
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Y, objectNumber, state);
                break;

            case "Z Axis":
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Z, objectNumber, state);
                break;

            case "X Rotation":
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Rx, objectNumber, state);
                break;

            case "Y Rotation":
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Ry, objectNumber, state);
                break;

            case "Z Rotation":
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Rz, objectNumber, state);
                break;

            case "Slider":
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Slider, objectNumber, state);
                break;

            case "Button":
                function = new DirectXControllerButton(controllerInterface, objectNumber, state);
                break;

            case "POV":
                function = new DirectXControllerPOVHat(controllerInterface, objectNumber);
                break;
            }

            return(function);
        }
Пример #4
0
        public static DirectXControllerFunction Create(DirectXControllerInterface controllerInterface, Guid objectType, int objectNumber, JoystickState initialState)
        {
            DirectXControllerFunction function = null;

            if (objectType == ObjectGuid.Button)
            {
                function = new DirectXControllerButton(controllerInterface, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.Slider)
            {
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Slider, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.XAxis)
            {
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.X, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.YAxis)
            {
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Y, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.ZAxis)
            {
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Z, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.RxAxis)
            {
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Rx, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.RyAxis)
            {
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Ry, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.RzAxis)
            {
                function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Rz, objectNumber, initialState);
            }
            else if (objectType == ObjectGuid.PovController)
            {
                function = new DirectXControllerPOVHat(controllerInterface, objectNumber, initialState);
            }

            return(function);
        }
        private void PopulateFunctions(IList <DeviceObjectInstance> objects)
        {
            Triggers.Clear();
            Values.Clear();
            _functions.Clear();

            _device.Poll();
            JoystickState state = GetState();

            int lastButton = -1;
            int lastSlider = -1;
            int lastPov    = -1;

            foreach (DeviceObjectInstance obj in objects)
            {
                int controlNum = -1;
                if (obj.ObjectType == ObjectGuid.Button)
                {
                    controlNum = ++lastButton;
                }
                else if (obj.ObjectType == ObjectGuid.Slider)
                {
                    controlNum = ++lastSlider;
                }
                else if (obj.ObjectType == ObjectGuid.PovController)
                {
                    controlNum = ++lastPov;
                }
                else if (obj.ObjectType != ObjectGuid.Unknown)
                {
                    controlNum = 0;
                }

                if (controlNum > -1)
                {
                    AddFunction(DirectXControllerFunction.Create(this, obj.ObjectType, controlNum, state));
                }
            }
        }
        private void AddFunction(DirectXControllerFunction function)
        {
            if (function != null)
            {
                Values.Add(function.Value);
                foreach (IBindingTrigger trigger in function.Triggers)
                {
                    Triggers.Add(trigger);
                }

                _functions.Add(function);
            }

        }