コード例 #1
0
        private static void DrawFullSegment(DisplaySetting ds, SKCanvas canvas, SKPoint position)
        {
            var segment = Res.GetRasterized(ds.Display, RasterizeLayer.Background, ds.SegmentType, ds.StyleDefinition.SegmentWeight, AlphaNumericResources.FullSegment);

            if (segment != null)
            {
                canvas.DrawSurface(segment, position);
            }
        }
コード例 #2
0
 public static void DrawSegment(DisplaySetting displaySetting, RasterizeLayer layer, ushort seg, SKCanvas canvas, SKPoint canvasPosition, double percentage)
 {
     using (var surfacePaint = new SKPaint()) {
         if (percentage < 1)
         {
             surfacePaint.Color = new SKColor(0, 0, 0, (byte)Math.Round(percentage * 255));
         }
         for (var j = 0; j < Res.SegmentSize[displaySetting.SegmentType]; j++)
         {
             var rasterizedSegment = Res.GetRasterized(displaySetting.Display, layer, displaySetting.SegmentType, displaySetting.StyleDefinition.SegmentWeight, j);
             if (((seg >> j) & 0x1) != 0 && rasterizedSegment != null)
             {
                 canvas.DrawSurface(rasterizedSegment, canvasPosition, surfacePaint);
             }
         }
     }
 }
コード例 #3
0
        private void OnPaintSurface(SKCanvas canvas, int width, int height)
        {
            var canvasSize = new SKSize(width, height);

            // check if we need to recreate the off-screen surface
            if (_screenCanvasSize != canvasSize)
            {
                _surface?.Dispose();
                _grContext?.Dispose();

                _grContext = GRContext.Create(GRBackend.OpenGL);
                _surface   = SKSurface.Create(_grContext, true, new SKImageInfo(width, height));

                _screenCanvasSize = canvasSize;
            }

            // draw onto off-screen gl context
            DrawOffscreen(_surface.Canvas, width, height);

            // draw offscreen surface onto screen
            canvas.DrawSurface(_surface, new SKPoint(0f, 0f));
        }
コード例 #4
0
ファイル: TaskSlider.xaml.cs プロジェクト: amrahm/Impromptu
        private void CanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKSurface surface = e.Surface;
            SKCanvas  canvas  = surface.Canvas;

            canvas.Clear();
            canvas.Translate(12, 12);
            _width  = e.Info.Width - 24;
            _height = e.Info.Height - 24;
            _dip    = e.Info.Height / (float)CanvasView.Height / 2.5f;

            _circleRadius = _height / 2f;
            float circlePosY = _height / 2f;

            if (_shouldRedrawCircle)
            {
                _shouldRedrawCircle = false;
                _circlePath         = new SKPathDraggable {
                    IsDraggableY = false
                };
                float circleOffset = _circleRadius + 5 * _dip;
                _circlePath.AddCircle(circleOffset, circleOffset, _circleRadius);

                _lightStroke.StrokeWidth    = 2 * _dip;
                _shadowBlurPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 5 * _dip);
                _shadowBlurOuter.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Outer, 10 * _dip);
                _circleSurface = SKSurface.Create(_height + 10, _height + 10, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
                SKCanvas cirCanv = _circleSurface.Canvas;
                cirCanv.Clear();
                cirCanv.DrawCircle(circleOffset - _circleRadius * 0.16f, circleOffset, _circleRadius - _circleRadius * 0.16f,
                                   _shadowBlurPaint);
                cirCanv.DrawPath(_circlePath, _lightColorPaint);

                _colorPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 3 * _dip);
                cirCanv.DrawOval(circleOffset - _circleRadius * 0.24f, circleOffset, _circleRadius - _circleRadius * 0.26f,
                                 _circleRadius - _circleRadius * 0.14f, _colorPaint);

                _colorPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 8 * _dip);
                cirCanv.DrawOval(circleOffset - _dip, circleOffset, _circleRadius * 0.8f, _circleRadius * 0.9f, _colorPaint);

                _colorPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 12 * _dip);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius * 0.5f, _colorPaint);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius + _dip, _lightStroke);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius * 0.75f - _dip, _shadowBlurOuter);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius * 0.75f, _lightStroke);

                _colorPaint.MaskFilter = null;

                _sliderBox = new SKRect(0, 7 * _dip, _width, _height - 7 * _dip);
            }

            _circlePath.OffsetX = 3 * _dip + (_width - 2 * _circleRadius - 3 * _dip) * TotalProgress;
            _circlePath.UpdatePosition();
            float circlePosX = _circlePath.TightBounds.MidX;

            float  hardShadowXOffset = 6 * _dip;
            float  hardShadowYOffset = 8 * _dip;
            SKPath path = new SKPath();

            path.AddCircle(circlePosX - 5 * _dip, circlePosY, _circleRadius);
            path.AddRect(_sliderBox);

            path.Offset(new SKPoint(hardShadowXOffset, hardShadowYOffset));
            canvas.DrawPath(path, _shadowHardPaint);

            canvas.DrawRect(_sliderBox, _lightColorPaint);

            float todayPos = 5 * _dip + (_width - _circleRadius) * TodayGoal;

            canvas.DrawRect(new SKRect(todayPos, 7 * _dip, todayPos + 6 * _dip, _height - 7 * _dip), _gray);
            _sliderBox.Right = circlePosX;
            canvas.DrawRect(_sliderBox, _colorPaint);
            _sliderBox.Right = _width;

            canvas.DrawSurface(_circleSurface, circlePosX - _circleRadius - 10 * _dip, -5 * _dip);
        }
コード例 #5
0
ファイル: UVPlotter.cs プロジェクト: BlueSquid1/UV_Mate
        //method responsible for drawing on the canvas
        public void DrawGraph(SKPaintGLSurfaceEventArgs e)
        {
            GRBackendRenderTargetDesc viewInfo = e.RenderTarget;

            this.fullPlotSurface = e.Surface;
            SKCanvas canvas = this.fullPlotSurface.Canvas;

            /*
             * initalize graph grid
             *
             * SKIA tries to be too smart by updating GRBackendRenderTargetDesc.Width and GRBackendRenderTargetDesc.Height
             * to reflect any scale applied to canvas. Need to remove any scaling to get pixel dimensions correct.
             */
            canvas.Save();
            //undo any scaling so canvas dimensions are back in pixels
            canvas.ResetMatrix();
            float pixelPerUnit = (float)(viewInfo.Width / this.canvasView.Width);
            //get grid width in xamarin units
            float gridWidth = (float)(this.canvasView.Width - gridPosX);
            //get grid width in pixels
            int gridWidthPixels = (int)(gridWidth * pixelPerUnit);
            //get grid height in xamarin units
            float gridHeight = (float)(this.canvasView.Height - paddingHeight);
            //get grid height in pixels
            int gridHeightPixels = (int)(gridHeight * pixelPerUnit);

            this.gridWidth  = gridWidth;
            this.gridHeight = gridHeight;
            //create the surface in pixels
            this.graphSurface = SKSurface.Create(gridWidthPixels, gridHeightPixels, SKColorType.Rgba8888, SKAlphaType.Premul);
            //scale surface so it's no in xamarin units
            this.graphSurface.Canvas.Scale(pixelPerUnit);
            canvas.Restore();

            //flip graph so origin is bottom left
            this.graphSurface.Canvas.Scale(1.0f, -1.0f);
            this.graphSurface.Canvas.Translate(0, -gridHeight);

            //calculate x and y scales
            float UVRange = (this.maxY + 1) - this.minY;

            this.unitsPerUVLevel = this.gridHeight / UVRange;

            TimeSpan timeRange = this.maxX - this.minX;

            this.unitsPerMinute = (float)(this.gridWidth / timeRange.TotalMinutes);

            //fill in background
            this.DrawBackground();

            //put axis titles on screen
            this.DrawAxes();

            //draw measured and approximated plot lines
            this.DrawUVPlots();

            //draw uv level dash lines
            this.DrawHorizontalDashes();

            //Write current UV
            this.DrawCurrentUV();

            /*
             * Again Skia tries to be smart by always updating GRBackendRenderTargetDesc.Width and GRBackendRenderTargetDesc.Height
             * to reflect any scale applied to canvas. Need to remove all scaling so all units are pixels before
             * drawing graph surface to the canvas.
             */
            canvas.Save();
            canvas.ResetMatrix();
            canvas.DrawSurface(this.graphSurface, gridPosX * pixelPerUnit, gridPosY * pixelPerUnit);
            canvas.Restore();
        }