/// <summary> /// Press one of the mouse buttons (at the moment of release) /// </summary> /// <param name="e">Mouse Properties</param> public void MouseUp(MouseEventArgs e) { if (this.initialConnector != null) { GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); if ((element != null) && !(element is GraphArrow)) { if (this.initialConnector.Parent == element) { if (this.initFixed) { Connector connector = element.GetConnector(e.Location); if (this.initialConnector == connector) { this.dragMode = false; } else if (connector != null) { this.finalConnector = this.presentConnector; this.Do(); } } else { this.dragMode = false; } } else if (!(element is GraphStart)) { this.finalConnector = this.presentConnector; this.Do(); } } } }
/// <summary> /// Press one of the mouse buttons (at the moment of pressing) /// </summary> /// <param name="e">Mouse Properties</param> public void MouseDown(MouseEventArgs e) { //If the initial connector is empty... if (this.initialConnector == null) { //You look for if you clicked on a different element of an arrow or a finish GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); if ((element != null) && !((element is GraphArrow) || (element is GraphFinish))) { Connector connector = element.GetConnector(e.Location); if (connector != null) { this.initialConnector = connector; this.initFixed = true; } else { this.initialConnector = this.GetConnector(element, e.Location); } if (this.initialConnector.Parent is GraphConditional) { this.conditionalOut = ((GraphConditional)this.initialConnector.Parent).GetPredefOut(this.initialConnector); } element.DisableConnectors(); element.EnableConnector(this.initialConnector); this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, e.Location); this.tempLayer.UpdateSurface(); } } }
public void MouseUp(MouseEventArgs e) { //Only checks for left mouse button if (e.Button == MouseButtons.Left) { //Looking for the affected element GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); //If there is none, it is changed to Operation Nop if (element == null) { //The context of the Select operation is cleaned this.ClearOperationContext(); throw new OperationException(Operation.Select, "Change to Nop Operation"); } else { //If you are pressing the CONTROL key, a multiple selection is being made if (Control.ModifierKeys == Keys.Control) { //If the item is selected, it is deselected if (element.Selected) { DeselectElement(element); //If there is no item selected, it changes to the NOP operation if (this.selectLayer.Elements.Count == 0) { //The context of the Select operation is cleaned this.ClearOperationContext(); throw new OperationException(Operation.Select, "Change to Nop Operation"); } } //without, it selects else { this.SelectElement(element); } this.selectLayer.UpdateSurface(); if (this.ElementSelectedChanged != null) { this.ElementSelectedChanged(this, new EventArgs()); } } //If the item is not selected, the others are deselected and the current is selected else if (!element.Selected) { this.DeselectAll(); this.SelectElement(element); //The temporary layer is updated this.selectLayer.UpdateSurface(); if (this.ElementSelectedChanged != null) { this.ElementSelectedChanged(this, new EventArgs()); } } } } }
public void MouseMove(MouseEventArgs e) { GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); //If you are right-clicking and no item found, you switch to Operation Nop if ((e.Button == MouseButtons.Right) && (element == null)) { //The context of the Select operation is cleaned this.ClearOperationContext(); throw new OperationException(Operation.Select, "Change to Nop operation"); } //If you are pressing the left button, the selection is checked and Drag & Drop operation starts else if (e.Button == MouseButtons.Left) { if (element == null) { element = GraphDiagram.GetElement(this.diagramLayer, this.downInitialpoint); } //If the item is not selected, it is selected before the drag & Drop operation is started if (!element.Selected) { //If the CONTROL key is not pressed the other elements are deselected if (Control.ModifierKeys != Keys.Control) { DeselectAll(); } SelectElement(element); //The temporary layer is updated this.selectLayer.UpdateSurface(); if (this.ElementSelectedChanged != null) { this.ElementSelectedChanged(this, new EventArgs()); } } throw new OperationException(Operation.Select, "Change to Drag&Drop operation"); } //The mouse cursor is updated as appropriate else { if (element == null) { if ((Cursor.Current != Cursors.Hand) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Hand)); } } else if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } } }
public void MouseDown(MouseEventArgs e) { //This is for the right and left mouse buttons if ((e.Button == MouseButtons.Left) || (e.Button == MouseButtons.Right)) { //The position of the Down event is saved for possible new operations this.downInitialpoint = e.Location; GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); //If it is not pressed on any element, it is changed to the Nop operation if (element == null) { //The context of the Select operation is cleaned this.ClearOperationContext(); throw new OperationException(Operation.Select, "Change to Nop Operation"); } } }
/// <summary> /// Occurs when the context menu is opened: Selects the item if it is not in that state /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Menu_Popup(object sender, EventArgs e) { GraphElement element = GraphDiagram.GetElement(this.diagramLayer, this.downInitialpoint); //You look at the selected state of the item if (!element.Selected) { //If the CONTROL key is not pressed the other elements are deselected if (Control.ModifierKeys != Keys.Control) { DeselectAll(); } SelectElement(element); //The temporary layer is updated this.selectLayer.UpdateSurface(); } }
/// <summary> /// Mouse movement over the GraphDrawing /// </summary> /// <param name="e">Mouse Properties</param> public void MouseMove(MouseEventArgs e) { if (this.initialConnector == null) { GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); if (element != null) { if (element != this.presentElement) { if (this.presentElement != null) { this.presentElement.DisableConnectors(); this.tempLayer.RemoveElement(this.presentElement); this.presentElement = null; } if (element.EnableNextConnectors()) { this.presentElement = element; this.tempLayer.Add(this.presentElement); //The cursor is updated to default if ((Cursor.Current != Cursors.Hand) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Hand)); } } else //The cursor is updated to default if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } this.tempLayer.UpdateSurface(); } } else if (this.presentElement != null) { this.presentElement.DisableConnectors(); this.tempLayer.RemoveElement(this.presentElement); this.presentElement = null; this.tempLayer.UpdateSurface(); //The cursor is updated to default if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } } } else { //The initial connector is updated if necessary if (!this.initFixed) { Connector connector = this.GetConnector(this.initialConnector.Parent, e.Location); if (this.initialConnector != connector) { this.initialConnector = connector; this.initialConnector.Parent.DisableConnectors(); this.initialConnector.Parent.EnableConnector(this.initialConnector); if (this.initialConnector.Parent is GraphConditional) { this.conditionalOut = ((GraphConditional)this.initialConnector.Parent).GetPredefOut(this.initialConnector); } } } //Looking for the final element GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); if (element != null) { if (this.presentElement != element) { if (this.presentElement != null) { this.presentElement.DisableConnectors(); if (this.presentElement == this.initialConnector.Parent) { this.presentElement.EnableConnector(this.initialConnector); } else { this.tempLayer.RemoveElement(this.presentElement); } this.presentElement = null; } if (this.initialConnector.Parent == element) { if ((this.initFixed) && (element.EnablePrevConnectors())) { this.presentElement = element; this.tempLayer.Add(this.presentElement); } } else if (element.EnablePrevConnectors()) { this.presentElement = element; this.tempLayer.Add(this.presentElement); } } if (this.presentElement == null) { this.presentConnector = null; this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, e.Location); } else { Connector connector = this.presentElement.GetConnector(e.Location); if (connector == null) { connector = this.GetPrevConnector(this.presentElement, e.Location); if (connector != this.presentConnector) { this.presentConnector = connector; this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, this.presentConnector.AbsCenter); } } else if (this.presentConnector != connector) { this.presentConnector = connector; this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, this.presentConnector.AbsCenter); } } } else { if (this.presentElement != null) { this.presentElement.DisableConnectors(); if (this.presentElement == this.initialConnector.Parent) { this.presentElement.EnableConnector(this.initialConnector); } else { this.tempLayer.RemoveElement(this.presentElement); } this.presentElement = null; } this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, e.Location); } } this.tempLayer.UpdateSurface(); }
/// <summary> /// This method is calling when you press any mouse button within the workspace /// </summary> /// <param name="e"></param> public void MouseDown(MouseEventArgs e) { GraphElement element; //Looking for an item in the given position if ((this.tempLayer.Elements.Count != 0) && (this.tempLayer.Elements[0].IntersectsWith(e.Location))) { element = this.tempLayer.Elements[0]; } else { element = GraphDiagram.GetElement(this.diagramLayer, e.Location); } //Position is saved for future operations this.downInitialPoint = e.Location; //If an item exists, the mouse button is checked for a change of operation if (element != null) { //If the button pressed is the left... if (e.Button == MouseButtons.Left) { //If the press is on an arrow if ((element is GraphArrow) && (this.tempLayer.Elements.Count == 1)) { ArrowModifier modifier = ((GraphArrow)this.tempLayer.Elements[0]).GetModifier(e.Location); if (modifier == null) { this.ClearOperationContext(); throw new OperationException(Operation.Nop, "Change to Select Operation"); } else if (modifier is ConnectorModifier) { throw new OperationException(Operation.Nop, "Change to Reconnect Operation"); } //If the press is on the element, it is passed to the selection operation else { throw new OperationException(Operation.Nop, "Change to ModifyArrow Operation"); } } //If the pulsation is over a connector is passed to the arrow insert operation else if (element.IntersectsWithConnector(e.Location)) { throw new OperationException(Operation.Nop, "Change to InsertArrow Operation"); } //If the press is on the element, it is passed to the selection operation else { this.ClearOperationContext(); throw new OperationException(Operation.Nop, "Change to Select Operation"); } } //If the button pressed is the left one, it is passed to the selection operation else if (e.Button == MouseButtons.Right) { this.ClearOperationContext(); throw new OperationException(Operation.Nop, "Change to Select Operation"); } } }
/// <summary> /// This method is called when the mouse moves into the workspace /// </summary> /// <param name="e"></param> public void MouseMove(MouseEventArgs e) { if (this.tempLayer.Elements.Count != 0) { if (this.tempLayer.Elements[0].IntersectsWith(e.Location)) { if (this.tempLayer.Elements[0] is GraphArrow) { ArrowModifier modifier = ((GraphArrow)this.tempLayer.Elements[0]).GetModifier(e.Location); if (modifier is ConnectorModifier) { if ((Cursor.Current != Cursors.Hand) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Hand)); } } else if (modifier is HorizontalModifier) { if ((Cursor.Current != Cursors.HSplit) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.HSplit)); } } else if (modifier is VerticalModifier) { if ((Cursor.Current != Cursors.VSplit) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.VSplit)); } } else { if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } } } else if (this.tempLayer.Elements[0].IntersectsWithConnector(e.Location)) { if ((Cursor.Current != Cursors.Hand) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Hand)); } } else if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } return; } } //Looking for an item in the given position GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); //If no items are found the operation is cancelled if (element == null) { //If there is any element in the temporal layer, it removes if (this.tempLayer.Elements.Count != 0) { this.ClearOperationContext(); //The temporary layer is updated this.tempLayer.UpdateSurface(); //The cursor is updated a default if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } } //If the left button is pressed, the zone selection operation starts if (e.Button == MouseButtons.Left) { throw new OperationException(Operation.Nop, "Change to SelectZone Operation"); } } else { if (this.tempLayer.Elements.Count == 0) { this.tempLayer.Visible = true; } else { //The temporary layer is cleaned if (this.tempLayer.Elements[0] is GraphArrow) { //The arrow modifiers are disabled ((GraphArrow)this.tempLayer.Elements[0]).DisableModifiers(); } else { //Disables connectors ((GraphElement)this.tempLayer.Elements[0]).DisableConnectors(); } //Removes the element from the temporary layer this.tempLayer.RemoveElement((GraphElement)this.tempLayer.Elements[0]); } if (element is GraphArrow) { ((GraphArrow)element).EnableModifiers(); //Added to the temporary layer this.tempLayer.AddElement(element); this.tempLayer.UpdateSurface(); //Updates to the corresponding cursor if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } } else { //The following connectors are enabled if (element.EnableNextConnectors()) { //Added to the temporary layer this.tempLayer.AddElement(element); this.tempLayer.UpdateSurface(); //Updates to the corresponding cursor if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null)) { this.CursorChanged(this, new CursorEventArgs(Cursors.Default)); } } else { this.tempLayer.ClearAndHide(); this.tempLayer.UpdateSurface(); } } } }
public void MouseMove(MouseEventArgs e) { GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location); if (element != null) { if (this.presentElement != element) { if (this.presentElement != null) { this.presentElement.DisableConnectors(); if (this.presentElement == this.initialConnector.Parent) { this.presentElement.EnableConnector(this.initialConnector); } else { this.tempLayer.RemoveElement(this.presentElement); } this.presentElement = null; } if (element.EnablePrevConnectors()) { this.presentElement = element; this.tempLayer.Add(this.presentElement); } } if (this.presentElement == null) { this.presentConnector = null; this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, e.Location); } else { Connector connector = this.presentElement.GetConnector(e.Location); if (connector == null) { this.presentConnector = null; this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, e.Location); } else if (this.presentConnector != connector) { this.presentConnector = connector; this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, this.presentConnector.AbsCenter); } } } else { if (this.presentElement != null) { this.presentElement.DisableConnectors(); if (this.presentElement == this.initialConnector.Parent) { this.presentElement.EnableConnector(this.initialConnector); } else { this.tempLayer.RemoveElement(this.presentElement); } this.presentElement = null; } this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, e.Location); } this.tempLayer.UpdateSurface(); }