Ejemplo n.º 1
0
 /// <summary>
 /// Peels the top shape at a given point,
 /// updates the render targets and puts the peeled shape to the stack of peelings.
 /// Used to enable removing a child shape - eg. a top shape in a layer
 /// </summary>
 /// <param name="point"></param>
 /// <param name="shapes"></param>
 /// <returns></returns>
 private DrawingShape PeelAtRecursive(Point2F point, IList <DrawingShape> shapes)
 {
     for (int i = shapes.Count - 1; i >= 0; i--)
     {
         if (shapes[i].HitTest(point))
         {
             if (shapes[i].ChildShapes == null)
             {
                 string statName = shapes[i].GetType().Name.Replace("Shape", " count");
                 UpdateStats(statName, -1);
                 peelings.Push(shapes[i]);
                 shapes.RemoveAt(i);
                 RefreshAll();
                 return(peelings.Peek());
             }
             DrawingShape shapePeeled = PeelAtRecursive(point, shapes[i].ChildShapes);
             if (shapePeeled == null)
             {
                 string statName = shapes[i].GetType().Name.Replace("Shape", " count");
                 UpdateStats(statName, -1);
                 peelings.Push(shapes[i]);
                 shapes.RemoveAt(i);
                 RefreshAll();
                 return(peelings.Peek());
             }
             return(shapePeeled);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders the scene to the given render target.
        /// Clears the scene, then draws all shapes
        /// </summary>
        /// <param name="renderTarget">The render target.</param>
        private void RenderScene(RenderTarget renderTarget)
        {
            Cursor c = null;

            if (renderMode != RenderModes.HwndRenderTarget)
            {
                c      = Cursor;
                Cursor = Cursors.WaitCursor;
            }
            renderTarget.BeginDraw();
            renderTarget.Clear(BackColorF);

            for (int i = 0; i < drawingShapes.Count; i++)
            {
                DrawingShape shape = drawingShapes[i];
                //tag with shape index for debugging
                renderTarget.Tags = new Tags((ulong)i, 0);
                shape.Draw(renderTarget);
            }
            Tags      tags;
            ErrorCode errorCode;

            if (!renderTarget.TryEndDraw(out tags, out errorCode))
            {
                Debug.WriteLine(String.Format("Failed EndDraw. Error: {0}, tag1: {1}, tag2: {2}, shape[{1}]: {3}",
                                              errorCode, tags.Tag1, tags.Tag2,
                                              (int)tags.Tag1 < drawingShapes.Count ? drawingShapes[(int)tags.Tag1].ToString() : "<none>"));
            }
            if (renderMode != RenderModes.HwndRenderTarget)
            {
                Cursor = c;
            }
        }
 private void d2dShapesControl_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         DrawingShape shape = d2dShapesControl.PeelAt(new Point2F(e.Location.X, e.Location.Y));
         if (shape != null)
         {
             RemoveFromTree(shape, treeViewAllShapes.Nodes);
         }
     }
     treeViewShapesAtPoint.Nodes.Clear();
     treeViewShapesAtPoint.Nodes.Add(d2dShapesControl.GetTreeAt(new Point2F(e.Location.X, e.Location.Y)));
     treeViewShapesAtPoint.ExpandAll();
     if (treeViewShapesAtPoint.Nodes.Count > 0)
     {
         TreeNode nodeToSelect = treeViewShapesAtPoint.Nodes[0];
         while (nodeToSelect.Nodes.Count > 0)
         {
             nodeToSelect = nodeToSelect.Nodes[0];
         }
         treeViewShapesAtPoint.SelectedNode = nodeToSelect;
         if (e.Button == MouseButtons.Left)
         {
             tabControl1.SelectedTab = tabPageShapes;
             tabControl2.SelectedTab = tabPageShapesAtPoint;
             treeViewShapesAtPoint.Focus();
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds a shape to compatible render target - avoids the need to redraw all shapes.
 /// </summary>
 /// <param name="shape">The shape.</param>
 private void AddToCompatibleRenderTarget(DrawingShape shape)
 {
     lock (renderSyncObject)
     {
         bitmapRenderTarget.BeginDraw();
         shape.Draw(bitmapRenderTarget);
         bitmapRenderTarget.EndDraw();
     }
 }
        private void buttonUnpeel_Click(object sender, System.EventArgs e)
        {
            DrawingShape shape = d2dShapesControl.UnpeelShape();

            if (shape != null)
            {
                AddToTree(shape);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Peels the specific shape.
 /// </summary>
 /// <param name="shape">The shape.</param>
 internal void PeelShape(DrawingShape shape)
 {
     Debug.Assert(shape != null);
     lock (renderSyncObject)
     {
         string statName = shape.GetType().Name.Replace("Shape", " count");
         UpdateStats(statName, -1);
         peelings.Push(shape);
         PeelShape(shape, drawingShapes);
         RefreshAll();
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds the shape to the list and updates the render targets.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns></returns>
 private DrawingShape AddShape(DrawingShape shape)
 {
     lock (renderSyncObject)
     {
         drawingShapes.Add(shape);
         string statName = shape.GetType().Name.Replace("Shape", " count");
         UpdateStats(statName, 1);
         if (UsingCompatibleRenderTarget)
         {
             AddToCompatibleRenderTarget(shape);
         }
         InvalidateClientRectangle();
         return(shape);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Peels the shape recursively.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="shapes">The shapes.</param>
 /// <returns></returns>
 private static bool PeelShape(DrawingShape shape, ICollection <DrawingShape> shapes)
 {
     foreach (var s in shapes)
     {
         if (s == shape)
         {
             shapes.Remove(shape);
             return(true);
         }
         if (s.ChildShapes != null && PeelShape(shape, s.ChildShapes))
         {
             return(true);
         }
     }
     return(false);
 }
 /// <summary>
 /// Remove shape from the tree node collection
 /// </summary>
 /// <param name="shape"></param>
 /// <param name="treeNodes"></param>
 /// <returns>true if removed</returns>
 private static bool RemoveFromTree(DrawingShape shape, TreeNodeCollection treeNodes)
 {
     foreach (TreeNode node in treeNodes)
     {
         if (node.Tag == shape)
         {
             treeNodes.Remove(node);
             return(true);
         }
         if (node.Nodes.Count > 0 && RemoveFromTree(shape, node.Nodes))
         {
             return(true);
         }
     }
     return(false);
 }
        private static void AddToTreeRecursive(DrawingShape shape, TreeNodeCollection treeNodeCollection)
        {
            var node = new TreeNode(shape.ToString())
            {
                Tag = shape
            };

            node.Expand();
            treeNodeCollection.Add(node);
            if (shape.ChildShapes != null && shape.ChildShapes.Count > 0)
            {
                foreach (DrawingShape s in shape.ChildShapes)
                {
                    AddToTreeRecursive(s, node.Nodes);
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Puts a shape from the stack of peelings back to the list of shapes and invalidates the render targets.
 /// </summary>
 /// <returns></returns>
 internal DrawingShape UnpeelShape()
 {
     lock (renderSyncObject)
     {
         if (peelings.Count == 0)
         {
             return(null);
         }
         DrawingShape shape    = peelings.Peek();
         string       statName = shape.GetType().Name.Replace("Shape", " count");
         UpdateStats(statName, 1);
         drawingShapes.Add(peelings.Pop());
         if (UsingCompatibleRenderTarget)
         {
             AddToCompatibleRenderTarget(shape);
         }
         InvalidateClientRectangle();
         return(shape);
     }
 }
 /// <summary>
 /// Remove shape from the tree node collection
 /// </summary>
 /// <param name="shape"></param>
 /// <param name="treeNodes"></param>
 /// <returns>true if removed</returns>
 private static bool RemoveFromTree(DrawingShape shape, TreeNodeCollection treeNodes)
 {
     foreach (TreeNode node in treeNodes)
     {
         if (node.Tag == shape)
         {
             treeNodes.Remove(node);
             return true;
         }
         if (node.Nodes.Count > 0 && RemoveFromTree(shape, node.Nodes))
             return true;
     }
     return false;
 } 
 private static void AddToTreeRecursive(DrawingShape shape, TreeNodeCollection treeNodeCollection)
 {
     var node = new TreeNode(shape.ToString()) { Tag = shape};
     node.Expand();
     treeNodeCollection.Add(node);
     if (shape.ChildShapes != null && shape.ChildShapes.Count > 0)
         foreach (DrawingShape s in shape.ChildShapes)
         {
             AddToTreeRecursive(s, node.Nodes);
         }
 } 
 private void AddToTree(DrawingShape shape)
 {
     AddToTreeRecursive(shape, treeViewAllShapes.Nodes);
 } 
Ejemplo n.º 15
0
 /// <summary>
 /// Adds the shape to the list and updates the render targets.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns></returns>
 private DrawingShape AddShape(DrawingShape shape)
 {
     lock (renderSyncObject)
     {
         drawingShapes.Add(shape);
         string statName = shape.GetType().Name.Replace("Shape", " count");
         UpdateStats(statName, 1);
         if (UsingCompatibleRenderTarget)
             AddToCompatibleRenderTarget(shape);
         InvalidateClientRectangle();
         return shape;
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Peels the shape recursively.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="shapes">The shapes.</param>
 /// <returns></returns>
 private static bool PeelShape(DrawingShape shape, ICollection<DrawingShape> shapes)
 {
     foreach (var s in shapes)
     {
         if (s == shape)
         {
             shapes.Remove(shape);
             return true;
         }
         if (s.ChildShapes != null && PeelShape(shape, s.ChildShapes))
             return true;
     }
     return false;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Peels the specific shape.
 /// </summary>
 /// <param name="shape">The shape.</param>
 internal void PeelShape(DrawingShape shape)
 {
     Debug.Assert(shape != null);
     lock (renderSyncObject)
     {
         string statName = shape.GetType().Name.Replace("Shape", " count");
         UpdateStats(statName, -1);
         peelings.Push(shape);
         PeelShape(shape, drawingShapes);
         RefreshAll();
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Adds a shape to compatible render target - avoids the need to redraw all shapes.
 /// </summary>
 /// <param name="shape">The shape.</param>
 private void AddToCompatibleRenderTarget(DrawingShape shape)
 {
     lock (renderSyncObject)
     {
         bitmapRenderTarget.BeginDraw();
         shape.Draw(bitmapRenderTarget);
         bitmapRenderTarget.EndDraw();
     }
 }
 private void AddToTree(DrawingShape shape)
 {
     AddToTreeRecursive(shape, treeViewAllShapes.Nodes);
 }