Beispiel #1
0
    private void inkoverlay_StrokesDeleting(object sender, InkOverlayStrokesDeletingEventArgs e)
    {
        dbg.WriteLine("----- inkoverlay_StrokesDeleting -----");

        // Ensure we're on the UI thread.
        dbg.Assert(!this.InvokeRequired);

        // Track region to repaint.
        Rectangle dirtybbox = Rectangle.Empty;

        try         // To prevent exceptions from propagating back to ink runtime.
        {
            // Get objects for stroke(s) to delete.
            RigidBodyBase[] bodies = doc.GetBodiesFor(e.StrokesToDelete);
            MechanismBase[] mechs  = doc.GetMechanismsFor(e.StrokesToDelete);

            // Delete mechanisms.
            foreach (MechanismBase mech in mechs)
            {
                doc.Mechanisms.Remove(mech);
                dirtybbox = Rectangle.Union(dirtybbox, mech.BoundingBox);
            }

            // Delete bodies and their attached mechanisms.
            foreach (RigidBodyBase body in bodies)
            {
                mechs = doc.GetMechanismsForBody(body);
                foreach (MechanismBase mech in mechs)
                {
                    doc.Mechanisms.Remove(mech);
                    dirtybbox = Rectangle.Union(dirtybbox, mech.BoundingBox);

                    Strokes mstrokes = doc.Ink.CreateStrokes(new int[] { mech.strokeid });
                    doc.Ink.DeleteStrokes(mstrokes);
                }

                doc.Bodies.Remove(body);
                dirtybbox = Rectangle.Union(dirtybbox, body.BoundingBox);
            }

            // Check if this stroke was the gravity vector's?
            if (doc.Gravity != null)
            {
                foreach (Stroke s in e.StrokesToDelete)
                {
                    if (s.Id == doc.Gravity.strokeid)
                    {
                        this.InvalidateInkSpaceRectangle(doc.Gravity.BoundingBox);
                        doc.Gravity = null;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            // Log the error.
            Global.HandleThreadException(this, new System.Threading.ThreadExceptionEventArgs(ex));
        }
        finally
        {
            // Repaint the affected area.
            InvalidateInkSpaceRectangle(dirtybbox);
        }
    }