public static MouseEvent fromGmsEventString(String gmsEventString, uint timeslot) { MouseEvent m = new MouseEvent(); String[] parts = gmsEventString.Split(' '); m.posX = UInt32.Parse(parts[0]); m.posY = UInt32.Parse(parts[1]); m.button1 = (parts[2] == "1" || parts[2] == "True"); m.button2 = (parts[3] == "1" || parts[3] == "True"); m.timeslot = timeslot; return m; }
public bool IsEqual(MouseEvent other) { if (other == null) return false; return (other.posX == posX && other.posY == posY && other.button1 == button1 && other.button2 == button2); }
private void canvas1_MouseMove(object sender, MouseEventArgs e) { // Retrieve the coordinate of the mouse position. Point pt = e.GetPosition((UIElement)sender); this.Title = String.Format("{0} {1}", pt.X, pt.Y); // Perform the hit test against a given portion of the visual object tree. HitTestResult result = VisualTreeHelper.HitTest(canvas1, pt); // go uint radius = 30; uint startX = (uint)pt.X - radius; uint endX = (uint)pt.X + radius; uint startY = (uint)pt.Y - radius; uint endY = (uint)pt.Y + radius; List<Rectangle> newNearRectangles = new List<Rectangle>(); for (uint thisX = startX; thisX < endX; thisX++) { for (uint thisY = startY; thisY < endY; thisY++) { MouseEvent m = null; if (hashedClickEvents.TryGetValue(makeKey(thisX , thisY), out m)) { Rectangle r = new Rectangle(); int strokewidth = 6; if (strokewidth < 0) strokewidth = strokewidth / (-1); r.Margin = new Thickness(m.posX - (strokewidth / 2), m.posY - (strokewidth / 2), m.posX + strokewidth, m.posY + strokewidth); r.Height = strokewidth; r.Width = strokewidth; r.Fill = brushSelected; newNearRectangles.Add(r); } } } foreach (Rectangle r in nearRectangles) { canvas1.Children.Remove(r); } nearRectangles = newNearRectangles; foreach (Rectangle r in nearRectangles) { canvas1.Children.Add(r); } if (result != null) { // Perform action on hit visual object. this.Title += " " + result.VisualHit.ToString(); if (result.VisualHit.ToString() == "System.Windows.Shapes.Path") return; if (selectedRectangle != null) { canvas1.Children.Remove(selectedRectangle); } selectedMouseEvent = null; foreach (MouseEvent mouseEvent in mouseEvents) { if (mouseEvent.posX == pt.X && mouseEvent.posY == pt.Y) { if (mouseEvent.button1) { selectedMouseEvent = mouseEvent; break; } } } if (selectedMouseEvent == null) return; selectedRectangle = new Rectangle(); int strokewidth = 4; selectedRectangle.Margin = new Thickness(selectedMouseEvent.posX, selectedMouseEvent.posY, selectedMouseEvent.posX + strokewidth, selectedMouseEvent.posY + strokewidth); selectedRectangle.Height = strokewidth; selectedRectangle.Width = strokewidth; selectedRectangle.Fill = brushSelected; canvas1.Children.Add(selectedRectangle); } }