示例#1
0
        // Previewer
        public IList <Bitmap> GeneratePreviews(TextEntry entry)
        {
            var pages = new List <Bitmap>();

            if (entry?.EditedText == null)
            {
                return(pages);
            }

            foreach (string page in entry.EditedText.Split('\x17'))
            {
                if (page.Trim() != string.Empty)
                {
                    Bitmap img = new Bitmap(1, 1);

                    switch (Enum.Parse(typeof(Scenes), Properties.Settings.Default.Scene))
                    {
                    case Scenes.TopScreen:
                        img = new Bitmap(background.Width, background.Height);
                        break;

                    case Scenes.BottomScreen:
                        img = new Bitmap(bottom.Width, bottom.Height);
                        break;
                    }

                    using (Graphics gfx = Graphics.FromImage(img))
                    {
                        gfx.SmoothingMode     = SmoothingMode.HighQuality;
                        gfx.InterpolationMode = InterpolationMode.Bilinear;
                        gfx.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                        float scaleDefaultX = 1.0f;
                        float scaleDefaultY = 1.05f;
                        float scaleName     = 0.8f;
                        float scaleCurrentX = scaleDefaultX;
                        float scaleCurrentY = scaleDefaultY;

                        var rectName = new RectangleF();
                        var rectText = new RectangleF();

                        Color colorDefault = Color.FromArgb(255, 37, 66, 167);

                        switch (Enum.Parse(typeof(Scenes), Properties.Settings.Default.Scene))
                        {
                        case Scenes.TopScreen:
                            gfx.DrawImage(background, 0, 0);
                            gfx.DrawImage(textBox, 0, 0);
                            gfx.DrawImage(nameBox, 0, 0);
                            rectName = new RectangleF(16, 2, 128, 17);
                            rectText = new RectangleF(30, 18, 340, 37);
                            break;

                        case Scenes.BottomScreen:
                            gfx.DrawImage(bottom, 0, 0);
                            rectName = new RectangleF(6, 2, 128, 17);
                            rectText = new RectangleF(20, 18, 280, 37);
                            break;
                        }

                        float x = rectText.X, pX = x;
                        float y = rectText.Y, pY = y;
                        float lineSpacing = 4;

                        string str = page.Replace("\x1F\x05", Properties.Settings.Default.PlayerName == string.Empty ? "Player" : Properties.Settings.Default.PlayerName);
                        font.SetColor(colorDefault);

                        for (int i = 0; i < str.Length; i++)
                        {
                            bool notEOS = i + 2 < str.Length;
                            char c      = str[i];
                            char c2     = ' ';
                            if (notEOS)
                            {
                                c2 = str[i + 1];
                            }

                            BCFNT.CharWidthInfo widthInfo = font.GetWidthInfo(c);

                            // Handle control codes
                            if (c == 0x001F && c2 == 0x0002) // Start Name
                            {
                                font.SetColor(Color.White);
                                scaleCurrentX = scaleName;
                                scaleCurrentY = scaleName;
                                float width = font.MeasureString(str.Substring(i + 2), (char)0x0002, scaleCurrentX);
                                pX = x;
                                pY = y;
                                x  = rectName.X + (rectName.Width / 2) - (width / 2);
                                y  = rectName.Y;
                                i++;
                                continue;
                            }
                            else if (c == 0x001F && (c2 == 0x0000 || c2 == 0x0100 || c2 == 0x0200 || c2 == 0x0103 || c2 == 0x0020 || c2 == 0x0115)) // Unknown/No Render Effect
                            {
                                i++;
                                continue;
                            }
                            else if (c == 0x0013 && c2 == 0x0000) // Default
                            {
                                font.SetColor(colorDefault);
                                i++;
                                continue;
                            }
                            else if (c == 0x0013 && c2 == 0x0001) // Red
                            {
                                font.SetColor(Color.Red);
                                i++;
                                continue;
                            }
                            else if (c == 0x0013 && c2 == 0x0003) // Light Blue
                            {
                                font.SetColor(Color.FromArgb(255, 54, 129, 216));
                                i++;
                                continue;
                            }
                            else if (c == 0x001F && c2 == 0x0015) // End Dialog
                            {
                                i++;
                                continue;
                            }
                            else if (c == 0x0017) // Next TextBox
                            {
                                //x = rectText.X;
                                //pX = x;
                                //y = rectText.Y + textBox.Height;
                                //pY += y;
                                continue;
                            }
                            else if (c == 0x0002) // End Name
                            {
                                font.SetColor(colorDefault);
                                scaleCurrentX = scaleDefaultX;
                                scaleCurrentY = scaleDefaultY;
                                x             = pX;
                                y             = pY;
                                continue;
                            }
                            else if (c == '\n' || x + (widthInfo.char_width * scaleCurrentX) - rectText.X > rectText.Width) // New Line/End of Textbox
                            {
                                x  = rectText.X;
                                y += (16 * scaleCurrentX) + lineSpacing;
                                if (c == '\n')
                                {
                                    continue;
                                }
                            }

                            // Otherwise it's a regular drawable character
                            font.Draw(c, gfx, x, y, scaleCurrentX, scaleCurrentY);
                            x += widthInfo.char_width * scaleCurrentX;
                        }
                    }

                    pages.Add(img);
                }
            }

            return(pages);
        }
示例#2
0
        // Previewer
        public IList <Bitmap> GeneratePreviews(TextEntry entry)
        {
            var pages = new List <Bitmap>();

            if (entry?.EditedText == null)
            {
                return(pages);
            }

            //string kuriimuString = _previewPairs.Aggregate(GetKuriimuString(entry.EditedText), (s, pair) => s.Replace(pair.Key, pair.Value));
            string kuriimuString = _previewPairs.Aggregate(GetKuriimuString(entry.EditedText), (s, pair) => s.Replace(pair.Key, pair.Value));

            Bitmap img = new Bitmap(1, 1);

            switch (Enum.Parse(typeof(BubbleType), Properties.Settings.Default.BubbleType))
            {
            case BubbleType.Type1:
                img = new Bitmap(bubble001.Width, bubble001.Height);
                break;

            case BubbleType.Type2:
                img = new Bitmap(bubble002.Width, bubble002.Height);
                break;
            }

            using (Graphics gfx = Graphics.FromImage(img))
            {
                gfx.SmoothingMode     = SmoothingMode.HighQuality;
                gfx.InterpolationMode = InterpolationMode.Bicubic;
                gfx.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                RectangleF rectText     = new RectangleF(0, 0, 0, 0);
                Color      colorDefault = Color.FromArgb(255, 0, 0, 0);

                switch (Enum.Parse(typeof(BubbleType), Properties.Settings.Default.BubbleType))
                {
                case BubbleType.Type1:
                    gfx.DrawImage(bubble001, 0, 0);
                    rectText = new RectangleF(12, 9, 370, 100);
                    break;

                case BubbleType.Type2:
                    gfx.DrawImage(bubble002, 0, 0);
                    rectText = new RectangleF(20, 11, 370, 100);
                    break;
                }

                float scaleDefault = 1.0f;
                float scaleCurrent = scaleDefault;
                float x = rectText.X, pX = x;
                float y = rectText.Y, pY = y;
                //float fontSize = 3.2f;
                float fontSize = 1.5f;

                for (int i = 0; i < kuriimuString.Length; i++)
                {
                    BCFNT.CharWidthInfo widthInfo = font.GetWidthInfo(kuriimuString[i]);
                    font.SetColor(colorDefault);

                    if (kuriimuString[i] == '\n')
                    {
                        switch (Enum.Parse(typeof(BubbleType), Properties.Settings.Default.BubbleType))
                        {
                        case BubbleType.Type1:
                            y += 15;
                            x  = 12;
                            continue;

                        case BubbleType.Type2:
                            y += 13;
                            x  = 18;
                            continue;
                        }
                    }

                    font.Draw(kuriimuString[i], gfx, x, y, scaleCurrent, scaleCurrent);
                    x += widthInfo.char_width - fontSize;
                }
            }

            pages.Add(img);

            return(pages);
        }
示例#3
0
        public Bitmap GeneratePreview(string rawString)
        {
            int boxes = rawString.Count(c => c == (char)0x17) + 1;

            Bitmap img = new Bitmap(textBox.Width, textBox.Height * boxes);

            using (Graphics gfx = Graphics.FromImage(img))
            {
                gfx.SmoothingMode     = SmoothingMode.HighQuality;
                gfx.InterpolationMode = InterpolationMode.Bicubic;
                gfx.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                for (int i = 0; i < boxes; i++)
                {
                    gfx.DrawImage(textBox, 0, i * textBox.Height);
                }

                RectangleF rectName = new RectangleF(15, 3, 114, 15);
                RectangleF rectText = new RectangleF(15, 22, 370, 60);

                Color colorDefault = Color.FromArgb(255, 37, 66, 167);

                float scaleDefault = 1.0f;
                float scaleName = 0.86f;
                float scaleCurrent = scaleDefault;
                float x = rectText.X, pX = x;
                float y = rectText.Y, pY = y;
                float yAdjust = 4;
                int   box     = 0;

                string str = rawString.Replace("\x1F\x05", "Player");
                font.SetTextColor(colorDefault);

                for (int i = 0; i < str.Length; i++)
                {
                    bool notEOS = i + 2 < str.Length;
                    char c      = str[i];
                    char c2     = ' ';
                    if (notEOS)
                    {
                        c2 = str[i + 1];
                    }

                    BCFNT.CharWidthInfo widthInfo = font.GetWidthInfo(c);

                    // Handle control codes
                    if (c == 0x001F && c2 == 0x0002)                     // Start Name
                    {
                        font.SetTextColor(Color.White);
                        scaleCurrent = scaleName;
                        float width = font.MeasureString(str.Substring(i + 2), (char)0x0002, scaleCurrent);
                        pX = x;
                        pY = y;
                        x  = rectName.X + (rectName.Width / 2) - (width / 2);
                        y  = rectName.Y;
                        i++;
                        continue;
                    }
                    else if (c == 0x001F && (c2 == 0x0000 || c2 == 0x0100 || c2 == 0x0200 || c2 == 0x0103 || c2 == 0x0020 || c2 == 0x0115))                     // Unknown/No Render Effect
                    {
                        i++;
                        continue;
                    }
                    else if (c == 0x0013 && c2 == 0x0000)                     // Default
                    {
                        font.SetTextColor(colorDefault);
                        i++;
                        continue;
                    }
                    else if (c == 0x0013 && c2 == 0x0001)                     // Red
                    {
                        font.SetTextColor(Color.Red);
                        i++;
                        continue;
                    }
                    else if (c == 0x0013 && c2 == 0x0003)                     // Light Blue
                    {
                        font.SetTextColor(Color.FromArgb(255, 54, 129, 216));
                        i++;
                        continue;
                    }
                    else if (c == 0x001F && c2 == 0x0015)                     // End Dialog
                    {
                        i++;
                        continue;
                    }
                    else if (c == 0x0017)                     // Next TextBox
                    {
                        box++;
                        x   = rectText.X;
                        pX  = x;
                        y   = rectText.Y + textBox.Height * box;
                        pY += y;
                        continue;
                    }
                    else if (c == 0x0002)                     // End Name
                    {
                        font.SetTextColor(colorDefault);
                        scaleCurrent = scaleDefault;
                        x            = pX;
                        y            = pY;
                        continue;
                    }
                    else if (c == '\n' || x + (widthInfo.char_width * scaleCurrent) - rectText.X > rectText.Width)                     // New Line/End of Textbox
                    {
                        x  = rectText.X;
                        y += (16 * scaleCurrent) + yAdjust;
                        if (c == '\n')
                        {
                            continue;
                        }
                    }

                    // Otherwise it's a regular drawable character
                    font.DrawCharacter(c, gfx, x, y, scaleCurrent);
                    x += widthInfo.char_width * scaleCurrent;
                }
            }

            return(img);
        }