Example #1
0
        public SimpleD3D11Renderer(ID3D11Context context, BrushCache brushCache, TextFormatCache textFormatCache)
        {
            this.context = context;

            this.brushCache      = brushCache;
            this.textFormatCache = textFormatCache;
        }
Example #2
0
        void MakePen()
        {
            SolidColorBrush brush = BrushCache.GetBrush(Colour);

            pen = new Pen(brush, Thickness);
            pen.Freeze();
        }
Example #3
0
 public static XamlBrush MapsuiBrushToXaml(Styles.Brush brush, BrushCache brushCache = null)
 {
     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;
     }
 }
Example #4
0
        public static XamlShapes.Shape RenderPoint(Point point, IStyle style, IViewport viewport,
            BrushCache brushCache = null)
        {
            XamlShapes.Shape symbol;
            var matrix = XamlMedia.Matrix.Identity;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;

                if (symbolStyle.BitmapId < 0)
                    symbol = CreateSymbolFromVectorStyle(symbolStyle, symbolStyle.Opacity, symbolStyle.SymbolType);
                else
                    symbol = CreateSymbolFromBitmap(symbolStyle.BitmapId, symbolStyle.Opacity, brushCache);
                matrix = CreatePointSymbolMatrix(viewport.Resolution, symbolStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle((style as VectorStyle) ?? new VectorStyle());
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }

            MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(point, viewport));

            symbol.RenderTransform = new XamlMedia.MatrixTransform {Matrix = matrix};
            symbol.IsHitTestVisible = false;

            return symbol;
        }
Example #5
0
 public D3D11Renderer(ID3D11Context context, BrushCache brushCache, TextFormatCache textFormatCache, D3D11TextureManager9 textureManager)
 {
     this.context         = context;
     this.brushCache      = brushCache;
     this.textFormatCache = textFormatCache;
     this.textureManager  = textureManager;
     context.Draw        += this.OnDraw;
 }
Example #6
0
        public SolidColorBrush GetBrush(string name)
        {
            InitAliasColorMappings();

            var mapping = _aliasToColorMapping[name];

            return(BrushCache.GetBrush(mapping.Color));
        }
Example #7
0
        void ShowWatermark()
        {
            if (string.IsNullOrEmpty(Text) && !string.IsNullOrEmpty(Watermark))
            {
                isWatermarked = true;

                //save the existing binding so it can be restored
                textBinding = BindingOperations.GetBinding(this, TextProperty);

                //blank out the existing binding so we can throw in our Watermark
                BindingOperations.ClearBinding(this, TextProperty);

                //set the signature watermark gray
                Foreground = BrushCache.GetBrush(Colors.LightGray);

                //display our watermark text
                Text = Watermark;
            }
        }
Example #8
0
        public object?Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            // For a more sophisticated converter, check also the targetType and react accordingly..
            if (value is Color color)
            {
                return(BrushCache.GetBrush(color));
            }

            // Could support more source types if wish

            Type type = value.GetType();

            throw new InvalidOperationException("Unsupported type [" + type.Name + "]");
        }
        public NodeControl()
        {
            InitializeComponent();

            // set the default handler for adding edges
            edgeAddingHandler = delegate(NodeBase from, NodeBase to)
            {
                EdgeBase edge = new Edge(from, to);
                myCanvas.AddEdge(edge);
            };

            newEdgePen = new Pen(BrushCache.GetBrush(Colors.White), 3);
            newEdgePen.Freeze();
            marqueePen = new Pen(BrushCache.GetBrush(Colors.White), 3);
            marqueePen.Freeze();
            marqueeFill = BrushCache.GetBrush(Color.FromArgb(50, 255, 255, 255));

            ResetView();
        }
Example #10
0
        internal void Render(Graphics Device)
        {
            Executor_.SetDevice(Device);
            WinConvert.SetDevice(Device);

            LGui.Begin();

            if (DemoIndex_ != -1)
            {
                DemoList_[DemoIndex_].Render();
            }
            else
            {
                Device.FillRectangle(BrushCache.GetOrCreate(LGuiColor.Red), 0, 0, WinSize.X, WinSize.Y);
            }

            LGui.End();

            Device.DrawString($"DrawCall : {LGui.GetDrawCall()}", TextFont_, Brushes.White, 800, 520);
        }
Example #11
0
        public SolidColorBrush GetBrush(string name)
        {
            InitAliasColorMappings();

            if (string.IsNullOrEmpty(name))
            {
                // Default color for example the unused space in knowledge loss
                return(DefaultDrawingPrimitives.DefaultBrush);
            }

            if (_aliasToColorMapping.ContainsKey(name) is false)
            {
                // A developer name is not known! This should not happen.
                Debug.WriteLine($"No color mapping found for developer {name}");
                return(Brushes.Black);
            }
            var mapping = _aliasToColorMapping[name];

            return(BrushCache.GetBrush(mapping.Color));
        }
Example #12
0
        private RectangleF DrawStringPart(CharacterRange range, Graphics g, string str, Style style, float offset)
        {
            string part = str.Substring(range.First, range.Length);

            UpdateTabStop(part, style);

            RectangleF size = MeasureStringPart(range, g, str, style);

            if (!style.Background.IsEmpty)
            {
                RectangleF textRect = size;
                textRect.X = 0;
                textRect.Offset(offset, 0);
                g.FillRectangle(BrushCache.getSolid(style.Background), textRect);
            }

            g.DrawString(part, FontCache.get(style), BrushCache.getForeground(style), offset, 0, stringFormat);

            return(size);
        }
Example #13
0
        public SimpleRenderer()
        {
            switch (Drawing.RenderMode)
            {
            case RenderMode.Dx9:
            {
                var context = new D3D9Context();
                var font    = new FontCache(context);
                this.active = new SimpleD3D9Renderer(context, font);
                break;
            }

            case RenderMode.Dx11:
            {
                var context = new D3D11Context();
                var brush   = new BrushCache(context);
                var text    = new TextFormatCache(context);
                this.active = new SimpleD3D11Renderer(context, brush, text);
                break;
            }
            }
        }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NeovimControl"/> class.
        /// </summary>
        /// <param name="parent">The parent control.</param>
        /// <param name="neovimClient">the neovim client.</param>
        public NeovimControl(IElement parent, NeovimClient.NeovimClient neovimClient)
            : base(parent)
        {
            this.neovimClient              = neovimClient;
            this.neovimClient.Redraw      += this.Invalidate;
            this.neovimClient.FontChanged += this.OnFontChanged;

            this.textAnalyzer        = new DWrite.TextAnalyzer(this.factoryDWrite);
            this.cursorEffects       = new CursorEffects(this.DeviceContext);
            this.brushCache          = new BrushCache();
            this.scriptAnalysesCache = new ScriptAnalysesCache();
            this.fontCache           = new FontCache(this.factoryDWrite);

            this.textParam = new TextLayoutParameters(
                this.factoryDWrite,
                "Consolas",
                11,
                false,
                false,
                false,
                false,
                this.Factory.DesktopDpi);
        }
Example #15
0
        public MyCanvas()
        {
            IsHitTestVisible = false;

            TransformGroup transforms = new TransformGroup();

            transforms.Children.Add(translate);
            transforms.Children.Add(scale);

            //RenderTransformOrigin = new Point(0.5, 0.5);
            RenderTransform = transforms;

            quadTree = new QuadTree();
            Physics  = new ForceDirectedPhysics();

            whiteBrush = BrushCache.GetBrush(Colors.White);
            fontColour = BrushCache.GetBrush(Colors.White);

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(16);
            timer.Tick    += timer_Tick;
            timer.Start();

            Thread physicsThread = new Thread(RunPhysics);

            physicsThread.IsBackground = true;
            //physicsThread.Start();

            SizeChanged += MyCanvas_SizeChanged;
        }
Example #16
0
 public static Media.Brush ToXaml(this Brush brush, BrushCache brushCache = null)
 {
     return(StyleConverter.MapsuiBrushToXaml(brush, brushCache));
 }
Example #17
0
 public static Media.Brush ToXaml(this Brush brush, BrushCache brushCache = null)
 {
     return StyleConverter.MapsuiBrushToXaml(brush, brushCache);
 }
Example #18
0
 private static ImageBrush CreateImageBrush(Styles.Brush brush, BrushCache brushCache = null)
 {
     return brushCache != null ? brushCache.GetImageBrush(brush.BitmapId, CreateImageBrush) : CreateImageBrush(BitmapRegistry.Instance.Get(brush.BitmapId));
 }
Example #19
0
        public static XamlShapes.Shape RenderPolygon(Polygon polygon, IStyle style, IViewport viewport, BrushCache brushCache = null)
        {
            if (!(style is VectorStyle)) throw new ArgumentException("Style is not of type VectorStyle");
            var vectorStyle = style as VectorStyle;

            XamlShapes.Path path = CreatePolygonPath(vectorStyle, viewport.Resolution, brushCache);
            path.Data = polygon.ToXaml();

            var matrixTransform = new XamlMedia.MatrixTransform { Matrix = CreateTransformMatrix1(viewport) };
            path.RenderTransform = matrixTransform;

            if (path.Fill != null)
                path.Fill.Transform = matrixTransform.Inverse as XamlMedia.MatrixTransform;
            path.UseLayoutRounding = true;
            return path;
        }
Example #20
0
        private static Canvas RenderVectorLayer(IViewport viewport, ILayer layer, bool rasterizing = false)
        {
            // todo:
            // find solution for try catch. Sometimes this method will throw an exception
            // when clearing and adding features to a layer while rendering
            var canvas = new Canvas
            {
                Opacity = layer.Opacity,
                IsHitTestVisible = false
            };

            try
            {
                var features = layer.GetFeaturesInView(viewport.Extent, viewport.RenderResolution).ToList();
                var layerStyles = BaseLayer.GetLayerStyles(layer);
                var brushCache = new BrushCache();

                foreach (var layerStyle in layerStyles)
                {
                    var style = layerStyle; // This is the default that could be overridden by an IThemeStyle

                    foreach (var feature in features)
                    {
                        if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
                        if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) ||
                            (style.MaxVisible < viewport.Resolution)) continue;

                        RenderFeature(viewport, canvas, feature, style, rasterizing, brushCache);
                    }
                }

                foreach (var feature in features)
                {
                    var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
                    foreach (var style in styles)
                        if ((feature.Styles != null) && style.Enabled)
                            RenderFeature(viewport, canvas, feature, style, rasterizing, brushCache);
                }

                return canvas;
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, "Unexpected error in renderer", ex);
                return canvas;
                // If exception happens inside RenderFeature function after
                // at -least one child has been added to the canvas,
                // returning new canvas will leave the previously created (but
                // not yet added to parent canvas) canvas abandoned, that will
                // cause the exception when resuing RenderedGeometry object, because
                // at -least one RenderedGeometry was attached to that abandoned canvas.
                // returning the same canvas will solve this error, as it will
                // be clear this canvas childs on next render call.
                // return new Canvas { IsHitTestVisible = false };
            }
        }
Example #21
0
 private static Shape RenderGeometry(IViewport viewport, IStyle style, IFeature feature,
     BrushCache brushCache = null)
 {
     if (feature.Geometry is Geometries.Point)
         return PointRenderer.RenderPoint(feature.Geometry as Geometries.Point, style, viewport, brushCache);
     if (feature.Geometry is MultiPoint)
         return GeometryRenderer.RenderMultiPoint(feature.Geometry as MultiPoint, style, viewport);
     if (feature.Geometry is LineString)
         return GeometryRenderer.RenderLineString(feature.Geometry as LineString, style, viewport);
     if (feature.Geometry is MultiLineString)
         return GeometryRenderer.RenderMultiLineString(feature.Geometry as MultiLineString, style, viewport);
     if (feature.Geometry is Polygon)
         return GeometryRenderer.RenderPolygon(feature.Geometry as Polygon, style, viewport, brushCache);
     if (feature.Geometry is MultiPolygon)
         return GeometryRenderer.RenderMultiPolygon(feature.Geometry as MultiPolygon, style, viewport);
     if (feature.Geometry is IRaster)
         return GeometryRenderer.RenderRaster(feature.Geometry as IRaster, style, viewport);
     return null;
 }
Example #22
0
        private static void RenderFeature(IViewport viewport, Canvas canvas, IFeature feature, IStyle style,
            bool rasterizing, BrushCache brushCache = null)
        {
            if (style is LabelStyle)
            {
                var labelStyle = (LabelStyle) style;
                canvas.Children.Add(SingleLabelRenderer.RenderLabel(feature.Geometry.GetBoundingBox().GetCentroid(),
                    labelStyle, viewport, labelStyle.GetLabelText(feature)));
            }
            else
            {
                var renderedGeometry = feature.RenderedGeometry.ContainsKey(style)
                    ? feature.RenderedGeometry[style] as Shape
                    : null;
                if (renderedGeometry == null)
                {
                    renderedGeometry = RenderGeometry(viewport, style, feature, brushCache);
                    if (!rasterizing) feature.RenderedGeometry[style] = renderedGeometry;
                }
                else
                {
                    PositionGeometry(renderedGeometry, viewport, style, feature);
                }

                if (!canvas.Children.Contains(renderedGeometry))
                    // Adding twice can happen when a single feature has two identical styles
                    canvas.Children.Add(renderedGeometry);
            }
        }
Example #23
0
        private static XamlShapes.Path CreatePolygonPath(VectorStyle style, double resolution, BrushCache brushCache = null)
        {
            var path = new XamlShapes.Path();

            if (style.Outline != null)
            {
                path.Stroke = new XamlMedia.SolidColorBrush(style.Outline.Color.ToXaml());
                path.StrokeThickness = style.Outline.Width * resolution;
                path.StrokeDashArray = style.Outline.PenStyle.ToXaml();
                path.Tag = style.Outline.Width; // see #linewidthhack
            }

            path.Fill = style.Fill.ToXaml(brushCache);
            path.IsHitTestVisible = false;
            return path;
        }
Example #24
0
 static GraphItem()
 {
     highlightBrush = BrushCache.GetBrush(Color.FromArgb(150, 255, 255, 0));
 }
Example #25
0
        private static XamlShapes.Shape CreateSymbolFromBitmap(int bmpId, double opacity, BrushCache brushCache = null)
        {
            XamlMedia.ImageBrush imageBrush;

            if (brushCache == null)
            {
                var data = BitmapRegistry.Instance.Get(bmpId);
                var bitmapImage = data.CreateBitmapImage();
                imageBrush = new XamlMedia.ImageBrush {ImageSource = bitmapImage};
            }
            else
            {
                imageBrush = brushCache.GetImageBrush(bmpId);
            }

            // note: It probably makes more sense to use PixelWith here:
            var width = imageBrush.ImageSource.Width;
            var height = imageBrush.ImageSource.Height;

            var path = new XamlShapes.Path
            {
                Data = new XamlMedia.RectangleGeometry
                {
                    Rect = new Rect(-width*0.5, -height*0.5, width, height)
                },
                Fill = imageBrush,
                Opacity = opacity
            };

            return path;
        }
Example #26
0
 protected override void OnColourChanged()
 {
     brush = BrushCache.GetBrush(Colour);
 }
Example #27
0
 private void UpdateText()
 {
     formattedText = new FormattedText("text!", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Helvetica"), 12, BrushCache.GetBrush(Colors.White));
 }