Ejemplo n.º 1
0
        public void AddRangeCaption(LineConstraintRange range, string caption)
        {
            if (_rangeTxtMapping.ContainsKey(range))
                return;

            var txt = new TextBlock();
            txt.FontSize = 16;
            txt.Text = caption;
            txt.Measure(new Size(1000, 1000));

            Canvas.SetLeft(txt,
                range.Min*Canvas.ActualWidth + ((range.Max - range.Min)*Canvas.ActualWidth - txt.ActualWidth)/2);
            Canvas.SetTop(txt, 13);
            _rangeTxtMapping.Add(range, txt);

            DrawRanges();
        }
Ejemplo n.º 2
0
        public void Consume(Stroq stroq)
        {
            if (stroq.BoundingRect.Width < 5)
                return;

            stroq.Translate(new Point(-60, 0));
            IList<IGesture> recognizedGestures = _gesturizer.Recognize(stroq);

            foreach (IGesture recognizedGesture in recognizedGestures)
            {
                if (recognizedGesture is ScribbleGesture)
                {
                    foreach (Stroq hitStroq in _scribbleGesture.HitStroqs)
                    {
                        LineConstraintRange r;
                        _stroqRangeMapping.TryGetValue(hitStroq, out r);
                        if (r != null)
                        {
                            Ranges.Remove(r);

                            if (_rangeTxtMapping.ContainsKey(r))
                            {
                                Canvas.Children.Remove(_rangeTxtMapping[r]);
                                _rangeTxtMapping.Remove(r);
                            }
                            _stroqRangeMapping.Remove(hitStroq);
                        }
                        _scribbleGesture.StroqsToCheck.Remove(hitStroq);
                        DrawRanges();
                        OnLineConstraintChange(this);
                    }
                    return;
                }
            }

            Rect bb = stroq.BoundingRect;
            double rangeMin = MathUtil.Clamp(0, 1, bb.X/(Canvas.ActualWidth));
            double rangeMax = MathUtil.Clamp(0, 1, (bb.X + bb.Width)/(Canvas.ActualWidth));

            foreach (LineConstraintRange r in Ranges.ToList())
            {
                if ((r.Min <= rangeMax && r.Max >= rangeMax) ||
                    (r.Max >= rangeMin && r.Min <= rangeMin) ||
                    (r.Min >= rangeMin && r.Max <= rangeMax))
                {
                    Ranges.Remove(r);
                    if (_rangeTxtMapping.ContainsKey(r))
                    {
                        Canvas.Children.Remove(_rangeTxtMapping[r]);
                        _rangeTxtMapping.Remove(r);
                    }
                    _stroqRangeMapping.Remove(r._stroq);
                    _scribbleGesture.StroqsToCheck.Remove(r._stroq);
                }
            }

            var range = new LineConstraintRange(rangeMin, rangeMax);
            Ranges.Add(range);

            double w = (range.Max - range.Min)*Canvas.ActualWidth;
            var s = new Stroq();
            s.Points.Add(new Point(range.Min*Canvas.ActualWidth, Canvas.ActualHeight/2));
            s.Points.Add(new Point(range.Min*Canvas.ActualWidth + w, Canvas.ActualHeight/2));
            range._stroq = s;

            _scribbleGesture.StroqsToCheck.Add(s);
            _stroqRangeMapping.Add(s, range);

            DrawRanges();
            OnLineConstraintChange(this);
        }