Esempio n. 1
0
        public void Scribble(byte[] data)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <byte[]>(this.Scribble), data);
            }
            else
            {
                if (this.IsPaused)
                {
                    return;
                }

                StringBuilder rtf = new StringBuilder();
                rtf.Append("{");
                rtf.Append("\\rtf");
                rtf.Append("\\par");

                using (Graphics g = this.CreateGraphics())
                    rtf.Append(Emoticons.GetRTFScribble(data, g));

                rtf.Append("}");

                this.SelectionLength = 0;
                this.SelectionStart  = this.Text.Length;
                this.TrimLines();
                this.SelectedRtf     = rtf.ToString();
                this.SelectionLength = 0;
                this.SelectionStart  = this.Text.Length;

                rtf = null;
            }
        }
Esempio n. 2
0
        public void RenderChannelListItem(ChannelListViewItem item, FavouritesListItem org)
        {
            using (Bitmap bmp = new Bitmap(154, 15))
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.Clear(Color.White);

                    String text    = org.Name;
                    char[] letters = text.ToCharArray();
                    int    x       = 0;

                    for (var i = 0; i < letters.Length; i++)
                    {
                        switch (letters[i])
                        {
                        case ' ':
                            x += 3;
                            break;

                        default:
                            int w = (int)Math.Round((double)g.MeasureString(letters[i].ToString(), this.t_font, 100, StringFormat.GenericTypographic).Width);

                            if ((w + x) < 154)
                            {
                                g.DrawString(letters[i].ToString(), this.t_font, Brushes.Black, new PointF(x, 0));
                            }

                            x += w;
                            break;
                        }

                        if (x >= 154)
                        {
                            break;
                        }
                    }

                    item.NameImg = new Bitmap(x + 2, 15);

                    using (Graphics g2 = Graphics.FromImage(item.NameImg))
                    {
                        g2.Clear(Color.Transparent);
                        g2.DrawImage(bmp, new Point(0, 0));
                    }
                }

            using (Bitmap bmp = new Bitmap(35, 15))
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.Clear(Color.White);

                    String text = org.CountString;

                    if (String.IsNullOrEmpty(text))
                    {
                        text = String.Empty;
                    }

                    char[] letters = text.ToCharArray();
                    int    x       = 0;

                    for (var i = 0; i < letters.Length; i++)
                    {
                        switch (letters[i])
                        {
                        case ' ':
                            x += 3;
                            break;

                        default:
                            int w = (int)Math.Round((double)g.MeasureString(letters[i].ToString(), this.t_font, 100, StringFormat.GenericTypographic).Width);

                            if ((w + x) < 35)
                            {
                                g.DrawString(letters[i].ToString(), this.t_font, Brushes.Black, new PointF(x, 0));
                            }

                            x += w;
                            break;
                        }

                        if (x >= 35)
                        {
                            break;
                        }
                    }

                    item.CountImg = new Bitmap(x + 2, 15);

                    using (Graphics g2 = Graphics.FromImage(item.CountImg))
                    {
                        g2.Clear(Color.Transparent);
                        g2.DrawImage(bmp, new Point(0, 0));
                    }
                }

            using (Bitmap bmp = new Bitmap(1024, 15))
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.Clear(Color.White);
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode  = InterpolationMode.HighQualityBilinear;

                    String    text = org.Topic;
                    char[]    letters = text.ToCharArray();
                    int       x = 0;
                    bool      bold = false, italic = false, underline = false;
                    Color     fore_color = Color.Black;
                    int       color_finder;
                    EmojiItem emoji_item;

                    for (var i = 0; i < letters.Length; i++)
                    {
                        switch (letters[i])
                        {
                        case '\x0006':
                            bold = !bold;
                            break;

                        case '\x0007':
                            underline = !underline;
                            break;

                        case '\x0009':
                            italic = !italic;
                            break;

                        case '\x0003':
                            if (letters.Length >= (i + 3))
                            {
                                if (int.TryParse(text.Substring(i + 1, 2), out color_finder))
                                {
                                    fore_color = this.GetColorFromCode(color_finder);
                                    i         += 2;
                                }
                                else
                                {
                                    goto default;
                                }
                            }
                            else
                            {
                                goto default;
                            }
                            break;

                        case '\x0005':
                            if (letters.Length >= (i + 3))
                            {
                                if (int.TryParse(text.Substring(i + 1, 2), out color_finder))
                                {
                                    Color back_color = this.GetColorFromCode(color_finder);
                                    i += 2;

                                    using (SolidBrush brush = new SolidBrush(back_color))
                                        g.FillRectangle(brush, new Rectangle(x + 2, 0, 1024 - x - 2, 15));
                                }
                                else
                                {
                                    goto default;
                                }
                            }
                            else
                            {
                                goto default;
                            }
                            break;

                        case ' ':
                            x += underline ? 2 : (bold ? 4 : 3);

                            if (underline)
                            {
                                using (Font font = new Font(this.t_font, this.CreateFont(bold, italic, underline)))
                                    using (SolidBrush brush = new SolidBrush(fore_color))
                                        g.DrawString(" ", font, brush, new PointF(x, 0));
                            }
                            break;

                        case '(':
                        case ':':
                        case ';':
                            Emotic em = Emoticons.FindEmoticon(text.Substring(i).ToUpper());

                            if (em != null)
                            {
                                g.DrawImage(Emoticons.emotic[em.Index], new RectangleF(x + 2, 0, 15, 15));
                                x += 15;
                                i += (em.Shortcut.Length - 1);
                                break;
                            }
                            else
                            {
                                goto default;
                            }

                        case (char)35:
                        case (char)48:
                        case (char)49:
                        case (char)50:
                        case (char)51:
                        case (char)52:
                        case (char)53:
                        case (char)54:
                        case (char)55:
                        case (char)56:
                        case (char)57:
                        case (char)169:
                        case (char)174:
                        case (char)55356:
                        case (char)55357:
                        case (char)8252:
                        case (char)8265:
                        case (char)8482:
                        case (char)8505:
                        case (char)8596:
                        case (char)8597:
                        case (char)8598:
                        case (char)8599:
                        case (char)8600:
                        case (char)8601:
                        case (char)8617:
                        case (char)8618:
                        case (char)8986:
                        case (char)8987:
                        case (char)9193:
                        case (char)9194:
                        case (char)9195:
                        case (char)9196:
                        case (char)9200:
                        case (char)9203:
                        case (char)9410:
                        case (char)9642:
                        case (char)9643:
                        case (char)9654:
                        case (char)9664:
                        case (char)9723:
                        case (char)9724:
                        case (char)9725:
                        case (char)9726:
                        case (char)9728:
                        case (char)9729:
                        case (char)9742:
                        case (char)9745:
                        case (char)9748:
                        case (char)9749:
                        case (char)9757:
                        case (char)9786:
                        case (char)9800:
                        case (char)9801:
                        case (char)9802:
                        case (char)9803:
                        case (char)9804:
                        case (char)9805:
                        case (char)9806:
                        case (char)9807:
                        case (char)9808:
                        case (char)9809:
                        case (char)9810:
                        case (char)9811:
                        case (char)9824:
                        case (char)9827:
                        case (char)9829:
                        case (char)9830:
                        case (char)9832:
                        case (char)9851:
                        case (char)9855:
                        case (char)9875:
                        case (char)9888:
                        case (char)9889:
                        case (char)9898:
                        case (char)9899:
                        case (char)9917:
                        case (char)9918:
                        case (char)9924:
                        case (char)9925:
                        case (char)9934:
                        case (char)9940:
                        case (char)9962:
                        case (char)9970:
                        case (char)9971:
                        case (char)9973:
                        case (char)9978:
                        case (char)9981:
                        case (char)9986:
                        case (char)9989:
                        case (char)9992:
                        case (char)9993:
                        case (char)9994:
                        case (char)9995:
                        case (char)9996:
                        case (char)9999:
                        case (char)10002:
                        case (char)10004:
                        case (char)10006:
                        case (char)10024:
                        case (char)10035:
                        case (char)10036:
                        case (char)10052:
                        case (char)10055:
                        case (char)10060:
                        case (char)10062:
                        case (char)10067:
                        case (char)10068:
                        case (char)10069:
                        case (char)10071:
                        case (char)10084:
                        case (char)10133:
                        case (char)10134:
                        case (char)10135:
                        case (char)10145:
                        case (char)10160:
                        case (char)10175:
                        case (char)10548:
                        case (char)10549:
                        case (char)11013:
                        case (char)11014:
                        case (char)11015:
                        case (char)11035:
                        case (char)11036:
                        case (char)11088:
                        case (char)11093:
                        case (char)12336:
                        case (char)12349:
                        case (char)12951:
                        case (char)12953:
                            emoji_item = Emoji.GetEmoji24(letters, i);

                            if (emoji_item != null)
                            {
                                g.DrawImage(emoji_item.Image, new RectangleF(x + 2, 0, 15, 15));
                                x += 15;
                                i += (emoji_item.Length - 1);
                                break;
                            }
                            else
                            {
                                goto default;
                            }

                        default:
                            using (Font f = new Font(this.t_font, this.CreateFont(bold, italic, underline)))
                                using (SolidBrush brush = new SolidBrush(fore_color))
                                {
                                    int w = (int)Math.Round((double)g.MeasureString(letters[i].ToString(), f, 100, StringFormat.GenericTypographic).Width);
                                    g.DrawString(letters[i].ToString(), f, brush, new PointF(x, 0));
                                    x += w;
                                }
                            break;
                        }
                    }

                    item.TopicImg = new Bitmap(x + 2, 15);

                    using (Graphics g2 = Graphics.FromImage(item.TopicImg))
                    {
                        g2.Clear(Color.Transparent);
                        g2.DrawImage(bmp, new Point(0, 0));
                    }
                }
        }
Esempio n. 3
0
        private void Render(String txt, String name, bool can_col, int first_col, AresFont _ff)
        {
            String text = txt.Replace("\r\n", "\r").Replace("\n",
                                                            "\r").Replace("", "").Replace("]̽", "").Replace(" ̽",
                                                                                                             "").Replace("͊", "").Replace("]͊", "").Replace("͠",
                                                                                                                                                            "").Replace("̶", "").Replace("̅", "");

            List <Color>  cols = new List <Color>();
            StringBuilder rtf  = new StringBuilder();
            int           col_index;
            String        bg_test;
            AresFont      ff = _ff;

            if (!Settings.GetReg <bool>("receive_ppl_fonts", true))
            {
                ff = null;
            }

            if (ff == null)
            {
                cols.Add(this.GetColorFromCode(first_col));
            }
            else
            {
                bg_test = ff.TextColor.ToUpper().Replace("#", String.Empty);

                if (bg_test == "000000" && this.IsBlack)
                {
                    bg_test = "#FFFFFF";
                }
                else if (bg_test == "FFFFFF" && !this.IsBlack)
                {
                    bg_test = "#000000";
                }
                else
                {
                    bg_test = ff.TextColor;
                }

                cols.Add(this.HTMLColorToColor(bg_test));
            }

            rtf.Append("\\cf1 ");

            if (this.GetColorIndex(ref cols, this.IsBlack ? Color.Black : Color.White) == -1)
            {
                cols.Add(this.IsBlack ? Color.Black : Color.White);
                rtf.Append("\\highlight2 ");
            }
            else
            {
                rtf.Append("\\highlight1 ");
            }

            char[]    letters = text.ToCharArray();
            bool      bold = false, italic = false, underline = false;
            bool      can_emoticon = Settings.GetReg <bool>("can_emoticon", true);
            int       emote_count  = 0;
            Color     back_color   = this.IsBlack ? Color.Black : Color.White;
            bool      bg_code_used = false;
            EmojiItem emojiitem;
            String    tmp;
            int       itmp;

            using (Graphics richtextbox = this.CreateGraphics())
            {
                for (int i = 0; i < letters.Length; i++)
                {
                    switch (letters[i])
                    {
                    case '\x0006':
                        bold = !bold;
                        rtf.Append(bold ? "\\b" : "\\b0");
                        break;

                    case '\x0007':
                        underline = !underline;
                        rtf.Append(underline ? "\\ul" : "\\ul0");
                        break;

                    case '\x0009':
                        italic = !italic;
                        rtf.Append(italic ? "\\i" : "\\i0");
                        break;

                    case '\x03':
                        if (letters.Length >= (i + 8))
                        {
                            tmp = text.Substring((i + 1), 7);

                            if (Helpers.IsHexCode(tmp))
                            {
                                if (!bg_code_used)
                                {
                                    if (this.IsBlack && tmp == "#000000")
                                    {
                                        itmp = 0;
                                    }
                                    else if (!this.IsBlack && tmp.ToUpper() == "#FFFFFF")
                                    {
                                        itmp = 1;
                                    }
                                }

                                col_index = this.GetColorIndex(ref cols, this.HTMLColorToColor(tmp));

                                if (col_index > -1)
                                {
                                    rtf.Append("\\cf0\\cf" + (col_index + 1) + " ");
                                }
                                else
                                {
                                    cols.Add(this.HTMLColorToColor(tmp));
                                    rtf.Append("\\cf0\\cf" + cols.Count + " ");
                                }

                                i += 7;
                                break;
                            }
                        }

                        if (letters.Length >= (i + 3))
                        {
                            tmp = text.Substring((i + 1), 2);

                            if (int.TryParse(tmp, out itmp))
                            {
                                if (!bg_code_used)
                                {
                                    if (this.IsBlack && itmp == 1)
                                    {
                                        itmp = 0;
                                    }
                                    else if (!this.IsBlack && itmp == 0)
                                    {
                                        itmp = 1;
                                    }
                                }

                                col_index = this.GetColorIndex(ref cols, this.GetColorFromCode(itmp));

                                if (col_index > -1)
                                {
                                    rtf.Append("\\cf0\\cf" + (col_index + 1) + " ");
                                }
                                else
                                {
                                    cols.Add(this.GetColorFromCode(itmp));
                                    rtf.Append("\\cf0\\cf" + cols.Count + " ");
                                }

                                i += 2;
                                break;
                            }
                        }
                        goto default;

                    case '\x05':
                        if (letters.Length >= (i + 8))
                        {
                            tmp = text.Substring((i + 1), 7);

                            if (Helpers.IsHexCode(tmp))
                            {
                                back_color = this.HTMLColorToColor(tmp);
                                col_index  = this.GetColorIndex(ref cols, back_color);

                                if (col_index > -1)
                                {
                                    rtf.Append("\\highlight0\\highlight" + (col_index + 1) + " ");
                                }
                                else
                                {
                                    cols.Add(back_color);
                                    rtf.Append("\\highlight0\\highlight" + cols.Count + " ");
                                }

                                bg_code_used = true;
                                i           += 7;
                                break;
                            }
                        }

                        if (letters.Length >= (i + 3))
                        {
                            tmp = text.Substring((i + 1), 2);

                            if (int.TryParse(tmp, out itmp))
                            {
                                back_color = this.GetColorFromCode(itmp);
                                col_index  = this.GetColorIndex(ref cols, back_color);

                                if (col_index > -1)
                                {
                                    rtf.Append("\\highlight0\\highlight" + (col_index + 1) + " ");
                                }
                                else
                                {
                                    cols.Add(back_color);
                                    rtf.Append("\\highlight0\\highlight" + cols.Count + " ");
                                }

                                bg_code_used = true;
                                i           += 2;
                                break;
                            }
                        }
                        goto default;

                    case (char)35:
                    case (char)48:
                    case (char)49:
                    case (char)50:
                    case (char)51:
                    case (char)52:
                    case (char)53:
                    case (char)54:
                    case (char)55:
                    case (char)56:
                    case (char)57:
                    case (char)169:
                    case (char)174:
                    case (char)55356:
                    case (char)55357:
                    case (char)8252:
                    case (char)8265:
                    case (char)8482:
                    case (char)8505:
                    case (char)8596:
                    case (char)8597:
                    case (char)8598:
                    case (char)8599:
                    case (char)8600:
                    case (char)8601:
                    case (char)8617:
                    case (char)8618:
                    case (char)8986:
                    case (char)8987:
                    case (char)9193:
                    case (char)9194:
                    case (char)9195:
                    case (char)9196:
                    case (char)9200:
                    case (char)9203:
                    case (char)9410:
                    case (char)9642:
                    case (char)9643:
                    case (char)9654:
                    case (char)9664:
                    case (char)9723:
                    case (char)9724:
                    case (char)9725:
                    case (char)9726:
                    case (char)9728:
                    case (char)9729:
                    case (char)9742:
                    case (char)9745:
                    case (char)9748:
                    case (char)9749:
                    case (char)9757:
                    case (char)9786:
                    case (char)9800:
                    case (char)9801:
                    case (char)9802:
                    case (char)9803:
                    case (char)9804:
                    case (char)9805:
                    case (char)9806:
                    case (char)9807:
                    case (char)9808:
                    case (char)9809:
                    case (char)9810:
                    case (char)9811:
                    case (char)9824:
                    case (char)9827:
                    case (char)9829:
                    case (char)9830:
                    case (char)9832:
                    case (char)9851:
                    case (char)9855:
                    case (char)9875:
                    case (char)9888:
                    case (char)9889:
                    case (char)9898:
                    case (char)9899:
                    case (char)9917:
                    case (char)9918:
                    case (char)9924:
                    case (char)9925:
                    case (char)9934:
                    case (char)9940:
                    case (char)9962:
                    case (char)9970:
                    case (char)9971:
                    case (char)9973:
                    case (char)9978:
                    case (char)9981:
                    case (char)9986:
                    case (char)9989:
                    case (char)9992:
                    case (char)9993:
                    case (char)9994:
                    case (char)9995:
                    case (char)9996:
                    case (char)9999:
                    case (char)10002:
                    case (char)10004:
                    case (char)10006:
                    case (char)10024:
                    case (char)10035:
                    case (char)10036:
                    case (char)10052:
                    case (char)10055:
                    case (char)10060:
                    case (char)10062:
                    case (char)10067:
                    case (char)10068:
                    case (char)10069:
                    case (char)10071:
                    case (char)10084:
                    case (char)10133:
                    case (char)10134:
                    case (char)10135:
                    case (char)10145:
                    case (char)10160:
                    case (char)10175:
                    case (char)10548:
                    case (char)10549:
                    case (char)11013:
                    case (char)11014:
                    case (char)11015:
                    case (char)11035:
                    case (char)11036:
                    case (char)11088:
                    case (char)11093:
                    case (char)12336:
                    case (char)12349:
                    case (char)12951:
                    case (char)12953:
                        if (can_emoticon)
                        {
                            emojiitem = Emoji.GetEmoji24(letters, i);

                            if (emojiitem != null)
                            {
                                if (emote_count++ < 8)
                                {
                                    rtf.Append(Emoticons.GetRTFEmoji(emojiitem.Image, back_color, richtextbox));
                                    i += (emojiitem.Length - 1);
                                    break;
                                }
                                else
                                {
                                    goto default;
                                }
                            }
                        }
                        goto default;


                    case '(':
                    case ':':
                    case ';':
                        if (can_emoticon)
                        {
                            Emotic em = Emoticons.FindEmoticon(text.ToString().Substring(i).ToUpper());

                            if (em != null)
                            {
                                if (emote_count++ < 8)
                                {
                                    rtf.Append(Emoticons.GetRTFEmoticon(em.Index, back_color, richtextbox));
                                    i += (em.Shortcut.Length - 1);
                                    break;
                                }
                                else
                                {
                                    goto default;
                                }
                            }

                            em = this.FindNewEmoticon(text.ToString().Substring(i).ToUpper());

                            if (em != null)
                            {
                                if (emote_count++ < 8)
                                {
                                    rtf.Append(Emoticons.GetRTFExEmoticon(em.Index, back_color, richtextbox));
                                    i += (em.Shortcut.Length - 1);
                                    break;
                                }
                                else
                                {
                                    goto default;
                                }
                            }
                        }
                        goto default;

                    default:
                        rtf.Append("\\u" + ((int)letters[i]) + "?");
                        break;
                    }
                }
            }

            if (underline)
            {
                rtf.Append("\\ul0");
            }
            if (italic)
            {
                rtf.Append("\\i0");
            }
            if (bold)
            {
                rtf.Append("\\b0");
            }

            rtf.Append("\\highlight0\\cf0");

            if (!String.IsNullOrEmpty(name))
            {
                StringBuilder name_builder = new StringBuilder();

                if (ff == null)
                {
                    Color colfromcode = this.GetColorFromCode(GlobalSettings.GetDefaultColorInt(GlobalSettings.DefaultColorType.Name, this.IsBlack));
                    col_index = this.GetColorIndex(ref cols, colfromcode);

                    if (col_index > -1)
                    {
                        name_builder.Append("\\cf" + (col_index + 1) + " ");
                    }
                    else
                    {
                        cols.Add(this.IsBlack ? Color.Yellow : Color.Black);
                        name_builder.Append("\\cf" + cols.Count + " ");
                    }
                }
                else
                {
                    bg_test = ff.NameColor.ToUpper().Replace("#", String.Empty);

                    if (bg_test == "000000" && this.IsBlack)
                    {
                        bg_test = "#FFFF00";
                    }
                    else if (bg_test == "FFFFFF" && !this.IsBlack)
                    {
                        bg_test = "#000000";
                    }
                    else
                    {
                        bg_test = ff.NameColor;
                    }

                    col_index = this.GetColorIndex(ref cols, this.HTMLColorToColor(bg_test));

                    if (col_index > -1)
                    {
                        name_builder.Append("\\cf" + (col_index + 1) + " ");
                    }
                    else
                    {
                        cols.Add(this.HTMLColorToColor(bg_test));
                        name_builder.Append("\\cf" + cols.Count + " ");
                    }
                }

                col_index = this.GetColorIndex(ref cols, this.IsBlack ? Color.Black : Color.White);

                if (col_index > -1)
                {
                    name_builder.Append("\\highlight" + (col_index + 1) + " ");
                }
                else
                {
                    cols.Add(this.IsBlack ? Color.Black : Color.White);
                    name_builder.Append("\\highlight" + cols.Count + " ");
                }

                char[] name_chrs = (name + "> ").ToCharArray();

                for (int i = 0; i < name_chrs.Length; i++)
                {
                    name_builder.Append("\\u" + ((int)name_chrs[i]) + "?");
                }

                name_builder.Append("\\highlight0\\cf0");
                rtf.Insert(0, name_builder.ToString());
                name_builder = null;
            }

            if (this.Lines.Length > 0)
            {
                rtf.Insert(0, "\\par");
            }

            if (ff == null)
            {
                rtf.Insert(0, "\\fs" + (Settings.GetReg <int>("global_font_size", 10) * 2));
            }
            else
            {
                int org_size   = Settings.GetReg <int>("global_font_size", 10);
                int difference = (org_size - 10);
                int user_size  = ff.Size + difference;
                rtf.Insert(0, "\\fs" + (user_size * 2));
            }

            StringBuilder header = new StringBuilder();

            header.Append("\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1040{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0");

            if (ff == null)
            {
                header.Append(Settings.GetReg <String>("global_font", "Tahoma") + ";}}");
            }
            else
            {
                header.Append(ff.FontName + ";}}");
            }

            header.Append(this.ColorsToRTFColorTable(cols.ToArray()));

            this.SelectionLength = 0;
            this.SelectionStart  = this.Text.Length;
            this.TrimLines();
            this.SelectedRtf     = "{" + header + rtf + "}";
            this.SelectionLength = 0;
            this.SelectionStart  = this.Text.Length;

            cols.Clear();
            cols = null;
            rtf  = null;
            text = null;

            while (this.CanUndo)
            {
                this.ClearUndo();
            }
        }
Esempio n. 4
0
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            Rectangle bounds = new Rectangle(0, 0, e.ToolStrip.Width, e.ToolStrip.Height);

            using (LinearGradientBrush brush = new LinearGradientBrush(bounds, Color.Gainsboro, Color.WhiteSmoke, LinearGradientMode.Vertical))
                e.Graphics.FillRectangle(brush, bounds);

            if (e.ToolStrip is ToolStripDropDownMenu)
            {
                return;
            }

            // topic
            if (this.TopicText != null)
            {
                Rectangle r = new Rectangle(2, (e.ToolStrip.Height / 2) - 9, (e.ToolStrip.Width - 60), 20);
                char[]    letters = this.TopicText.ToCharArray();
                Color     fg = Color.Black;
                bool      bold = false, italic = false, underline = false, back_color_required = false;
                int       x = r.X, y = r.Y, max_x = (r.Width + 2), clen = 0, tcol = 0;
                EmojiItem emoji_item;

                for (int i = 0; i < letters.Length; i++)
                {
                    switch (letters[i])
                    {
                    case '\x0006':
                        bold = !bold;
                        break;

                    case '\x0007':
                        underline = !underline;
                        break;

                    case '\x0009':
                        italic = !italic;
                        break;

                    case '\x0003':
                        if (letters.Length >= (i + 3))
                        {
                            if (int.TryParse(this.TopicText.Substring(i + 1, 2), out tcol))
                            {
                                fg = this.GetColorFromCode(tcol);
                                i += 2;
                            }
                            else
                            {
                                goto default;
                            }
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case '\x0005':
                        if (letters.Length >= (i + 3))
                        {
                            if (int.TryParse(this.TopicText.Substring(i + 1, 2), out tcol))
                            {
                                Color back_color = this.GetColorFromCode(tcol);
                                back_color_required = true;
                                i += 2;

                                if ((max_x - x) > 0)
                                {
                                    using (SolidBrush brush = new SolidBrush(back_color))
                                        e.Graphics.FillRectangle(brush, new Rectangle(x + 2, y, max_x - x, 20));
                                }
                            }
                            else
                            {
                                goto default;
                            }
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case ' ':
                        x += underline ? 2 : (bold ? 4 : 3);

                        if (x >= max_x)
                        {
                            break;
                        }

                        if (underline)
                        {
                            using (Font font = new Font(this.t_font, this.CreateFont(bold, italic, underline)))
                                using (SolidBrush brush = new SolidBrush(fg))
                                    e.Graphics.DrawString(" ", font, brush, new PointF(x, (y + 1)));
                        }
                        break;

                    case '(':
                    case ':':
                    case ';':
                        Emotic emote_index = Emoticons.FindEmoticon(this.TopicText.Substring(i).ToUpper());

                        if (emote_index != null)
                        {
                            if ((x + 15) >= max_x)
                            {
                                x += 15;
                                break;
                            }

                            e.Graphics.DrawImage(Emoticons.emotic[emote_index.Index], new RectangleF(x + 3, y + 2, 16, 16));
                            x += 18;
                            i += (emote_index.Shortcut.Length - 1);
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    case (char)35:
                    case (char)48:
                    case (char)49:
                    case (char)50:
                    case (char)51:
                    case (char)52:
                    case (char)53:
                    case (char)54:
                    case (char)55:
                    case (char)56:
                    case (char)57:
                    case (char)169:
                    case (char)174:
                    case (char)55356:
                    case (char)55357:
                    case (char)8252:
                    case (char)8265:
                    case (char)8482:
                    case (char)8505:
                    case (char)8596:
                    case (char)8597:
                    case (char)8598:
                    case (char)8599:
                    case (char)8600:
                    case (char)8601:
                    case (char)8617:
                    case (char)8618:
                    case (char)8986:
                    case (char)8987:
                    case (char)9193:
                    case (char)9194:
                    case (char)9195:
                    case (char)9196:
                    case (char)9200:
                    case (char)9203:
                    case (char)9410:
                    case (char)9642:
                    case (char)9643:
                    case (char)9654:
                    case (char)9664:
                    case (char)9723:
                    case (char)9724:
                    case (char)9725:
                    case (char)9726:
                    case (char)9728:
                    case (char)9729:
                    case (char)9742:
                    case (char)9745:
                    case (char)9748:
                    case (char)9749:
                    case (char)9757:
                    case (char)9786:
                    case (char)9800:
                    case (char)9801:
                    case (char)9802:
                    case (char)9803:
                    case (char)9804:
                    case (char)9805:
                    case (char)9806:
                    case (char)9807:
                    case (char)9808:
                    case (char)9809:
                    case (char)9810:
                    case (char)9811:
                    case (char)9824:
                    case (char)9827:
                    case (char)9829:
                    case (char)9830:
                    case (char)9832:
                    case (char)9851:
                    case (char)9855:
                    case (char)9875:
                    case (char)9888:
                    case (char)9889:
                    case (char)9898:
                    case (char)9899:
                    case (char)9917:
                    case (char)9918:
                    case (char)9924:
                    case (char)9925:
                    case (char)9934:
                    case (char)9940:
                    case (char)9962:
                    case (char)9970:
                    case (char)9971:
                    case (char)9973:
                    case (char)9978:
                    case (char)9981:
                    case (char)9986:
                    case (char)9989:
                    case (char)9992:
                    case (char)9993:
                    case (char)9994:
                    case (char)9995:
                    case (char)9996:
                    case (char)9999:
                    case (char)10002:
                    case (char)10004:
                    case (char)10006:
                    case (char)10024:
                    case (char)10035:
                    case (char)10036:
                    case (char)10052:
                    case (char)10055:
                    case (char)10060:
                    case (char)10062:
                    case (char)10067:
                    case (char)10068:
                    case (char)10069:
                    case (char)10071:
                    case (char)10084:
                    case (char)10133:
                    case (char)10134:
                    case (char)10135:
                    case (char)10145:
                    case (char)10160:
                    case (char)10175:
                    case (char)10548:
                    case (char)10549:
                    case (char)11013:
                    case (char)11014:
                    case (char)11015:
                    case (char)11035:
                    case (char)11036:
                    case (char)11088:
                    case (char)11093:
                    case (char)12336:
                    case (char)12349:
                    case (char)12951:
                    case (char)12953:
                        emoji_item = Emoji.GetEmoji24(letters, i);

                        if (emoji_item != null)
                        {
                            if ((x + 15) >= max_x)
                            {
                                x += 15;
                                break;
                            }

                            e.Graphics.DrawImage(emoji_item.Image, new RectangleF(x + 3, y + 2, 16, 16));
                            x += 18;
                            i += (emoji_item.Length - 1);
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    default:
                        using (Font font = new Font(this.t_font, this.CreateFont(bold, italic, underline)))
                        {
                            clen = (int)Math.Round((double)e.Graphics.MeasureString(letters[i].ToString(), font, 100, StringFormat.GenericTypographic).Width);

                            if ((x + clen) >= max_x)
                            {
                                x += clen;
                                break;
                            }

                            using (SolidBrush brush = new SolidBrush(fg))
                                e.Graphics.DrawString(letters[i].ToString(), font, brush, new PointF(x, (y + 1)));

                            x += clen;
                        }
                        break;
                    }

                    if (x >= max_x)
                    {
                        break;
                    }
                }

                if (back_color_required)
                {
                    if ((max_x - x) > 0)
                    {
                        Rectangle excess = new Rectangle((x + 2), 0, (max_x - x), e.ToolStrip.Height);

                        using (LinearGradientBrush lb = new LinearGradientBrush(excess, Color.Gainsboro, Color.WhiteSmoke, LinearGradientMode.Vertical))
                            e.Graphics.FillRectangle(lb, excess);
                    }
                }
            }

            // close
            if (this.close_hottracking)
            {
                Rectangle rec = new Rectangle(e.ToolStrip.Width - 19, 7, 12, 10);
                e.Graphics.FillRectangle(this.close_brush, rec);
            }
        }
Esempio n. 5
0
        public void Draw(DrawItemEventArgs e, bool selected, bool tracked, bool is_black)
        {
            Color item_bg = is_black ? Color.Black : Color.White;

            if (tracked)
            {
                item_bg = is_black ? Color.DimGray : Color.Gainsboro;
            }
            if (selected)
            {
                item_bg = is_black ? Color.DarkBlue : Color.LightSteelBlue;
            }

            using (SolidBrush brush = new SolidBrush(item_bg))
                e.Graphics.FillRectangle(brush, e.Bounds);

            if (this.Owner.AvatarBytes.Length > 0)
            {
                using (MemoryStream ms = new MemoryStream(this.Owner.AvatarBytes))
                    using (Bitmap bmp = new Bitmap(ms))
                        e.Graphics.DrawImage(bmp, new Point(e.Bounds.X + 1, e.Bounds.Y + 2));
            }
            else
            {
                using (MemoryStream ms = new MemoryStream(Avatar.DefaultAvatar))
                    using (Bitmap bmp = new Bitmap(ms))
                        e.Graphics.DrawImage(bmp, new Point(e.Bounds.X + 1, e.Bounds.Y + 2));
            }

            int img_x = 58;

            Color name_color = is_black ? Color.White : Color.Black;

            if (this.Owner.Level == 3)
            {
                name_color = Color.Red;
            }
            else if (this.Owner.Level == 2)
            {
                name_color = is_black ? Color.Lime : Color.Green;
            }
            else if (this.Owner.Level == 1)
            {
                name_color = is_black ? Color.Aqua : Color.Blue;
            }

            if (this.Owner.HasFiles)
            {
                using (MemoryStream ms = new MemoryStream(Avatar.BrowseIcon))
                    using (Bitmap bmp = new Bitmap(ms))
                        e.Graphics.DrawImage(bmp, new Rectangle(e.Bounds.X + img_x, e.Bounds.Y + 7, 14, 14));

                img_x += 15;
            }

            if (this.Owner.IsAway)
            {
                using (MemoryStream ms = new MemoryStream(Avatar.AwayIcon))
                    using (Bitmap bmp = new Bitmap(ms))
                        e.Graphics.DrawImage(bmp, new Rectangle(e.Bounds.X + img_x, e.Bounds.Y + 7, 14, 14));

                img_x += 15;
            }

            if (this.Owner.SupportsVC)
            {
                using (MemoryStream ms = new MemoryStream(is_black ? Avatar.VoiceIconBlack : Avatar.VoiceIcon))
                    using (Bitmap bmp = new Bitmap(ms))
                        e.Graphics.DrawImage(bmp, new Rectangle(e.Bounds.X + img_x, e.Bounds.Y + 7, 14, 14));

                img_x += 15;
            }

            using (Font name_font = new Font(e.Font, FontStyle.Bold))
                using (SolidBrush brush = new SolidBrush(name_color))
                {
                    char[] n_letters   = this.Owner.Name.ToCharArray();
                    int    n_x_pos     = e.Bounds.X + img_x;
                    int    n_y_pos     = e.Bounds.Y + 7;
                    int    n_max_width = (n_x_pos + e.Bounds.Width);

                    for (int i = 0; i < n_letters.Length; i++)
                    {
                        switch (n_letters[i])
                        {
                        case ' ':
                            n_x_pos += 4;
                            break;

                        default:
                            try
                            {
                                int w = (int)Math.Round((double)e.Graphics.MeasureString(n_letters[i].ToString(), name_font, 100, StringFormat.GenericTypographic).Width);

                                if ((n_x_pos + w) < n_max_width)
                                {
                                    e.Graphics.DrawString(n_letters[i].ToString(), name_font, brush, new PointF(n_x_pos, n_y_pos));
                                }

                                n_x_pos += w;
                            }
                            catch { break; }
                            break;
                        }

                        if (n_x_pos >= n_max_width)
                        {
                            break;
                        }
                    }
                }

            try
            {
                using (SolidBrush brush = new SolidBrush(is_black ? Color.WhiteSmoke : Color.Gray))
                    e.Graphics.DrawString(this.Owner.ToASLString(), e.Font, brush, new PointF(e.Bounds.X + 58, e.Bounds.Y + 24));
            }
            catch { }

            String text    = this.Owner.PersonalMessage;
            bool   is_song = false;

            if (text.StartsWith("\x0007"))
            {
                text = Helpers.StripColors(text);

                if (is_black)
                {
                    text = "\x0007\x000311" + text;
                }
                else
                {
                    text = "\x0007\x000312" + text;
                }

                is_song = true;
            }

            if (!String.IsNullOrEmpty(text))
            {
                char[]    letters = text.ToCharArray();
                bool      bold = false, italic = false, underline = false;
                int       x = e.Bounds.X + 58, y = e.Bounds.Y + 38;
                int       max_width  = (e.Bounds.X + e.Bounds.Width);
                Color     fore_color = is_black ? Color.WhiteSmoke : Color.Gray;
                int       color_finder;
                EmojiItem emojiitem;

                if (is_song)
                {
                    using (MemoryStream ms = new MemoryStream(is_black ? Avatar.MusicIconBlack : Avatar.MusicIcon))
                        using (Bitmap bmp = new Bitmap(ms))
                            e.Graphics.DrawImage(bmp, new RectangleF(x, y, 14, 14));

                    x += 15;
                }

                for (int i = 0; i < letters.Length; i++)
                {
                    switch (letters[i])
                    {
                    case '\x0006':
                        bold = !bold;
                        break;

                    case '\x0007':
                        underline = !underline;
                        break;

                    case '\x0009':
                        italic = !italic;
                        break;

                    case '\x0003':
                        if (letters.Length >= (i + 3))
                        {
                            if (int.TryParse(text.Substring(i + 1, 2), out color_finder))
                            {
                                fore_color = this.GetColorFromCode(color_finder);
                                i         += 2;
                            }
                            else
                            {
                                goto default;
                            }
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case '\x0005':
                        if (letters.Length >= (i + 3))
                        {
                            if (int.TryParse(text.Substring(i + 1, 2), out color_finder))
                            {
                                i += 2;
                            }
                            else
                            {
                                goto default;
                            }
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case ' ':
                        x += underline ? 2 : (bold ? 4 : 3);
                        break;

                    case '(':
                    case ':':
                    case ';':
                        Emotic em = Emoticons.FindEmoticon(text.Substring(i).ToUpper());

                        if (em != null && !is_song)
                        {
                            if ((x + 15) < max_width)
                            {
                                e.Graphics.DrawImage(Emoticons.emotic[em.Index], new RectangleF(x + 3, y, 14, 14));
                            }

                            x += 15;
                            i += (em.Shortcut.Length - 1);
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    case (char)35:
                    case (char)48:
                    case (char)49:
                    case (char)50:
                    case (char)51:
                    case (char)52:
                    case (char)53:
                    case (char)54:
                    case (char)55:
                    case (char)56:
                    case (char)57:
                    case (char)169:
                    case (char)174:
                    case (char)55356:
                    case (char)55357:
                    case (char)8252:
                    case (char)8265:
                    case (char)8482:
                    case (char)8505:
                    case (char)8596:
                    case (char)8597:
                    case (char)8598:
                    case (char)8599:
                    case (char)8600:
                    case (char)8601:
                    case (char)8617:
                    case (char)8618:
                    case (char)8986:
                    case (char)8987:
                    case (char)9193:
                    case (char)9194:
                    case (char)9195:
                    case (char)9196:
                    case (char)9200:
                    case (char)9203:
                    case (char)9410:
                    case (char)9642:
                    case (char)9643:
                    case (char)9654:
                    case (char)9664:
                    case (char)9723:
                    case (char)9724:
                    case (char)9725:
                    case (char)9726:
                    case (char)9728:
                    case (char)9729:
                    case (char)9742:
                    case (char)9745:
                    case (char)9748:
                    case (char)9749:
                    case (char)9757:
                    case (char)9786:
                    case (char)9800:
                    case (char)9801:
                    case (char)9802:
                    case (char)9803:
                    case (char)9804:
                    case (char)9805:
                    case (char)9806:
                    case (char)9807:
                    case (char)9808:
                    case (char)9809:
                    case (char)9810:
                    case (char)9811:
                    case (char)9824:
                    case (char)9827:
                    case (char)9829:
                    case (char)9830:
                    case (char)9832:
                    case (char)9851:
                    case (char)9855:
                    case (char)9875:
                    case (char)9888:
                    case (char)9889:
                    case (char)9898:
                    case (char)9899:
                    case (char)9917:
                    case (char)9918:
                    case (char)9924:
                    case (char)9925:
                    case (char)9934:
                    case (char)9940:
                    case (char)9962:
                    case (char)9970:
                    case (char)9971:
                    case (char)9973:
                    case (char)9978:
                    case (char)9981:
                    case (char)9986:
                    case (char)9989:
                    case (char)9992:
                    case (char)9993:
                    case (char)9994:
                    case (char)9995:
                    case (char)9996:
                    case (char)9999:
                    case (char)10002:
                    case (char)10004:
                    case (char)10006:
                    case (char)10024:
                    case (char)10035:
                    case (char)10036:
                    case (char)10052:
                    case (char)10055:
                    case (char)10060:
                    case (char)10062:
                    case (char)10067:
                    case (char)10068:
                    case (char)10069:
                    case (char)10071:
                    case (char)10084:
                    case (char)10133:
                    case (char)10134:
                    case (char)10135:
                    case (char)10145:
                    case (char)10160:
                    case (char)10175:
                    case (char)10548:
                    case (char)10549:
                    case (char)11013:
                    case (char)11014:
                    case (char)11015:
                    case (char)11035:
                    case (char)11036:
                    case (char)11088:
                    case (char)11093:
                    case (char)12336:
                    case (char)12349:
                    case (char)12951:
                    case (char)12953:
                        emojiitem = Emoji.GetEmoji24(letters, i);

                        if (emojiitem != null && !is_song)
                        {
                            if ((x + 15) < max_width)
                            {
                                e.Graphics.DrawImage(emojiitem.Image, new RectangleF(x + 3, y, 14, 14));
                            }

                            x += 15;
                            i += (emojiitem.Length - 1);
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    default:
                        using (Font f = new Font(e.Font, this.CreateFont(bold, italic, underline)))
                            using (SolidBrush brush = new SolidBrush(fore_color))
                            {
                                try
                                {
                                    int w = (int)Math.Round((double)e.Graphics.MeasureString(letters[i].ToString(), f, 100, StringFormat.GenericTypographic).Width);

                                    if ((x + w) < max_width)
                                    {
                                        e.Graphics.DrawString(letters[i].ToString(), f, brush, new PointF(x, y));
                                    }

                                    x += w;
                                }
                                catch { break; }
                            }
                        break;
                    }

                    if (x >= max_width)
                    {
                        break;
                    }
                }
            }
        }