Exemple #1
0
        public void DrawDropletPulledVer(SKCanvas canvas, string label, bool biggie, SKPoint c1, SKPoint c2, KDeviceHandler.Direction dir, float r, float r1, float neckX, float r2, float textStrokeWidth, SKPaint fillPaint, float strokeWidth, float accentStrokeWidth, Swipe swipe)
        {
            float ratio = ((r1 + r2) / 2) / r;

            //strokeWidth = strokeWidth * ratio;
            textStrokeWidth   = textStrokeWidth * ratio;
            accentStrokeWidth = accentStrokeWidth * ratio;

            float lr = r1 - (strokeWidth + accentStrokeWidth) / 2.0f;
            float dr = r2 - (strokeWidth + accentStrokeWidth) / 2.0f;

            // place the neck in an Y-position proportional to the rate between r1 and r2, with m1+r1Y to the top leading to c1.Y, and m2+r2Y to the bot leading to c2.Y
            float m1 = (2 * r - (r1 + r2)) / (1 + r2 / r1);
            float m2 = m1 * r2 / r1;
            // position of the neck
            float nY = c1.Y + r1 + m1;
            float nX = c1.X;
            // Control points: a1*2 is on a line from nY,nX-neckX to c1.Y,c.X-r1 where it intersects c1.Y+r1; we divide it by 2 to make the curve smoother
            float a1 = (m1 * (r1 - neckX) / (r1 + m1)) / 2;
            float a2 = (m2 * (r2 - neckX) / (r2 + m2)) / 2;

            var path = new SKPath();

            path.MoveTo(swipe % new SKPoint(c1.X - r1, c1.Y));
            path.CubicTo(swipe % new SKPoint(c1.X - r1, c1.Y + 0.5f * r1), swipe % new SKPoint(nX - (neckX + a1), c1.Y + r1), swipe % new SKPoint(nX - neckX, nY));
            path.CubicTo(swipe % new SKPoint(nX - (neckX + a2), c2.Y - r2), swipe % new SKPoint(c2.X - r2, c2.Y - 0.5f * r2), swipe % new SKPoint(c2.X - r2, c2.Y));

            path.CubicTo(swipe % new SKPoint(c2.X - r2, c2.Y + 0.75f * r2), swipe % new SKPoint(c2.X - 0.75f * r2, c2.Y + r2), swipe % new SKPoint(c2.X, c2.Y + r2));
            path.CubicTo(swipe % new SKPoint(c2.X + 0.75f * r2, c2.Y + r2), swipe % new SKPoint(c2.X + r2, c2.Y + 0.75f * r2), swipe % new SKPoint(c2.X + r2, c2.Y));

            path.CubicTo(swipe % new SKPoint(c2.X + r2, c2.Y - 0.5f * r2), swipe % new SKPoint(nX + (neckX + a2), c2.Y - r2), swipe % new SKPoint(nX + neckX, nY));
            path.CubicTo(swipe % new SKPoint(nX + (neckX + a1), c1.Y + r1), swipe % new SKPoint(c1.X + r1, c1.Y + 0.5f * r1), swipe % new SKPoint(c1.X + r1, c1.Y));

            path.CubicTo(swipe % new SKPoint(c1.X + r1, c1.Y - 0.75f * r1), swipe % new SKPoint(c1.X + 0.75f * r1, c1.Y - r1), swipe % new SKPoint(c1.X, c1.Y - r1));
            path.CubicTo(swipe % new SKPoint(c1.X - 0.75f * r1, c1.Y - r1), swipe % new SKPoint(c1.X - r1, c1.Y - 0.75f * r1), swipe % new SKPoint(c1.X - r1, c1.Y));
            path.Close();

            var darkPath = new SKPath();

            darkPath.MoveTo(swipe % new SKPoint(c2.X, c2.Y + dr));
            darkPath.CubicTo(swipe % new SKPoint(c2.X + 0.75f * dr, c2.Y + dr), swipe % new SKPoint(c2.X + dr, c2.Y + 0.75f * dr), swipe % new SKPoint(c2.X + dr, c2.Y));

            var lightPath = new SKPath();

            lightPath.MoveTo(swipe % new SKPoint(c1.X, c1.Y - lr));
            lightPath.CubicTo(swipe % new SKPoint(c1.X - 0.75f * lr, c1.Y - lr), swipe % new SKPoint(c1.X - lr, c1.Y - 0.75f * lr), swipe % new SKPoint(c1.X - lr, c1.Y));

            using (var strokePaint = new SKPaint {
                Style = SKPaintStyle.Stroke, Color = new SKColor(0, 0, 0, 191), StrokeWidth = swipe % strokeWidth, IsAntialias = true
            })
                using (var accentLightPaint = new SKPaint {
                    Style = SKPaintStyle.Stroke, Color = new SKColor(255, 255, 255, 191), StrokeWidth = swipe % accentStrokeWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true
                })
                    using (var accentDarkPaint = new SKPaint {
                        Style = SKPaintStyle.Stroke, Color = new SKColor(0, 0, 0, 95), StrokeWidth = swipe % accentStrokeWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true
                    }) {
                        canvas.DrawPath(path, fillPaint);
                        canvas.DrawPath(darkPath, accentDarkPaint);
                        canvas.DrawPath(lightPath, accentLightPaint);
                        canvas.DrawPath(path, strokePaint);
                    }

            float   rYtext = (r1 == r2) ? ((dir == KDeviceHandler.Direction.Top) ? r1 : r2) : (r1 > r2) ? r1 : r2;
            SKPoint cText  = (r1 == r2) ? ((dir == KDeviceHandler.Direction.Top) ? c1 : c2) : (r1 > r2) ? c1 : c2;

            DrawDropletLabel(canvas, label, cText, rYtext, textStrokeWidth, biggie, swipe);
        }
        public void DrawDropletPulledHor(CGContext canvas, string label, bool biggie, SKPoint c1, SKPoint c2, KDeviceHandler.Direction dir, float r, float r1, float neckY, float r2, float textStrokeWidth, SKPaint fillPaint, float strokeWidth, float accentStrokeWidth, Swipe swipe)
        {
            float ratio = ((r1 + r2) / 2) / r;

            //strokeWidth = strokeWidth * ratio;
            textStrokeWidth   = textStrokeWidth * ratio;
            accentStrokeWidth = accentStrokeWidth * ratio;

            float lr = r1 - (strokeWidth + accentStrokeWidth) / 2.0f;
            float dr = r2 - (strokeWidth + accentStrokeWidth) / 2.0f;

            // place the neck in an X-position proportional to the rate between r1 and r2, with m1+r1X to the left leading to c1.X, and m2+r2X to the right leading to c2.X
            float m1 = (2 * r - (r1 + r2)) / (1 + r2 / r1);
            float m2 = m1 * r2 / r1;
            // position of the neck
            float nX = c1.X + r1 + m1;
            float nY = c1.Y;
            // Control points: a1*2 is on a line from nX,nY-neckY to c1.X,c.Y-r1 where it intersects c1.X+r1; we divide it by 2 to make the curve smoother
            float a1 = (m1 * (r1 - neckY) / (r1 + m1)) / 2;
            float a2 = (m2 * (r2 - neckY) / (r2 + m2)) / 2;

            var path = new CGPath();

            path.MoveToPoint(CG.Point(swipe % new SKPoint(c1.X, c1.Y - r1)));
            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c1.X + 0.5f * r1, c1.Y - r1)), CG.Point(swipe % new SKPoint(c1.X + r1, nY - (neckY + a1))), CG.Point(swipe % new SKPoint(nX, nY - neckY)));
            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c2.X - r2, nY - (neckY + a2))), CG.Point(swipe % new SKPoint(c2.X - 0.5f * r2, c2.Y - r2)), CG.Point(swipe % new SKPoint(c2.X, c2.Y - r2)));

            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c2.X + 0.75f * r2, c2.Y - r2)), CG.Point(swipe % new SKPoint(c2.X + r2, c2.Y - 0.75f * r2)), CG.Point(swipe % new SKPoint(c2.X + r2, c2.Y)));
            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c2.X + r2, c2.Y + 0.75f * r2)), CG.Point(swipe % new SKPoint(c2.X + 0.75f * r2, c2.Y + r2)), CG.Point(swipe % new SKPoint(c2.X, c2.Y + r2)));

            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c2.X - 0.5f * r2, c2.Y + r2)), CG.Point(swipe % new SKPoint(c2.X - r2, nY + (neckY + a2))), CG.Point(swipe % new SKPoint(nX, nY + neckY)));
            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c1.X + r1, nY + (neckY + a1))), CG.Point(swipe % new SKPoint(c1.X + 0.5f * r1, c1.Y + r1)), CG.Point(swipe % new SKPoint(c1.X, c1.Y + r1)));

            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c1.X - 0.75f * r1, c1.Y + r1)), CG.Point(swipe % new SKPoint(c1.X - r1, c1.Y + 0.75f * r1)), CG.Point(swipe % new SKPoint(c1.X - r1, c1.Y)));
            path.AddCurveToPoint(CG.Point(swipe % new SKPoint(c1.X - r1, c1.Y - 0.75f * r1)), CG.Point(swipe % new SKPoint(c1.X - 0.75f * r1, c1.Y - r1)), CG.Point(swipe % new SKPoint(c1.X, c1.Y - r1)));
            path.CloseSubpath();

            var darkPath = new CGPath();

            darkPath.MoveToPoint(CG.Point(swipe % new SKPoint(c2.X + dr, c2.Y)));
            darkPath.AddCurveToPoint(CG.Point(swipe % new SKPoint(c2.X + dr, c2.Y + 0.75f * dr)), CG.Point(swipe % new SKPoint(c2.X + 0.75f * dr, c2.Y + dr)), CG.Point(swipe % new SKPoint(c2.X, c2.Y + dr)));

            var lightPath = new CGPath();

            lightPath.MoveToPoint(CG.Point(swipe % new SKPoint(c1.X - lr, c1.Y)));
            lightPath.AddCurveToPoint(CG.Point(swipe % new SKPoint(c1.X - lr, c1.Y - 0.75f * lr)), CG.Point(swipe % new SKPoint(c1.X - 0.75f * lr, c1.Y - lr)), CG.Point(swipe % new SKPoint(c1.X, c1.Y - lr)));

            using (var strokePaint = new SKPaint {
                Style = SKPaintStyle.Stroke, Color = new SKColor(0, 0, 0, 191), StrokeWidth = swipe % strokeWidth, IsAntialias = true
            })
                using (var accentLightPaint = new SKPaint {
                    Style = SKPaintStyle.Stroke, Color = new SKColor(255, 255, 255, 191), StrokeWidth = swipe % accentStrokeWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true
                })
                    using (var accentDarkPaint = new SKPaint {
                        Style = SKPaintStyle.Stroke, Color = new SKColor(0, 0, 0, 95), StrokeWidth = swipe % accentStrokeWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true
                    })
                    {
                        canvas.AddPath(path);
                        canvas.SetFillColor(CG.Color(fillPaint.Color));
                        canvas.FillPath();

                        canvas.AddPath(darkPath);
                        canvas.SetStrokeColor(CG.Color(accentDarkPaint.Color));
                        canvas.SetLineWidth(accentDarkPaint.StrokeWidth);
                        canvas.SetLineJoin(CG.LineJoin(accentDarkPaint.StrokeJoin));
                        canvas.SetLineCap(CG.LineCap(accentDarkPaint.StrokeCap));
                        canvas.StrokePath();

                        canvas.AddPath(lightPath);
                        canvas.SetStrokeColor(CG.Color(accentLightPaint.Color));
                        canvas.SetLineWidth(accentLightPaint.StrokeWidth);
                        canvas.SetLineJoin(CG.LineJoin(accentLightPaint.StrokeJoin));
                        canvas.SetLineCap(CG.LineCap(accentLightPaint.StrokeCap));
                        canvas.StrokePath();

                        canvas.AddPath(path);
                        canvas.SetStrokeColor(CG.Color(strokePaint.Color));
                        canvas.SetLineWidth(strokePaint.StrokeWidth);
                        canvas.SetLineJoin(CG.LineJoin(strokePaint.StrokeJoin));
                        canvas.SetLineCap(CG.LineCap(strokePaint.StrokeCap));
                        canvas.StrokePath();
                    }

            float   rText = (r1 == r2) ? ((dir == KDeviceHandler.Direction.Lft) ? r1 : r2) : (r1 > r2) ? r1 : r2;
            SKPoint cText = (r1 == r2) ? ((dir == KDeviceHandler.Direction.Lft) ? c1 : c2) : (r1 > r2) ? c1 : c2;

            DrawDropletLabel(canvas, label, cText, rText, textStrokeWidth, biggie, swipe);
        }