Пример #1
0
        private void OnDragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (Direction == Direction.Move && SizeColorBar.Current.Selected != Tool.Null)
            {
                switch (SizeColorBar.Current.Selected)
                {
                case Tool.Rectangle:
                    if (_Rectangle != null)
                    {
                        ResetLimit(Canvas.GetLeft(_Rectangle), Canvas.GetTop(_Rectangle), Canvas.GetLeft(_Rectangle) + _Rectangle.Width, Canvas.GetTop(_Rectangle) + _Rectangle.Height);
                        MainWindow.Register(_Rectangle);
                        _Rectangle = null;
                    }
                    break;

                case Tool.Ellipse:
                    if (_Ellipse != null)
                    {
                        ResetLimit(Canvas.GetLeft(_Ellipse), Canvas.GetTop(_Ellipse), Canvas.GetLeft(_Ellipse) + _Ellipse.Width, Canvas.GetTop(_Ellipse) + _Ellipse.Height);
                        MainWindow.Register(_Ellipse);
                        _Ellipse = null;
                    }
                    break;

                case Tool.Arrow:
                    if (_Arrow != null)
                    {
                        geometry.Clear();
                        ResetLimit(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y));
                        points = null;
                        MainWindow.Register(_Arrow);
                        _Arrow = null;
                    }
                    break;

                case Tool.Line:
                    if (_Line != null)
                    {
                        geometry.Clear();
                        ResetLimit(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y));
                        points = null;
                        MainWindow.Register(_Line);
                        _Line = null;
                    }
                    break;

                case Tool.Text:
                    break;

                default:
                    break;
                }
            }
            Direction = Direction.Null;
        }
Пример #2
0
        private void DrawDecorativeBorder(double W, double H, DrawingContext drawingContext)
        {
            _tempCornerRadius = CornerRadius.Coerce(W, H);

            if (_streamGeometryCache == null)
            {
                _streamGeometryCache = new StreamGeometry();
            }
            else
            {
                _streamGeometryCache.Clear();
            }

            using (var ctx = _streamGeometryCache.Open())
            {
                ctx.BeginFigure(new Point(0, _tempCornerRadius.TopLeft), true, true);

                DrawLeftBorderWithArc(ctx, H);
                DrawBottomBorderWithArc(ctx, W, H);
                DrawRightBorderWithArc(ctx, W, H);
                DrawTopBorderWithArc(ctx, W);
            }

            drawingContext.DrawGeometry(Background, new Pen(BorderBrush, BorderThickness), _streamGeometryCache);

            SetValue(ActualRenderWidthPropertyKey, _streamGeometryCache.Bounds.Width);
            SetValue(ActualRenderHeightPropertyKey, _streamGeometryCache.Bounds.Height);
        }
        /// <summary>
        /// 重绘整个曲线
        /// </summary>
        void RedrawWholeCurve()
        {
            gStream_Line.Clear();

            /* 如果显示曲线的Panel尺寸为 0, 则不绘制曲线 */
            if (szPanelView.Height == 0 || szPanelView.Width == 0)
            {
                return;
            }

            /* 如果两点间的间距为 0, 则不绘制曲线 */
            if (dblPointsInterval == 0)
            {
                return;
            }

            /* 获取数据序列中的最大 Y 值 *
             * 该值用来计算即将绘制的点在View上的 纵坐标 */
            dblMaxPointValue = _points.MaxByY.Value;

            using (StreamGeometryContext ctx = gStream_Line.Open())
            {
                using (StreamGeometryContext ctx_area = gStream_Area.Open())
                {
                    ctx_area.BeginFigure(new Point(0, szPanelView.Height), true, true);

                    for (int i = 0; i < _points.Count; i++)
                    {
                        if (i == 0) // 如果是第一个点,则调用BegingFigure方法
                        {
                            ptNext.X = 0;
                            ptNext.Y = CalPointY(_points[i].Value, dblMaxPointValue, szPanelView.Height);
                            ctx.BeginFigure(ptNext, true, false);
                        }
                        else // 从第二个点开始,调用LintTo方法
                        {
                            ptNext.X += dblPointsInterval;
                            ptNext.Y  = CalPointY(_points[i].Value, dblMaxPointValue, szPanelView.Height);
                            ctx.LineTo(ptNext, true, true);
                        }

                        ctx_area.LineTo(ptNext, true, true);
                    }

                    ctx_area.LineTo(new Point(ptNext.X, szPanelView.Height), true, true);
                }
            }

            /*  通知父类曲线已经重绘 */
            RaiseCurveUpdatedEvent();
        }
 /// <summary>
 /// Does a one off calculation of the geometry to be rendered
 /// </summary>
 protected void CalculateGeometry()
 {
     if (recalcGeometry)
     {
         bool firstPass = true;
         geometry.Clear();
         using (StreamGeometryContext ctx = geometry.Open())
         {
             foreach (Point point in points)
             {
                 if (!firstPass)
                 {
                     ctx.LineTo(point, !filled, true);
                 }
                 else
                 {
                     ctx.BeginFigure(point, filled, filled);
                 }
                 firstPass = false;
             }
             recalcGeometry = false;
         }
     }
 }