Ejemplo n.º 1
0
        protected void MakeNameTexture()
        {
            using (Font font = new Font(game.FontName, 24)) {
                DrawTextArgs args = new DrawTextArgs(DisplayName, font, false);
                Size         size = game.Drawer2D.MeasureBitmappedSize(ref args);
                if (size.Width == 0)
                {
                    nameTex = new Texture(-1, 0, 0, 0, 0, 1, 1); return;
                }
                size.Width += 3; size.Height += 3;

                using (IDrawer2D drawer = game.Drawer2D)
                    using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                    {
                        drawer.SetBitmap(bmp);
                        args.Text = "&\xFF" + Utils.StripColours(args.Text);
                        game.Drawer2D.Colours['\xFF'] = new FastColour(80, 80, 80);
                        game.Drawer2D.DrawBitmappedText(ref args, 3, 3);
                        game.Drawer2D.Colours['\xFF'] = default(FastColour);

                        args.Text = DisplayName;
                        game.Drawer2D.DrawBitmappedText(ref args, 0, 0);
                        nameTex = game.Drawer2D.Make2DTexture(bmp, size, 0, 0);
                    }
            }
        }
Ejemplo n.º 2
0
        public void SetText(string value)
        {
            chatInputText.Clear();
            chatInputText.Append(0, value);
            DrawTextArgs args     = new DrawTextArgs(value, font, false);
            Size         textSize = game.Drawer2D.MeasureChatSize(ref args);

            // Ensure we don't have 0 text height
            if (textSize.Height == 0)
            {
                args.Text       = Validator.Range;
                textSize.Height = game.Drawer2D.MeasureChatSize(ref args).Height;
                args.Text       = value;
            }
            else
            {
                args.SkipPartsCheck = true;
            }

            Size size = new Size(Math.Max(textSize.Width, DesiredMaxWidth),
                                 Math.Max(textSize.Height, DesiredMaxHeight));

            yOffset = 0;
            if (textSize.Height < DesiredMaxHeight)
            {
                yOffset = DesiredMaxHeight / 2 - textSize.Height / 2;
            }

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    drawer.DrawRect(backColour, 0, 0, size.Width, size.Height);
                    drawer.DrawChatText(ref args, 3, yOffset);

                    args.Text           = Validator.Range;
                    args.SkipPartsCheck = false;
                    Size hintSize = drawer.MeasureChatSize(ref args);

                    args.SkipPartsCheck = true;
                    int hintX = size.Width - hintSize.Width;
                    if (textSize.Width + 3 < hintX)
                    {
                        drawer.DrawChatText(ref args, hintX, yOffset);
                    }
                    chatInputTexture = drawer.Make2DTexture(bmp, size, 0, 0);
                }

            X = CalcOffset(game.Width, size.Width, XOffset, HorizontalAnchor);
            Y = CalcOffset(game.Height, size.Height, YOffset, VerticalAnchor);
            chatCaretTexture.X1  = chatInputTexture.X1 = X;
            chatCaretTexture.X1 += textSize.Width;
            chatCaretTexture.Y1  = chatInputTexture.Y1 = Y;
            chatCaretTexture.Y1  = (Y + size.Height) - chatCaretTexture.Height;
            Width  = size.Width;
            Height = size.Height;
        }
Ejemplo n.º 3
0
        /// <summary> Remakes the raw texture containg all the chat lines. </summary>
        /// <remarks> Also updates the dimensions of the widget. </remarks>
        public virtual void RemakeTexture()
        {
            int totalHeight = 0, maxWidth = 0;

            for (int i = 0; i < UsedLines; i++)
            {
                totalHeight += lineSizes[i].Height;
                maxWidth     = Math.Max(maxWidth, lineSizes[i].Width);
            }
            Size size = new Size(maxWidth, totalHeight);

            caretAccumulator = 0;

            int realHeight = 0;

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    DrawTextArgs args = new DrawTextArgs(null, font, true);
                    if (Prefix != null)
                    {
                        args.Text = Prefix;
                        drawer.DrawText(ref args, 0, 0);
                    }

                    for (int i = 0; i < lines.Length; i++)
                    {
                        if (lines[i] == null)
                        {
                            break;
                        }
                        args.Text = lines[i];
                        char lastCol = GetLastColour(0, i);
                        if (!IDrawer2D.IsWhiteCol(lastCol))
                        {
                            args.Text = "&" + lastCol + args.Text;
                        }

                        int offset = i == 0 ? prefixWidth : 0;
                        drawer.DrawText(ref args, offset, realHeight);
                        realHeight += lineSizes[i].Height;
                    }
                    inputTex = drawer.Make2DTexture(bmp, size, 0, 0);
                }

            Width  = size.Width;
            Height = realHeight == 0 ? prefixHeight : realHeight;
            Reposition();
            inputTex.X1 = X + Padding; inputTex.Y1 = Y;
        }
Ejemplo n.º 4
0
        public override void RemakeTexture()
        {
            DrawTextArgs args = new DrawTextArgs(lines[0], font, false);
            Size         size = game.Drawer2D.MeasureSize(ref args);

            caretAccumulator = 0;

            // Ensure we don't have 0 text height
            if (size.Height == 0)
            {
                args.Text   = Validator.Range;
                size.Height = game.Drawer2D.MeasureSize(ref args).Height;
                args.Text   = lines[0];
            }
            else
            {
                args.SkipPartsCheck = true;
            }

            Width  = Math.Max(size.Width, MinWidth);
            Height = Math.Max(size.Height, MinHeight);
            Size adjSize = size; adjSize.Width = Width;

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(adjSize))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    drawer.DrawText(ref args, Padding, 0);

                    args.Text           = Validator.Range;
                    args.SkipPartsCheck = false;
                    Size hintSize = drawer.MeasureSize(ref args);

                    args.SkipPartsCheck = true;
                    int hintX = adjSize.Width - hintSize.Width;
                    if (size.Width + 3 < hintX)
                    {
                        drawer.DrawText(ref args, hintX, 0);
                    }
                    inputTex = drawer.Make2DTexture(bmp, adjSize, 0, 0);
                }

            Reposition();
            inputTex.X1 = X; inputTex.Y1 = Y;
            if (size.Height < MinHeight)
            {
                inputTex.Y1 += MinHeight / 2 - size.Height / 2;
            }
        }
Ejemplo n.º 5
0
        Texture MakeNameTextureImpl(Size size, DrawTextArgs args)
        {
            size.Width += 3; size.Height += 3;

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                {
                    drawer.SetBitmap(bmp);
                    args.Text = "&\xFF" + Utils.StripColours(args.Text);
                    IDrawer2D.Cols['\xFF'] = new FastColour(80, 80, 80);
                    game.Drawer2D.DrawText(ref args, 3, 3);
                    IDrawer2D.Cols['\xFF'] = default(FastColour);

                    args.Text = DisplayName;
                    game.Drawer2D.DrawText(ref args, 0, 0);
                    return(game.Drawer2D.Make2DTexture(bmp, size, 0, 0));
                }
        }
        void DrawString()
        {
            int totalHeight = 0;

            for (int i = 0; i < lines; i++)
            {
                totalHeight += sizes[i].Height;
            }
            Size size = new Size(maxWidth, totalHeight);

            int realHeight = 0;

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    DrawTextArgs args = new DrawTextArgs("> ", font, true);
                    drawer.DrawChatText(ref args, 0, 0);

                    for (int i = 0; i < parts.Length; i++)
                    {
                        if (parts[i] == null)
                        {
                            break;
                        }
                        args.Text = parts[i];
                        char lastCol = GetLastColour(0, i);
                        if (!IDrawer2D.IsWhiteColour(lastCol))
                        {
                            args.Text = "&" + lastCol + args.Text;
                        }

                        int offset = i == 0 ? defaultWidth : 0;
                        drawer.DrawChatText(ref args, offset, realHeight);
                        realHeight += sizes[i].Height;
                    }
                    inputTex = drawer.Make2DTexture(bmp, size, 10, 0);
                }

            Height      = realHeight == 0 ? defaultHeight : realHeight;
            Y           = game.Height - Height - YOffset;
            inputTex.Y1 = Y;
            Width       = size.Width;
        }
Ejemplo n.º 7
0
        void MakeTexture(string text)
        {
            DrawTextArgs args = new DrawTextArgs(text, font, true);
            Size         size = game.Drawer2D.MeasureChatSize(ref args);

            int xOffset = Math.Max(size.Width, DesiredMaxWidth) - size.Width;

            size.Width = Math.Max(size.Width, DesiredMaxWidth);
            int yOffset = Math.Max(size.Height, DesiredMaxHeight) - size.Height;

            size.Height = Math.Max(size.Height, DesiredMaxHeight);

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    args.SkipPartsCheck = true;
                    drawer.DrawChatText(ref args, xOffset / 2, yOffset / 2);
                    texture = drawer.Make2DTexture(bmp, size, 0, 0);
                }
        }
Ejemplo n.º 8
0
        Texture MakeNameTextureImpl(Size size, DrawTextArgs args)
        {
            size.Width += 3; size.Height += 3;

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                {
                    drawer.SetBitmap(bmp);
                    PackedCol origWhiteCol = IDrawer2D.Cols['f'];

                    IDrawer2D.Cols['f'] = new PackedCol(80, 80, 80);
                    args.Text           = Utils.StripColours(args.Text);
                    game.Drawer2D.DrawText(ref args, 3, 3);

                    IDrawer2D.Cols['f'] = origWhiteCol;
                    args.Text           = DisplayName;
                    game.Drawer2D.DrawText(ref args, 0, 0);

                    return(game.Drawer2D.Make2DTexture(bmp, size, 0, 0));
                }
        }
        unsafe void Make(Element e, Font font)
        {
            Size *sizes = stackalloc Size[e.Contents.Length / e.CharsPerItem];

            MeasureContentSizes(e, font, sizes);
            Size bodySize = CalculateContentSize(e, sizes, out elementSize);
            int  titleWidth = MeasureTitles(font), titleHeight = elements[0].TitleSize.Height;
            Size size = new Size(Math.Max(bodySize.Width, titleWidth), bodySize.Height + titleHeight);

            using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size))
                using (IDrawer2D drawer = game.Drawer2D)
                {
                    drawer.SetBitmap(bmp);
                    DrawTitles(drawer, font);
                    drawer.Clear(new FastColour(30, 30, 30, 200), 0, titleHeight,
                                 size.Width, bodySize.Height);

                    DrawContent(drawer, font, e, titleHeight);
                    texture = drawer.Make2DTexture(bmp, size, X, Y);
                }
        }
Ejemplo n.º 10
0
        unsafe Texture DrawAdvanced(ref DrawTextArgs args, int index, string text)
        {
            LinkData data      = Split(index, text);
            Size     total     = Size.Empty;
            Size *   partSizes = stackalloc Size[data.parts.Length];

            linkData[index] = data;

            for (int i = 0; i < data.parts.Length; i++)
            {
                args.Text    = data.parts[i];
                args.Font    = (i & 1) == 0 ? font : underlineFont;
                partSizes[i] = game.Drawer2D.MeasureChatSize(ref args);
                total.Height = Math.Max(partSizes[i].Height, total.Height);
                total.Width += partSizes[i].Width;
            }

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total))
                {
                    drawer.SetBitmap(bmp);
                    int x = 0;

                    for (int i = 0; i < data.parts.Length; i++)
                    {
                        args.Text = data.parts[i];
                        args.Font = (i & 1) == 0 ? font : underlineFont;
                        Size size = partSizes[i];

                        drawer.DrawChatText(ref args, x, 0);
                        data.bounds[i].X     = x;
                        data.bounds[i].Width = size.Width;
                        x += size.Width;
                    }
                    return(drawer.Make2DTexture(bmp, total, 0, 0));
                }
        }
Ejemplo n.º 11
0
        void MakePosTextWidget()
        {
            DrawTextArgs args = new DrawTextArgs("", posFont, true);

            for (int i = 0; i < possibleChars.Length; i++)
            {
                args.Text = new String(possibleChars[i], 1);
                widths[i] = game.Drawer2D.MeasureChatSize(ref args).Width;
            }

            using (IDrawer2D drawer = game.Drawer2D) {
                args.Text = "Feet pos: ";
                Size size = game.Drawer2D.MeasureChatSize(ref args);
                baseWidth   = size.Width;
                size.Width += 16 * possibleChars.Length;

                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) {
                    drawer.SetBitmap(bmp);
                    drawer.DrawChatText(ref args, 0, 0);

                    for (int i = 0; i < possibleChars.Length; i++)
                    {
                        args.Text = new String(possibleChars[i], 1);
                        drawer.DrawChatText(ref args, baseWidth + 16 * i, 0);
                    }

                    int y = fpsText.Height + 2;
                    posTex = drawer.Make2DTexture(bmp, size, 0, y);
                    game.Drawer2D.ReducePadding(ref posTex,
                                                Utils.Floor(font.Size));

                    posTex.U2    = (float)baseWidth / bmp.Width;
                    posTex.Width = (short)baseWidth;
                    texWidth     = bmp.Width;
                }
            }
        }
Ejemplo n.º 12
0
        unsafe Texture DrawAdvanced(ref DrawTextArgs args, int index, string text)
        {
            char *   chars         = stackalloc char[lines.Length * 96];
            Portion *portions      = stackalloc Portion[(96 / httpLen) * 2];
            int      portionsCount = Reduce(chars, index, portions);

            Size  total     = Size.Empty;
            Size *partSizes = stackalloc Size[portionsCount];

            for (int i = 0; i < portionsCount; i++)
            {
                Portion bit = portions[i];
                args.Text = text.Substring(bit.LineBeg, bit.LineLen);
                args.Font = (bit.Len & 0x8000) == 0 ? font : underlineFont;

                partSizes[i] = game.Drawer2D.MeasureText(ref args);
                total.Height = Math.Max(partSizes[i].Height, total.Height);
                total.Width += partSizes[i].Width;
            }

            using (IDrawer2D drawer = game.Drawer2D)
                using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(total))
                {
                    drawer.SetBitmap(bmp);
                    for (int i = 0, x = 0; i < portionsCount; i++)
                    {
                        Portion bit = portions[i];
                        args.Text = text.Substring(bit.LineBeg, bit.LineLen);
                        args.Font = (bit.Len & 0x8000) == 0 ? font : underlineFont;

                        drawer.DrawText(ref args, x, 0);
                        x += partSizes[i].Width;
                    }
                    return(drawer.Make2DTexture(bmp, total, 0, 0));
                }
        }