Exemplo n.º 1
0
        internal void OnCanvasTouchStart(int id, float x, float y)
        {
            if (_activeTouchpoints.ContainsKey(id))
            {
                throw new InvalidOperationException($"HTML Touch id {id} is already tracked. Cannot track another touchpoint using this id.");
            }

            var inx = NextFreeTouchIndex;

            if (inx < 0)
            {
                return;
            }

            _activeTouchpoints[id] = inx;
            ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs {
                Button = _tpButtonDescs[(int)TouchPoints.Touchpoint_0 + inx].ButtonDesc, Pressed = true
            });
            AxisValueChanged?.Invoke(this, new AxisValueChangedArgs {
                Axis = _tpAxisDescs[(int)TouchAxes.Touchpoint_0_X + 2 * inx].AxisDesc, Value = x
            });
            AxisValueChanged?.Invoke(this, new AxisValueChangedArgs {
                Axis = _tpAxisDescs[(int)TouchAxes.Touchpoint_0_Y + 2 * inx].AxisDesc, Value = y
            });
        }
Exemplo n.º 2
0
        internal void OnCanvasMouseUp(int button)
        {
            MouseButtons mb;

            switch (button)
            {
            case 0:
                ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs
                {
                    Button  = _btnLeftDesc.ButtonDesc,
                    Pressed = false
                });
                break;

            case 1:
                ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs
                {
                    Button  = _btnMiddleDesc.ButtonDesc,
                    Pressed = false
                });
                break;

            case 2:
                ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs
                {
                    Button  = _btnRightDesc.ButtonDesc,
                    Pressed = false
                });
                break;
            }
        }
Exemplo n.º 3
0
        internal void OnViewTouchEnd(int id, float x, float y)
        {
            // Diagnostics.Log($"TouchEnd {id}");
            int inx;

            if (!_activeTouchpoints.TryGetValue(id, out inx))
            {
                return;
            }

            AxisValueChanged?.Invoke(this,
                                     new AxisValueChangedArgs
            {
                Axis  = _tpAxisDescs[(int)TouchAxes.Touchpoint_0_X + 2 * inx].AxisDesc,
                Value = x
            });
            AxisValueChanged?.Invoke(this,
                                     new AxisValueChangedArgs
            {
                Axis  = _tpAxisDescs[(int)TouchAxes.Touchpoint_0_Y + 2 * inx].AxisDesc,
                Value = y
            });
            ButtonValueChanged?.Invoke(this,
                                       new ButtonValueChangedArgs
            {
                Button  = _tpButtonDescs[(int)TouchPoints.Touchpoint_0 + inx].ButtonDesc,
                Pressed = false
            });
            _activeTouchpoints.Remove(id);
        }
Exemplo n.º 4
0
 private void ButtonValueChange(GpioPin gpioPin, EncoderRotaryEventArgs encoderEventArgs)
 {
     if (ButtonValueChanged != null)
     {
         ButtonValueChanged.Invoke(gpioPin, encoderEventArgs);
     }
 }
Exemplo n.º 5
0
 private void OnCanvasKeyUp(int key)
 {
     ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs
     {
         Button  = _keyDescriptions[key],
         Pressed = false
     });
 }
Exemplo n.º 6
0
        internal void OnCanvasTouchCancel(int id, float x, float y)
        {
            int inx;

            if (!_activeTouchpoints.TryGetValue(id, out inx))
            {
                return;
            }
            ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs {
                Button = _tpButtonDescs[(int)TouchPoints.Touchpoint_0 + inx].ButtonDesc, Pressed = false
            });
            _activeTouchpoints.Remove(id);
        }
Exemplo n.º 7
0
        internal void PreRender()
        {
            if (Time.DeltaTime != 0)
            {
                // Calculate derived axes first.
                foreach (var derivedAxis in _calculatedAxes) //.OrderBy(a => a.Key))
                {
                    derivedAxis.Value.CurrentAxisValue = derivedAxis.Value.Calculator(Time.DeltaTime);
                }
            }

            // See if any listeners need to be triggered about changes on axes.
            if (AxisValueChanged != null)
            {
                foreach (var axisId in _axesToPoll.Keys.ToArray()) // ToArray: get the list up-front because we will change the _axesToPoll dictionary during iteration
                {
                    float curVal;
                    if (!TryGetPolledAxis(axisId, out curVal))
                    {
                        throw new InvalidOperationException($"Invalid axis Id {axisId} - should be polled or derived.");
                    }

                    if (_axesToPoll[axisId] != curVal)
                    {
                        AxisValueChanged(this, new AxisValueChangedArgs {
                            Axis = _axes[axisId], Value = curVal
                        });
                        _axesToPoll[axisId] = curVal;
                    }
                }
            }

            // Do this for all polled buttons no matter if a listener is registered to maintain IsKeyDown/IsKeyUp funtionality
            foreach (var buttonId in _buttonsToPoll.Keys.ToArray()) // ToArray: get the list up-front because we will change the _buttonsToPoll dictionary during iteration
            {
                var curVal = _inpDevImp.GetButton(buttonId);
                if (_buttonsToPoll[buttonId] != curVal)
                {
                    if (curVal)
                    {
                        _buttonsDown.Add(buttonId);
                    }
                    else
                    {
                        _buttonsUp.Add(buttonId);
                    }

                    ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs {
                        Button = _buttons[buttonId], Pressed = curVal
                    });
                    _buttonsToPoll[buttonId] = curVal;
                }
            }

            // Now handle to-be-listened-to buttons that fired during the last frame until just now.
            foreach (var b in _buttonsToListenJustChanged)
            {
                if (b.Value != _buttonsToListen[b.Key])
                {
                    if (b.Value)
                    {
                        _buttonsDown.Add(b.Key);
                    }
                    else
                    {
                        _buttonsUp.Add(b.Key);
                    }
                }

                _buttonsToListen[b.Key] = b.Value;
                ButtonValueChanged?.Invoke(this, new ButtonValueChangedArgs {
                    Button = _buttons[b.Key], Pressed = b.Value
                });
            }
            _buttonsToListenJustChanged.Clear();
        }