Exemplo n.º 1
0
        public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
        {
            bool isStyleLibraryDirty           = _context.StyleLibrary.IsStyleLibraryDirty();
            bool isCurrentContainerDirty       = _view.CurrentContainer.IsCanvasContainerDirty();
            bool isWorkingContainerDirty       = _view.WorkingContainer.IsCanvasContainerDirty();
            bool isPointsCurrentContainerDirty = _view.CurrentContainer.IsPointsDirty();
            bool isPointsWorkingContainerDirty = _view.WorkingContainer.IsPointsDirty();
            bool isShapesCurrentDirty          = isCurrentContainerDirty == true || isPointsCurrentContainerDirty == true || _previousZX != zx || _previousZY != zy;
            bool isShapesWorkingDirty          = isWorkingContainerDirty == true || isPointsWorkingContainerDirty == true || _previousZX != zx || _previousZY != zy;

            if (_pictureShapesCurrent == null || isShapesCurrentDirty == true || isStyleLibraryDirty == true)
            {
                if (_pictureShapesCurrent != null)
                {
                    _pictureShapesCurrent.Dispose();
                }

                _pictureShapesCurrent = RecordPicture(_view, _skiaRenderer, zx, DrawShapesCurrent);
            }

            if (_pictureShapesWorking == null || isShapesWorkingDirty == true || isStyleLibraryDirty == true)
            {
                if (_pictureShapesWorking != null)
                {
                    _pictureShapesWorking.Dispose();
                }

                _pictureShapesWorking = RecordPicture(_view, _skiaRenderer, zx, DrawShapesWorking);
            }

            bool isSelectionDirty = _view.SelectionState.IsDirty == true || isShapesCurrentDirty == true || isShapesWorkingDirty == true;

#if USE_DEBUG_DIRTY
            Log.WriteLine(
                $"{nameof(isStyleLibraryDirty)}: {isStyleLibraryDirty}, " +
                $"{nameof(isShapesCurrentDirty)}: {isShapesCurrentDirty}, " +
                $"{nameof(isShapesWorkingDirty)}: {isShapesWorkingDirty}, " +
                $"{nameof(isCurrentContainerDirty)}: {isCurrentContainerDirty}, " +
                $"{nameof(isWorkingContainerDirty)}: {isWorkingContainerDirty}, " +
                $"{nameof(isSelectionDirty)}: {isSelectionDirty}");
#endif
            if (_view.SelectionState.IsDirty == true)
            {
                _view.SelectionState.Invalidate();
            }

            if (_pictureDecorators == null || isSelectionDirty == true || isStyleLibraryDirty == true)
            {
                if (_pictureDecorators != null)
                {
                    _pictureDecorators.Dispose();
                }

                _pictureDecorators = RecordPicture(_view, _skiaRenderer, zx, DrawDecorators);
            }

            if (_picturePoints == null || isSelectionDirty == true || isStyleLibraryDirty == true)
            {
                if (_picturePoints != null)
                {
                    _picturePoints.Dispose();
                }

                _picturePoints = RecordPicture(_view, _skiaRenderer, zx, DrawPoints);
            }

            _previousZX = zx;
            _previousZY = zy;

            var canvas = context as SKCanvas;

            if (_view.InputBackground != null)
            {
                canvas.Clear(SkiaHelper.ToSKColor(_view.InputBackground));
            }
            else
            {
                canvas.Clear();
            }

            if (_view.WorkBackground != null)
            {
                GetSKPaintFill(_view.WorkBackground, false, out var brush);
                canvas.Save();
                canvas.Translate((float)dx, (float)dy);
                canvas.Scale((float)zx, (float)zy);
                canvas.DrawRect(SkiaHelper.ToSKRect(0.0, 0.0, _view.Width, _view.Height), brush);
                canvas.Restore();
            }

            // TODO: Fix grid X and Y position.
            //DrawGrid(canvas, dx, dy, zx, zy);

            DrawPicture(canvas, _pictureShapesCurrent, dx, dy, zx, zy);
            DrawPicture(canvas, _pictureShapesWorking, dx, dy, zx, zy);
            DrawPicture(canvas, _pictureDecorators, dx, dy, zx, zy);
            DrawPicture(canvas, _picturePoints, dx, dy, zx, zy);

            if (_enablePictureCache == false)
            {
                _picturePoints.Dispose();
                _picturePoints = null;

                _pictureDecorators.Dispose();
                _pictureDecorators = null;

                _pictureShapesWorking.Dispose();
                _pictureShapesWorking = null;

                _pictureShapesCurrent.Dispose();
                _pictureShapesCurrent = null;
            }

            if (isCurrentContainerDirty == true)
            {
                _view.CurrentContainer?.Invalidate();
            }

            if (isWorkingContainerDirty == true)
            {
                _view.WorkingContainer?.Invalidate();
            }

            if (isStyleLibraryDirty == true)
            {
                _context.StyleLibrary?.Invalidate();
            }
        }