void SurfaceMouseMove(object sender, MouseEventArgs e) { Point currentMouse = MouseHelper.FixMouseCoordinates(e); if (DrawingMode != DrawingModes.None) { Cursor = Cursors.Cross; } else { Cursor = Cursors.Default; } if (mouseDown) { if (mouseDownElement != null) // an element is currently dragged { mouseDownElement.Invalidate(); selectedElements.HideGrippers(); // Move the element if (mouseDownElement.Selected) { if (!isSurfaceMoveMadeUndoable) { // Only allow one undoable per mouse-down/move/up "cycle" isSurfaceMoveMadeUndoable = true; selectedElements.MakeBoundsChangeUndoable(false); } // dragged element has been selected before -> move all selectedElements.MoveBy(currentMouse.X - mouseStart.X, currentMouse.Y - mouseStart.Y); } else { if (!isSurfaceMoveMadeUndoable) { // Only allow one undoable per mouse-down/move/up "cycle" isSurfaceMoveMadeUndoable = true; mouseDownElement.MakeBoundsChangeUndoable(false); } // dragged element is not among selected elements -> just move dragged one mouseDownElement.MoveBy(currentMouse.X - mouseStart.X, currentMouse.Y - mouseStart.Y); } mouseStart = currentMouse; mouseDownElement.Invalidate(); modified = true; } else if (drawingElement != null) { if (!drawingElement.HandleMouseMove(currentMouse.X, currentMouse.Y)) { // an element is currently drawn drawingElement.Invalidate(); drawingElement.Width = currentMouse.X - drawingElement.Left; drawingElement.Height = currentMouse.Y - drawingElement.Top; drawingElement.Invalidate(); } modified = true; } } }
public void RemoveElement(DrawableContainer element, bool makeUndoable) { DeselectElement(element); elements.Remove(element); element.FieldChanged -= element_FieldChanged; element.PropertyChanged -= ElementPropertyChanged; // Do not dispose, the memento should!! element.Dispose(); element.Invalidate(); if (makeUndoable) { MakeUndoable(new DeleteElementMemento(this, element), false); } modified = true; }
/// <summary> /// Add a new element to the surface /// </summary> /// <param name="element">the new element</param> /// <param name="makeUndoable">true if the adding should be undoable</param> public void AddElement(DrawableContainer element, bool makeUndoable) { elements.Add(element); element.FieldChanged += element_FieldChanged; element.PropertyChanged += ElementPropertyChanged; if (element.Status == EditStatus.UNDRAWN) { element.Status = EditStatus.IDLE; } element.Invalidate(); if (makeUndoable) { MakeUndoable(new AddElementMemento(this, element), false); } modified = true; }
public void SelectElement(IDrawableContainer container) { DrawableContainer element = container as DrawableContainer; if (!selectedElements.Contains(element)) { selectedElements.Add(element); element.ShowGrippers(); element.Selected = true; FieldAggregator.BindElement(element); if (MovingElementChanged != null) { MovingElementChanged(this, selectedElements); } element.Invalidate(); } }
public void DeselectAllElements() { if (HasSelectedElements()) { while (selectedElements.Count > 0) { DrawableContainer element = selectedElements[0]; element.Invalidate(); element.HideGrippers(); element.Selected = false; selectedElements.Remove(element); FieldAggregator.UnbindElement(element); } if (MovingElementChanged != null) { MovingElementChanged(this, selectedElements); } } }
/// <summary> /// Add a new element to the surface /// </summary> /// <param name="element">the new element</param> /// <param name="makeUndoable">true if the adding should be undoable</param> public void AddElement(DrawableContainer element, bool makeUndoable) { elements.Add(element); element.FieldChanged += element_FieldChanged; element.PropertyChanged += ElementPropertyChanged; if(element.Status == EditStatus.UNDRAWN) { element.Status = EditStatus.IDLE; } element.Invalidate(); if (makeUndoable) { MakeUndoable(new AddElementMemento(this, element), false); } modified = true; }
void SurfaceMouseUp(object sender, MouseEventArgs e) { Point currentMouse = MouseHelper.FixMouseCoordinates(e); elements.Status = EditStatus.IDLE; if (mouseDownElement != null) { mouseDownElement.Status = EditStatus.IDLE; } mouseDown = false; mouseDownElement = null; if (DrawingMode == DrawingModes.None) { // check whether an existing element was clicked DrawableContainer element = elements.ClickableElementAt(currentMouse.X, currentMouse.Y); bool shiftModifier = (Control.ModifierKeys & Keys.Shift) == Keys.Shift; if (element != null) { element.Invalidate(); bool alreadySelected = selectedElements.Contains(element); if (shiftModifier) { if (alreadySelected) { DeselectElement(element); } else { SelectElement(element); } } else { if (!alreadySelected) { DeselectAllElements(); SelectElement(element); } } } else if (!shiftModifier) { DeselectAllElements(); } } if (selectedElements.Count > 0) { selectedElements.ShowGrippers(); selectedElements.Selected = true; } if (drawingElement != null) { if (!drawingElement.InitContent()) { elements.Remove(drawingElement); drawingElement.Invalidate(); } else { drawingElement.HandleMouseUp(currentMouse.X, currentMouse.Y); drawingElement.Invalidate(); if (Math.Abs(drawingElement.Width) < 5 && Math.Abs(drawingElement.Height) < 5) { drawingElement.Width = 25; drawingElement.Height = 25; } SelectElement(drawingElement); drawingElement.Selected = true; } drawingElement = null; } }