示例#1
0
        public void SingleDeviceSelection(int id)
        {
            var mouse = new MouseInputManager();

            Assert.Raises <DeviceListChangedEventArgs <Mouse> >(h => mouse.DeviceListChanged += h, h => mouse.DeviceListChanged -= h, () => { });
            mouse.SelectDevice(id);
            Assert.NotEmpty(mouse.RawDevices);
            Assert.NotEmpty(mouse.Devices);
            Assert.NotEmpty(mouse.DeviceNames);
            Assert.NotNull(mouse.DeviceNames[0]);
            Assert.NotEqual("Dummy", mouse.DeviceNames[0]);
            Assert.True(mouse.DeviceNames[0].Length > 0);
            Console.WriteLine(mouse.DeviceNames[0]);
        }
示例#2
0
        private void OnInitialized(object sender, EventArgs e)
        {
            var mergedmouseman     = new MouseInputManager();
            var individualmouseman = new MouseInputManager();

            individualmouseman.SelectDevice(false, (info, i) => true);
            var mice       = mergedmouseman.WrappedDevices.Concat(individualmouseman.WrappedDevices).ToArray();
            var mousenames = mergedmouseman.DeviceNames.Concat(individualmouseman.DeviceNames).ToArray();
            var accmice    = mice.Select(currmnouse =>
            {
                var res = new AccumulatingMouseObserver();
                res.SubscribeTo(currmnouse.Device.MouseNotifications);
                return(res);
            }).ToArray();

            Dispatcher.BeginInvoke((Action)(() =>
            {
                for (int i = 0; i < accmice.Length; i++)
                {
                    Mice.Items.Add(new MouseDevice(mice[i], accmice[i]));
                }
            }));

            var mergedkeyman = new KeyboardInputManager();

            mergedkeyman.SelectDevice(-1);
            var individualkeyman = new KeyboardInputManager();

            individualkeyman.SelectDevice(Enumerable.Range(0, mergedkeyman.RawDevices.Count).ToArray());
            var keyboards     = mergedkeyman.Devices.Concat(individualkeyman.Devices).ToArray();
            var keyboardnames = mergedkeyman.DeviceNames.Concat(individualkeyman.DeviceNames).ToArray();
            var acckeyboards  = keyboards.Select(currkb =>
            {
                var res = new AccumulatingKeyboardObserver();
                res.SubscribeTo(currkb.KeyNotifications);
                return(res);
            }).ToArray();

            Dispatcher.BeginInvoke((Action)(() =>
            {
                AggregatedKeyboards = new ObservableCollection <string>(new string[acckeyboards.Length]);
                Keyboards.ItemsSource = AggregatedKeyboards;
                Observable.Interval(new TimeSpan(0, 0, 0, 0, 20)).Subscribe(t =>
                {
                    Dispatcher.BeginInvoke((Action)(() =>
                    {
                        for (int i = 0; i < AggregatedKeyboards.Count; i++)
                        {
                            AggregatedKeyboards[i] = acckeyboards[i].Keypresses
                                                     .Where(kvp => kvp.Value.Pressed)
                                                     .Aggregate(keyboardnames[i] + Environment.NewLine, (s, key) =>
                            {
                                return(s += (s == keyboardnames[i] + Environment.NewLine ? "" : ", ") +
                                            key.Key.ToString()
                                            //.Repeat(Math.Max(key.Value.Count, 1))
                                            .Aggregate("", (s1, c) => s1 + c));
                            });
                            acckeyboards[i].ResetAccumulation();
                        }
                    }));
                });
            }));
        }
示例#3
0
 public void Evaluate(int SpreadMax)
 {
     if (FKeyboard.IsChanged || FMouse.IsChanged)
     {
         MouseMan.SelectDevice(FMouse[0]);
         KeyMan.SelectDevice(FKeyboard[0]);
     }
     if (Camera == null)
     {
         var qrot = Quaternion.RotationYawPitchRoll((float)(FDefRot[0].y * Math.PI * 2), (float)(FDefRot[0].x * Math.PI * 2), (float)(FDefRot[0].z * Math.PI * 2));
         Camera = new ModularCam()
         {
             Default = new ModularCam()
             {
                 Translation   = FDefTrans[0],
                 Rotation      = qrot,
                 PivotDistance = FDefPivotDist[0],
                 Fov           = FDefFov[0],
                 Near          = FDefNear[0],
                 Far           = FDefFar[0]
             },
             Translation   = FDefTrans[0],
             Rotation      = qrot,
             PivotDistance = FDefPivotDist[0],
             Fov           = FDefFov[0],
             Near          = FDefNear[0],
             Far           = FDefFar[0],
             RotationSpeed = FRotSpeed[0]
         };
     }
     Camera.InputView   = FTrIn[0];
     Camera.InputAspect = FAspectIn[0];
     if (FRotSpeed.IsChanged || FResetAll[0])
     {
         Camera.RotationSpeed = FRotSpeed[0];
     }
     if (FDefTrans.IsChanged || FResetAll[0])
     {
         Camera.Translation         = FDefTrans[0];
         Camera.Default.Translation = FDefTrans[0];
     }
     if (FDefRot.IsChanged || FResetAll[0])
     {
         var qrot = Quaternion.RotationYawPitchRoll((float)(FDefRot[0].y * Math.PI * 2), (float)(FDefRot[0].x * Math.PI * 2), (float)(FDefRot[0].z * Math.PI * 2));
         Camera.Rotation         = qrot;
         Camera.Default.Rotation = qrot;
     }
     if (FDefPivotDist.IsChanged || FResetAll[0])
     {
         Camera.PivotDistance         = FDefPivotDist[0];
         Camera.Default.PivotDistance = FDefPivotDist[0];
     }
     if (FDefFov.IsChanged || FResetAll[0])
     {
         Camera.Fov         = FDefFov[0];
         Camera.Default.Fov = FDefFov[0];
     }
     if (FDefNear.IsChanged || FResetAll[0])
     {
         Camera.Near         = FDefNear[0];
         Camera.Default.Near = FDefNear[0];
     }
     if (FDefFar.IsChanged || FResetAll[0])
     {
         Camera.Far         = FDefFar[0];
         Camera.Default.Far = FDefFar[0];
     }
     if (FDeltas.SliceCount > 0 && FDeltas[0] != null)
     {
         if (FDeltas.Any(delta => delta.LockCursor))
         {
             SetCursorPos(CursorPos.X, CursorPos.Y);
         }
         else
         {
             GetCursorPos(out CursorPos);
         }
         var hoverhandle  = WindowFromPoint(CursorPos);
         var parenthandle = GetParent((IntPtr)FHandle[0]);
         for (int i = 0; i < FDeltas.SliceCount; i++)
         {
             var delta = FDeltas[i];
             delta.InputMouse      = MouseMan.Devices[0];
             delta.InputKeyboard   = KeyMan.Devices[0];
             delta.ConnectedCamera = Camera;
             if (FHandle[0] > 0)
             {
                 delta.InteractUpstream =
                     FHandle[0] == hoverhandle.ToInt32() ||
                     parenthandle == hoverhandle;
             }
             else
             {
                 delta.InteractUpstream = true;
             }
             FFrameTime[0] = FHDEHost.FrameTime - PrevFrameTime;
             Camera.Move(delta, FHDEHost.FrameTime - PrevFrameTime);
         }
     }
     FCameraOut[0]               = Camera;
     FViewOut[0]                 = Camera.View;
     FProjectionOut[0]           = Camera.Projection;
     FProjectionWithAspectOut[0] = Camera.ProjectionWithAspect;
     PrevFrameTime               = FHDEHost.FrameTime;
 }
示例#4
0
        public void Evaluate(int SpreadMax)
        {
            var qrot = Quaternion.RotationYawPitchRoll(
                (float)(FDefRot[0].y * Math.PI * 2),
                (float)(FDefRot[0].x * Math.PI * 2),
                (float)(FDefRot[0].z * Math.PI * 2)
                );
            var defcam = new CameraProperties(
                FTrIn[0],
                FDefTrans[0],
                qrot,
                FDefPivotDist[0],
                FDefFov[0],
                FDefNear[0],
                FDefFar[0]
                );

            if (FKeyboard.IsChanged || FMouse.IsChanged)
            {
                _mouseMan.SelectDevice(FMouse[0]);
                _keyMan.SelectDevice(FKeyboard[0]);
            }
            if (_camera == null)
            {
                _camera = new ModularCam()
                {
                    Default       = defcam,
                    Properties    = defcam,
                    RotationSpeed = FRotSpeed[0]
                };
            }
            if (_resetter == null)
            {
                _resetter = new CameraDelta();
            }

            _resetter.ResetTranslation   = FDefTrans.IsChanged || FResetAll[0];
            _resetter.ResetRotation      = FDefRot.IsChanged || FResetAll[0];
            _resetter.ResetPivotDistance = FDefPivotDist.IsChanged || FResetAll[0];
            _resetter.ResetFov           = FDefFov.IsChanged || FResetAll[0];
            _resetter.ResetNear          = FDefNear.IsChanged || FResetAll[0];
            _resetter.ResetFar           = FDefFar.IsChanged || FResetAll[0];

            _camera.InputAspect = FAspectIn[0];
            if (FRotSpeed.IsChanged || FResetAll[0])
            {
                _camera.RotationSpeed = FRotSpeed[0];
            }

            _camera.Default    = defcam;
            _camera.Properties = new CameraProperties(_camera.Properties, defcam, _resetter);

            if (FDeltas.SliceCount > 0 && FDeltas[0] != null)
            {
                if (FDeltas.Any(delta => delta.LockCursor))
                {
                    SetCursorPos(_cursorPos.X, _cursorPos.Y);
                }
                else
                {
                    GetCursorPos(out _cursorPos);
                }
                var hoverhandle  = WindowFromPoint(_cursorPos);
                var parenthandle = GetParent((IntPtr)FHandle[0]);
                for (int i = 0; i < FDeltas.SliceCount; i++)
                {
                    var delta = FDeltas[i];
                    delta.InputMouse      = _mouseMan.Devices[0];
                    delta.InputKeyboard   = _keyMan.Devices[0];
                    delta.ConnectedCamera = _camera;
                    if (FHandle[0] > 0)
                    {
                        delta.InteractUpstream =
                            FHandle[0] == hoverhandle.ToInt32() ||
                            parenthandle == hoverhandle;
                    }
                    else
                    {
                        delta.InteractUpstream = true;
                    }
                    _camera.Move(delta, FHDEHost.FrameTime - _prevFrameTime);
                }
            }
            FCameraOut[0]               = _camera;
            FViewOut[0]                 = _camera.View;
            FProjectionOut[0]           = _camera.Projection;
            FProjectionWithAspectOut[0] = _camera.ProjectionWithAspect;
            _prevFrameTime              = FHDEHost.FrameTime;
        }