Esempio n. 1
0
        public void AddText(Point baselineOrigin, IList <GlyphData> glyphs, IList <Vector> offsets, string fontFamily, double fontSize, Color color)
        {
            if (glyphs.Count != offsets.Count)
            {
                throw new ArgumentException($"The length of {nameof(glyphs)} must be equal to {nameof(offsets)}.");
            }

            DrawCommand cmd = new DrawCommand();

            cmd.ClipRect    = ClipRectStack.Peek();
            cmd.TextureData = null;
            this.TextMesh.Commands.Add(cmd);

            var oldIndexBufferCount = this.TextMesh.IndexBuffer.Count;

            var scale = OSImplementation.TypographyTextContext.GetScale(fontFamily, fontSize);

            // get glyph data from typeface
            for (var i = 0; i < glyphs.Count; i++)
            {
                var    glyphData   = glyphs[i];
                Vector glyphOffset = offsets[i];
                this.TextMesh.Append((Vector)baselineOrigin, glyphData, glyphOffset, scale, color, false);
            }

            var newIndexBufferCount = this.TextMesh.IndexBuffer.Count;

            // Update command
            var command = this.TextMesh.Commands[this.TextMesh.Commands.Count - 1];

            command.ElemCount += newIndexBufferCount - oldIndexBufferCount;
            this.TextMesh.Commands[this.TextMesh.Commands.Count - 1] = command;
        }
Esempio n. 2
0
        public override void DrawImage(ITexture texture, Rect rectangle, Point uvMin, Point uvMax)
        {
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

            Color tintColor = Color.White;//TODO define tint color as a brush property

            //add a new draw command
            //TODO check if we need to add a new draw command
            DrawCommand cmd = new DrawCommand();

            cmd.ClipRect    = ClipRectStack.Peek();
            cmd.TextureData = texture;
            this.ImageMesh.CommandBuffer.Add(cmd);

            this.ImageMesh.PrimReserve(6, 4);
            AddImageRect(rectangle, uvMin, uvMax, tintColor);
        }
Esempio n. 3
0
        private bool EnsureDrawCommand()
        {
            var clipRect = ClipRectStack.Peek();

            if (clipRect.IsEmpty)
            {
                //completely clipped
                //no render
                return(false);
            }

            var cmdBuf = this.ShapeMesh.CommandBuffer;

            if (cmdBuf.Count == 0)
            {
                AddCmd();
                return(true);
            }

            var lastCmd = cmdBuf[cmdBuf.Count - 1];

            if (lastCmd.ClipRect != clipRect)
            {
                AddCmd();
                return(true);
            }

            return(true);

            void AddCmd()
            {
                var cmd = new DrawCommand
                {
                    ClipRect    = clipRect,
                    ElemCount   = 0,
                    TextureData = null,
                };

                cmdBuf.Add(cmd);
            }
        }