protected override void OnDragOver(DragEventArgs e) { base.OnDragOver(e); Point mouseLocation = e.GetPosition(sharedCanvas); Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); // If the Cursor is within the Canvas if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y) { // Ensure the Ghost and Text are Visible while dragging MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Visible; ghostTextBlock.Visibility = System.Windows.Visibility.Visible; // Relocate Ghost Canvas.SetLeft(MainWindow.GhostBorder, mouseLocation.X - (MainWindow.GhostBorder.Width / 2)); Canvas.SetTop(MainWindow.GhostBorder, mouseLocation.Y - (MainWindow.GhostBorder.Height / 2)); // Update Location Text Point p = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); ghostTextBlock.Text = "(" + Math.Round(p.X, 1) + ", " + Math.Round(p.Y, 1) + ")"; // Relocate Ghost Text Canvas.SetLeft(ghostTextBlock, mouseLocation.X - (MainWindow.GhostBorder.Width / 2)); Canvas.SetTop(ghostTextBlock, mouseLocation.Y - (MainWindow.GhostBorder.Height / 2)); } // If the Cursor is not within the Canvas else { // Hide the Ghost and Text because it would be drawn off the Canvas MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; } }
protected override void OnDrop(DragEventArgs e) { string DataType = e.Data.GetFormats(true)[0]; //if the object dropped is a tracker if (DataType == "trackerControl") { base.OnDrop(e); Point mouseLocation = e.GetPosition(sharedCanvas); // Grab the data we packed into the DataObject TrackerControl trackerControl = (TrackerControl)e.Data.GetData("trackerControl"); // Hide the Ghost and Text since a Drop has been made MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; // Return the Opacity of the TrackerControl trackerControl.Opacity = 1; trackerControl.Tracker.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); // Check if the TrackerControl is already a child of Shared Canvas Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); if (!trackerControl.IsDescendantOf(SharedCanvas)) { trackerControl.formatForCanvas(); kinectWrapPanel.Children.Remove(trackerControl); SharedCanvas.Children.Add(trackerControl); if (trackerControl.Tracker.Orientation == null) { trackerControl.Tracker.Orientation = 270; } } // if the cursor is outside the canvas, put the tracker back in stackpanel. else if (!(mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y)) { trackerControl.Tracker.StopStreaming(); cleanUpKinectPersons(trackerControl.Tracker.Identifier); trackerControl.formatForStackPanel(); SharedCanvas.Children.Remove(trackerControl); kinectWrapPanel.Children.Add(trackerControl); } } //if the objet dropped is a device. else if (DataType == "deviceControl") { base.OnDrop(e); Point mouseLocation = e.GetPosition(sharedCanvas); // Grab the data we packed into the DataObject DeviceControl deviceControl = (DeviceControl)e.Data.GetData("deviceControl"); // Hide the Ghost and Text since a Drop has been made MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; // Return the Opacity of the DeviceControl deviceControl.Opacity = 1; PairableDevice device = deviceControl.PairableDevice; IADevice iaDevice = deviceControl.IADevice; IARequest request = new IARequest(Routes.SetLocationRoute); request.Parameters["identifier"] = iaDevice.Name; Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); //if the dragged device is a pairable device (i.e iPad) if (!iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute)) { Point mouseLocationOnCanvas = mouseLocation = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); bool pairedToNewDevice = false; foreach (KeyValuePair <PairablePerson, PersonControl> keyPair in PersonControlDictionary) { Point personLocation = keyPair.Key.Location.Value; double distance = Math.Sqrt(Math.Pow(mouseLocationOnCanvas.X - personLocation.X, 2) + Math.Pow(mouseLocationOnCanvas.Y - personLocation.Y, 2)); //if the mouse drop is close to a person, pair the device with that person. if (distance < 0.3 && (device.HeldByPersonIdentifier == keyPair.Key.Identifier || keyPair.Key.PairingState != PairingState.Paired)) { if (device.PairingState == PairingState.Paired || device.PairingState == PairingState.PairedButOccluded) { kinectManager.PairingRecognizer.UnpairDevice(device); } kinectManager.PairingRecognizer.Pair(device, keyPair.Key); pairedToNewDevice = true; break; } } //if the mouse drop is not close to a person then unpair the device. if (!pairedToNewDevice) { kinectManager.PairingRecognizer.UnpairDevice(device); } } //if the dragged device is not a pairable device (i.e table-top) else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute)) { if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y) { // Dropped within Canvas, so we want to place it on the canvas device.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); request.SetBodyWith(new IntermediatePoint(device.Location.Value)); } else { // Not dropped within Canvas, so we want to put it back on the stack panel device.Location = null; request.SetBodyWith(null); } // Send a request to the Device that their location has changed kinectManager.IntAirAct.SendRequest(request, iaDevice); } } }