public void InvokePointerDrag(Vector2 pointerPosition, Vector2 delta) { if (PointerDrag != null) { PointerDrag.Invoke(this, new PointerDraggedGraphicalElementEventArgs(pointerPosition, delta)); } }
private void canvasControl_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (!svgSupported) { return; } pointerDrag = new PointerDrag(e.GetCurrentPoint(canvasControl).Position); canvasControl.Invalidate(); }
private void canvasControl_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (pointerDrag == null) { return; // Nothing to do } // Commit the shape into the document CanvasSvgNamedElement newChild = null; if (CurrentShapeType == ShapeType.Rectangle) { Rect r = pointerDrag.GetRectangle(); newChild = svgDocument.Root.CreateAndAppendNamedChildElement("rect"); newChild.SetFloatAttribute("x", (float)r.Left); newChild.SetFloatAttribute("y", (float)r.Top); newChild.SetFloatAttribute("width", (float)r.Width); newChild.SetFloatAttribute("height", (float)r.Height); } else if (CurrentShapeType == ShapeType.Ellipse) { var ellipse = pointerDrag.GetEllipse(); newChild = svgDocument.Root.CreateAndAppendNamedChildElement("ellipse"); newChild.SetFloatAttribute("cx", ellipse.CenterX); newChild.SetFloatAttribute("cy", ellipse.CenterY); newChild.SetFloatAttribute("rx", ellipse.RadiusX); newChild.SetFloatAttribute("ry", ellipse.RadiusY); } else if (CurrentShapeType == ShapeType.Circle) { var circle = pointerDrag.GetCircle(); newChild = svgDocument.Root.CreateAndAppendNamedChildElement("circle"); newChild.SetFloatAttribute("cx", circle.Center.X); newChild.SetFloatAttribute("cy", circle.Center.Y); newChild.SetFloatAttribute("r", circle.Radius); } else if (CurrentShapeType == ShapeType.Line) { var start = pointerDrag.StartLocation.ToVector2(); var end = pointerDrag.CurrentLocation.ToVector2(); newChild = svgDocument.Root.CreateAndAppendNamedChildElement("line"); newChild.SetFloatAttribute("x1", start.X); newChild.SetFloatAttribute("y1", start.Y); newChild.SetFloatAttribute("x2", end.X); newChild.SetFloatAttribute("y2", end.Y); } newChild.SetColorAttribute("fill", colorPicker.CurrentColor); newChild.SetColorAttribute("stroke", Colors.Black); newChild.SetFloatAttribute("stroke-width", 4.0f); pointerDrag = null; canvasControl.Invalidate(); }
public void OnDrag(PointerEventData eventData) { if (!pointerDown) { return; } if (eventData.pointerCurrentRaycast.gameObject == null || eventData.pointerCurrentRaycast.gameObject.tag != "Brick") { return; } int index = eventData.pointerCurrentRaycast.gameObject.transform.GetSiblingIndex(); PointerDrag?.Invoke(index); }