/// <summary> /// A constructor that builds a HidContactInfo from a WiiContact and a HID state. /// </summary> /// <param name="eState"></param> /// <param name="contact"></param> internal HidContactInfo(HidContactState eState, WiiContact pContact) { // Save the state. State = eState; // If we have a contact then shoehorn its details into our class. if (pContact != null) { // Convert the ID. Perhaps ensure we are going to work with larger values. Id = unchecked ((UInt16)pContact.ID); // Convert the point into HID space. Point tPoint = transformPoint(pContact.Position); X = Convert.ToUInt16(tPoint.X); Y = Convert.ToUInt16(tPoint.Y); // Save the width and height. Width = Convert.ToUInt16(pContact.Size.X); Height = Convert.ToUInt16(pContact.Size.Y); // Compute the pressure from the area. Pressure = Convert.ToUInt16(Math.Max(0, Math.Min(MaxSize, pContact.Area))); // Save the timestamp and WiiContact. Timestamp = DateTime.Now; Contact = pContact; } }
public void queueContact(WiiContact contact) { if (enabled) { contactQueue.Enqueue(contact); } }
void pWiiProvider_OnNewFrame(object sender, FrameEventArgs e) { List <WiiContact> lContacts = new List <WiiContact>(e.Contacts); if (lContacts.Count > 0) { // Get the contact. WiiContact pContact = lContacts[0]; // If it is a down contact. if (pContact.Type != ContactType.Start) { return; } // Reference the touch contact from the event. Vector vPoint = new Vector(pContact.Position.X, pContact.Position.Y); // Select what to do based on the calibration phase. switch (iCalibrationPhase) { case 1: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.TopLeft = vPoint; iCalibrationPhase = 2; this.stepCalibration(); break; case 2: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.TopRight = vPoint; iCalibrationPhase = 3; this.stepCalibration(); break; case 3: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.BottomLeft = vPoint; iCalibrationPhase = 4; this.stepCalibration(); break; case 4: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.BottomRight = vPoint; iCalibrationPhase = 5; this.stepCalibration(); break; default: throw new Exception("Unknown calibration phase '" + iCalibrationPhase + "' to handle this touch event!"); } } }
public void queueContact(WiiContact contact) { throw new NotImplementedException(); }
public void queueContact(WiiContact contact) { contactQueue.Enqueue(contact); }
public Queue <WiiContact> getFrame() { Queue <WiiContact> newFrame = new Queue <WiiContact>(1); //master if (masterPosition != null) { ContactType contactType; if (!this.masterReleased) { if (this.masterHovering) { contactType = ContactType.Start; this.masterHovering = false; } else { contactType = ContactType.Move; } if (this.isFirstMasterContact) { this.firstMasterContact = this.masterPosition; } else { if (this.masterHoldPosition) { /* if (Math.Abs(this.firstMasterContact.X - this.masterPosition.X) < TouchHoldThreshold && Math.Abs(this.firstMasterContact.Y - this.masterPosition.Y) < TouchHoldThreshold) * { * /*Console.WriteLine("DiffX: " + Math.Abs(this.firstMasterContact.X - this.masterPosition.X) + " DiffY: " + Math.Abs(this.firstMasterContact.Y - this.masterPosition.Y));*/ /*this.masterPosition = this.firstMasterContact; * this.masterHoldPosition = true; * } * else * {*/ this.masterHoldPosition = false; //} } //Helps to perform "edge swipe" guestures if (this.firstMasterContact.X < EdgeHelperMargins && this.masterPosition.X < EdgeHelperRelease) //Left { this.masterPosition.Y = (this.firstMasterContact.Y + this.firstMasterContact.Y + this.masterPosition.Y) / 3; } if (this.firstMasterContact.X > (this.screenBounds.Width - EdgeHelperMargins) && this.masterPosition.X > (this.screenBounds.Width - EdgeHelperRelease)) //Right { this.masterPosition.Y = (this.firstMasterContact.Y + this.firstMasterContact.Y + this.masterPosition.Y) / 3; } if (this.firstMasterContact.Y < EdgeHelperMargins && this.masterPosition.Y < EdgeHelperRelease) //Top { this.masterPosition.X = (this.firstMasterContact.X + this.firstMasterContact.X + this.masterPosition.X) / 3; } if (this.firstMasterContact.Y > (this.screenBounds.Height - EdgeHelperMargins) && this.masterPosition.Y > (this.screenBounds.Height - EdgeHelperRelease)) //Bottom { this.masterPosition.X = (this.firstMasterContact.X + this.firstMasterContact.X + this.masterPosition.X) / 3; } } System.Windows.Vector vec = new System.Windows.Vector(masterPosition.X, masterPosition.Y); masterPosition.X = vec.X; masterPosition.Y = vec.Y; this.isFirstMasterContact = false; } else //Released = hovering { if (!this.masterHovering) //End the touch first { if (this.hoverDisabled) { contactType = ContactType.End; } else { contactType = ContactType.EndToHover; } this.masterPosition = lastMasterContact.Position; this.masterHovering = true; } else { contactType = ContactType.Hover; Vector vec = new Vector(masterPosition.X, masterPosition.Y); masterPosition.X = vec.X; masterPosition.Y = vec.Y; } this.isFirstMasterContact = true; this.masterHoldPosition = true; } if (!(contactType == ContactType.Hover && this.hoverDisabled)) { if (this.stepIDs && contactType == ContactType.EndToHover) //If we release slave touch before we release master touch we want to make sure Windows treats master as the main touch point again { this.lastMasterContact = new WiiContact(this.masterID, ContactType.End, this.masterPosition, this.masterPriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); this.masterID = (this.masterID - this.startID + 2) % 4 + this.startID; this.slaveID = (this.slaveID - this.startID + 2) % 4 + this.startID; this.stepIDs = false; } else { this.lastMasterContact = new WiiContact(this.masterID, contactType, this.masterPosition, this.masterPriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); } newFrame.Enqueue(this.lastMasterContact); } } //slave if (slavePosition != null) { ContactType contactType; if (!this.slaveReleased) { if (this.slaveHovering) { contactType = ContactType.Start; this.slaveHovering = false; } else { contactType = ContactType.Move; } if (!this.masterReleased) { if (!this.usingMidpoint) { this.midpoint = calculateMidpoint(this.masterPosition, this.slavePosition); this.usingMidpoint = true; } this.slavePosition = reflectThroughMidpoint(this.masterPosition, this.midpoint); if (this.slavePosition.X < 0) { this.slavePosition.X = 0; } if (this.slavePosition.Y < 0) { this.slavePosition.Y = 0; } if (this.slavePosition.X > this.screenBounds.Width) { this.slavePosition.X = this.screenBounds.Width - 1; } if (this.slavePosition.Y > this.screenBounds.Height) { this.slavePosition.Y = this.screenBounds.Height - 1; } } else { this.usingMidpoint = false; } this.slaveEnded = false; this.stepIDs = false; } else { if (!this.slaveHovering) { contactType = ContactType.EndToHover; this.slavePosition = lastSlaveContact.Position; this.slaveHovering = true; } else { contactType = ContactType.EndFromHover; } } if (!this.slaveEnded) { this.lastSlaveContact = new WiiContact(this.slaveID, contactType, this.slavePosition, this.slavePriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); newFrame.Enqueue(this.lastSlaveContact); if (contactType == ContactType.EndFromHover) { this.slaveEnded = true; if (!this.masterReleased) //If we release slave before master { this.stepIDs = true; } else { this.masterID = (this.masterID - this.startID + 2) % 4 + this.startID; this.slaveID = (this.slaveID - this.startID + 2) % 4 + this.startID; this.stepIDs = false; } } } } return(newFrame); }
private void setPosition(Provider.CursorPos cursorPos) { if (!mightTimeOut) { timeoutCursorPos = cursorPos; this.timeoutTimer.Start(); } if (!this.touchDownMaster && !this.touchDownSlave && Math.Abs(this.timeoutCursorPos.X - cursorPos.X) < Settings.Default.pointer_cursorStillThreshold && Math.Abs(this.timeoutCursorPos.Y - cursorPos.Y) < Settings.Default.pointer_cursorStillThreshold) { this.mightTimeOut = true; } else { this.mightTimeOut = false; this.timedOut = false; this.timeoutTimer.Stop(); } if (!cursorPos.OutOfReach && !timedOut) { if (timedOut) { this.timedOut = false; } Queue <WiiContact> lFrame = new Queue <WiiContact>(1); // Store the state. if (this.usingCursors()) { this.masterCursor.Show(); } //significant = true; if (this.touchDownMaster) { duoTouch.setContactMaster(); } else { duoTouch.releaseContactMaster(); } duoTouch.setMasterPosition(new System.Windows.Point(cursorPos.X, cursorPos.Y)); if (this.touchDownSlave) { if (this.usingCursors()) { this.slaveCursor.Show(); } duoTouch.setSlavePosition(new System.Windows.Point(cursorPos.X, cursorPos.Y)); duoTouch.setContactSlave(); } else { duoTouch.releaseContactSlave(); if (this.usingCursors()) { this.slaveCursor.Hide(); } } lastCursorPos = cursorPos; lFrame = duoTouch.getFrame(); foreach (WiiContact contact in lFrame) { this.handler.queueContact(contact); } if (this.usingCursors()) { 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(cursorPos.Rotation); } if (slave != null) { this.slaveCursor.SetPosition(slave.Position); this.slaveCursor.SetRotation(cursorPos.Rotation); } } } else //pointer out of reach { if (this.usingCursors()) { this.masterCursor.Hide(); this.masterCursor.SetPosition(new System.Windows.Point(cursorPos.X, cursorPos.Y)); } } }
/// <summary> /// Enqueue a new contact into the current list. /// </summary> /// <remarks>Yes I know it is horrible and iccky to do this here.. but yea.. I didn't want to expose too much of the HID stuff at this stage.</remarks> /// <param name="eState">The HidContactState of the contact.</param> /// <param name="pContact">The reference to the WiiContact generated by the provider.</param> public void enqueueContact(HidContactState eState, WiiContact pContact) { this.enqueueContact(new HidContactInfo(eState, pContact)); }