示例#1
0
        /// <summary>
        /// Combines two drawing objects into single canvas object.
        /// If both drawing objects are canvas, first canvas will get all second canvas drawing objects and second canvas will be cleared.
        /// If only one of the objects is canvas, second object will be added to the canvas.
        /// If none of the objects is canvas, new canvas will be created with both drawings.
        /// </summary>
        /// <param name="graphics"><see cref="IGraphics"/> object.</param>
        /// <param name="drawing1">First drawing object.</param>
        /// <param name="drawing2">Second drawing object.</param>
        /// <returns>Canvas object containing both drawing objects.</returns>
        public static ICanvas Combine(this IGraphics graphics, IDrawing drawing1, IDrawing drawing2)
        {
            ICanvas canvas1 = drawing1 as ICanvas;
            ICanvas canvas2 = drawing2 as ICanvas;

            if (canvas1 != null && canvas2 != null)
            {
                IDrawing[] drawings = canvas2.Drawings.ToArray();

                canvas2.Clear();
                foreach (IDrawing drawing in drawings)
                {
                    canvas1.AddDrawing(drawing);
                }
                return(canvas1);
            }
            else if (canvas1 != null)
            {
                canvas1.AddDrawing(drawing2);
                return(canvas1);
            }
            else if (canvas2 != null)
            {
                canvas2.AddDrawing(drawing1);
                return(canvas2);
            }
            else
            {
                return(graphics.CreateCanvas(drawing1, drawing2));
            }
        }
示例#2
0
 /// <summary>
 /// Adds drawing objects to the list of drawing objects.
 /// </summary>
 /// <param name="canvas"><see cref="ICanvas"/> object.</param>
 /// <param name="drawings">Drawing objects.</param>
 public static void Add(this ICanvas canvas, params IDrawing[] drawings)
 {
     foreach (IDrawing drawing in drawings)
     {
         canvas.AddDrawing(drawing);
     }
 }