Ejemplo n.º 1
0
        public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            if (data.EventAction == TorqueInputDevice.Action.Break)
            {
                // ignore mouse movement...
                if (data.DeviceTypeId == TorqueInputDevice.KeyboardId || data.DeviceTypeId == TorqueInputDevice.GamePadId)
                {
                    if (_finishedDelegate != null)
                        _finishedDelegate();

                    return true;
                }
            }

            return false;
        }
        /// <summary>
        /// Register an input device with the InputManager.
        /// </summary>
        /// <param name="device">Input device to register.</param>
        /// <returns>Index of device in input manager.</returns>
        public int AddDevice(TorqueInputDevice device)
        {
            // for sanity sake, make sure we aren't already added
            // while we're at it, get highest count of similar devices
            int count = -1;
            for (int i = 0; i < _devices.Count; i++)
            {
                if (_devices[i] == device)
                    return i;
                if (_devices[i].DeviceTypeId == device.DeviceTypeId)
                    count = _devices[i]._deviceInstance;
            }

            _devices.Add(device);
            // Note: we won't worry too much about repeating old device instance
            // numbers since we aren't geared toward adding/removing devices
            // and re-using number should work fine anyway.  But take the trivial
            // precaution of choosing max prior instance +1 rather than simply
            // counting current instances +1 (otherwise could get a duplication).
            device._setDeviceIdentifiers(_devices.Count - 1, count + 1);
            return _devices.Count - 1;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Undoes any previous call to BindCommand, BindAction, and/or BindMove for
        /// the passed combination of deviceNumber, objectId, and modifier.
        /// </summary>
        /// <param name="deviceNumber">e.g. InputManager.Instance.FindDevice("keyboard")</param>
        /// <param name="objectId">e.g. (int)Keys.S</param>
        /// <param name="modifier">e.g. TorqueInputDevice.Action.Shift</param>
        /// <returns>Whether deviceNumber and objectId are valid.</returns>
        public bool UnbindInput(int deviceNumber, int objectId, TorqueInputDevice.Action modifier)
        {
            TorqueInputDevice device = InputManager.Instance.GetDevice(deviceNumber);
            if (device == null || !device.IsValidObject(objectId))
                return false;

            int index = _FindInputNode(deviceNumber, objectId, modifier);
            if (index < 0)
                return true; //no binding, yet, for that combination

            InputNode node = _inputNodes[index];

            node.Flags = InputNode.ActionFlags.None;
            node.MakeDelegate = null;
            node.BreakDelegate = null;
            node.ActionDelegate = null;
            node.Modifier = TorqueInputDevice.Action.None;
            node.MoveIndex = -1;

            _inputNodes[index] = node;

            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fires any actions, commands, or moves bound to passed input.  This method is
        /// generally only called by the input manager.
        /// </summary>
        /// <param name="data">Input event data.</param>
        /// <returns>True if input map processes the input event.</returns>
        public bool ProcessInput(TorqueInputDevice.InputEventData data)
        {
            int idx = _FindInputNode(data.DeviceNumber, data.ObjectId, data.Modifier);
            if (idx < 0)
                return false;

            if (data.DeviceNumber < 5 && data.DeviceNumber >= 0)
                _deviceNumber = data.DeviceNumber;

            if (data.EventAction == TorqueInputDevice.Action.Break)
                return _CheckBreakTable(data);

            float value = data.Value;
            InputNode.ActionFlags flags = _inputNodes[idx].Flags;
            if ((flags & InputNode.ActionFlags.BindCmd) != 0)
            {
                if (data.EventAction == TorqueInputDevice.Action.Make)
                {
                    if (_inputNodes[idx].MakeDelegate != null)
                        _inputNodes[idx].MakeDelegate();

                    _EnterBreakEvent(data, idx);
                    return true;
                }
            }
            else
            {
                if (data.EventAction == TorqueInputDevice.Action.Make || data.EventAction == TorqueInputDevice.Action.Move)
                {
                    _MakeBreakModifyEventValue(ref value, _inputNodes[idx]);
                    if (_inputNodes[idx].ActionDelegate != null)
                        _inputNodes[idx].ActionDelegate(value);
                    else if (_inputNodes[idx].MoveIndex >= 0)
                        _SetMoveValue(_inputNodes[idx].MoveMapType, _inputNodes[idx].MoveIndex, value);
                }
                if (data.EventAction == TorqueInputDevice.Action.Make)
                    _EnterBreakEvent(data, idx);
                return true;
            }

            return false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Bind move manager move to particular make/break/move event.
        /// </summary>
        /// <param name="deviceName">Name of device to bind to, e.g. "gamepad1", "mouse0", "keyboard0".</param>
        /// <param name="inputObject">Name of input object to bind to, e.g. "ThumbStickX", "LeftTriggerButton".</param>
        /// <param name="modifier">Restrict binding to be in effect only when given modifier is present.  Valid modifiers are 
        /// Shift, Ctrl, LeftClick, MiddleClick, RightClick</param>
        /// <param name="mapType">Type of move map binding.  This parameter controls whether we bind to a move stick, lever, trigger,
        /// or button, and whether we assume a digital input (e.g., keypress, button press) or an analog input (e.g., thumbstick).</param>
        /// <param name="moveIdx">Index of stick, lever, trigger, or button on the move manager to bind to.</param>
        /// <returns>True if binding is successful.</returns>
        public bool BindMove(String deviceName, String inputObject, TorqueInputDevice.Action modifier, MoveMapTypes mapType, int moveIdx)
        {
            int deviceNumber = InputManager.Instance.FindDevice(deviceName);
            if (deviceNumber == -1)
                return false;

            TorqueInputDevice device = InputManager.Instance.GetDevice(deviceNumber);
            int objectId = device.GetObjectId(inputObject);
            if (objectId == -1)
                return false;

            return BindMove(deviceNumber, objectId, modifier, mapType, moveIdx);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Bind move manager move to particular make/break/move event.
        /// </summary>
        /// <param name="deviceNumber">Device number to bind.</param>
        /// <param name="objectId">Device object to bind to.  E.g., GamePads have thumb sticks, buttons, and triggers, which 
        /// have id's corresponding to XGamePadDevice.GamePadObjects enum values.</param>
        /// <param name="modifier">Restrict binding to be in effect only when given modifier is present.  Valid modifiers are 
        /// Shift, Ctrl, LeftClick, MiddleClick, RightClick</param>
        /// <param name="mapType">Type of move map binding.  This parameter controls whether we bind to a move stick, lever, trigger,
        /// or button, and whether we assume a digital input (e.g., keypress, button press) or an analog input (e.g., thumbstick).</param>
        /// <param name="moveIdx">Index of stick, lever, trigger, or button on the move manager to bind to.</param>
        /// <returns>True if binding is successful.</returns>
        public bool BindMove(int deviceNumber, int objectId, TorqueInputDevice.Action modifier, MoveMapTypes mapType, int moveIdx)
        {
            if (deviceNumber < 0 || deviceNumber >= InputManager.Instance.GetNumDevices())
                return false;
            TorqueInputDevice device = InputManager.Instance.GetDevice(deviceNumber);
            if (!device.IsValidObject(objectId))
                return false;

            InputNode node = new InputNode();
            node.DeviceNumber = deviceNumber;
            node.ObjectId = objectId;
            node.Modifier = modifier;
            node.Flags = InputNode.ActionFlags.None;
            node.DeadZoneBegin = 0.0f;
            node.DeadZoneEnd = 0.0f;
            node.ScaleFactor = 1.0f;
            node.MoveIndex = moveIdx;
            node.MoveMapType = mapType;

            _currentBindIndex = _SetInputNode(deviceNumber, objectId, modifier, ref node);
            _UpdateMoveManager(node);

            return true;
        }
        /// <summary>
        /// Callback to TorqueInputEvent -- all input in Torque X is passed via this method.
        /// </summary>
        /// <param name="eventName">Name of event for which this callback.</param>
        /// <param name="inputData">Input data.</param>
        public void ProcessInputEvent(String eventName, TorqueInputDevice.InputEventData inputData)
        {
            // send input to global input map
            if (InputMap.Global.ProcessInput(inputData))
                return;

            // if not handled, send to gui
            if (GUICanvas.Instance.ProcessInput(inputData))
                return;

            // if not handled, send to rest of the input maps (go in reverse order so most recent push first)
            for (int i = _inputMaps.Count - 1; i >= 0; i--)
            {
                InputMap map = _inputMaps[i];
                if (map.ProcessInput(inputData))
                    return;
            }
        }
Ejemplo n.º 8
0
        int _SetInputNode(int deviceNumber, int objectId, TorqueInputDevice.Action modifier, ref InputNode node)
        {
            int ret = _FindInputNode(deviceNumber, objectId, modifier);

            if (ret >= 0)
            {
                //_inputNodes[ret] = node;
                //    return ret;

                if (null == node.ActionDelegate &&
                    null == node.MakeDelegate &&
                    null == node.BreakDelegate &&
                    node.MoveIndex < 0)
                {
                    _inputNodes.RemoveAt(ret);
                    return _inputNodes.Count - 1;
                }
                else
                {
                    _inputNodes[ret] = node;
                    return ret;
                }

            }

            _inputNodes.Add(node);
            return _inputNodes.Count - 1;
        }
Ejemplo n.º 9
0
 void _EnterBreakEvent(TorqueInputDevice.InputEventData data, int inputNodeIdx)
 {
     int deviceNumber = _inputNodes[inputNodeIdx].DeviceNumber;
     int objectId = _inputNodes[inputNodeIdx].ObjectId;
     InputNode node;
     for (int i = 0; i < _breakTable.Count; i++)
     {
         if (_breakTable[i].DeviceNumber == deviceNumber && _breakTable[i].ObjectId == objectId)
         {
             node = _inputNodes[inputNodeIdx];
             node._map = this;
             _breakTable[i] = node;
             return;
         }
     }
     node = _inputNodes[inputNodeIdx];
     node._map = this;
     _breakTable.Add(node);
 }
Ejemplo n.º 10
0
        public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            if (data.DeviceTypeId == XGamePadDevice.GamePadId)
            {
                switch (data.ObjectId)
                {
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbX:
                        ConsoleGui.Instance._scroll.ActiveScrollY = -data.Value;
                        return true;

                    case (int)XGamePadDevice.GamePadObjects.LeftThumbY:
                        ConsoleGui.Instance._scroll.ActiveScrollY = data.Value;
                        return true;

                    // trap these so they don't get used for focus changing by the canvas
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbUpButton:
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbDownButton:
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbLeftButton:
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbRightButton:
                        return true;
                }
            }
            else if (data.DeviceTypeId == XKeyboardDevice.KeyboardId)
            {
                switch (data.ObjectId)
                {
                    case (int)Keys.PageUp:
                        if(data.EventAction == TorqueInputDevice.Action.Make)
                            ConsoleGui.Instance._scroll.ActiveScrollY = 1;
                        else
                            ConsoleGui.Instance._scroll.ActiveScrollY = 0;
                        return true;

                    case (int)Keys.PageDown:
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                            ConsoleGui.Instance._scroll.ActiveScrollY = -1;
                        else
                            ConsoleGui.Instance._scroll.ActiveScrollY = 0;
                        return true;

                    case (int)Keys.Left:
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                            ConsoleGui.Instance._scroll.ActiveScrollX = 1;
                        else
                            ConsoleGui.Instance._scroll.ActiveScrollX = 0;
                        return base.OnInputEvent(ref data);

                    case (int)Keys.Right:
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                            ConsoleGui.Instance._scroll.ActiveScrollX = -1;
                        else
                            ConsoleGui.Instance._scroll.ActiveScrollX = 0;
                        return base.OnInputEvent(ref data);
                }
            }

            return base.OnInputEvent(ref data);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Called by the InputManager. First tries to pass the input event to the
        /// current focus control. If no focus control is present, then tries to 
        /// pass the input event to the current content control. If neither exists
        /// or handles the event, the input will not be handled.
        /// </summary>
        /// <param name="data">The input event data from the InputManager.</param>
        /// <returns>True if a control handled the input event.</returns>
        public bool ProcessInput(TorqueInputDevice.InputEventData data)
        {
            if (_focusControl != null)
            {
                // if the first responder or one of its parents handles the event
                if (_focusControl.OnInputEvent(ref data))
                    return true;
            }
            else
            {
                if (GetNumObjects() > 0)
                {
                    // since we don't have a focus control use the content control
                    GUIControl content = (GUIControl)GetObject(0);

                    if (content != null)
                    {
                        if (content.OnInputEvent(ref data))
                            return true;
                    }
                }
            }

            // if we are here, then no controls handled the input
            return false;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// The general input handler for the canvas. Input events are routed here if a
        /// focus control or content control did not want to handle the input event. The
        /// canvas can use the input event to determine if the focus control needs to
        /// change.
        /// </summary>
        /// <param name="data">The input event data from the InputManager.</param>
        /// <returns>True if the canvas handled the input event.</returns>
        public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            // handle keyboard input
            if (data.DeviceTypeId == TorqueInputDevice.KeyboardId)
            {
                // tab focus
                if (data.ObjectId == (int)Microsoft.Xna.Framework.Input.Keys.Tab)
                {
                    if (data.EventAction == TorqueInputDevice.Action.Make)
                    {
                        if ((data.Modifier & TorqueInputDevice.Action.Shift) != 0)
                        {
                            if (FocusPrev(SearchPolicy.Horizontal))
                                return true;
                            else if (FocusPrev(SearchPolicy.Vertical))
                                return true;
                        }
                        else if (data.Modifier == TorqueInputDevice.Action.None)
                        {
                            if (FocusNext(SearchPolicy.Horizontal))
                                return true;
                            else if (FocusNext(SearchPolicy.Vertical))
                                return true;
                        }
                    }
                }
            }

            // handle mouse input
            else if (data.DeviceTypeId == TorqueInputDevice.MouseId)
            {
                // rdbtodo: need to handle mouse input, pick controls, etc.
                // rdbtodo: drawing mouse cursor
            }

            // handle gamepad input
            else if (data.DeviceTypeId == TorqueInputDevice.GamePadId)
            {
                // directional focus change
                if (data.EventAction == TorqueInputDevice.Action.Make)
                {
                    switch (data.ObjectId)
                    {
                        case (int)XGamePadDevice.GamePadObjects.LeftThumbLeftButton:
                        case (int)XGamePadDevice.GamePadObjects.Left:
                            if (FocusPrev(SearchPolicy.Horizontal))
                                return true;
                            break;

                        case (int)XGamePadDevice.GamePadObjects.LeftThumbRightButton:
                        case (int)XGamePadDevice.GamePadObjects.Right:
                            if (FocusNext(SearchPolicy.Horizontal))
                                return true;
                            break;

                        case (int)XGamePadDevice.GamePadObjects.LeftThumbUpButton:
                        case (int)XGamePadDevice.GamePadObjects.Up:
                            if (FocusPrev(SearchPolicy.Vertical))
                                return true;
                            break;

                        case (int)XGamePadDevice.GamePadObjects.LeftThumbDownButton:
                        case (int)XGamePadDevice.GamePadObjects.Down:
                            if (FocusNext(SearchPolicy.Vertical))
                                return true;
                            break;
                    }
                }
            }

            return false;
        }
        // adltodo: There's a lot of functionality that isn't here, like highlighting for instance.
        public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            if (_inputMap != null)
            {
                if (_inputMap.ProcessInput(data))
                    return true;
            }

            // only need keyboard events
            if (data.DeviceTypeId != TorqueInputDevice.GetDeviceTypeId("keyboard"))
                return base.OnInputEvent(ref data);

            // capture break events, but we don't need to use them
            if (data.EventAction == TorqueInputDevice.Action.Break)
            {
                if (data.ObjectId == (int)_heldKey)
                    _heldKey = Keys.None;

                return true;
            }

            // record the state of the shift modifier
            _shiftPressed = (data.Modifier & TorqueInputDevice.Action.Shift) != 0;

            // only handle make events otherwise!
            if (data.EventAction != TorqueInputDevice.Action.Make)
                return false;

            // let the parent handle it for control focusing
            if (data.ObjectId == (int)Keys.Tab)
                return base.OnInputEvent(ref data);

            // record this key as pressed
            _heldKey = (Keys)data.ObjectId;
            _keyPressedTime = TorqueEngineComponent.Instance.TorqueTime;

            return _ProcessKey(data.ObjectId);
        }
 /// <summary>
 /// Unregister a device from the input manager.
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 public bool RemoveDevice(TorqueInputDevice device)
 {
     for (int i = 0; i < _devices.Count; i++)
         if (_devices[i] == device)
         {
             _devices.RemoveAt(i);
             return true;
         }
     return false;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Undoes any previous call to BindCommand, BindAction, and/or BindMove for
        /// the passed combination of deviceName, objectName, and modifier.
        /// </summary>
        /// <param name="deviceName">e.g. "keyboard"</param>
        /// <param name="objectName">e.g. "S"</param>
        /// <param name="modifier">e.g. TorqueInputDevice.Action.Shift</param>
        /// <returns>Whether deviceNumber and objectId are valid.</returns>
        public bool UnbindInput(String deviceName, String objectName, TorqueInputDevice.Action modifier)
        {
            int deviceNumber = InputManager.Instance.FindDevice(deviceName);
            if (deviceNumber == -1)
                return false;

            TorqueInputDevice device = InputManager.Instance.GetDevice(deviceNumber);
            int objectId = device.GetObjectId(objectName);
            if (objectId == -1)
                return false;

            return UnbindInput(deviceNumber, objectId, modifier);
        }
Ejemplo n.º 16
0
        public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            if (_inputMap != null)
            {
                if (_inputMap.ProcessInput(data))
                    return true;
            }

            if (data.DeviceTypeId == XGamePadDevice.GamePadId)
            {
                switch (data.ObjectId)
                {
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbX:
                        _scrollAmountX = -data.Value;
                        return true;

                    case (int)XGamePadDevice.GamePadObjects.LeftThumbY:
                        _scrollAmountY = data.Value;
                        return true;

                    // trap these so they don't get used for focus changing by the canvas
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbUpButton:
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbDownButton:
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbLeftButton:
                    case (int)XGamePadDevice.GamePadObjects.LeftThumbRightButton:
                        return true;
                }
            }
            else if (data.DeviceTypeId == XKeyboardDevice.KeyboardId)
            {
                switch (data.ObjectId)
                {
                    case (int)Keys.PageUp:
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                            _scrollAmountY = 1;
                        else
                            _scrollAmountY = 0;
                        return true;

                    case (int)Keys.PageDown:
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                            _scrollAmountY = -1;
                        else
                            _scrollAmountY = 0;
                        return true;

                    case (int)Keys.Left:
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                            _scrollAmountX = 1;
                        else
                            _scrollAmountX = 0;
                        return true;

                    case (int)Keys.Right:
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                            _scrollAmountX = -1;
                        else
                            _scrollAmountX = 0;
                        return true;
                }
            }

            return base.OnInputEvent(ref data);
        }
Ejemplo n.º 17
0
 bool _CheckBreakTable(TorqueInputDevice.InputEventData data)
 {
     for (int i = 0; i < _breakTable.Count; i++)
     {
         if (_breakTable[i].DeviceNumber == data.DeviceNumber && _breakTable[i].ObjectId == data.ObjectId)
         {
             if ((_breakTable[i].Flags & InputNode.ActionFlags.BindCmd) != 0)
             {
                 if (_breakTable[i].BreakDelegate != null)
                     _breakTable[i].BreakDelegate();
             }
             else
             {
                 if (_breakTable[i].ActionDelegate != null)
                 {
                     float value = data.Value;
                     _MakeBreakModifyEventValue(ref value, _breakTable[i]);
                     _breakTable[i].ActionDelegate(value);
                 }
                 else if (_breakTable[i].MoveIndex >= 0)
                 {
                     Assert.Fatal(_breakTable[i]._map != null, "Input map should never be null in break table");
                     float value = data.Value;
                     _breakTable[i]._map._MakeBreakModifyEventValue(ref value, _breakTable[i]);
                     _breakTable[i]._map._SetMoveValue(_breakTable[i].MoveMapType, _breakTable[i].MoveIndex, value);
                 }
             }
             _breakTable.RemoveAt(i);
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Bind delegates to particular make/break input event.
        /// </summary>
        /// <param name="deviceNumber">Device number to bind.</param>
        /// <param name="objectId">Device object to bind to.  E.g., GamePads have thumb sticks, buttons, and triggers, which 
        /// have id's corresponding to XGamePadDevice.GamePadObjects enum values.</param>
        /// <param name="modifier">Restrict binding to be in effect only when given modifier is present.  Valid modifiers are 
        /// Shift, Ctrl, LeftClick, MiddleClick, RightClick</param>
        /// <param name="makeDelegate">Delegate to invoke on make events.</param>
        /// <param name="breakDelegate">Delegate to invoke on break events.</param>
        /// <returns>True if binding was succesful.</returns>
        public bool BindCommand(int deviceNumber, int objectId, TorqueInputDevice.Action modifier, MakeDelegate makeDelegate, BreakDelegate breakDelegate)
        {
            if (deviceNumber < 0 || deviceNumber >= InputManager.Instance.GetNumDevices())
                return false;
            TorqueInputDevice device = InputManager.Instance.GetDevice(deviceNumber);
            if (!device.IsValidObject(objectId))
                return false;

            InputNode node = new InputNode();
            node.DeviceNumber = deviceNumber;
            node.ObjectId = objectId;
            node.Modifier = modifier;
            node.Flags = InputNode.ActionFlags.BindCmd;
            node.DeadZoneBegin = 0.0f;
            node.DeadZoneEnd = 0.0f;
            node.ScaleFactor = 1.0f;
            node.MoveIndex = -1;
            node.MakeDelegate = makeDelegate;
            node.BreakDelegate = breakDelegate;
            _SetInputNode(deviceNumber, objectId, modifier, ref node);
            _currentBindIndex = -1;

            return true;
        }
Ejemplo n.º 19
0
 int _FindInputNode(int deviceNumber, int objectId, TorqueInputDevice.Action modifier)
 {
     for (int i = 0; i < _inputNodes.Count; i++)
     {
         if (_inputNodes[i].DeviceNumber == deviceNumber && _inputNodes[i].ObjectId == objectId && _inputNodes[i].Modifier == modifier)
             return i;
     }
     return -1;
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Bind delegates to particular make/break input event.
        /// </summary>
        /// <param name="deviceName">Name of device to bind to, e.g. "gamepad1", "mouse0", "keyboard0".</param>
        /// <param name="inputObject">Name of input object to bind to, e.g. "ThumbStickX", "LeftTriggerButton".</param>
        /// <param name="modifier">Restrict binding to be in effect only when given modifier is present.  Valid modifiers are 
        /// Shift, Ctrl, LeftClick, MiddleClick, RightClick</param>
        /// <param name="makeDelegate">Delegate to invoke on make events.</param>
        /// <param name="breakDelegate">Delegate to invoke on break events.</param>
        /// <returns>True if binding is successful.</returns>
        public bool BindCommand(String deviceName, String inputObject, TorqueInputDevice.Action modifier, MakeDelegate makeDelegate, BreakDelegate breakDelegate)
        {
            int deviceNumber = InputManager.Instance.FindDevice(deviceName);
            if (deviceNumber == -1)
                return false;

            TorqueInputDevice device = InputManager.Instance.GetDevice(deviceNumber);
            int objectId = device.GetObjectId(inputObject);
            if (objectId == -1)
                return false;

            return BindCommand(deviceNumber, objectId, modifier, makeDelegate, breakDelegate);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// The general input handler for this control. Input events are routed here first
        /// before they are given to this control's InputMap, if one exists. If a Parent
        /// control exists, input should be routed to the Parent if this control or its 
        /// InputMap did not handle the event.
        /// </summary>
        /// <param name="data">The input event data from the InputManager.</param>
        /// <returns>True if this control or its Parent handled the input event.</returns>
        public virtual bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            if (_inputMap != null)
            {
                if (_inputMap.ProcessInput(data))
                    return true;
            }

            // if we got here, this control didn't handle the input,
            //  pass it up to the parent if we have one
            if (Parent != null)
                return Parent.OnInputEvent(ref data);

            return false;
        }
Ejemplo n.º 22
0
        public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            // an inactive button is a disabled button
            if (Active)
            {
                if (_inputMap != null)
                {
                    if (_inputMap.ProcessInput(data))
                    {
                        if (data.EventAction == TorqueInputDevice.Action.Make)
                        {
                            _buttonState = ButtonState.Pushed;
                        }
                        else if (data.EventAction == TorqueInputDevice.Action.Break)
                        {
                            if (GUICanvas.Instance.GetFocusControl() == this)
                                _buttonState = ButtonState.Selected;
                            else
                                _buttonState = ButtonState.Normal;
                        }

                        return true;
                    }
                }

                // if the button is currently pushed, eat input until it is released
                if (_buttonState == ButtonState.Pushed)
                    return false;
            }

            // if we got here, this control didn't handle the input,
            //  pass it up to the parent if we have one
            return (Parent != null ? Parent.OnInputEvent(ref data) : false);
        }