예제 #1
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }

            var p = new List <int>();

            for (int i = 1; i < Points.Count; i++)
            {
                if (double.IsNaN(Points[i].X) || double.IsNaN(Points[i].Y) || double.IsNaN(Points[i - 1].X) || double.IsNaN(Points[i - 1].Y))
                {
                    continue;
                }
                var points = dirtyModelRect.CohenSutherlandLineClip(Points[i - 1], Points[i]);
                if (points == null)
                {
                    continue;
                }

                var x1 = writeableBitmap.CheckX(GetClientX(points[0].X));
                var y1 = writeableBitmap.CheckY(GetClientY(points[0].Y));
                var x2 = writeableBitmap.CheckX(GetClientX(points[1].X));
                var y2 = writeableBitmap.CheckY(GetClientY(points[1].Y));

                _drawAction(writeableBitmap, x1, y1, x2, y2, IntColor);
            }
        }
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }

            var p = new List <int>();

            for (int i = 1; i < Points.Count; i++)
            {
                if (double.IsNaN(Points[i].X) || double.IsNaN(Points[i].Y) || double.IsNaN(Points[i - 1].X) || double.IsNaN(Points[i - 1].Y))
                {
                    continue;
                }
                //var points = dirtyModelRect.CohenSutherlandLineClip(Points[i - 1], Points[i]);
                //if (points == null) continue;

                p.Add(writeableBitmap.CheckX(GetClientX(Points[i - 1].X)));
                p.Add(writeableBitmap.CheckY(GetClientY(Points[i - 1].Y)));
                p.Add(writeableBitmap.CheckX(GetClientX(Points[i].X)));
                p.Add(writeableBitmap.CheckY(GetClientY(Points[i].Y)));
            }

            var pAr = p.ToArray();

            if (pAr.Length > 7)
            {
                writeableBitmap.FillPolygon(pAr, Color.FromArgb(120, Color.R, Color.G, Color.B));
                writeableBitmap.DrawPolyline(pAr, Color);
            }
        }
예제 #3
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }

            for (int i = 1; i < Points.Count; i++)
            {
                if (double.IsNaN(Points[i].X) || double.IsNaN(Points[i].Y) || double.IsNaN(Points[i - 1].X) || double.IsNaN(Points[i - 1].Y))
                {
                    continue;
                }
                var points = dirtyModelRect.CohenSutherlandLineClip(Points[i - 1], Points[i]);
                if (points == null)
                {
                    continue;
                }

                var x1 = writeableBitmap.CheckX(GetClientX(points[0].X));
                var y1 = writeableBitmap.CheckY(GetClientY(points[0].Y));
                var x2 = writeableBitmap.CheckX(GetClientX(points[1].X));
                var y2 = writeableBitmap.CheckY(GetClientY(points[1].Y));
                writeableBitmap.DrawLineAa(x1, y1, x2, y2, _intColor);
            }

            foreach (var point in Points.Where(dirtyModelRect.Contains))
            {
                DrawMark(writeableBitmap, point);
            }
        }
        /// <summary>
        /// Не оптимизированно для случая интерактивного масштабирования!!
        /// </summary>
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            dirtyModelRect.Intersect(_modelRect);
            var client = Viewport.ModelToClient(dirtyModelRect);
            var x1     = writeableBitmap.CheckX(client.Left);
            var x2     = writeableBitmap.CheckX(client.Right);
            var y1     = writeableBitmap.CheckY(client.Top);
            var y2     = writeableBitmap.CheckY(client.Bottom);
            int wd     = x2 - x1;
            int hg     = y2 - y1;

            if (wd <= 0 || hg <= 0)
            {
                return;
            }

            // нарисовать все полоски
            for (int i = 0; i < _lines.Count; i++)
            {
                var line            = _lines[i];
                var lineX           = (line.Last().Key - line.First().Key);
                var lineModelBounds = Viewport.ModelToClient(new Rect(line.First().Key, i + 1 - 0.3, lineX, 0.6));

                DrawLine(writeableBitmap,
                         (int)lineModelBounds.Top, (int)lineModelBounds.Height,
                         (int)lineModelBounds.Left, (int)lineModelBounds.Right,
                         line);
            }
        }
예제 #5
0
        private void DrawCap(WriteableBitmap writeableBitmap, int x, int y)
        {
            if (y < 0 || y >= writeableBitmap.PixelHeight)
            {
                return;
            }
            var x1 = writeableBitmap.CheckX(x - _capSize);
            var x2 = writeableBitmap.CheckX(x + _capSize + 1);

            writeableBitmap.DrawLineAa(x1, y, x2, y, _intColor);
        }
예제 #6
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var dirtyRect = _dirtyRect.GetValueOrDefault();

            if (!dirtyRect.IsEmpty)
            {
                using (_backBuffer.GetBitmapContext()) {
                    var h = _viewport.HorizontalAxis;
                    var v = _viewport.VerticalAxis;

                    var x1 = _backBuffer.CheckX(h.ModelToClient(dirtyRect.Left));
                    var y1 = _backBuffer.CheckY(v.ModelToClient(dirtyRect.Top));
                    var x2 = _backBuffer.CheckX(h.ModelToClient(dirtyRect.Right));
                    var y2 = _backBuffer.CheckY(v.ModelToClient(dirtyRect.Bottom));

                    if (y1 > y2)
                    {
                        Swap(ref y1, ref y2);
                    }
                    if (x1 > x2)
                    {
                        Swap(ref x1, ref x2);
                    }

                    _backBuffer.FillRectangle(x1, y1, x2, y2, Colors.Transparent);

                    if (PolarAxis)
                    {
                        DrawPolarGrid(_backBuffer);
                    }
                    else
                    {
                        DrawGridDefault(_backBuffer);
                    }

                    foreach (var element in _chartElements)
                    {
                        element.Draw(_backBuffer, dirtyRect);
                    }

                    _backBuffer.DrawRectangle(x1, y1, x2, y2, Colors.Black);
                }



                _dirtyRect = null;
            }

            base.OnRender(drawingContext);
        }
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (Points.Count == 0 || writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }
            var prevX      = _points[0].X; //writeableBitmap.CheckX(GetClientX(_points[0].X));
            var prevY      = 0.0;          // writeableBitmap.CheckY(GetClientY(_points[0].Y));
            var prevModelY = 0.0;

            for (int i = 0; i < Points.Count; i++)
            {
                var x = Points[i].X;              //writeableBitmap.CheckX(GetClientX(Points[i].X));
                var y = Points[i].Y + prevModelY; //writeableBitmap.CheckY(GetClientY(Points[i].Y + prevModelY)) ;
                prevModelY = Points[i].Y + prevModelY;
                //y = writeableBitmap.CheckY(y);
                if (double.IsInfinity(y))
                {
                    y = dirtyModelRect.Bottom;
                }
                var line1 = dirtyModelRect.CohenSutherlandLineClip(new Point(x, y), new Point(x, prevY));
                var line2 = dirtyModelRect.CohenSutherlandLineClip(new Point(x, prevY), new Point(prevX, prevY));
                if (line1 != null)
                {
                    var x1 = writeableBitmap.CheckX(GetClientX(line1[0].X));
                    var y1 = writeableBitmap.CheckY(GetClientY(line1[0].Y));
                    var x2 = writeableBitmap.CheckX(GetClientX(line1[1].X));
                    var y2 = writeableBitmap.CheckY(GetClientY(line1[1].Y));
                    writeableBitmap.DrawLineAa(x1, y1, x2, y2, IntColor);
                }
                if (line2 != null)
                {
                    var x1 = writeableBitmap.CheckX(GetClientX(line2[0].X));
                    var y1 = writeableBitmap.CheckY(GetClientY(line2[0].Y));
                    var x2 = writeableBitmap.CheckX(GetClientX(line2[1].X));
                    var y2 = writeableBitmap.CheckY(GetClientY(line2[1].Y));
                    writeableBitmap.DrawLineAa(x1, y1, x2, y2, IntColor);
                }
                //writeableBitmap.DrawLineAa(x, prevY, x, y, IntColor);
                //writeableBitmap.DrawLineAa(x, prevY, prevX, prevY, IntColor);
                if (_markedPoint == i && _markedArea != StepLineArea.None)
                {
                    DrawMark(writeableBitmap, x, y, prevX, prevY, _markedArea);
                }
                prevX = x;
                prevY = y;
            }
        }
예제 #8
0
        private void DrawMark(WriteableBitmap wb, Point point, int intColor)
        {
            var x = wb.CheckX(GetClientX(point.X));
            var y = wb.CheckY(GetClientY(point.Y));

            _drawAction.Invoke(wb, x, y, intColor);
        }
예제 #9
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            var x = writeableBitmap.CheckX(GetClientX(_mx));
            var y = writeableBitmap.CheckY(GetClientY(_my));

            var size = _textRenderer.MeasureString(_text, _orientation);

            if (_alignment == ContentAlignment.BottomCenter || _alignment == ContentAlignment.BottomLeft || _alignment == ContentAlignment.BottomRight)
            {
                y = y - size.Item2;
            }
            if (_alignment == ContentAlignment.MiddleCenter || _alignment == ContentAlignment.MiddleLeft || _alignment == ContentAlignment.MiddleRight)
            {
                y = y - size.Item2 / 2;
            }

            if (_alignment == ContentAlignment.BottomRight || _alignment == ContentAlignment.MiddleRight || _alignment == ContentAlignment.TopRight)
            {
                x = x - size.Item1;
            }
            if (_alignment == ContentAlignment.BottomCenter || _alignment == ContentAlignment.MiddleCenter || _alignment == ContentAlignment.TopCenter)
            {
                x = x - size.Item1 / 2;
            }

            writeableBitmap.DrawString(_text, x, y, _textRenderer, _orientation);
        }
예제 #10
0
        public void DrawToMiniMap(WriteableBitmap writeableBitmap, Rect modelRect)
        {
            var cw = writeableBitmap.PixelWidth;
            var ch = writeableBitmap.PixelHeight;

            lock (_groups)
            {
                for (int i = 0; i < _groups.Count; i++)
                {
                    var g = _groups[i];

                    //foreach (var g in Groups)
                    //{
                    var x1 = writeableBitmap.CheckX(((g.Start - modelRect.X) / modelRect.Width * cw));
                    var x2 = writeableBitmap.CheckX(((g.End - modelRect.X) / modelRect.Width * cw));
                    if (x1 >= x2)
                    {
                        continue;
                    }

                    for (int j = 0; j < g.Cells.Count; j++)
                    {
                        var cell = g.Cells[j];
                        //foreach (var cell in g.Cells)
                        //{
                        var y1 = writeableBitmap.CheckY((Viewport.VerticalAxis.ViewToHomogenous(cell.Start) -
                                                         Viewport.VerticalAxis.ViewToHomogenous(modelRect.Y)) /
                                                        (Viewport.VerticalAxis.ViewToHomogenous(modelRect.Bottom) -
                                                         Viewport.VerticalAxis.ViewToHomogenous(modelRect.Top)) * ch);
                        var y2 = writeableBitmap.CheckY((Viewport.VerticalAxis.ViewToHomogenous(cell.End) -
                                                         Viewport.VerticalAxis.ViewToHomogenous(modelRect.Y)) /
                                                        (Viewport.VerticalAxis.ViewToHomogenous(modelRect.Bottom) -
                                                         Viewport.VerticalAxis.ViewToHomogenous(modelRect.Top)) * ch);
                        if (y1 >= y2)
                        {
                            continue;
                        }

                        writeableBitmap.FillRectangle(x1, y1, x2, y2, cell.BackColor);
                    }
                }
            }
        }
예제 #11
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            for (int i = 0; i < Points.Count; i++)
            {
                if (Points[i].X1 >= Viewport.HorizontalAxis.ModelEnd ||
                    Points[i].X2 <= Viewport.HorizontalAxis.ModelStart)
                {
                    continue;
                }
                var x1 = writeableBitmap.CheckX(GetClientX(Points[i].X1));
                var x2 = writeableBitmap.CheckX(GetClientX(Points[i].X2));
                var y1 = writeableBitmap.CheckY(GetClientY(Points[i].Y));
                var y2 = Viewport.VerticalAxis.IsReversed ? writeableBitmap.PixelHeight - 1 : 0;

                writeableBitmap.FillRectangle(x1, y1, x2, y2, Points[i].Color);
                if (Points[i].BorderColor != 0)
                {
                    writeableBitmap.DrawRectangle(x1, y1, x2, y2 + 1, Points[i].BorderColor);
                }
            }
        }
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (_bmp == null)
            {
                CreatePrint();
            }

            bool draw = false;

            if (_chartRect != dirtyModelRect)
            {
                _chartRect = dirtyModelRect;
                CreateCurrentPrint(dirtyModelRect);
                draw = true;
            }
            dirtyModelRect.Intersect(_modelRect);
            var client = Viewport.ModelToClient(dirtyModelRect);
            var x1     = writeableBitmap.CheckX(client.Left);
            var x2     = writeableBitmap.CheckX(client.Right);
            var y1     = writeableBitmap.CheckY(client.Top);
            var y2     = writeableBitmap.CheckY(client.Bottom);
            int wd     = x2 - x1;
            int hg     = y2 - y1;

            if (wd <= 0 || hg <= 0)
            {
                return;
            }

            if (_curResizeBmp == null ||
                wd != _curResizeBmp.PixelWidth || hg != _curResizeBmp.PixelHeight)
            {
                draw = true;
            }
            if (draw)
            {
                _curResizeBmp = _curBmp.Resize(wd, hg, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
            }
            writeableBitmap.Blit(new Rect(x1 + 1, y1 + 1, wd, hg), _curResizeBmp, new Rect(0, 0, wd, hg));
        }
예제 #13
0
        private void DrawGridDefault(WriteableBitmap bitmap)
        {
            LeftMarkProvider?.IterateMinorGrid(Viewport.VerticalAxis,
                                               v => bitmap.DrawLine(0, bitmap.CheckY(v), bitmap.PixelWidth, bitmap.CheckY(v), _minorGridColor));

            BottomMarkProvider?.IterateMinorGrid(Viewport.HorizontalAxis,
                                                 v => bitmap.DrawLine(bitmap.CheckX(v), 0, bitmap.CheckX(v), bitmap.PixelHeight, _minorGridColor));

            if (RightMarkProvider != LeftMarkProvider)
            {
                RightMarkProvider?.IterateMinorGrid(Viewport.VerticalAxis,
                                                    v => bitmap.DrawLine(0, bitmap.CheckY(v), bitmap.PixelWidth, bitmap.CheckY(v), _minorGridColor));
            }

            if (TopMarkProvider != BottomMarkProvider)
            {
                TopMarkProvider?.IterateMinorGrid(Viewport.HorizontalAxis,
                                                  v => bitmap.DrawLine(bitmap.CheckX(v), 0, bitmap.CheckX(v), bitmap.PixelHeight, _minorGridColor));
            }



            LeftMarkProvider?.IterateMajorGrid(Viewport.VerticalAxis,
                                               v => bitmap.DrawLine(0, bitmap.CheckY(v), bitmap.PixelWidth, bitmap.CheckY(v), _majorGridColor));

            BottomMarkProvider?.IterateMajorGrid(Viewport.HorizontalAxis,
                                                 v => bitmap.DrawLine(bitmap.CheckX(v), 0, bitmap.CheckX(v), bitmap.PixelHeight, _majorGridColor));

            if (RightMarkProvider != LeftMarkProvider)
            {
                RightMarkProvider?.IterateMajorGrid(Viewport.VerticalAxis,
                                                    v => bitmap.DrawLine(0, bitmap.CheckY(v), bitmap.PixelWidth, bitmap.CheckY(v), _majorGridColor));
            }

            if (TopMarkProvider != BottomMarkProvider)
            {
                TopMarkProvider?.IterateMajorGrid(Viewport.HorizontalAxis,
                                                  v => bitmap.DrawLine(bitmap.CheckX(v), 0, bitmap.CheckX(v), bitmap.PixelHeight, _majorGridColor));
            }
        }
        private void DrawMark(WriteableBitmap writeableBitmap, double cx, double cy, double px, double py, StepLineArea area)
        {
            int x;
            int y;

            switch (area)
            {
            case StepLineArea.None:
                return;

            case StepLineArea.Horizontal:
                x = (writeableBitmap.CheckX(GetClientX(px)) + writeableBitmap.CheckX(GetClientX(cx))) / 2;
                y = writeableBitmap.CheckY(GetClientY(py));
                break;

            case StepLineArea.PointPrev:
                x = writeableBitmap.CheckX(GetClientX(cx));
                y = writeableBitmap.CheckY(GetClientY(py));
                break;

            case StepLineArea.Vertical:
                x = writeableBitmap.CheckX(GetClientX(cx));
                y = (writeableBitmap.CheckY(GetClientY(py)) + writeableBitmap.CheckY(GetClientY(cy))) / 2;
                break;

            case StepLineArea.PointCurrent:
                x = writeableBitmap.CheckX(GetClientX(cx));
                y = writeableBitmap.CheckY(GetClientY(cy));
                break;

            default:
                throw new ArgumentOutOfRangeException("area");
            }
            if (x < 3 || x > writeableBitmap.PixelWidth - 3 || y < 3 || y > writeableBitmap.PixelHeight - 3)
            {
                return;
            }
            writeableBitmap.FillEllipseCentered(x, y, 3, 3, _intColor);
        }
예제 #15
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            if (writeableBitmap.PixelHeight < 2 || writeableBitmap.PixelWidth < 2)
            {
                return;
            }

            for (int i = 0; i < Points.Count; i++)
            {
                if (double.IsNaN(Points[i].X) || double.IsNaN(Points[i].Y))
                {
                    continue;
                }
                if (Points[i].X <dirtyModelRect.Left || Points[i].X> dirtyModelRect.Right)
                {
                    continue;
                }

                var x1 = writeableBitmap.CheckX(GetClientX(Points[i].X));

                var y   = GetClientY(Points[i].Y);
                var y1  = GetClientY(Points[i].YMax);
                var y2  = GetClientY(Points[i].YMin);
                var y11 = writeableBitmap.CheckY(y1);
                var y21 = writeableBitmap.CheckY(y2);
                if (y1 >= 0 && y1 < writeableBitmap.PixelHeight && y1 != y)
                {
                    DrawCap(writeableBitmap, x1, y11);
                }
                if (y2 >= 0 && y2 < writeableBitmap.PixelHeight && y2 != y)
                {
                    DrawCap(writeableBitmap, x1, y21);
                }

                writeableBitmap.DrawLineAa(x1, y11, x1, y21, _intColor);
            }
        }
예제 #16
0
        public override void Draw(WriteableBitmap writeableBitmap, Rect dirtyModelRect)
        {
            foreach (var g in _groups)
            {
                if (g.Start > dirtyModelRect.Right || g.End < dirtyModelRect.Left)
                {
                    continue;
                }
                var x1 = writeableBitmap.CheckX(GetClientX(g.Start));
                var x2 = writeableBitmap.CheckX(GetClientX(g.End));
                foreach (var cell in g.Cells)
                {
                    if (cell.Start > dirtyModelRect.Bottom || cell.End < dirtyModelRect.Top)
                    {
                        continue;
                    }
                    var y1 = writeableBitmap.CheckY(GetClientY(cell.Start));
                    var y2 = writeableBitmap.CheckY(GetClientY(cell.End));
                    if (x1 >= x2)
                    {
                        continue;
                    }
                    if (y1 >= y2)
                    {
                        continue;
                    }

                    writeableBitmap.FillRectangle(x1, y1, x2, y2, cell.BackColor);

                    if (_drawHorizontalSplits)
                    {
                        writeableBitmap.DrawLine(x1, y1, x2, y1, _splitsColor);
                        writeableBitmap.DrawLine(x1, y2, x2, y2, _splitsColor);
                    }

                    var textSize = _textRenderer.MeasureString(cell.Tag.ToString());
                    if (textSize.Item1 < x2 - x1 && textSize.Item2 < y2 - y1)
                    {
                        var tx = (x1 + x2) / 2 - textSize.Item1 / 2;
                        var ty = (y1 + y2 - textSize.Item2) / 2;
                        _textRenderer.Color = cell.BackColor.GetContrastColor();
                        writeableBitmap.DrawString(cell.Tag.ToString(), tx, ty, _textRenderer);
                    }
                }

                if (_drawVerticalSplit && g.Cells.Count != 0)
                {
                    var y1 = writeableBitmap.CheckY(GetClientY(g.Cells[0].Start));
                    var y2 = writeableBitmap.PixelHeight;
                    writeableBitmap.DrawLine(x1, y1, x1, y2, SplitsColor);
                    writeableBitmap.DrawLine(x2, y1, x2, y2, SplitsColor);
                }

                if (_selectedGroupIndex >= 0 && _selectedGroupIndex < _groups.Count &&
                    g == _groups[_selectedGroupIndex])
                {
                    var x  = writeableBitmap.CheckX(GetClientX(g.Position));
                    var y  = 0;
                    var y2 = writeableBitmap.PixelHeight;
                    writeableBitmap.DrawLine(x, y, x, y2, Colors.Red);
                }
            }

            if (_markData.Area != HitTestArea.None)
            {
                DrawMark(writeableBitmap, _markData.GroupIndex, _markData.CellIndex, _markData.Area);
            }
        }
예제 #17
0
        private void DrawMark(WriteableBitmap wb, int gi, int ci, HitTestArea area)
        {
            var g  = _groups[gi];
            var x1 = wb.CheckX(GetClientX(g.Start));
            var x2 = wb.CheckX(GetClientX(g.End));
            var y1 = wb.CheckY(GetClientY(g.Cells[ci].Start));
            var y2 = wb.CheckY(GetClientY(g.Cells[ci].End));

            if (y1 - y2 == 0 || x1 - x2 == 0)
            {
                return;
            }
            if (area.HasFlag(HitTestArea.GroupStart))
            {
                wb.FillEllipse(wb.CheckX(x1 - 2), wb.CheckY((y2 + y1) / 2 - 2), wb.CheckX(x1 + 2), wb.CheckY((y2 + y1) / 2 + 2), g.Cells[ci].BackColor.GetContrastColor());
            }
            else if (area.HasFlag(HitTestArea.GroupEnd))
            {
                wb.FillEllipse(wb.CheckX(x2 - 2), wb.CheckY((y2 + y1) / 2 - 2), wb.CheckX(x2 + 2), wb.CheckY((y2 + y1) / 2 + 2), g.Cells[ci].BackColor.GetContrastColor());
            }
            else if (area.HasFlag(HitTestArea.CellStart))
            {
                wb.FillEllipse(wb.CheckX((x1 + x2) / 2 - 2), wb.CheckY(y1 - 2), wb.CheckX((x1 + x2) / 2 + 2), wb.CheckY(y1 + 2), g.Cells[ci].BackColor.GetContrastColor());
            }
            else if (area.HasFlag(HitTestArea.CellEnd))
            {
                wb.FillEllipse(wb.CheckX((x1 + x2) / 2 - 2), wb.CheckY(y2 - 2), wb.CheckX((x1 + x2) / 2 + 2), wb.CheckY(y2 + 2), g.Cells[ci].BackColor.GetContrastColor());
            }
            else if (area.HasFlag(HitTestArea.CellBody))
            {
                wb.DrawRectangle(wb.CheckX(x1 + 1), wb.CheckY(y1 + 1), wb.CheckX(x2), wb.CheckY(y2), g.Cells[ci].BackColor.GetContrastColor());
            }
        }