Ejemplo n.º 1
0
        spriteRect trect = new spriteRect();//ness

        //绘制字体,只画一行,字体沿着左上角对齐,如需其他,参考源码自制
        public void drawText(string font, string text, spriteRect rect, spriteColor color = null, spriteColor color2 = null)
        {
            if (color == null)
            {
                color = spriteColor.white;
            }
            if (color2 == null)
            {
                color2 = spriteColor.black;
            }
            var f = fontMgr.Instance().load(this.webgl, font);

            if (f == null)
            {
                return;
            }
            if (f.cmap == Script.Undefined)
            {
                return;
            }
            float xadd = 0;

            for (var i = 0; i < text.Length; i++)
            {
                var c     = text.CharAt(i);
                var cinfo = f.cmap[c] as charinfo;
                if (cinfo == Script.Undefined)
                {
                    continue;
                }
                var s = rect.h / f.lineHeight;

                this.trect.x = rect.x + xadd + cinfo.xOffset * s;//xadd 横移,cinfo.xOffset * s 偏移

                this.trect.y = rect.y - cinfo.yOffset * s + f.baseline * s;
                //cinfo.yOffset * s 偏移
                //f.baseline * s字体基线,不管字体基线字体的零零点在字体左下角,现在需要左上脚,需要其他对齐方式另说


                this.trect.h = s * cinfo.ySize;
                this.trect.w = s * cinfo.xSize;

                xadd += (cinfo.xAddvance * s);
                if (xadd >= rect.w)
                {
                    break;//超出绘制限定框,不画了
                }
                f.draw(this.spriteBatcher, cinfo, this.trect, color, color2);
            }
        }
Ejemplo n.º 2
0
        public void drawSprite9Custom(string atlas, string sprite, spriteMat _mat, spriteRect rect, spriteBorder border, spriteColor color = null, spriteColor color2 = null)
        {
            if (color == null)
            {
                color = spriteColor.white;
            }
            if (color2 == null)
            {
                color2 = spriteColor.white;
            }
            var a = atlasMgr.Instance().load(this.webgl, atlas);

            if (a == null)
            {
                return;
            }
            var _r = a.sprites[sprite];

            if (_r == Script.Undefined)
            {
                return;
            }

            var l = (border.l - 1) / a.texturewidth;
            var r = (border.r - 1) / a.texturewidth;
            var t = (border.t - 1) / a.textureheight;
            var b = (border.b - 1) / a.textureheight;

            //left top
            this.uvrect.x = _r.x;
            this.uvrect.y = _r.y;
            this.uvrect.w = l;
            this.uvrect.h = t;

            this.trect.x = rect.x;
            this.trect.y = rect.y;
            this.trect.w = border.l;
            this.trect.h = border.t;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);

            //top
            this.uvrect.x = _r.x + l;
            this.uvrect.y = _r.y;
            this.uvrect.w = _r.w - r - l;
            this.uvrect.h = t;

            this.trect.x = rect.x + border.l;
            this.trect.y = rect.y;
            this.trect.w = rect.w - border.r - border.l;
            this.trect.h = border.t;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);
            //right top
            this.uvrect.x = _r.x + _r.w - r;
            this.uvrect.y = _r.y;
            this.uvrect.w = r;
            this.uvrect.h = t;

            this.trect.x = rect.x + rect.w - border.r;
            this.trect.y = rect.y;
            this.trect.w = border.r;
            this.trect.h = border.t;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);
            //left
            this.uvrect.x = _r.x;
            this.uvrect.y = _r.y + t;
            this.uvrect.w = l;
            this.uvrect.h = _r.h - t - b;

            this.trect.x = rect.x;
            this.trect.y = rect.y + border.t;
            this.trect.w = border.l;
            this.trect.h = rect.h - border.t - border.b;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);
            //center
            this.uvrect.x = _r.x + l;
            this.uvrect.y = _r.y + t;
            this.uvrect.w = _r.w - r - l;
            this.uvrect.h = _r.h - t - b;

            this.trect.x = rect.x + border.l;
            this.trect.y = rect.y + border.t;
            this.trect.w = rect.w - border.r - border.l;
            this.trect.h = rect.h - border.t - border.b;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);
            //right
            this.uvrect.x = _r.x + _r.w - r;
            this.uvrect.y = _r.y + t;
            this.uvrect.w = r;
            this.uvrect.h = _r.h - t - b;

            this.trect.x = rect.x + rect.w - border.r;
            this.trect.y = rect.y + border.t;
            this.trect.w = border.r;
            this.trect.h = rect.h - border.t - border.b;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);

            //left bottom
            this.uvrect.x = _r.x;
            this.uvrect.y = _r.h + _r.y - b;
            this.uvrect.w = l;
            this.uvrect.h = b;

            this.trect.x = rect.x;
            this.trect.y = rect.y + rect.h - border.b;
            this.trect.w = border.l;
            this.trect.h = border.b;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);
            //bottom
            this.uvrect.x = _r.x + l;
            this.uvrect.y = _r.h + _r.y - b;
            this.uvrect.w = _r.w - r - l;
            this.uvrect.h = b;

            this.trect.x = rect.x + border.l;
            this.trect.y = rect.y + rect.h - border.b;
            this.trect.w = rect.w - border.r - border.l;
            this.trect.h = border.b;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);
            //right bottom
            this.uvrect.x = _r.x + _r.w - r;
            this.uvrect.y = _r.h + _r.y - b;
            this.uvrect.w = r;
            this.uvrect.h = b;
            this.trect.x  = rect.x + rect.w - border.r;
            this.trect.y  = rect.y + rect.h - border.b;
            this.trect.w  = border.r;
            this.trect.h  = border.b;
            a.texture.drawCustom(this.spriteBatcher, _mat, this.uvrect, this.trect, color, color2);
        }
Ejemplo n.º 3
0
 //draw tools
 public void drawTexture(spriteTexture texture, spriteRect rect, spriteRect uvrect, spriteColor color = null)
 {
     //if (uvrect == null)
     //    uvrect = spriteRect.one;
     if (color == null)
     {
         color = spriteColor.white;
     }
     texture.draw(this.spriteBatcher, uvrect, rect, color);
 }
Ejemplo n.º 4
0
        public void drawChar(spriteBatcher sb, string cname, spriteRect rect, spriteColor c = null, spriteColor colorBorder = null)
        {
            var r = this.cmap[cname];

            if (r == Script.Undefined)
            {
                return;
            }
            if (c == null)
            {
                c = spriteColor.white;
            }
            if (colorBorder == null)
            {
                colorBorder = new spriteColor(0f, 0f, 0f, 0.5f);
            }
            {
                var p = this.pointbuf[0];
                p.x  = rect.x; p.y = rect.y; p.z = 0;
                p.u  = r.x; p.v = r.y;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;

                p    = this.pointbuf[1];
                p.x  = rect.x + rect.w; p.y = rect.y; p.z = 0;
                p.u  = r.x + r.w; p.v = r.y;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;

                p    = this.pointbuf[2];
                p.x  = rect.x; p.y = rect.y + rect.h; p.z = 0;
                p.u  = r.x; p.v = r.y + r.h;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;

                p    = this.pointbuf[3];
                p.x  = rect.x + rect.w; p.y = rect.y + rect.h; p.z = 0;
                p.u  = r.x + r.w; p.v = r.y + r.h;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;
            }
            sb.setMat(this.mat);
            sb.addRect(this.pointbuf);
        }
Ejemplo n.º 5
0
        public void draw(spriteBatcher sb, charinfo r, spriteRect rect, spriteColor c = null, spriteColor colorBorder = null)
        {
            if (c == null)
            {
                c = spriteColor.white;
            }
            if (colorBorder == null)
            {
                colorBorder = new spriteColor(0f, 0f, 0f, 0.5f);
            }
            //if (r==null)
            {
                var p = this.pointbuf[0];
                p.x  = rect.x; p.y = rect.y + rect.h; p.z = 0;
                p.u  = r.x; p.v = r.y + r.h;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;

                p    = this.pointbuf[1];
                p.x  = rect.x + rect.w; p.y = rect.y + rect.h; p.z = 0;
                p.u  = r.x + r.w; p.v = r.y + r.h;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;

                p    = this.pointbuf[2];
                p.x  = rect.x; p.y = rect.y; p.z = 0;
                p.u  = r.x; p.v = r.y;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;

                p    = this.pointbuf[3];
                p.x  = rect.x + rect.w; p.y = rect.y; p.z = 0;
                p.u  = r.x + r.w; p.v = r.y;
                p.r  = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
                p.r2 = colorBorder.r; p.g2 = colorBorder.g; p.b2 = colorBorder.b; p.a2 = colorBorder.a;
            }
            sb.setMat(this.mat);
            sb.addRect(this.pointbuf);
        }
Ejemplo n.º 6
0
        public void drawCustom(spriteBatcher spriteBatcher, spriteMat _mat, spriteRect uv, spriteRect rect, spriteColor c, spriteColor c2)
        {
            _mat.tex0 = this;
            {
                var p = this.pointbuf[0];
                p.x = rect.x; p.y = rect.y; p.z = 0;
                p.u = uv.x; p.v = uv.y;
                p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a;

                p   = this.pointbuf[1];
                p.x = rect.x + rect.w; p.y = rect.y; p.z = 0;
                p.u = uv.x + uv.w; p.v = uv.y;
                p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a;

                p   = this.pointbuf[2];
                p.x = rect.x; p.y = rect.y + rect.h; p.z = 0;
                p.u = uv.x; p.v = uv.y + uv.h;
                p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a;

                p   = this.pointbuf[3];
                p.x = rect.x + rect.w; p.y = rect.y + rect.h; p.z = 0;
                p.u = uv.x + uv.w; p.v = uv.y + uv.h;
                p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a;
            }
            spriteBatcher.setMat(_mat);
            spriteBatcher.addRect(this.pointbuf);
        }
Ejemplo n.º 7
0
        public void drawSpriteCustom(string atlas, string sprite, spriteMat _mat, spriteRect rect, spriteColor color = null, spriteColor color2 = null)
        {
            if (color == null)
            {
                color = spriteColor.white;
            }
            if (color2 == null)
            {
                color2 = spriteColor.white;
            }
            var a = atlasMgr.Instance().load(this.webgl, atlas);

            if (a == null)
            {
                return;
            }
            var r = a.sprites[sprite];

            if (r == Script.Undefined)
            {
                return;
            }
            if (a.texture == null)
            {
                return;
            }

            a.texture.drawCustom(this.spriteBatcher, _mat, r.ToRect(), rect, color, color2);
        }
Ejemplo n.º 8
0
 public void drawTextureCustom(spriteTexture texture, spriteMat _mat, spriteRect rect, spriteRect uvrect, spriteColor color = null, spriteColor color2 = null)
 {
     //if (uvrect == null)
     //    uvrect = spriteRect.one;
     if (color == null)
     {
         color = spriteColor.white;
     }
     if (color2 == null)
     {
         color2 = spriteColor.white;
     }
     texture.drawCustom(this.spriteBatcher, _mat, uvrect, rect, color, color2);
 }