private void MainImage_MouseDown(object sender, MouseButtonEventArgs e) { if (DataContext is ViewModel vm) { if (e.LeftButton == MouseButtonState.Pressed) { if (e.ClickCount == 2) { vm.SolidMode = false; vm.SetRotation(0.0, 0.0); } else if (e.ClickCount < 2) { _draggingMode = DraggingMode.Left; _x = vm.CenterX; _y = vm.CenterY; _dragStart = e.GetPosition(MainImage); MainImage.CaptureMouse(); } } else if (e.RightButton == MouseButtonState.Pressed) { _draggingMode = DraggingMode.Right; _x = vm.Yaw; _y = vm.Pitch; _dragStart = e.GetPosition(MainImage); MainImage.CaptureMouse(); } else { _draggingMode = DraggingMode.None; MainImage.ReleaseMouseCapture(); } } }
private void Drag(object target, DraggingMode draggingMode, System.Windows.Input.MouseEventArgs e) { mouseMoving = true; if (e.LeftButton == MouseButtonState.Pressed) { System.Windows.Controls.Control targetControl = target as System.Windows.Controls.Control; System.Windows.Point position = e.GetPosition(dragCanvas); if (Math.Abs(position.X - mouseStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(position.Y - mouseStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance) { isDragging = true; double x = position.X - targetControl.Width / 2; double y = position.Y - targetControl.Height / 2; //Console.WriteLine(position.X + ":" + position.Y + " ~ " + targetControl.Margin.Left + ":" + targetControl.Margin.Top); switch (draggingMode) { case DraggingMode.Horizontal: Canvas.SetLeft(targetControl, x); break; case DraggingMode.Vertical: Canvas.SetTop(targetControl, y); break; case DraggingMode.Both: //targetControl.Margin = new Thickness(x, y, 0, 0); Canvas.SetLeft(targetControl, x); Canvas.SetTop(targetControl, y); break; } } } }
private void GraphEditorClass_MouseUp(object sender, MouseEventArgs e) { if (_heldButton == e.Button) { _heldButton = MouseButtons.None; PointF documentPoint = ClientToDocumentPoint(new PointF(e.X, e.Y)); switch (_draggingMode) { case DraggingMode.MoveNode: UpdateSelectedObject(documentPoint); break; case DraggingMode.DrawLine: GraphNode destShape = GetHitObjectInternal(documentPoint) as GraphNode; if ((destShape != null) && (destShape != _selectedObject) && (_selectedObject is GraphNode)) { AddLine(_selectedObject as GraphNode, destShape); } Invalidate(); break; case DraggingMode.ScrollWindow: Cursor = Cursors.Arrow; break; } _draggingMode = DraggingMode.None; } }
/// <summary> /// Drags elements by the delta. /// </summary> /// <param name="delta"></param> /// <param name="draggingMode">describes the way we process the dragging </param> /// <param name="lastPointerPosition">the last position of the pointer.</param> internal void Drag(Point delta, DraggingMode draggingMode, Point lastPointerPosition) { GraphBoundingBoxGetsExtended = false; if (delta.X != 0 || delta.Y != 0) { if (EditedEdge == null) { if (EdgeRoutingMode != EdgeRoutingMode.Rectilinear && EdgeRoutingMode != EdgeRoutingMode.RectilinearToCenter) { DragObjectsForNonRectilinearCase(delta, draggingMode); } else { DragObjectsForRectilinearCase(delta); } } else { DragEdgeEdit(lastPointerPosition, delta); UpdateGraphBoundingBoxWithCheck(EditedEdge); } } }
private void GraphEditorClass_MouseDown(object sender, MouseEventArgs e) { PointF mousePos = ClientToDocumentPoint(new PointF(e.X, e.Y)); if (_heldButton == MouseButtons.None) { if ((e.Button == MouseButtons.Left) && (ModifierKeys != Keys.Control)) { SelectObjectInternal(mousePos); _lastDragPoint = mousePos; _heldButton = e.Button; _draggingMode = DraggingMode.MoveNode; } else if ((e.Button == MouseButtons.Middle) || ((e.Button == MouseButtons.Left) && (ModifierKeys == Keys.Control))) { IGraphObject s = SelectObjectInternal(mousePos); if ((s != null) && (s is GraphNode)) { _lastDragPoint = mousePos; _heldButton = e.Button; _draggingMode = DraggingMode.DrawLine; } else if (s == null) { _lastDragPoint = mousePos; _heldButton = e.Button; _draggingMode = DraggingMode.ScrollWindow; this.Cursor = Cursors.SizeAll; } } } Focus(); }
private void RangeHistogram_MouseUp(object sender, MouseEventArgs e) { whiteToolTip.Hide(this); blackToolTip.Hide(this); m_DragMode = DraggingMode.NONE; m_mousePrev.X = m_mousePrev.Y = -1; }
// This handler tries to figure out which handle (white or black) you were trying to // grab when you clicked. private void RangeHistogram_MouseDown(object sender, MouseEventArgs e) { if(e.Button != MouseButtons.Left || !ValidRange) return; Rectangle rect = this.ClientRectangle; rect.Inflate(-m_TotalSpace, -m_TotalSpace); int whiteX = (int)(m_WhiteDelta * rect.Width); int blackX = (int)(m_BlackDelta * rect.Width); var whiteVec = new PointF(whiteX - e.Location.X, ClientRectangle.Height - e.Location.Y); var blackVec = new PointF(blackX-e.Location.X, e.Location.Y); float whitedist = (float)Math.Sqrt(whiteVec.X * whiteVec.X + whiteVec.Y * whiteVec.Y); float blackdist = (float)Math.Sqrt(blackVec.X * blackVec.X + blackVec.Y * blackVec.Y); System.Diagnostics.Trace.WriteLine(string.Format("white {0} black {1}", whitedist, blackdist)); if (whitedist < blackdist && whitedist < 18.0f) m_DragMode = DraggingMode.WHITE; else if (blackdist < whitedist && blackdist < 18.0f) m_DragMode = DraggingMode.BLACK; else if (e.Location.X > whiteX) m_DragMode = DraggingMode.WHITE; else if (e.Location.X < blackX) m_DragMode = DraggingMode.BLACK; if (m_DragMode == DraggingMode.WHITE) { float newWhite = (float)(e.Location.X - m_TotalSpace) / (float)m_RegionWidth; m_WhiteDelta = Math.Max(m_BlackDelta + m_MinRangeSize, Math.Min(1.0f, newWhite)); } else if (m_DragMode == DraggingMode.BLACK) { float newBlack = (float)(e.Location.X - m_TotalSpace) / (float)m_RegionWidth; m_BlackDelta = Math.Min(m_WhiteDelta - m_MinRangeSize, Math.Max(0.0f, newBlack)); } OnRangeUpdated(new RangeHistogramEventArgs(BlackPoint, WhitePoint)); if (m_DragMode != DraggingMode.NONE) { this.Invalidate(); this.Update(); } m_mousePrev.X = e.X; m_mousePrev.Y = e.Y; }
void DragObjectsForNonRectilinearCase(Point delta, DraggingMode draggingMode) { if (draggingMode == DraggingMode.Incremental) { DragIncrementally(delta); } else if (EdgeRoutingMode == EdgeRoutingMode.Spline || EdgeRoutingMode == EdgeRoutingMode.SplineBundling) { DragWithSplinesOrBundles(delta); } else { DragWithStraightLines(delta); } }
/// <summary> /// Default constructor /// </summary> public GraphEditorControl() { _nodes = new List<GraphNode>(); _lines = new List<GraphLine>(); _linkLines = new List<GraphLinkLine>(); _heldButton = MouseButtons.None; _lastDragPoint = new PointF(); _draggingMode = DraggingMode.None; _scrollPosition = new PointF(); _dirty = false; _zoom = 1.0f; _graphLock = new object(); MouseWheel += new MouseEventHandler(GraphEditorControl_MouseWheel); InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); Controls.Add(vScrollBar); Controls.Add(hScrollBar); }
/// <summary> /// Default constructor /// </summary> public GraphEditorControl() { _nodes = new List <GraphNode>(); _lines = new List <GraphLine>(); _linkLines = new List <GraphLinkLine>(); _heldButton = MouseButtons.None; _lastDragPoint = new PointF(); _draggingMode = DraggingMode.None; _scrollPosition = new PointF(); _dirty = false; _zoom = 1.0f; _graphLock = new object(); MouseWheel += new MouseEventHandler(GraphEditorControl_MouseWheel); InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); Controls.Add(vScrollBar); Controls.Add(hScrollBar); }
/// <summary> /// Default constructor /// </summary> public GraphEditorControl() { _nodes = new List <GraphNode>(); _lines = new List <GraphLine>(); _linkLines = new List <GraphLinkLine>(); _heldButton = MouseButtons.None; _lastDragPoint = new PointF(); _draggingMode = DraggingMode.None; _scrollPosition = new PointF(); _dirty = false; _graphLock = new object(); using (Graphics g = CreateGraphics()) { _xscale = g.DpiX / 96.0f; _yscale = g.DpiY / 96.0f; } DocumentWidth = (int)(DEFAULT_DOCUMENT_WIDTH * _xscale); DocumentHeight = (int)(DEFAULT_DOCUMENT_HEIGHT * _yscale); MouseWheel += new MouseEventHandler(GraphEditorControl_MouseWheel); InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); Controls.Add(vScrollBar); Controls.Add(hScrollBar); }
public DragObject SetDraggingMode(DraggingMode mode) { draggingMode = mode; return(this); }
/// <summary> /// drags elements by the delta /// </summary> /// <param name="delta"></param> /// <param name="draggingMode">describes the way we process the dragging </param> /// <param name="lastMousePosition">the last position of the mouse pointer </param> internal void Drag(Point delta, DraggingMode draggingMode, Point lastMousePosition) { GraphBoundingBoxGetsExtended = false; if (delta.X != 0 || delta.Y != 0) { if (EditedEdge == null) if (EdgeRoutingMode != EdgeRoutingMode.Rectilinear && EdgeRoutingMode != EdgeRoutingMode.RectilinearToCenter) DragObjectsForNonRectilinearCase(delta, draggingMode); else DragObjectsForRectilinearCase(delta); else { DragEdgeEdit(lastMousePosition, delta); UpdateGraphBoundingBoxWithCheck(EditedEdge); } } }
/// <summary> /// prepares for node dragging /// </summary> /// <param name="markedObjects">markedObjects will be dragged</param> /// <param name="dragMode"> is shift is pressed then the mode changes </param> /// <returns></returns> internal void PrepareForObjectDragging(IEnumerable <GeometryObject> markedObjects, DraggingMode dragMode) { EditedEdge = null; CalculateDragSets(markedObjects); InsertToListAndSetTheBoxBefore(new ObjectDragUndoRedoAction(graph)); if (dragMode == DraggingMode.Incremental) { InitIncrementalDragger(); } }
void DragObjectsForNonRectilinearCase(Point delta, DraggingMode draggingMode) { if (draggingMode == DraggingMode.Incremental) DragIncrementally(delta); else if (EdgeRoutingMode == EdgeRoutingMode.Spline || EdgeRoutingMode == EdgeRoutingMode.SplineBundling) DragWithSplinesOrBundles(delta); else DragWithStraightLines(delta); }
/// <summary> /// prepares for node dragging /// </summary> /// <param name="markedObjects">markedObjects will be dragged</param> /// <param name="dragMode"> is shift is pressed then the mode changes </param> /// <returns></returns> internal void PrepareForObjectDragging(IEnumerable<GeometryObject> markedObjects, DraggingMode dragMode) { EditedEdge = null; CalculateDragSets(markedObjects); InsertToListAndSetTheBoxBefore(new ObjectDragUndoRedoAction(graph)); if (dragMode == DraggingMode.Incremental) InitIncrementalDragger(); }