Esempio n. 1
0
        public void Tick()
        {
            var eventPoints = new List<Tuple<Tuple<Point3D, Vector3D>[], long>>();

            lock (_lock)
            {
                double currentTime = _clock.CurrentTime;

                int index = 0;
                while (index < _strokes.Count)
                {
                    if (currentTime > _strokes[index].DeathTime)
                    {
                        // Remove old stroke
                        eventPoints.Add(Tuple.Create(_strokes[index].Points, _strokes[index].Token));
                        _strokes.RemoveAt(index);
                    }
                    else
                    {
                        index++;
                    }
                }
            }

            // Raise Events
            if (this.PointsChanged != null && eventPoints.Count > 0)
            {
                foreach (var points in eventPoints)
                {
                    PointsChangedArgs args = new PointsChangedArgs(PointChangeType.RemoveStroke_Timeout, points.Item1, points.Item2);
                    this.PointsChanged(this, args);
                }
            }
        }
Esempio n. 2
0
        public void Clear()
        {
            var eventPoints = new List<Tuple<Tuple<Point3D, Vector3D>[], long?>>();

            lock (_lock)
            {
                // Remove pre points
                if (_addingPoints.Count > 0)
                {
                    eventPoints.Add(Tuple.Create(_addingPoints.Select(o => Tuple.Create(o.Item1, o.Item2 ?? new Vector3D(0, 0, 0))).ToArray(), (long?)null));
                    _addingPoints.Clear();
                }

                // Remove strokes
                while (_strokes.Count > 0)
                {
                    eventPoints.Add(Tuple.Create(_strokes[0].Points, (long?)_strokes[0].Token));
                    _strokes.RemoveAt(0);
                }
            }

            // Raise Event
            if (this.PointsChanged != null && eventPoints.Count > 0)
            {
                foreach (var points in eventPoints)
                {
                    PointsChangedArgs args = new PointsChangedArgs(PointChangeType.RemoveStroke_Clear, points.Item1, points.Item2);
                    this.PointsChanged(this, args);
                }
            }
        }
Esempio n. 3
0
        public void RemoveStroke(long token)
        {
            Tuple<Point3D, Vector3D>[] eventPoints = null;

            lock (_lock)
            {
                // Find it
                for (int cntr = 0; cntr < _strokes.Count; cntr++)
                {
                    if (_strokes[cntr].Token == token)
                    {
                        // Remove it
                        eventPoints = _strokes[cntr].Points;
                        _strokes.RemoveAt(cntr);
                        break;
                    }
                }
            }

            // Raise Event
            if (this.PointsChanged != null && eventPoints != null)
            {
                PointsChangedArgs args = new PointsChangedArgs(PointChangeType.RemoveStroke_Remove, eventPoints, token);
                this.PointsChanged(this, args);
            }
        }
Esempio n. 4
0
        public void AddStroke(IEnumerable<Point3D> points)
        {
            Tuple<Point3D, Vector3D>[] eventPoints;
            long token;

            // Add it
            lock (_lock)
            {
                eventPoints = BuildStroke(points.ToArray(), _smallestSubstrokeSize);
                _strokes.Add(new Stroke(eventPoints, GetStopTime()));

                token = _strokes[_strokes.Count - 1].Token;
            }

            // Raise Event
            if (this.PointsChanged != null)
            {
                PointsChangedArgs args = new PointsChangedArgs(PointChangeType.AddNewStroke, eventPoints, token);
                this.PointsChanged(this, args);
            }
        }
Esempio n. 5
0
        public void StopStroke()
        {
            Tuple<Point3D, Vector3D?>[] fromPoints;
            Tuple<Point3D, Vector3D>[] toPoints;
            long token;

            lock (_lock)
            {
                if (_addingPoints.Count == 0)
                {
                    return;
                }

                // Build refined stroke
                fromPoints = _addingPoints.ToArray();
                toPoints = BuildStroke(fromPoints, _smallestSubstrokeSize);

                _addingPoints.Clear();
                _strokes.Add(new Stroke(toPoints, GetStopTime()));
                token = _strokes[_strokes.Count - 1].Token;
            }

            // Raise events
            if (this.PointsChanged != null)
            {
                PointsChangedArgs args = new PointsChangedArgs(PointChangeType.ConvertStroke_Remove, fromPoints.Select(o => Tuple.Create(o.Item1, o.Item2 ?? new Vector3D(0, 0, 0))).ToArray());
                this.PointsChanged(this, args);

                args = new PointsChangedArgs(PointChangeType.ConvertStroke_Add, toPoints, token);
                this.PointsChanged(this, args);
            }
        }
Esempio n. 6
0
        public void AddPointToStroke(Point3D point, Vector3D? velocity = null)
        {
            // Add point
            lock (_lock)
            {
                _addingPoints.Add(Tuple.Create(point, velocity));
            }

            // Raise event
            if (this.PointsChanged != null)
            {
                PointsChangedArgs args = new PointsChangedArgs(PointChangeType.AddingPointsToStroke, new[] { Tuple.Create(point, velocity ?? new Vector3D(0, 0, 0)) });
                this.PointsChanged(this, args);
            }
        }