示例#1
0
        public void PopulateDrawingVisual()
        {
            void Populate(DrawingContext drawingContext)
            {
                drawingContext.DrawLine(new Pen(Color.Red, 4), new Point(10, 20), new Point(100, 60));
                drawingContext.DrawLine(new Pen(Color.Blue, 4), new Point(60, 100), new Point(20, 10));
                drawingContext.DrawRectangle(new Brush(Color.Aqua), new Pen(Color.Black, 3),
                                             new Rect(new Point(30, 30), new Point(80, 80)));
            }

            //write records into visual's content
            var visual  = new DrawingVisual(1);
            var context = visual.RenderOpen();

            Populate(context);
            context.Close();

            //write records into ContentChecker
            var checker = new ContentChecker();

            Populate(checker);

            //read records from visual to checker and compare
            checker.StartCheck();
            visual.RenderContent(new RenderContext(checker, null));
        }
示例#2
0
        public void PopulateDrawingVisualWithGlyphRun()
        {
            throw new System.Exception("DrawGlyphRun methods should be unified to a single one:" +
                                       "void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun);" +
                                       "Another overload should be removed," +
                                       "and the text layout/hittest algorithm should be extracted to a proper place");

            void Populate(DrawingContext drawingContext)
            {
                drawingContext.DrawGlyphRun(new Brush(Color.Black),
                                            new GlyphRun("啊rABC", GUIStyle.Default.FontFamily, 24, FontStyle.Normal, FontWeight.Normal));
            }

            //write records into visual's content
            var visual  = new DrawingVisual(1);
            var context = visual.RenderOpen();

            Populate(context);
            context.Close();

            //write records into ContentChecker
            var checker = new ContentChecker();

            Populate(checker);

            //read records from visual to checker and compare
            checker.StartCheck();
            visual.RenderContent(new RenderContext(checker, null));
        }
示例#3
0
            public void DrawABoxModelWithImageContent()
            {
                Node node = new Node(1, "imageNode", new Rect(10, 10, 300, 200));
                StyleRuleSetBuilder ruleSetBuilder = new StyleRuleSetBuilder(node.RuleSet);

                ruleSetBuilder
                .Border((5, 10, 5, 10))
                .BorderColor(Color.HotPink)
                .Padding((4, 2, 4, 2));
                node.UseBoxModel = true;

                var texture = new FakeTexture();

                texture.LoadImage(@"assets\images\logo.png");

                void Populate(DrawingContext dc, ImGui.OSAbstraction.Graphics.ITexture t, StyleRuleSet rule, Rect r)
                {
                    dc.DrawBoxModel(t, rule, r);
                }

                var context = node.RenderOpen();

                Populate(context, texture, node.RuleSet, node.Rect);
                context.Close();

                //write records into ContentChecker
                var checker = new ContentChecker();

                Populate(checker, texture, node.RuleSet, node.Rect);

                //read records from visual to checker and compare
                checker.StartCheck();
                node.RenderContent(new RenderContext(checker, null));
            }
示例#4
0
            public void DrawABoxModelWithTextContent()
            {
                void Populate(DrawingContext dc, string t, StyleRuleSet rule, Rect r)
                {
                    dc.DrawBoxModel(t, rule, r);
                }

                var node                = new Node(1, new Rect(10, 10, 300, 60));
                var styleRuleSet        = new StyleRuleSet();
                var styleRuleSetBuilder = new StyleRuleSetBuilder(styleRuleSet);

                styleRuleSetBuilder
                .BackgroundColor(Color.White)
                .Border((1, 3, 1, 3))
                .BorderColor(Color.Black)
                .Padding((10, 5, 10, 5));
                const string text = "啊rABC";

                var context = node.RenderOpen();

                Populate(context, text, styleRuleSet, node.Rect);
                context.Close();

                //write records into ContentChecker
                var checker = new ContentChecker();

                Populate(checker, text, styleRuleSet, node.Rect);

                //read records from visual to checker and compare
                checker.StartCheck();
                node.RenderContent(new RenderContext(checker, null));
            }
示例#5
0
            public void DrawWithClipRect()
            {
                var node = new Node(1, new Rect(20, 20, 200, 200));

                void Populate(DrawingContext dc)
                {
                    dc.PushClip(new RectangleGeometry(new Rect(0, 0, 200, 200)));
                    dc.DrawLine(node.RuleSet, new Point(1, 1), new Point(1000, 1000));
                    dc.PushClip(new RectangleGeometry(new Rect(0, 0, 100, 100)));
                    dc.DrawLine(node.RuleSet, new Point(1000, 1), new Point(1, 1000));
                    dc.Pop();
                    dc.Pop();
                }

                var context = node.RenderOpen();

                Populate(context);
                context.Close();

                //write records into ContentChecker
                var checker = new ContentChecker();

                Populate(checker);

                //read records from visual to checker and compare with node's content
                checker.StartCheck();
                node.RenderContent(new RenderContext(checker, null));
            }
示例#6
0
        public void PopulateNodeWithStyle()
        {
            void Populate(DrawingContext drawingContext, Node n)
            {
                drawingContext.DrawRectangle(n.RuleSet, new Rect(new Point(30, 30), new Point(80, 80)));
            }

            var node = new Node(1, new Rect(10, 20, 300, 60));

            node.RuleSet.StrokeColor = Color.Black;
            node.RuleSet.StrokeWidth = 4;
            node.RuleSet.FillColor   = Color.Green;
            node.RuleSet.Set(StylePropertyName.FillColor, Color.Red, GUIState.Hover);

            {
                node.State = GUIState.Normal;
                var context = node.RenderOpen();
                Populate(context, node);
                context.Close();

                //write records into ContentChecker
                var checker = new ContentChecker();
                Populate(checker, node);

                //read records from visual to checker and compare
                checker.StartCheck();
                node.RenderContent(new RenderContext(checker, null));
            }

            {
                node.State = GUIState.Hover;
                var context = node.RenderOpen();
                Populate(context, node);
                context.Close();

                //write records into ContentChecker
                var checker = new ContentChecker();
                Populate(checker, node);

                //read records from visual to checker and compare
                checker.StartCheck();
                node.RenderContent(new RenderContext(checker, null));
            }
        }
示例#7
0
            public void DrawABoxModelWithDifferentBorder()
            {
                var node = new Node(1, new Rect(20, 20, 200, 80));

                node.RuleSet.Border      = (10, 20, 30, 40);
                node.RuleSet.BorderColor = (Color.Red, Color.DarkGreen, Color.DeepSkyBlue, Color.YellowGreen);

                var context = node.RenderOpen();

                context.DrawBoxModel(node.RuleSet, node.Rect);
                context.Close();

                //write records into ContentChecker
                var checker = new ContentChecker();

                checker.DrawBoxModel(node.RuleSet, node.Rect);

                //read records from visual to checker and compare
                checker.StartCheck();
                node.RenderContent(new RenderContext(checker, null));
            }
示例#8
0
            public void DrawABoxModelWithRoundBorder()
            {
                var node = new Node(1, new Rect(20, 20, 200, 200));

                node.RuleSet.Border          = (top : 20, right : 30, bottom : 20, left : 40);
                node.RuleSet.BorderColor     = (Color.Red, Color.DarkGreen, Color.DeepSkyBlue, Color.Black);
                node.RuleSet.BorderRadius    = (TopLeft : 50, TopRight : 40, BottomRight : 20, BottomLeft : 30);
                node.RuleSet.BackgroundColor = Color.AliceBlue;

                var context = node.RenderOpen();

                context.DrawBoxModel(node.RuleSet, node.Rect);
                context.Close();

                //write records into ContentChecker
                var checker = new ContentChecker();

                checker.DrawBoxModel(node.RuleSet, node.Rect);

                //read records from visual to checker and compare
                checker.StartCheck();
                node.RenderContent(new RenderContext(checker, null));
            }
示例#9
0
        public void PopulateNode()
        {
            var geometry = new PathGeometry();
            var figure   = new PathFigure();

            figure.StartPoint = new Point(5, 90);
            figure.Segments.Add(new LineSegment(new Point(125, 0), true));
            figure.Segments.Add(new LineSegment(new Point(245, 90), true));
            figure.Segments.Add(new LineSegment(new Point(200, 230), true));
            figure.Segments.Add(new LineSegment(new Point(52, 230), true));
            figure.Segments.Add(new LineSegment(new Point(5, 90), true));
            geometry.Figures.Add(figure);
            GlyphRun glyphRun = new GlyphRun(Point.Zero, "123", GUIStyle.Default.FontFamily, 20);

            void Populate(DrawingContext drawingContext)
            {
                drawingContext.DrawGeometry(new Brush(Color.BlueViolet), new Pen(Color.Black, 4), geometry);
                drawingContext.DrawRectangle(new Brush(Color.YellowGreen), new Pen(Color.Cornsilk, 4), new Rect(100, 100, 50, 50));
                drawingContext.DrawGlyphRun(new Brush(Color.Red), glyphRun);
            }

            var node    = new Node(1, new Rect(10, 20, 300, 60));
            var context = node.RenderOpen();

            Populate(context);
            context.Close();

            //write records into ContentChecker
            var checker = new ContentChecker();

            Populate(checker);

            //read records from visual to checker and compare
            checker.StartCheck();
            node.RenderContent(new RenderContext(checker, null));
        }
示例#10
0
        public void PopulateDrawingVisualWithFormattedText()
        {
            void Populate(DrawingContext drawingContext)
            {
                drawingContext.DrawText(new Brush(Color.Black),
                                        new FormattedText(Point.Zero, "啊rABC", GUIStyle.Default.FontFamily, 24));
            }

            //write records into visual's content
            var visual  = new DrawingVisual(1);
            var context = visual.RenderOpen();

            Populate(context);
            context.Close();

            //write records into ContentChecker
            var checker = new ContentChecker();

            Populate(checker);

            //read records from visual to checker and compare
            checker.StartCheck();
            visual.RenderContent(new RenderContext(checker, null));
        }