/// <summary>
        /// Restore selection to its state before change.
        /// </summary>
        public override void Undo(DrawingCanvas drawingCanvas)
        {
            // Replace all objects in the list with objects from listBefore
            ReplaceObjects(drawingCanvas.GraphicsList, listBefore);

            drawingCanvas.RefreshClip();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete objects again.
        /// </summary>
        public override void Redo(DrawingCanvas drawingCanvas)
        {
            // Delete from list all objects kept in cloneList.
            // Use object IDs for deleting, don't beleive to objects order.

            int n = drawingCanvas.GraphicsList.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                bool toDelete = false;
                GraphicsBase currentObject = (GraphicsBase)drawingCanvas.GraphicsList[i];

                foreach (PropertiesGraphicsBase o in cloneList)
                {
                    if (o.ID == currentObject.Id)
                    {
                        toDelete = true;
                        break;
                    }
                }

                if (toDelete)
                {
                    drawingCanvas.GraphicsList.RemoveAt(i);
                }
            }
        }
        /// <summary>
        /// Apply new font family
        /// </summary>
        public static bool ApplyFontFamily(DrawingCanvas drawingCanvas, string value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange = false;

            foreach (GraphicsBase g in drawingCanvas.Selection)
            {
                GraphicsText gt = g as GraphicsText;

                if (gt != null)
                {
                    if (gt.TextFontFamilyName != value)
                    {
                        gt.TextFontFamilyName = value;
                        wasChange = true;
                    }
                }
            }

            if (wasChange  && addToHistory )
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return wasChange;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Restore deleted objects
        /// </summary>
        public override void Undo(DrawingCanvas drawingCanvas)
        {
            // Insert all objects from cloneList to GraphicsList

            int currentIndex = 0;
            int indexToInsert;

            foreach (PropertiesGraphicsBase o in cloneList)
            {
                indexToInsert = indexes[currentIndex];

                if ( indexToInsert >=0  &&  indexToInsert <= drawingCanvas.GraphicsList.Count )   // "<=" is correct !
                {
                    drawingCanvas.GraphicsList.Insert(indexToInsert, o.CreateGraphics());
                }
                else
                {
                    // Bug: we should not be here.
                    // Add to the end anyway.
                    drawingCanvas.GraphicsList.Add(o.CreateGraphics());

                    System.Diagnostics.Trace.WriteLine("CommandDelete.Undo - incorrect index");
                }

                currentIndex++;
            }

            drawingCanvas.RefreshClip();
        }
        /// <summary>
        /// Add all deleted objects to GraphicsList
        /// </summary>
        public override void Undo(DrawingCanvas drawingCanvas)
        {
            foreach (PropertiesGraphicsBase o in cloneList)
            {
                drawingCanvas.GraphicsList.Add(o.CreateGraphics());
            }

            drawingCanvas.RefreshClip();
        }
Ejemplo n.º 6
0
 /// <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;
     }
 }
        // Create this command BEFORE applying Delete All function.
        public CommandDeleteAll(DrawingCanvas drawingCanvas)
        {
            cloneList = new List<PropertiesGraphicsBase>();

            // Make clone of the whole list.
            foreach(GraphicsBase g in drawingCanvas.GraphicsList)
            {
                cloneList.Add(g.CreateSerializedObject());
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add new object to drawing canvas.
        /// Function is called when user left-clicks drawing canvas,
        /// and one of ToolObject-derived tools is active.
        /// </summary>
        protected static void AddNewObject(DrawingCanvas drawingCanvas, GraphicsBase o)
        {
            HelperFunctions.UnselectAll(drawingCanvas);

            o.IsSelected = true;
            drawingCanvas.SelectedObject = o;
            o.Clip = new RectangleGeometry(new Rect(0, 0, drawingCanvas.ActualWidth, drawingCanvas.ActualHeight));

            drawingCanvas.GraphicsList.Add(o);
            drawingCanvas.CaptureMouse();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Add object again
        /// </summary>
        public override void Redo(DrawingCanvas drawingCanvas)
        {
            HelperFunctions.UnselectAll(drawingCanvas);

            // Create full object from the clone and add it to list
            drawingCanvas.GraphicsList.Add(newObjectClone.CreateGraphics());

            // Object created from the clone doesn't contain clip information,
            // refresh it.
            drawingCanvas.RefreshClip();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Left mouse is released.
        /// New object is created and resized.
        /// </summary>
        public override void OnMouseUp(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            if (drawingCanvas.Count > 0)
            {
                drawingCanvas[drawingCanvas.Count - 1].Normalize();

                drawingCanvas.AddCommandToHistory(new CommandAdd(drawingCanvas[drawingCanvas.Count - 1]));
            }

            //drawingCanvas.Tool = ToolType.Pointer;
            drawingCanvas.Cursor = HelperFunctions.DefaultCursor;
            drawingCanvas.ReleaseMouseCapture();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create new TableBlock
        /// </summary>
        public override void OnMouseDown(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            Point p = e.GetPosition(drawingCanvas);

            AddNewObject(drawingCanvas,
                new GraphicsTableBlock(
                p.X,
                p.Y,
                p.X + 1,
                p.Y + 1,
                drawingCanvas.LineWidth,
                drawingCanvas.ObjectColor,
                drawingCanvas.ActualScale));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Set cursor and resize new polyline
        /// </summary>
        public override void OnMouseMove(DrawingCanvas drawingCanvas, MouseEventArgs e)
        {
            drawingCanvas.Cursor = ToolCursor;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (drawingCanvas.IsMouseCaptured)
                {
                    if (drawingCanvas.Count > 0)
                    {
                        drawingCanvas[drawingCanvas.Count - 1].MoveTo(e.GetPosition(drawingCanvas));
                    }
                }

            }
        }
Ejemplo n.º 13
0
        List<int> indexes; // contains indexes of deleted items

        #endregion Fields

        #region Constructors

        // Create this command BEFORE applying Delete function.
        public CommandDelete(DrawingCanvas drawingCanvas)
        {
            cloneList = new List<PropertiesGraphicsBase>();
            indexes = new List<int>();

            // Make clone of the list selection.

            int currentIndex = 0;

            foreach (GraphicsBase g in drawingCanvas.Selection)
            {
                cloneList.Add(g.CreateSerializedObject());
                indexes.Add(currentIndex);

                currentIndex++;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Create textbox for in-place editing
        /// </summary>
        public void CreateTextBox(GraphicsText graphicsText, DrawingCanvas drawingCanvas)
        {
            graphicsText.IsSelected = false;  // selection marks don't look good with textbox

            // Keep old text in the case Esc is pressed while editing
            oldText = graphicsText.Text;

            // Keep reference to edited object
            editedGraphicsText = graphicsText;

            textBox = new TextBox();

            textBox.Width = graphicsText.Rectangle.Width;
            textBox.Height = graphicsText.Rectangle.Height;
            textBox.FontFamily = new FontFamily(graphicsText.TextFontFamilyName);
            textBox.FontSize = graphicsText.TextFontSize;
            textBox.FontStretch = graphicsText.TextFontStretch;
            textBox.FontStyle = graphicsText.TextFontStyle;
            textBox.FontWeight = graphicsText.TextFontWeight;
            textBox.Text = graphicsText.Text;

            textBox.AcceptsReturn = true;
            textBox.TextWrapping = TextWrapping.Wrap;

            drawingCanvas.Children.Add(textBox);

            Canvas.SetLeft(textBox, graphicsText.Rectangle.Left);
            Canvas.SetTop(textBox, graphicsText.Rectangle.Top);
            textBox.Width = textBox.Width;
            textBox.Height = textBox.Height;

            textBox.Focus();

            textBox.LostFocus += new RoutedEventHandler(textBox_LostFocus);
            textBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(textBox_LostKeyboardFocus);
            textBox.PreviewKeyDown += new KeyEventHandler(textBox_PreviewKeyDown);
            textBox.ContextMenu = null;     // see notes in textBox_LostKeyboardFocus

            // Initially textbox is set to the same rectangle as graphicsText.
            // After textbox loading its template is available, and we can
            // correct textbox position - see details in the textBox_Loaded function.
            textBox.Loaded += new RoutedEventHandler(textBox_Loaded);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Delete added object
        /// </summary>
        public override void Undo(DrawingCanvas drawingCanvas)
        {
            // Find object to delete by its ID.
            // Don't use objects order in the list.

            GraphicsBase objectToDelete = null;

            // Remove object from the list
            foreach(GraphicsBase b in drawingCanvas.GraphicsList)
            {
                if ( b.Id == newObjectClone.ID )
                {
                    objectToDelete = b;
                    break;
                }
            }

            if ( objectToDelete != null )
            {
                drawingCanvas.GraphicsList.Remove(objectToDelete);
            }
        }
Ejemplo n.º 16
0
        /// <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;
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Set cursor
 /// </summary>
 public override void SetCursor(DrawingCanvas drawingCanvas)
 {
     drawingCanvas.Cursor = this.toolCursor;
 }
Ejemplo n.º 18
0
 public abstract void OnMouseMove(DrawingCanvas drawingCanvas, MouseEventArgs e);
Ejemplo n.º 19
0
 public abstract void OnMouseUp(DrawingCanvas drawingCanvas, MouseButtonEventArgs e);
 // Call this function AFTER operation.
 public void NewState(DrawingCanvas drawingCanvas)
 {
     // Keep objects state after operation.
     FillList(drawingCanvas.GraphicsList, ref listAfter);
 }
 // Create this command BEFORE operation.
 public CommandChangeOrder(DrawingCanvas drawingCanvas)
 {
     FillList(drawingCanvas.GraphicsList, ref listBefore);
 }
Ejemplo n.º 22
0
 public abstract void SetCursor(DrawingCanvas drawingCanvas);
 /// <summary>
 /// Restore order to its state after change.
 /// </summary>
 public override void Redo(DrawingCanvas drawingCanvas)
 {
     ChangeOrder(drawingCanvas.GraphicsList, listAfter);
 }
 /// <summary>
 /// Detete All again
 /// </summary>
 public override void Redo(DrawingCanvas drawingCanvas)
 {
     drawingCanvas.GraphicsList.Clear();
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Left mouse is released.
        /// New object is created and resized.
        /// </summary>
        public override void OnMouseUp(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            drawingCanvas.Tool = ToolType.Pointer;
            drawingCanvas.Cursor = HelperFunctions.DefaultCursor;
            drawingCanvas.ReleaseMouseCapture();

            if (drawingCanvas.Count > 0)
            {
                drawingCanvas[drawingCanvas.Count - 1].Normalize();

                GraphicsText t = drawingCanvas[drawingCanvas.Count - 1] as GraphicsText;

                if ( t != null )
                {
                    // Create textbox for editing of graphics object which is just created
                    CreateTextBox(t, drawingCanvas);
                }
            }

            // Commnnd will be added to History later, after closing
            // in-place textbox.
        }
Ejemplo n.º 26
0
 public ToolText(DrawingCanvas drawingCanvas)
 {
     this.drawingCanvas = drawingCanvas;
     MemoryStream stream = new MemoryStream(Properties.Resources.Text);
     ToolCursor = new Cursor(stream);
 }
 // Call this function AFTER operation.
 public void NewState(DrawingCanvas drawingCanvas)
 {
     FillList(drawingCanvas.GraphicsList, ref listAfter);
 }
 // Create this command BEFORE operation.
 public CommandChangeState(DrawingCanvas drawingCanvas)
 {
     // Keep objects state before operation.
     FillList(drawingCanvas.GraphicsList, ref listBefore);
 }
 /// <summary>
 /// Restore order to its state before change.
 /// </summary>
 public override void Undo(DrawingCanvas drawingCanvas)
 {
     ChangeOrder(drawingCanvas.GraphicsList, listBefore);
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Create new text object
        /// </summary>
        public override void OnMouseDown(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            Point p = e.GetPosition(drawingCanvas);

            AddNewObject(drawingCanvas,
                new GraphicsText(
                String.Empty,
                p.X,
                p.Y,
                p.X + 1,
                p.Y + 1,
                drawingCanvas.ObjectColor,
                drawingCanvas.TextFontSize,
                drawingCanvas.TextFontFamilyName,
                drawingCanvas.TextFontStyle,
                drawingCanvas.TextFontWeight,
                drawingCanvas.TextFontStretch,
                drawingCanvas.ActualScale));
        }