Esempio n. 1
0
        public void DrawDevice(KDeviceHandler.KDevice device, SKCanvas canvas,
                               float canvasX, float canvasY, float canvasWidth, float canvasHeight,
                               float deviceX, float deviceY, float deviceWidth, float deviceHeight,
                               float padRadius, float margin, Swipe swipe)
        {
            DrawBackground(canvas, canvasX, canvasY, canvasWidth, canvasHeight); // excluding the area outside the fitted region covered by the deviceImage

            float padStrokeWidth       = padRadius / 10.0f;
            float padStrokeWidthAccent = 0.75f * padStrokeWidth;

            SKRect coldZoneRect = new SKRect(deviceX + margin, deviceY + margin, deviceX + margin + device.coldZoneWidth * 2 * padRadius, deviceY + margin + device.rowsNo * 2 * padRadius);
            SKRect hotZoneRect  = new SKRect(deviceX + margin + (device.coldZoneWidth + device.warmZoneWidth) * 2 * padRadius, deviceY + margin, deviceX + margin + (device.coldZoneWidth + device.warmZoneWidth + device.hotZoneWidth) * 2 * padRadius, deviceY + margin + device.rowsNo * 2 * padRadius);

            DrawHeatZone(canvas, coldZoneRect, padRadius, coldZoneRect.Width / (2 * device.coldZoneWidth), coldColor, swipe);
            DrawHeatZone(canvas, hotZoneRect, padRadius, hotZoneRect.Width / (2 * device.hotZoneWidth), hotColor, swipe);
            DrawText(canvas, "< " + KDeviceHandler.coldTemp, new SKPoint(coldZoneRect.MidX, coldZoneRect.Bottom + margin), padRadius, SKColors.Blue, swipe);
            DrawText(canvas, "> " + KDeviceHandler.hotTemp, new SKPoint(hotZoneRect.MidX, hotZoneRect.Bottom + margin), padRadius, SKColors.Blue, swipe);

            float strokePaintStrokeWidth       = padStrokeWidth;
            float strokeAccentPaintStrokeWidth = padStrokeWidthAccent;

            using (var strokePaint = new SKPaint {
                Style = SKPaintStyle.Stroke, Color = SKColors.Black, StrokeWidth = swipe % strokePaintStrokeWidth, StrokeJoin = SKStrokeJoin.Round, IsAntialias = true
            })
                using (var strokeAccentPaint = new SKPaint {
                    Style = SKPaintStyle.Stroke, Color = SKColors.White, StrokeWidth = swipe % strokeAccentPaintStrokeWidth, StrokeJoin = SKStrokeJoin.Round, StrokeCap = SKStrokeCap.Round, IsAntialias = true
                })
                    using (var fillPaint = new SKPaint {
                        Style = SKPaintStyle.Fill, Color = SKColors.Goldenrod, IsAntialias = true
                    })                                                                                                        // SKColors.DarkGoldenrod / Goldenrod / PaleGoldenrod / LightGoldenrodYellow / Gold
                        using (var holePaint = new SKPaint {
                            Style = SKPaintStyle.Fill, Color = SKColors.Black, IsAntialias = true
                        })
                            using (var holeAccentPaint = new SKPaint {
                                Style = SKPaintStyle.Fill, Color = SKColors.White, IsAntialias = true
                            })
                            {
                                for (int j = 0; j < device.rowsNo; j++)
                                {
                                    for (int i = 0; i < device.colsNo; i++)
                                    {
                                        DrawPad(canvas, new SKPoint(deviceX + margin + padRadius + i * 2 * padRadius, deviceY + margin + padRadius + j * 2 * padRadius), padRadius, strokePaint, strokePaintStrokeWidth, fillPaint, holePaint, strokeAccentPaint, strokeAccentPaintStrokeWidth, holeAccentPaint, swipe);
                                    }
                                }
                            }
        }
Esempio n. 2
0
        public /*interface DevicePainter*/ void Draw(KDeviceHandler.KDevice device, int canvasX, int canvasY, int canvasWidth, int canvasHeight)
        {
            (float margin, float padRadius, float deviceWidth, float deviceHeight) = device.FittedDimensions(canvasWidth, canvasHeight);
            float strokeWidth       = padRadius / 10.0f;
            float accentStrokeWidth = 1.5f * strokeWidth;
            float textStrokeWidth   = accentStrokeWidth / 2.0f;
            float deviceX           = canvasX + (canvasWidth - deviceWidth) / 2.0f;
            float deviceY           = canvasY + (canvasHeight - deviceHeight) / 2.0f;

            // don't lock device here, it will dedlock
            if (device.sizeChanged || cachedBackground == null || cachedBackground.Width != canvasWidth || cachedBackground.Height != canvasHeight)
            {
                cachedBackground = new SKBitmap(canvasWidth, canvasHeight);
                using (var backgroundCanvas = new SKCanvas(cachedBackground)) {
                    DrawDevice(device, backgroundCanvas,
                               canvasX, canvasY, canvasWidth, canvasHeight,
                               deviceX, deviceY, deviceWidth, deviceHeight,
                               padRadius, margin, device.pinchPan);
                }
                device.sizeChanged = false;
            }

            if (!device.sizeChanged)
            {
                canvas.DrawBitmap(cachedBackground, 0, 0); // do not apply pinchPan: background bitmap is alread scaled by it
            }
            if (device.displayPinchOrigin)
            {
                // same as: GraphSharp.GraphLayout.CanvasDrawCircle(canvas, pinchOrigin, 20, false, SKColors.LightGray);
                using (var paint = FillPaint(SKColors.LightGray)) { DrawCircle(device.pinchOrigin, 20, paint); }
                //using (var paint = new SKPaint()) {
                //    paint.TextSize = 10; paint.IsAntialias = true; paint.Color = SKColors.LightGray; paint.IsStroke = false;
                //    canvas.DrawCircle(device.pinchOrigin.X, device.pinchOrigin.Y, 20, paint);
                //}
            }

            using (var dropletFillPaint = new SKPaint {
                Style = SKPaintStyle.Fill, Color = device.dropletColor, IsAntialias = true
            })
                using (var dropletBiggieFillPaint = new SKPaint {
                    Style = SKPaintStyle.Fill, Color = device.dropletBiggieColor, IsAntialias = true
                }) {
                    KDeviceHandler.Place[,] places = device.places;
                    KDeviceHandler.Placement placement = device.placement;
                    for (int row = 0; row < places.GetLength(0); row++)
                    {
                        for (int col = 0; col < places.GetLength(1); col++)
                        {
                            KDeviceHandler.Place place = places[row, col];
                            if (place != null && placement.IsOccupied(place))
                            {
                                SampleValue sample       = placement.SampleOf(place);
                                float       volumeRadius = padRadius * (float)Math.Sqrt((sample.Volume()) * 1000000.0); // normal radius = 1μL
                                float       diameter     = 2 * padRadius;
                                SKPaint     fillPaint    = dropletFillPaint;
                                bool        biggie       = false;
                                if (volumeRadius > 2 * padRadius)
                                {
                                    biggie       = true;
                                    volumeRadius = 2 * padRadius;
                                    fillPaint    = dropletBiggieFillPaint;
                                }
                                SKPoint here  = new SKPoint(deviceX + margin + padRadius + col * diameter, deviceY + margin + padRadius + row * diameter);
                                SKPoint rht   = new SKPoint(deviceX + margin + padRadius + (col + 1) * diameter, deviceY + margin + padRadius + row * diameter);
                                SKPoint lft   = new SKPoint(deviceX + margin + padRadius + (col - 1) * diameter, deviceY + margin + padRadius + row * diameter);
                                SKPoint bot   = new SKPoint(deviceX + margin + padRadius + col * diameter, deviceY + margin + padRadius + (row + 1) * diameter);
                                SKPoint top   = new SKPoint(deviceX + margin + padRadius + col * diameter, deviceY + margin + padRadius + (row - 1) * diameter);
                                string  label = sample.symbol.Raw(); // sample.FormatSymbol(placement.StyleOf(sample, style))
                                if (place.IsAnimation(KDeviceHandler.Animation.None))
                                {
                                    DrawDroplet(canvas, label, biggie, here,
                                                padRadius, volumeRadius, textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.SizeHalf))
                                {
                                    DrawDroplet(canvas, label, biggie, here,
                                                padRadius, volumeRadius / 2, textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.SizeQuarter))
                                {
                                    DrawDroplet(canvas, label, biggie, here,
                                                padRadius, volumeRadius / 4, textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.PullRht))
                                {
                                    DrawDropletPulledHor(canvas, label, biggie, here, rht, KDeviceHandler.Direction.Rht,
                                                         padRadius, volumeRadius * 5 / 6, volumeRadius * 5 / 12, volumeRadius * 1 / 3,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.SplitRht))
                                {
                                    DrawDropletPulledHor(canvas, label, biggie, here, rht, KDeviceHandler.Direction.Rht,
                                                         padRadius, volumeRadius * 2 / 3, volumeRadius * 1 / 3, volumeRadius * 2 / 3,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.PullLft))
                                {
                                    DrawDropletPulledHor(canvas, label, biggie, lft, here, KDeviceHandler.Direction.Lft,
                                                         padRadius, volumeRadius * 1 / 3, volumeRadius * 5 / 12, volumeRadius * 5 / 6,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.SplitLft))
                                {
                                    DrawDropletPulledHor(canvas, label, biggie, lft, here, KDeviceHandler.Direction.Lft,
                                                         padRadius, volumeRadius * 2 / 3, volumeRadius * 1 / 3, volumeRadius * 2 / 3,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.PullBot))
                                {
                                    DrawDropletPulledVer(canvas, label, biggie, here, bot, KDeviceHandler.Direction.Bot,
                                                         padRadius, volumeRadius * 5 / 6, volumeRadius * 5 / 12, volumeRadius * 1 / 3,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.SplitBot))
                                {
                                    DrawDropletPulledVer(canvas, label, biggie, here, bot, KDeviceHandler.Direction.Bot,
                                                         padRadius, volumeRadius * 2 / 3, volumeRadius * 1 / 3, volumeRadius * 2 / 3,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.PullTop))
                                {
                                    DrawDropletPulledVer(canvas, label, biggie, top, here, KDeviceHandler.Direction.Top,
                                                         padRadius, volumeRadius * 1 / 3, volumeRadius * 5 / 12, volumeRadius * 5 / 6,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                                if (place.IsAnimation(KDeviceHandler.Animation.SplitTop))
                                {
                                    DrawDropletPulledVer(canvas, label, biggie, top, here, KDeviceHandler.Direction.Top,
                                                         padRadius, volumeRadius * 2 / 3, volumeRadius * 1 / 3, volumeRadius * 2 / 3,
                                                         textStrokeWidth, fillPaint, strokeWidth, accentStrokeWidth, device.pinchPan);
                                }
                            }
                        }
                    }
                }

            canvas.Flush();
        }