private static VisualBrush CreateHatchBrush(Styles.Brush brush, int viewbox, int viewport, IEnumerable <Geometry> geometries) { var elements = new List <UIElement>(); if (brush.Background != null) { elements.Add(CreateBackground(brush.Background, viewbox)); } var stroke = new SolidColorBrush(GetColor(brush.Color)); var canvas = new Canvas(); foreach (var geometry in geometries) { canvas.Children.Add(new Path { Stroke = stroke, Data = geometry, StrokeThickness = 1, SnapsToDevicePixels = false }); } canvas.Arrange(new Rect(0, 0, viewbox, viewbox)); elements.Add(canvas); return(CreatePatternVisual(elements, viewport, viewbox)); }
public static XamlBrush MapsuiBrushToXaml(Styles.Brush brush, BrushCache brushCache = null) { #if !NETFX_CORE if (brush == null) { return(null); } switch (brush.FillStyle) { case FillStyle.Cross: return(CreateHatchBrush(brush, 12, 10, new List <Geometry> { Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 0 10 l 10 -10") })); case FillStyle.BackwardDiagonal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 10 l 10 -10"), Geometry.Parse("M -0.5 0.5 l 10 -10"), Geometry.Parse("M 8 12 l 10 -10") })); case FillStyle.Bitmap: return(CreateImageBrush(brush, brushCache)); case FillStyle.Dotted: return(DottedBrush(brush)); case FillStyle.DiagonalCross: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 0 10 l 10 -10") })); case FillStyle.ForwardDiagonal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M -1 9 l 10 10"), Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 9 -1 l 10 10") })); case FillStyle.Hollow: return(new SolidColorBrush(Colors.Transparent)); case FillStyle.Horizontal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 5 h 10") })); case FillStyle.Solid: return(new SolidColorBrush(brush.Color != null ? brush.Color.ToXaml() : brush.Background != null ? brush.Color.ToXaml() : Colors.Transparent)); case FillStyle.Vertical: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 5 0 l 0 10") })); default: return((brush.Color != null) ? new SolidColorBrush(brush.Color.ToXaml()) : null); } #else return(new SolidColorBrush(brush.Color.ToXaml())); #endif }
/// <summary> /// Gets the GDI brush. /// </summary> /// <param name="brush">The GDI brush.</param> /// <returns></returns> public System.Drawing.Brush GetBrush(Styles.Brush brush) { System.Drawing.Brush gdiBrush; if (!brushes.TryGetValue(brush, out gdiBrush)) { gdiBrush = new System.Drawing.SolidBrush(brush.Color.ToGdi()); } return(gdiBrush); }
private static ImageBrush CreateImageBrush(Styles.Brush brush) { var bmp = BitmapRegistry.Instance.Get(brush.BitmapId).CreateBitmapImage(); var imageBrush = new ImageBrush(bmp) { Viewbox = new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight), Viewport = new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight), ViewportUnits = BrushMappingMode.Absolute, ViewboxUnits = BrushMappingMode.Absolute, TileMode = TileMode.Tile }; return(imageBrush); }
private static VisualBrush DottedBrush(Styles.Brush brush) { const int viewboxSize = 12; const int viewportSize = 10; var elements = new List <UIElement>(); if (brush.Background != null) { elements.Add(CreateBackground(brush.Background, viewboxSize)); } elements.Add(new Ellipse { Fill = new SolidColorBrush(GetColor(brush.Color)), Width = 10, Height = 10 }); return(CreatePatternVisual(elements, viewportSize, viewboxSize)); }
private static ImageBrush CreateImageBrush(Styles.Brush brush, BrushCache brushCache = null) { return(brushCache != null?brushCache.GetImageBrush(brush.BitmapId, CreateImageBrush) : CreateImageBrush(BitmapRegistry.Instance.Get(brush.BitmapId))); }
/// <summary> /// Renders a label to the map. /// </summary> /// <param name="graphics">Graphics reference</param> /// <param name="labelPoint">Label placement</param> /// <param name="offset">Offset of label in screen coordinates</param> /// <param name="font">Font used for rendering</param> /// <param name="forecolor">Font forecolor</param> /// <param name="backcolor">Background color</param> /// <param name="halo">Color of halo</param> /// <param name="rotation">Text rotation in degrees</param> /// <param name="text">Text to render</param> /// <param name="viewport"></param> public static void DrawLabel(Graphics graphics, Point labelPoint, Styles.Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport) { SizeF fontSize = graphics.MeasureString(text, font.Convert()); //Calculate the size of the text labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset if (rotation != 0 && !double.IsNaN(rotation)) { graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y); graphics.RotateTransform((float)rotation); graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2); if (backcolor != null && backcolor.Convert() != Brushes.Transparent) { graphics.FillRectangle(backcolor.Convert(), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f); } var path = new GraphicsPath(); path.AddString(text, new FontFamily(font.FontFamily), (int)font.Convert().Style, font.Convert().Size, new System.Drawing.Point(0, 0), null); if (halo != null) { graphics.DrawPath(halo.Convert(), path); } graphics.FillPath(new SolidBrush(forecolor.Convert()), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0); } else { if (backcolor != null && backcolor.Convert() != Brushes.Transparent) { graphics.FillRectangle(backcolor.Convert(), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f); } var path = new GraphicsPath(); //Arial hack path.AddString(text, new FontFamily("Arial"), (int)font.Convert().Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null); if (halo != null) { graphics.DrawPath(halo.Convert(), path); } graphics.FillPath(new SolidBrush(forecolor.Convert()), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y); } }
private static BitmapImage GetOrCreateBitmapImage(Styles.Brush brush, SymbolCache symbolCache = null) { return(symbolCache != null ? (BitmapImage)symbolCache.GetOrCreate(brush.BitmapId): ((System.IO.Stream)BitmapRegistry.Instance.Get(brush.BitmapId)).ToBitmapImage()); }
public static XamlBrush MapsuiBrushToXaml(Styles.Brush brush, SymbolCache symbolCache = null, double rotate = 0) { if (brush == null) { return(null); } switch (brush.FillStyle) { case FillStyle.Cross: return(CreateHatchBrush(brush, 12, 10, new List <Geometry> { Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 0 10 l 10 -10") })); case FillStyle.BackwardDiagonal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 10 l 10 -10"), Geometry.Parse("M -0.5 0.5 l 10 -10"), Geometry.Parse("M 8 12 l 10 -10") })); case FillStyle.Bitmap: return(GetOrCreateBitmapImage(brush, symbolCache).ToTiledImageBrush()); case FillStyle.BitmapRotated: RotateTransform aRotateTransform = new RotateTransform(); aRotateTransform.CenterX = 0.5; aRotateTransform.CenterY = 0.5; aRotateTransform.Angle = rotate; var b = GetOrCreateBitmapImage(brush, symbolCache).ToTiledImageBrush(); b.RelativeTransform = aRotateTransform; return(b); case FillStyle.Svg: return(null); case FillStyle.Dotted: return(DottedBrush(brush)); case FillStyle.DiagonalCross: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 0 10 l 10 -10") })); case FillStyle.ForwardDiagonal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M -1 9 l 10 10"), Geometry.Parse("M 0 0 l 10 10"), Geometry.Parse("M 9 -1 l 10 10") })); case FillStyle.Hollow: return(new SolidColorBrush(Colors.Transparent)); case FillStyle.Horizontal: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 0 5 h 10") })); case FillStyle.Solid: return(new SolidColorBrush(brush.Color != null ? brush.Color.ToXaml() : brush.Background != null ? brush.Color.ToXaml() : Colors.Transparent)); case FillStyle.Vertical: return(CreateHatchBrush(brush, 10, 10, new List <Geometry> { Geometry.Parse("M 5 0 l 0 10") })); default: return((brush.Color != null) ? new SolidColorBrush(brush.Color.ToXaml()) : null); } }
private static BitmapImage GetOrCreateBitmapImage(Styles.Brush brush, SymbolCache symbolCache = null) { return(symbolCache != null? symbolCache.GetOrCreate(brush.BitmapId) : BitmapRegistry.Instance.Get(brush.BitmapId).ToBitmapImage()); }