Example #1
0
 /// <summary>
 /// 绘制文本
 /// </summary>
 /// <param name="renderer">着色器</param>
 /// <param name="str">提供字符串</param>
 /// <param name="x">书写坐标</param>
 /// <param name="y">书写坐标</param>
 /// <param name="percent">字体显示大小所占百分比</param>
 /// <param name="Col_diatanceMax">列的最大范围</param>
 /// <param name="color">想要展示的颜色</param>
 /// <param name="CharacterPercent">展示字体的百分比</param>
 public virtual void DrawString(Renderer renderer, string str, double x, double y, float percent,
    double Col_diatanceMax, Color color ,float CharacterPercent)
 {
     if (!Binded)
         throw new Exception("当前工具没有绑定字体");
     Sprite sprite;
     Extra.VariableSprite Chac = new Extra.VariableSprite();          //可变倍率纹理精灵
     massege.SetString(str);                          //绑定字符串
     int CurrentCharIndex = 0;                        //当前字符所在索引项
     Char[] Arr = str.ToCharArray();
     int count = Arr.Length;
     double offsetx = 0;
     int offsety = 0;
     float h_distance = percent * 24;
     for (int i = 0; i < count; i++)
     {
         string s = Arr[i].ToString();
         if (s == "\n")
         {
             offsetx = 0;
             offsety++;
             continue;
         }
         else if (s == " ") { offsetx += 24 * percent; CurrentCharIndex += 1; }
         else
         {
             double showP = massege.GetAttribute(CharacterPercent, CurrentCharIndex);
             sprite = SelectFont.GetAci(s);
             Chac.BindSprite(sprite);
             Chac.SetAttribute(x + offsetx, y - offsety * h_distance, showP,
                 (float)sprite.GetWidth() * percent, (float)sprite.GetHeight() * percent);
             showP = showP * showP * showP;
             Chac.SetColorVol(new Color(color.Red, color.Green, color.Blue, color.Alpha),
                 new Color(color.Red, color.Green, color.Blue, color.Alpha * (float)showP));
             sprite = Chac.GetSprite();
             double width = sprite.GetWidth();
             if (width < 16 * percent)
                 offsetx += 16 * percent + 1;
             else
                 offsetx += width + 1;       //至少保留1象素
             renderer.DrawSprite(sprite);
             CurrentCharIndex += 1;
         }
         if (offsetx >= Col_diatanceMax)
         {
             offsetx = 0;
             offsety++;
         }
     }
 }
Example #2
0
        /// <summary>
        /// 绘制文本
        /// </summary>
        /// <param name="renderer">着色器</param>
        /// <param name="str">提供字符串</param>
        /// <param name="x">书写坐标</param>
        /// <param name="y">书写坐标</param>
        /// <param name="percent">字体显示大小所占百分比</param>
        /// <param name="Col_diatanceMax">列的最大范围</param>
        /// <param name="color">想要展示的颜色</param>
        /// <param name="CharacterPercent">展示字体的百分比</param>
        public virtual void DrawString(Renderer renderer, string str, double x, double y, float percent,
                                       double Col_diatanceMax, Color color, float CharacterPercent)
        {
            if (!Binded)
            {
                throw new Exception("当前工具没有绑定字体");
            }
            Sprite sprite;

            Extra.VariableSprite Chac = new Extra.VariableSprite(); //可变倍率纹理精灵
            massege.SetString(str);                                 //绑定字符串
            int CurrentCharIndex = 0;                               //当前字符所在索引项

            Char[] Arr        = str.ToCharArray();
            int    count      = Arr.Length;
            double offsetx    = 0;
            int    offsety    = 0;
            float  h_distance = percent * 24;

            for (int i = 0; i < count; i++)
            {
                string s = Arr[i].ToString();
                if (s == "\n")
                {
                    offsetx = 0;
                    offsety++;
                    continue;
                }
                else if (s == " ")
                {
                    offsetx += 24 * percent; CurrentCharIndex += 1;
                }
                else
                {
                    double showP = massege.GetAttribute(CharacterPercent, CurrentCharIndex);
                    sprite = SelectFont.GetAci(s);
                    Chac.BindSprite(sprite);
                    Chac.SetAttribute(x + offsetx, y - offsety * h_distance, showP,
                                      (float)sprite.GetWidth() * percent, (float)sprite.GetHeight() * percent);
                    showP = showP * showP * showP;
                    Chac.SetColorVol(new Color(color.Red, color.Green, color.Blue, color.Alpha),
                                     new Color(color.Red, color.Green, color.Blue, color.Alpha * (float)showP));
                    sprite = Chac.GetSprite();
                    double width = sprite.GetWidth();
                    if (width < 16 * percent)
                    {
                        offsetx += 16 * percent + 1;
                    }
                    else
                    {
                        offsetx += width + 1;       //至少保留1象素
                    }
                    renderer.DrawSprite(sprite);
                    CurrentCharIndex += 1;
                }
                if (offsetx >= Col_diatanceMax)
                {
                    offsetx = 0;
                    offsety++;
                }
            }
        }