protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index) { DesignerThumb designerThumb = new MultiPointThumb { Index = index, Alignment = alignment, Cursor = cursor, IsPrimarySelection = true }; AdornerPlacement ap = Place(designerThumb, alignment, index); (designerThumb as MultiPointThumb).AdornerPlacement = ap; AdornerPanel.SetPlacement(designerThumb, ap); adornerPanel.Children.Add(designerThumb); DragListener drag = new DragListener(designerThumb); WeakEventManager <DesignerThumb, MouseButtonEventArgs> .AddHandler(designerThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp); drag.Started += drag_Started; drag.Changed += drag_Changed; drag.Completed += drag_Completed; return(designerThumb); }
private void SelectThumb(MultiPointThumb mprt) { PointCollection points = GetPointCollection(); Point p = points[mprt.Index]; _selectedPoints.Add(mprt.Index, p); mprt.IsPrimarySelection = false; }
// TODO : Remove all hide/show extensions from here. protected void drag_Started(DragListener drag) { //get current thumb MultiPointThumb mprt = (drag.Target as MultiPointThumb); if (mprt != null) { SetOperation(); } }
private void SelectThumb(MultiPointThumb mprt) { PointCollection points = GetPointCollection(); Point p = points[mprt.Index]; _selectedThumbs.Add(mprt.Index, new Bounds { X = p.X, Y = p.Y }); mprt.IsPrimarySelection = false; }
private void ResizeThumbOnMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs) { //get current thumb MultiPointThumb mprt = sender as MultiPointThumb; if (mprt != null) { //shift+ctrl will remove selected point if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))) { //unselect all points ResetThumbs(); PointCollection points = GetPointCollection(); //iterate thumbs to lower index of remaining thumbs foreach (MultiPointThumb m in adornerPanel.Children) { if (m.Index > mprt.Index) { m.Index--; } } //remove point and thumb points.RemoveAt(mprt.Index); adornerPanel.Children.Remove(mprt); Invalidate(); } else { //if not keyboard ctrl is pressed and selected point is not previously selected, clear selection if (!_selectedPoints.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) & !Keyboard.IsKeyDown(Key.RightCtrl)) { ResetThumbs(); } //add selected thumb, if ctrl pressed this could be all points in poly if (!_selectedPoints.ContainsKey(mprt.Index)) { SelectThumb(mprt); } _isDragging = false; } } }
protected void drag_Completed(DragListener drag) { MultiPointThumb mprt = drag.Target as MultiPointThumb; if (mprt != null) { if (operation != null && drag.IsCanceled) { operation.Abort(); } else if (drag.IsCanceled) { changeGroup.Abort(); } CommitOperation(); } }
protected void drag_Changed(DragListener drag) { PointCollection points = GetPointCollection(); MultiPointThumb mprt = drag.Target as MultiPointThumb; if (mprt != null) { double dx = 0; double dy = 0; //if has zoomed if (_zoom != null) { dx = drag.Delta.X * (1 / _zoom.CurrentZoom); dy = drag.Delta.Y * (1 / _zoom.CurrentZoom); } Double theta; //if one point selected snapping angle is calculated in relation to previous point if (_selectedPoints.Count == 1 && mprt.Index > 0) { theta = (180 / Math.PI) * Math.Atan2(_selectedPoints[mprt.Index].Y + dy - points[mprt.Index - 1].Y, _selectedPoints[mprt.Index].X + dx - points[mprt.Index - 1].X); } else //if multiple points snapping angle is calculated in relation to mouse dragging angle { theta = (180 / Math.PI) * Math.Atan2(dy, dx); } //snappingAngle is used for snapping function to horizontal or vertical plane in line drawing, and is activated by pressing ctrl or shift button int?snapAngle = null; //shift+alt gives a new point if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))) { //if dragging occurs on a point and that point is the only selected, a new node will be added. //_isCtrlDragging is needed since this method is called for every x pixel that the mouse moves //so it could be many thousands of times during a single dragging if (!_isDragging && _selectedPoints.Count == 1 && (Math.Abs(dx) > 0 || Math.Abs(dy) > 0)) { //duplicate point that is selected Point p = points[mprt.Index]; //insert duplicate points.Insert(mprt.Index, p); //create adorner marker CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, mprt.Index); //set index of all points that had a higher index than selected to +1 foreach (FrameworkElement rt in adornerPanel.Children) { if (rt is MultiPointThumb) { MultiPointThumb t = rt as MultiPointThumb; if (t.Index > mprt.Index) { t.Index++; } } } //set index of new point to old point index + 1 mprt.Index = mprt.Index + 1; ResetThumbs(); SelectThumb(mprt); } snapAngle = 10; } //snapping occurs when mouse is within 10 degrees from horizontal or vertical plane if shift is pressed else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) { snapAngle = 10; } //snapping occurs within 45 degree intervals that is line will always be horizontal or vertical if alt is pressed else if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)) { snapAngle = 45; } _isDragging = true; points = MovePoints(points, dx, dy, theta, snapAngle); } (drag.Target as DesignerThumb).InvalidateArrange(); }