Esempio n. 1
0
        protected override bool RenderInternal(RenderComposer c)
        {
            if (!base.RenderInternal(c))
            {
                return(false);
            }

            c.SetClipRect(new Rectangle(Position, Size));
            EditorHelpers.RenderToolGrid(c, Position, Size, _calculatedColor, (int)Maths.RoundClosest(DebugGridSize * GetScale()));
            c.SetClipRect(null);

            Vector2 posVec2 = Position.ToVec2();

            c.RenderLine(posVec2 + new Vector2(Size.X / 2, 0), posVec2 + new Vector2(Size.X / 2, Size.Y), Color.White * 0.7f);
            c.RenderLine(posVec2 + new Vector2(0, Size.Y / 2), posVec2 + new Vector2(Size.X, Size.Y / 2), Color.White * 0.7f);
            return(true);
        }
Esempio n. 2
0
        public static void RenderGlyphs(Font font, RenderComposer composer, List <DrawableGlyph> glyphs, Vector3 offset, uint clr, float scale, Rectangle[]?dstRects = null)
        {
            for (var c = 0; c < glyphs.Count; c++)
            {
                DrawableGlyph atlasGlyph = glyphs[c];
                FontGlyph     fontGlyph  = atlasGlyph.FontGlyph;

                Rectangle dst = dstRects != null ? dstRects[c] : atlasGlyph.GlyphUV;
                if (CLIP_GLYPH_TEXTURES)
                {
                    composer.SetClipRect(dst);
                }

                float   baseline       = font.Descender * scale;
                Vector3 atlasRenderPos = (dst.Position - new Vector2(atlasGlyph.XBearing, baseline)).ToVec3();
                atlasRenderPos += offset;
                composer.PushModelMatrix(Matrix4x4.CreateScale(scale, scale, 1) * Matrix4x4.CreateTranslation(atlasRenderPos));

                // Count vertices.
                GlyphDrawCommand[]? commands = fontGlyph.Commands;
                if (commands == null)
                {
                    continue;
                }

                var verticesCount = 0;
                for (var v = 0; v < commands.Length; v++)
                {
                    GlyphDrawCommand currentCommand = commands[v];
                    if (currentCommand.Type != GlyphDrawCommandType.Move)
                    {
                        verticesCount++;
                    }
                }

                // Draw lines between all vertex points.
                Span <VertexData> lines = composer.RenderStream.GetStreamMemory((uint)(verticesCount * 3), BatchMode.SequentialTriangles);
                for (var j = 0; j < lines.Length; j++)
                {
                    lines[j].UV    = Vector2.Zero;
                    lines[j].Color = clr;
                }

                Vector3 prevPos             = Vector3.Zero;
                int     currentContourStart = -1;
                var     currentVertIdx      = 0;
                for (var i = 0; i < commands.Length; i++)
                {
                    GlyphDrawCommand currentCommand = commands[i];
                    if (currentContourStart == -1)
                    {
                        currentContourStart = i;
                    }
                    if (currentCommand.Type != GlyphDrawCommandType.Move)
                    {
                        Vector3 currentVertPos = currentCommand.P0.ToVec3();

                        if (currentCommand.Type == GlyphDrawCommandType.Close)
                        {
                            GlyphDrawCommand startingVert = commands[currentContourStart];
                            currentVertPos      = startingVert.P0.ToVec3();
                            currentContourStart = -1;
                        }

                        lines[currentVertIdx].Vertex = Vector3.Zero;
                        currentVertIdx++;
                        lines[currentVertIdx].Vertex = currentVertPos;
                        currentVertIdx++;
                        lines[currentVertIdx].Vertex = prevPos;
                        currentVertIdx++;
                    }

                    prevPos = currentCommand.P0.ToVec3();
                }

                // Draw curves. These will flip pixels in the curve approximations from above.
                for (var i = 0; i < commands.Length; i++)
                {
                    GlyphDrawCommand currentCommand = commands[i];
                    if (currentCommand.Type == GlyphDrawCommandType.Curve)
                    {
                        Span <VertexData> memory = composer.GetStreamedQuadraticCurveMesh(prevPos, currentCommand.P0.ToVec3(), currentCommand.P1.ToVec3());
                        for (var j = 0; j < memory.Length; j++)
                        {
                            memory[j].UV    = Vector2.Zero;
                            memory[j].Color = clr;
                        }
                    }

                    prevPos = currentCommand.P0.ToVec3();
                }

                composer.PopModelMatrix();
                if (CLIP_GLYPH_TEXTURES)
                {
                    composer.SetClipRect(null);
                }
            }
        }