private static IPen SetPenForGameTile(StylePaint tpe) { //These pens are saved with a fixed drawing width to match game tiles. int imgX = 0, imgY = 0; MapTileSupport.GetPlusCodeImagePixelSize("22334455", out imgX, out imgY); var info = new ImageStats(OpenLocationCode.DecodeValid("22334455"), imgX, imgY); var widthMod = resolutionCell11Lon * IMapTiles.GameTileScale; string htmlColor = tpe.HtmlColorCode; if (htmlColor.Length == 8) { htmlColor = htmlColor.Substring(2, 6) + htmlColor.Substring(0, 2); } Pen p; if (String.IsNullOrWhiteSpace(tpe.LinePattern) || tpe.LinePattern == "solid") { p = new Pen(Rgba32.ParseHex(htmlColor), tpe.LineWidthDegrees * (float)info.pixelsPerDegreeX); } else { float[] linesAndGaps = tpe.LinePattern.Split('|').Select(t => float.Parse(t)).ToArray(); p = new Pen(Rgba32.ParseHex(htmlColor), tpe.LineWidthDegrees * (float)info.pixelsPerDegreeX, linesAndGaps); } return(p); }
/// <summary> /// Create the SKPaint object for each style and store it in the requested object. /// </summary> /// <param name="tpe">the TagParserPaint object to populate</param> private static SKPaint SetPaintForTPP(StylePaint tpe) { var paint = new SKPaint(); paint.StrokeJoin = SKStrokeJoin.Round; paint.IsAntialias = true; paint.Color = SKColor.Parse(tpe.HtmlColorCode); if (tpe.FillOrStroke == "fill") { paint.Style = SKPaintStyle.StrokeAndFill; } else { paint.Style = SKPaintStyle.Stroke; } paint.StrokeWidth = tpe.LineWidthDegrees; paint.StrokeCap = SKStrokeCap.Round; if (tpe.LinePattern != "solid") { float[] linesAndGaps = tpe.LinePattern.Split('|').Select(t => float.Parse(t)).ToArray(); paint.PathEffect = SKPathEffect.CreateDash(linesAndGaps, 0); paint.StrokeCap = SKStrokeCap.Butt; } if (!string.IsNullOrEmpty(tpe.FileName)) { SKBitmap fillPattern = cachedBitmaps[tpe.FileName]; //cachedBitmaps.TryAdd(tpe.fileName, fillPattern); //For icons. SKShader tiling = SKShader.CreateBitmap(fillPattern, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat); //For fill patterns. paint.Shader = tiling; } return(paint); }
/// <summary> /// Create the Brush object for each style and store it for later use. /// </summary> /// <param name="tpe">the TagParserPaint object to populate</param> private static IBrush SetPaintForTPP(StylePaint tpe) { //SkiaSharp now implements rounding line ends, but they're only for Pens //(which only work on lines), and my stuff all currently uses a Brush. //It's possible that I want pens instead of brushes for lines with patterns? string htmlColor = tpe.HtmlColorCode; if (htmlColor.Length == 8) { htmlColor = htmlColor.Substring(2, 6) + htmlColor.Substring(0, 2); } IBrush paint = new SolidBrush(Rgba32.ParseHex(htmlColor)); if (!string.IsNullOrEmpty(tpe.FileName)) { paint = new ImageBrush(cachedBitmaps[tpe.FileName]); } return(paint); }