예제 #1
0
        /// <summary>
        /// Receive stroke for Presenter 1.
        /// </summary>
        /// <param name="bc"></param>
        private void ReceiveStroke(BufferChunk bc)
        {
            BinaryFormatter formatter    = new BinaryFormatter();
            MemoryStream    memoryStream = new MemoryStream(bc.Buffer, 1, bc.Length - 1);
            int             slideIndex   = (int)formatter.Deserialize(memoryStream);

            if (this.SlideDeck != null && slideIndex >= 0)
            {
                InkScribble s = (InkScribble)this.SlideDeck.GetOverlay(slideIndex).Scribble;

                // Restore the bytes to ink.
                byte[] bytes = new byte[memoryStream.Length - memoryStream.Position];
                memoryStream.Read(bytes, 0, bytes.Length);

                Ink.Ink ink = new Ink.Ink();
                ink.Load(bytes);

                // Delete the previous version of this stroke if necessary.
                foreach (Ink.Stroke stroke in ink.Strokes)
                {
                    if (stroke.ExtendedProperties.DoesPropertyExist(GUID_TAG))
                    {
                        Ink.Stroke foundStroke;
                        bool       found = FastFindStrokeFromGuid(s,
                                                                  new Guid((string)stroke.ExtendedProperties[GUID_TAG].Data),
                                                                  out foundStroke, GUID_TAG);
                        if (found)
                        {
                            s.Ink.DeleteStroke(foundStroke);
                        }
                    }
                }

                lock (this) {
                    Rectangle r = ink.Strokes.GetBoundingBox();
                    r.X      = (int)(r.X * XinkScaleFactor);
                    r.Y      = (int)(r.Y * YinkScaleFactor);
                    r.Width  = (int)(r.Width * XinkScaleFactor);
                    r.Height = (int)(r.Height * YinkScaleFactor);
                    s.Ink.AddStrokesAtRectangle(ink.Strokes, r);

                    // Make note of the ink's strokes in the guidtable.
                    // ASSUME that these strokes went on the end.
                    int sCount   = s.Ink.Strokes.Count;
                    int newCount = ink.Strokes.Count;
                    for (int i = sCount - newCount; i < sCount; i++)
                    {
                        Ink.Stroke stroke = s.Ink.Strokes[i];
                        if (stroke.ExtendedProperties.Contains(GUID_TAG))
                        {
                            Guid guid = new Guid((string)stroke.ExtendedProperties[GUID_TAG].Data);
                            this.myGuidTable[new ScribbleIntPair(s, stroke.Id)] = guid;
                            this.myGuidReverseTable[guid] = new ScribbleIntPair(s, stroke.Id);
                        }
                    }
                }
            }
        }
예제 #2
0
        public override void DeserializePoints(Stream stream)
        {
            // Check if there was a partial stroke; if so, delete the current last stroke.
            IFormatter formatter = new BinaryFormatter();
            bool       partial   = (bool)formatter.Deserialize(stream);

            if (partial)
            {
                if (this.myInk.Strokes.Count == 0)
                {
                    System.Diagnostics.Debug.WriteLine("no partial stroke to delete", "WARNING");
                }
                else
                {
                    this.myInk.DeleteStroke(this.myInk.Strokes[this.myInk.Strokes.Count - 1]);
                }
            }

            // Deserialize all remaining strokes.
            int length = (int)formatter.Deserialize(stream);

            if (length > 0)
            {
                byte[] inkBytes = new byte[length];
                stream.Read(inkBytes, 0, length);
                Ink.Ink ink = new Ink.Ink();
                ink.Load(inkBytes);
                // Note: AddStrokesAtRectangle is used since the documentation for AddStrokes
                // states that the strokes must *already* be in the ink object (so, it's only
                // used for updating custom strokes collections??).
                if (ink.Strokes.Count > 0)
                {
                    this.myInk.AddStrokesAtRectangle(ink.Strokes, ink.Strokes.GetBoundingBox());
                }
            }

            foreach (Ink.Stroke stroke in this.myInk.Strokes)
            {
                this.OnStroke(new NumericEventArgs(stroke.Id));
            }
        }