/// <summary> /// Apply new line width /// </summary> public static bool ApplyLineWidth(DrawingCanvas drawingCanvas, double value, bool addToHistory) { CommandChangeState command = new CommandChangeState(drawingCanvas); bool wasChange = false; // LineWidth is set for all objects except of GraphicsText. // Though GraphicsText has this property, it should remain constant. foreach (GraphicsBase g in drawingCanvas.Selection) { if (g is GraphicsRectangle || g is GraphicsLine || g is GraphicsPolyLine) { if (g.LineWidth != value) { g.LineWidth = value; wasChange = true; } } } if (wasChange && addToHistory) { command.NewState(drawingCanvas); drawingCanvas.AddCommandToHistory(command); } return(wasChange); }
/// <summary> /// Move selection to back /// </summary> public static void MoveSelectionToBack(DrawingCanvas drawingCanvas) { // Moving to back of z-order means moving // to the beginning of VisualCollection. // Read GraphicsList in the reverse order, and move every selected object // to temporary list. List <GraphicsBase> list = new List <GraphicsBase>(); CommandChangeOrder command = new CommandChangeOrder(drawingCanvas); for (int i = drawingCanvas.Count - 1; i >= 0; i--) { if (drawingCanvas[i].IsSelected) { list.Add(drawingCanvas[i]); drawingCanvas.GraphicsList.RemoveAt(i); } } // Add all items from temporary list to the beginning of GraphicsList foreach (GraphicsBase g in list) { drawingCanvas.GraphicsList.Insert(0, g); } if (list.Count > 0) { command.NewState(drawingCanvas); drawingCanvas.AddCommandToHistory(command); } }
/// <summary> /// Delete all graphic objects /// </summary> public static void DeleteAll(DrawingCanvas drawingCanvas) { if (drawingCanvas.GraphicsList.Count > 0) { drawingCanvas.AddCommandToHistory(new CommandDeleteAll(drawingCanvas)); drawingCanvas.GraphicsList.Clear(); } }
/// <summary> /// Add change to history. /// Called after finishing moving/resizing. /// </summary> public void AddChangeToHistory(DrawingCanvas drawingCanvas) { if (commandChangeState != null && wasMove) { // Keep state after moving/resizing and add command to history commandChangeState.NewState(drawingCanvas); drawingCanvas.AddCommandToHistory(commandChangeState); commandChangeState = null; } }
/// <summary> /// Return true if currently active properties (line width, color etc.) /// can be applied to selected items. /// /// If at least one selected object has property different from currently /// active property value, properties can be applied. /// </summary> //public static bool CanApplyProperties(DrawingCanvas drawingCanvas) //{ // foreach(GraphicsBase graphicsBase in drawingCanvas.GraphicsList) // { // if ( ! graphicsBase.IsSelected ) // { // continue; // } // // ObjectColor - used in all graphics objects // if ( graphicsBase.ObjectColor != drawingCanvas.ObjectColor ) // { // return true; // } // return false; //} /// <summary> /// Apply currently active properties to selected objects /// </summary> public static void ApplyProperties(DrawingCanvas drawingCanvas) { // Apply every property. // Call every Apply* function with addToHistory = false. // History is updated here and not in called functions. CommandChangeState command = new CommandChangeState(drawingCanvas); bool wasChange = false; if (wasChange) { command.NewState(drawingCanvas); drawingCanvas.AddCommandToHistory(command); } }
/// <summary> /// Delete selected graphic objects /// </summary> public static void DeleteSelection(DrawingCanvas drawingCanvas) { CommandDelete command = new CommandDelete(drawingCanvas); bool wasChange = false; for (int i = drawingCanvas.Count - 1; i >= 0; i--) { if (drawingCanvas[i].IsSelected) { drawingCanvas.GraphicsList.RemoveAt(i); wasChange = true; } } if (wasChange) { drawingCanvas.AddCommandToHistory(command); } }
/// <summary> /// Apply new color /// </summary> public static bool ApplyColor(DrawingCanvas drawingCanvas, Color value, bool addToHistory) { CommandChangeState command = new CommandChangeState(drawingCanvas); bool wasChange = false; foreach (GraphicsBase g in drawingCanvas.Selection) { if (g.ObjectColor != value) { g.ObjectColor = value; wasChange = true; } } if (wasChange && addToHistory) { command.NewState(drawingCanvas); drawingCanvas.AddCommandToHistory(command); } return(wasChange); }
/// <summary> /// Left mouse is released. /// New object is created and resized. /// </summary> public override void OnMouseUp(DrawingCanvas drawingCanvas, Point position) { if (drawingCanvas.Count > 0) { GraphicsBase o = drawingCanvas[drawingCanvas.Count - 1] as GraphicsBase; o.MoveMouse(position); if (!o.HasDelta()) { drawingCanvas.GraphicsList.Remove(o); } } if (drawingCanvas.Count > 0) { drawingCanvas[drawingCanvas.Count - 1].Normalize(); drawingCanvas.AddCommandToHistory(new CommandAdd(drawingCanvas[drawingCanvas.Count - 1])); } drawingCanvas.Cursor = Cursors.Arrow; drawingCanvas.ReleaseMouseCapture(); drawingCanvas.InvalidateMeasure(); }