Ejemplo n.º 1
0
 public string Truncate(string text, IFont font, int width)
 {
     if (font.GetStringWidth(text) > width)
     {
         while ((text.Length > 0) && (font.GetStringWidth(text + "...") > width))
         {
             text = text.Substring(0, text.Length - 1);
         }
         text = text + "...";
     }
     return(text);
 }
Ejemplo n.º 2
0
 public string Truncate(string text, IFont font, int width)
 {
     if (font.GetStringWidth(text) > width)
     {
         while ((text.Length > 0) && (font.GetStringWidth(text + "...") > width))
         {
             text = text.Substring(0, text.Length - 1);
         }
         text = text + "...";
     }
     return text;
 }
Ejemplo n.º 3
0
        private void ProcessLayout(LayoutEntry[] list, string[] text)
        {
            int  num1 = 0;
            int  num2 = 0;
            bool flag = false;

            for (int index = 0; index < list.Length; ++index)
            {
                LayoutEntry le = list[index];
                switch (le.Name)
                {
                case "nodispose":
                case "noresize":
                    goto case "nodispose";

                case "checkertrans":
                    this.Pages(num1).Add((Gump) new GTransparentRegion(this, le[0], le[1], le[2], le[3]));
                    goto case "nodispose";

                case "page":
                    num1 = le[0];
                    if (num1 == 0)
                    {
                        flag = false;
                        num2 = 0;
                        goto case "nodispose";
                    }
                    else if (!flag || num1 < num2)
                    {
                        num2 = num1;
                        flag = true;
                        goto case "nodispose";
                    }
                    else
                    {
                        goto case "nodispose";
                    }

                case "noclose":
                    this.m_CanClose = false;
                    goto case "nodispose";

                case "nomove":
                    this.m_CanMove = false;
                    goto case "nodispose";

                case "resizepic":
                    this.Pages(num1).Add((Gump) new GServerBackground(this, le[0], le[1], le[3], le[4], le[2] + 4, true));
                    goto case "nodispose";

                case "gumppictiled":
                    this.Pages(num1).Add((Gump) new GServerBackground(this, le[0], le[1], le[2], le[3], le[4], false));
                    goto case "nodispose";

                case "gumppic":
                    string attribute = le.GetAttribute("hue");
                    IHue   hue;
                    if (attribute != null)
                    {
                        try
                        {
                            hue = Hues.Load(Convert.ToInt32(attribute) + 1);
                        }
                        catch
                        {
                            hue = Hues.Default;
                        }
                    }
                    else
                    {
                        hue = Hues.Default;
                    }
                    if (le.GetAttribute("class") == "VirtueGumpItem")
                    {
                        this.Pages(num1).Add((Gump) new GVirtueItem(this, le[0], le[1], le[2], hue));
                        goto case "nodispose";
                    }
                    else
                    {
                        this.Pages(num1).Add((Gump) new GServerImage(this, le[0], le[1], le[2], hue));
                        goto case "nodispose";
                    }

                case "textentry":
                    this.Pages(num1).Add((Gump) new GServerTextBox(text[le[6]], le));
                    goto case "nodispose";

                case "tilepic":
                    this.Pages(num1).Add((Gump) new GItemArt(le[0], le[1], le[2]));
                    goto case "nodispose";

                case "tilepichue":
                    this.Pages(num1).Add((Gump) new GItemArt(le[0], le[1], le[2], Hues.GetItemHue(le[2], le[3] + 1)));
                    goto case "nodispose";

                case "button":
                    this.Pages(num1).Add((Gump) new GServerButton(this, le));
                    goto case "nodispose";

                case "radio":
                    this.Pages(num1).Add((Gump) new GServerRadio(this, le));
                    goto case "nodispose";

                case "checkbox":
                    this.Pages(num1).Add((Gump) new GServerCheckBox(this, le));
                    goto case "nodispose";

                case "text":
                    int num3 = le[2];
                    this.Pages(num1).Add((Gump) new GLabel(text[le[3]], (IFont)Engine.GetUniFont(1), Hues.Load(num3 + 1), le[0] - 1, le[1]));
                    goto case "nodispose";

                case "croppedtext":
                    int    num4   = le[4];
                    string str    = text[le[5]];
                    int    xWidth = le[2];
                    IFont  Font   = (IFont)Engine.GetUniFont(1);
                    if (Font.GetStringWidth(str) > xWidth)
                    {
                        while (str.Length > 0 && Font.GetStringWidth(str + "...") > xWidth)
                        {
                            str = str.Substring(0, str.Length - 1);
                        }
                        str += "...";
                    }
                    GLabel glabel = new GLabel(str, Font, Hues.Load(num4 + 1), le[0] - 1, le[1]);
                    glabel.Scissor(0, 0, xWidth, le[3]);
                    this.Pages(num1).Add((Gump)glabel);
                    goto case "nodispose";

                case "xmfhtmlgump":
                    this.ProcessHtmlGump(num1, le[0], le[1], le[2], le[3], Localization.GetString(le[4]), le[5] != 0, le[6] != 0, le[5] != 0 || le[6] == 0 ? 0 : 16777215);
                    goto case "nodispose";

                case "xmfhtmlgumpcolor":
                    this.ProcessHtmlGump(num1, le[0], le[1], le[2], le[3], Localization.GetString(le[4]), le[5] != 0, le[6] != 0, Engine.C16232(le[7]));
                    goto case "nodispose";

                case "htmlgump":
                    this.ProcessHtmlGump(num1, le[0], le[1], le[2], le[3], text[le[4]], le[5] != 0, le[6] != 0, le[5] != 0 || le[6] == 0 ? 0 : 16777215);
                    goto case "nodispose";

                default:
                    Engine.AddTextMessage(le.Name);
                    goto case "nodispose";
                }
            }
            this.Page = num2 == 0 ? 1 : num2;
        }
Ejemplo n.º 4
0
 public static string WrapText(string text, int width, IFont f)
 {
     WrapKey key = new WrapKey(text, width);
     object obj2 = f.WrapCache[key];
     if (obj2 != null)
     {
         return (string) obj2;
     }
     if (f.GetStringWidth(text) <= width)
     {
         f.WrapCache.Add(key, text);
         return text;
     }
     string[] strArray = text.Split(new char[] { ' ' });
     StringBuilder builder = new StringBuilder();
     ArrayList dataStore = GetDataStore();
     for (int i = 0; i < strArray.Length; i++)
     {
         if (f.GetStringWidth(builder.ToString() + strArray[i]) > width)
         {
             if (f.GetStringWidth(strArray[i]) > width)
             {
                 builder.Append(strArray[i]);
                 while ((builder.Length > 1) && (f.GetStringWidth(builder.ToString()) > width))
                 {
                     StringBuilder builder2 = new StringBuilder();
                     builder2.Append(builder[0]);
                     for (int k = 1; k < builder.Length; k++)
                     {
                         if (f.GetStringWidth(builder2.ToString() + builder[k]) > width)
                         {
                             dataStore.Add(builder2);
                             builder = new StringBuilder(builder.ToString().Substring(builder2.Length));
                             continue;
                         }
                         builder2.Append(builder[k]);
                     }
                 }
                 if (i < (strArray.Length - 1))
                 {
                     builder.Append(' ');
                 }
                 continue;
             }
             if (builder.Length > 0)
             {
                 dataStore.Add(builder);
             }
             builder = new StringBuilder(strArray[i]);
             if (i < (strArray.Length - 1))
             {
                 builder.Append(' ');
             }
             continue;
         }
         builder.Append(strArray[i]);
         if (i < (strArray.Length - 1))
         {
             builder.Append(' ');
         }
     }
     if (builder.Length > 0)
     {
         while ((builder.Length > 1) && (f.GetStringWidth(builder.ToString()) > width))
         {
             StringBuilder builder3 = new StringBuilder();
             builder3.Append(builder[0]);
             for (int m = 1; m < builder.Length; m++)
             {
                 if (f.GetStringWidth(builder3.ToString() + builder[m]) > width)
                 {
                     dataStore.Add(builder3);
                     builder = new StringBuilder(builder.ToString().Substring(builder3.Length));
                     continue;
                 }
                 builder3.Append(builder[m]);
             }
         }
         if (builder.Length > 0)
         {
             dataStore.Add(builder);
         }
     }
     StringBuilder builder4 = new StringBuilder();
     int count = dataStore.Count;
     for (int j = 0; j < count; j++)
     {
         builder4.Append(((StringBuilder) dataStore[j]).ToString());
         if (j < (count - 1))
         {
             builder4.Append('\n');
         }
     }
     string str = builder4.ToString();
     f.WrapCache.Add(key, str);
     ReleaseDataStore(dataStore);
     return str;
 }