private void DrawAPath(SKCanvas canvas, SKPaint paint, DrawPath drawPath) { using (var path = new SKPath()) { // nasty hack because the Cocoa version defaults to Black var pathColorName = (drawPath.color == "Black") ? "Charcoal" : drawPath.color; var pathColor = SwatchColor.ColorsByName[pathColorName].Color; paint.Color = pathColor; var isFirst = true; foreach (var point in drawPath.points) { // for compatibility with iOS Realm, stores floats, normalised to NORMALISE_TO var fx = (float)point.x; var fy = (float)point.y; ScalePointsToDraw(ref fx, ref fy); if (isFirst) { isFirst = false; path.MoveTo(fx, fy); } else { path.LineTo(fx, fy); } } canvas.DrawPath(path, paint); } }
public void StartDrawing(float inX, float inY) { _currentlyDrawing = null; // don't clear in Stop as will lose last point, clear when we know done _ignoringTouches = false; // when not logged in, entire screen acts as control area that will trigger CredentialsEditor if (TouchInControlArea(inX, inY)) { _ignoringTouches = true; return; } // check if needs login, eg: if login failed and touch blank screen should cope if (_realm == null) { if (!_waitingForLogin) { LoginToServerAsync(); } return; // not yet logged into server, let next touch invoke us } _lastX = inX; _lastY = inY; // start a local path for responsive drawing _currentlyDrawing = new SKPath(); _currentlyDrawing.MoveTo(inX, inY); ScalePointsToStore(ref inX, ref inY); _isDrawing = true; _realm.Write(() => { _drawPath = new DrawPath { color = CurrentColor.Name }; // Realm saves name of color _drawPath.points.Add(new DrawPoint { x = inX, y = inY }); _realm.Add(_drawPath); }); }