Esempio n. 1
0
 private void WiiKeyMap_ConfigChanged(WiiKeyMapConfigChangedEvent evt)
 {
     if (firstConfig)
     {
         currentKeymap = evt.Filename;
         firstConfig   = false;
     }
     else if (evt.Filename != currentKeymap)
     {
         currentKeymap = evt.Filename;
         OverlayWindow.Current.ShowNotice("Layout for Wiimote " + this.Status.ID + " changed to \"" + evt.Name + "\"", this.Status.ID);
     }
     if (evt.Pointer.ToLower() == "touch")
     {
         this.showPointer = true;
         this.mouseMode   = false;
         this.duoTouch.enableHover();
         if (this.usingCursors())
         {
             this.masterCursor.Show();
         }
     }
     else if (evt.Pointer.ToLower() == "mouse")
     {
         this.mouseMode   = true;
         this.gamingMouse = false;
         this.duoTouch.disableHover();
         if (this.usingCursors())
         {
             this.masterCursor.Hide();
             this.slaveCursor.Hide();
         }
         MouseSimulator.WakeCursor();
     }
     else if (evt.Pointer.ToLower() == "gamingmouse")
     {
         this.mouseMode   = true;
         this.gamingMouse = true;
         this.duoTouch.disableHover();
         if (this.usingCursors())
         {
             this.masterCursor.Hide();
             this.slaveCursor.Hide();
         }
         MouseSimulator.WakeCursor();
     }
     else
     {
         this.showPointer = false;
         this.mouseMode   = false;
         this.duoTouch.disableHover();
         if (this.usingCursors())
         {
             this.masterCursor.Hide();
             this.slaveCursor.Hide();
         }
     }
 }
Esempio n. 2
0
 private void WiiKeyMap_ConfigChanged(WiiKeyMapConfigChangedEvent evt)
 {
     if (evt.Pointer.ToLower() == "touch")
     {
         this.mouseMode = false;
         if (this.showPointer)
         {
             this.duoTouch.enableHover();
         }
     }
     else if (evt.Pointer.ToLower() == "mouse")
     {
         this.mouseMode = true;
         this.duoTouch.disableHover();
         MouseSimulator.WakeCursor();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// This is called when the state of the wiimote changes and a new state report is available.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void handleWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            // Obtain mutual excluseion.
            pDeviceMutex.WaitOne();

            // If we not running then leave.
            if (!bRunning)
            {
                pDeviceMutex.ReleaseMutex();
                return;
            }
            Queue <WiiContact> lFrame = new Queue <WiiContact>(1);
            // Store the state.
            WiimoteState pState = e.WiimoteState;

            // Contain active sensor data.
            List <SpatioTemporalInput> lInputs = new List <SpatioTemporalInput>();

            bool pointerOutOfReach = false;

            WiimoteLib.Point newpoint = lastpoint;

            CursorPos temp = screenPositionCalculator.CalculateCursorPos(e);

            newpoint.X = temp.X;
            newpoint.Y = temp.Y;

            if (newpoint.X < 0 || newpoint.Y < 0)
            {
                newpoint          = lastpoint;
                pointerOutOfReach = true;
            }

            //Temporary solution to the "diamond cursor" problem.

            /*
             * if (this.changeSystemCursor)
             * {
             *  try
             *  {
             *      MouseSimulator.RefreshMainCursor();
             *  }
             *  catch (Exception error)
             *  {
             *      Console.WriteLine(error.ToString());
             *  }
             * }
             */
            WiimoteState ws = e.WiimoteState;

            keyMapper.processWiimoteState(ws);

            if (!pointerOutOfReach)
            {
                if (this.touchDownMaster)
                {
                    duoTouch.setContactMaster();
                }
                else
                {
                    duoTouch.releaseContactMaster();
                }

                duoTouch.setMasterPosition(new System.Windows.Point(newpoint.X, newpoint.Y));

                if (this.touchDownSlave)
                {
                    duoTouch.setSlavePosition(new System.Windows.Point(newpoint.X, newpoint.Y));
                    duoTouch.setContactSlave();
                }
                else
                {
                    duoTouch.releaseContactSlave();
                }

                lastpoint = newpoint;

                lFrame = duoTouch.getFrame();

                FrameEventArgs pFrame = new FrameEventArgs((ulong)Stopwatch.GetTimestamp(), lFrame);

                this.OnNewFrame(this, pFrame);

                if (mouseMode && !this.touchDownMaster && !this.touchDownSlave && this.showPointer) //Mouse mode
                {
                    this.inputSimulator.Mouse.MoveMouseToPositionOnVirtualDesktop((65535 * newpoint.X) / this.ScreenSize.X, (65535 * newpoint.Y) / this.ScreenSize.Y);
                    MouseSimulator.WakeCursor();
                    //MouseSimulator.SetCursorPosition(newpoint.X, newpoint.Y);
                }
            }
            this.BatteryState = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery);

            // Release mutual exclusion.
            pDeviceMutex.ReleaseMutex();
        }
Esempio n. 4
0
        public bool handleWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            // Obtain mutual excluseion.
            WiimoteMutex.WaitOne();

            bool significant = false;

            try
            {
                this.screenBounds          = Util.ScreenBounds;
                this.duoTouch.screenBounds = Util.ScreenBounds;

                Queue <WiiContact> lFrame = new Queue <WiiContact>(1);
                // Store the state.
                WiimoteState pState = e.WiimoteState;

                this.Status.Battery = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery);

                bool pointerOutOfReach = false;

                CursorPos newpoint = lastpoint;

                newpoint = screenPositionCalculator.CalculateCursorPos(e);

                if (newpoint.X < 0 || newpoint.Y < 0)
                {
                    newpoint          = lastpoint;
                    pointerOutOfReach = true;
                }

                WiimoteState ws = e.WiimoteState;
                if (keyMapper.processWiimoteState(ws))
                {
                    significant           = true;
                    this.lastWiimoteState = ws;
                }


                if (!pointerOutOfReach)
                {
                    if (this.usingCursors() && !mouseMode && showPointer)
                    {
                        this.masterCursor.Show();
                    }
                    significant = true;
                    if (this.touchDownMaster)
                    {
                        duoTouch.setContactMaster();
                    }
                    else
                    {
                        duoTouch.releaseContactMaster();
                    }

                    duoTouch.setMasterPosition(new System.Windows.Point(newpoint.X, newpoint.Y));

                    if (this.touchDownSlave)
                    {
                        if (this.usingCursors() && !mouseMode && showPointer)
                        {
                            this.slaveCursor.Show();
                        }
                        duoTouch.setSlavePosition(new System.Windows.Point(newpoint.X, newpoint.Y));
                        duoTouch.setContactSlave();
                    }
                    else
                    {
                        duoTouch.releaseContactSlave();
                        if (this.usingCursors() && !mouseMode)
                        {
                            this.slaveCursor.Hide();
                        }
                    }

                    lastpoint = newpoint;

                    lFrame = duoTouch.getFrame();
                    if (this.usingCursors() && !mouseMode)
                    {
                        WiiContact master = null;
                        WiiContact slave  = null;
                        foreach (WiiContact contact in lFrame)
                        {
                            if (master == null)
                            {
                                master = contact;
                            }
                            else if (master.Priority > contact.Priority)
                            {
                                slave  = master;
                                master = contact;
                            }
                            else
                            {
                                slave = contact;
                            }
                        }
                        if (master != null)
                        {
                            this.masterCursor.SetPosition(master.Position);
                            this.masterCursor.SetRotation(newpoint.Rotation);
                        }
                        if (slave != null)
                        {
                            this.slaveCursor.SetPosition(slave.Position);
                            this.slaveCursor.SetRotation(newpoint.Rotation);
                        }
                    }

                    FrameEventArgs pFrame = new FrameEventArgs((ulong)Stopwatch.GetTimestamp(), lFrame);

                    this.FrameQueue.Enqueue(pFrame);
                    this.LastFrameEvent = pFrame;

                    if (mouseMode && !this.touchDownMaster && !this.touchDownSlave && this.showPointer) //Mouse mode
                    {
                        if (gamingMouse)
                        {
                            double deltaX = (newpoint.X - ((double)this.screenBounds.Width / 2.0)) / (double)this.screenBounds.Width;
                            double deltaY = (newpoint.Y - ((double)this.screenBounds.Height / 2.0)) / (double)this.screenBounds.Height;
                            deltaX        = Math.Sign(deltaX) * deltaX * deltaX * 50;
                            deltaY        = Math.Sign(deltaY) * deltaY * deltaY * 50 * ((double)this.screenBounds.Width / (double)this.screenBounds.Height);
                            deltaXBuffer += deltaX % 1;
                            deltaYBuffer += deltaY % 1;
                            int roundDeltaX = (int)deltaX;
                            int roundDeltaY = (int)deltaY;
                            if (deltaXBuffer > 1 || deltaXBuffer < -1)
                            {
                                roundDeltaX  += Math.Sign(deltaXBuffer);
                                deltaXBuffer -= Math.Sign(deltaXBuffer);
                            }
                            if (deltaYBuffer > 1 || deltaYBuffer < -1)
                            {
                                roundDeltaY  += Math.Sign(deltaYBuffer);
                                deltaYBuffer -= Math.Sign(deltaYBuffer);
                            }
                            this.inputSimulator.Mouse.MoveMouseBy(roundDeltaX, roundDeltaY);
                        }
                        else
                        {
                            this.inputSimulator.Mouse.MoveMouseToPositionOnVirtualDesktop((65535 * newpoint.X) / this.screenBounds.Width, (65535 * newpoint.Y) / this.screenBounds.Height);
                        }
                        MouseSimulator.WakeCursor();
                    }
                }
                else //pointer out of reach
                {
                    if (this.usingCursors() && !mouseMode)
                    {
                        this.masterCursor.Hide();
                        this.masterCursor.SetPosition(new System.Windows.Point(lastpoint.X, lastpoint.Y));
                    }
                }

                if (significant)
                {
                    this.LastSignificantWiimoteEventTime = DateTime.Now;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error handling Wiimote in WiimoteControl: " + ex.Message);
                return(significant);
            }
            //this.BatteryState = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery);


            // Release mutual exclusion.
            WiimoteMutex.ReleaseMutex();
            return(significant);
        }