コード例 #1
0
ファイル: DrawingContextFacts.cs プロジェクト: zwcloud/ImGui
        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
ファイル: Util.cs プロジェクト: peter-819/ImGui
        internal static void DrawDrawingVisualToImage(out byte[] imageRawBytes,
                                                      int width, int height, DrawingVisual drawingVisual)
        {
            //convert geometries inside the drawingVisual's content to meshes stored in a MeshList with a BuiltinGeometryRenderer
            MeshList meshList = new MeshList();

            using BuiltinGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer();
            RenderContext renderContext = new RenderContext(geometryRenderer, meshList);

            drawingVisual.RenderContent(renderContext);

            //merge meshes in the MeshList to a MeshBuffer
            MeshBuffer meshBuffer = new MeshBuffer();

            meshBuffer.Clear();
            meshBuffer.Init();
            meshBuffer.Build(meshList);

            //created a mesh IRenderer
            Application.Init();
            var window = Application.PlatformContext.CreateWindow(Point.Zero, new Size(100, 100),
                                                                  WindowTypes.Hidden);
            var renderer = Application.PlatformContext.CreateRenderer() as Win32OpenGLRenderer;//TEMP HACK

            Debug.Assert(renderer != null, nameof(renderer) + " != null");
            renderer.Init(window.Pointer, window.ClientSize);

            //clear the canvas and draw mesh in the MeshBuffer with the mesh renderer
            renderer.Clear(Color.White);
            renderer.StartDrawMeshToImage(width, height);
            imageRawBytes = renderer.DrawMeshToImage(width, height, meshBuffer.ShapeMesh, OpenGLMaterial.shapeMaterial);
            renderer.EndDrawMeshToImage();

            //clear native resources: window and IRenderer
            renderer.ShutDown();
            window.Close();
        }
コード例 #4
0
ファイル: DrawingContextFacts.cs プロジェクト: zwcloud/ImGui
        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));
        }