示例#1
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;
        }
        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;
            }
        }
        public override void Redraw(IDrawer2D drawer)
        {
            if (Window.Minimised)
            {
                return;
            }
            string text = Text;

            if (!Active)
            {
                text = "&7" + text;
            }
            int          xOffset = Width - textSize.Width, yOffset = Height - textSize.Height;
            DrawTextArgs args = new DrawTextArgs(text, font, true);

            DrawBorder(drawer);
            if (Window.ClassicMode)
            {
                DrawClassic(drawer, xOffset, yOffset);
            }
            else
            {
                DrawNormal(drawer, xOffset, yOffset);
            }

            drawer.DrawText(ref args, X + xOffset / 2, Y + yOffset / 2);
        }
        public void Redraw(IDrawer2D drawer, string text, Font font)
        {
            if (!Active)
            {
                text = "&7" + Text;
            }
            DrawTextArgs args = new DrawTextArgs(text, font, true);
            Size         size = drawer.MeasureSize(ref args);
            int          xOffset = Width - size.Width, yOffset = Height - size.Height;

            FastColour backCol = LauncherSkin.ButtonBorderCol;

            drawer.Clear(backCol, X + 1, Y, Width - 2, border);
            drawer.Clear(backCol, X + 1, Y + Height - border, Width - 2, border);
            drawer.Clear(backCol, X, Y + 1, border, Height - 2);
            drawer.Clear(backCol, X + Width - border, Y + 1, border, Height - 2);

            FastColour foreCol = Active ? LauncherSkin.ButtonForeActiveCol : LauncherSkin.ButtonForeCol;

            drawer.Clear(foreCol, X + border, Y + border, Width - border * 2, Height - border * 2);
            args.SkipPartsCheck = true;
            drawer.DrawText(ref args, X + xOffset / 2, Y + yOffset / 2);
            if (!Active)
            {
                FastColour lineCol = LauncherSkin.ButtonHighlightCol;
                drawer.Clear(lineCol, X + border + 1, Y + border, Width - (border * 2 + 1), border);
            }
        }
        void DrawTitle()
        {
            using (IDrawer2D drawer = Drawer) {
                drawer.SetBitmap(Framebuffer);

                drawer.UseBitmappedChat = (useBitmappedFont || ClassicBackground) && fontPng;
                DrawTextArgs args   = new DrawTextArgs("&eClassical&fSharp", logoFont, false);
                Size         size   = drawer.MeasureSize(ref args);
                int          xStart = Width / 2 - size.Width / 2;

                args.Text = "&0Classical&0Sharp";
                drawer.DrawText(ref args, xStart + 4, 4);
                args.Text = "&eClassical&fSharp";
                drawer.DrawText(ref args, xStart, 0);
                drawer.UseBitmappedChat = false;
            }
        }
        public override void Redraw(IDrawer2D drawer)
        {
            string text = Text;

            if (Password)
            {
                text = new String('*', text.Length);
            }
            DrawTextArgs args = new DrawTextArgs(text, font, true);

            Size size = drawer.MeasureSize(ref args);

            Width               = Math.Max(ButtonWidth, size.Width + 15);
            textHeight          = size.Height;
            args.SkipPartsCheck = true;
            if (Window.Minimised)
            {
                return;
            }

            FastColour col = Active ? new FastColour(240, 240, 240) : new FastColour(180, 180, 180);

            drawer.Clear(col, X + 1, Y, Width - 2, 2);
            drawer.Clear(col, X + 1, Y + Height - 2, Width - 2, 2);
            drawer.Clear(col, X, Y + 1, 2, Height - 2);
            drawer.Clear(col, X + Width - 2, Y + 1, 2, Height - 2);
            drawer.Clear(FastColour.Black, X + 2, Y + 2, Width - 4, Height - 4);

            if (Text.Length != 0 || HintText == null)
            {
                int y = Y + 2 + (Height - textHeight) / 2;
                drawer.DrawText(ref args, X + 5, y);
            }
            else
            {
                args.SkipPartsCheck = false;
                args.Text           = HintText;
                args.Font           = hintFont;

                Size hintSize = drawer.MeasureSize(ref args);
                int  y        = Y + (Height - hintSize.Height) / 2;
                args.SkipPartsCheck = true;
                drawer.DrawText(ref args, X + 5, y);
            }
        }
示例#7
0
        void DrawText(IDrawer2D drawer, DrawTextArgs args)
        {
            if (Text.Length != 0 || HintText == null)
            {
                int y = Y + 2 + (Height - textHeight) / 2;
                drawer.DrawText(ref args, X + 5, y);
            }
            else
            {
                args.SkipPartsCheck = false;
                args.Text           = HintText;
                args.Font           = hintFont;

                Size hintSize = drawer.MeasureSize(ref args);
                int  y        = Y + (Height - hintSize.Height) / 2;
                args.SkipPartsCheck = true;
                drawer.DrawText(ref args, X + 5, y);
            }
        }
        public override void Redraw(IDrawer2D drawer)
        {
            if (Window.Minimised)
            {
                return;
            }
            DrawTextArgs args = new DrawTextArgs(Text, font, true);

            drawer.DrawText(ref args, X, Y);
        }
        public void Redraw(IDrawer2D drawer, string text, Font font)
        {
            DrawTextArgs args = new DrawTextArgs(text, font, true);
            Size         size = drawer.MeasureSize(ref args);

            Width = size.Width; Height = size.Height;

            args.SkipPartsCheck = true;
            drawer.DrawText(ref args, X, Y);
            Text = text;
        }
示例#10
0
        public static void DrawClippedText(ref DrawTextArgs args, IDrawer2D drawer,
                                           int x, int y, int maxWidth)
        {
            Size size = drawer.MeasureSize(ref args);

            // No clipping necessary
            if (size.Width <= maxWidth)
            {
                drawer.DrawText(ref args, x, y); return;
            }
            DrawTextArgs copy = args;

            copy.SkipPartsCheck = true;

            char[] chars = new char[args.Text.Length + 2];
            for (int i = 0; i < args.Text.Length; i++)
            {
                chars[i] = args.Text[i];
            }
            chars[args.Text.Length]     = '.';
            chars[args.Text.Length + 1] = '.';

            for (int len = args.Text.Length; len > 0; len--)
            {
                chars[len] = '.';
                if (chars[len - 1] == ' ')
                {
                    continue;
                }

                copy.Text = new string(chars, 0, len + 2);
                size      = drawer.MeasureSize(ref copy);
                if (size.Width > maxWidth)
                {
                    continue;
                }

                drawer.DrawText(ref copy, x, y); return;
            }
        }
 public void Redraw(IDrawer2D drawer)
 {
     drawer.DrawRect(FastColour.Black, X, Y, Width, Height);
     if (Value)
     {
         DrawTextArgs args = new DrawTextArgs("X", font, false);
         Size         size = drawer.MeasureSize(ref args);
         args.SkipPartsCheck = true;
         drawer.DrawText(ref args, X + (Width + 2 - size.Width) / 2,                  // account for border
                         Y + (Height - size.Height) / 2);
     }
     drawer.DrawRectBounds(FastColour.White, 2, X, Y, Width, Height);
 }
示例#12
0
        public static void DrawClippedText(ref DrawTextArgs args, IDrawer2D drawer,
                                           int x, int y, int maxWidth)
        {
            Size size = drawer.MeasureText(ref args);

            // No clipping needed
            if (size.Width <= maxWidth)
            {
                args.SkipPartsCheck = true;
                drawer.DrawText(ref args, x, y); return;
            }

            string text = args.Text;

            char[] chars = new char[text.Length + 2];

            for (int i = 0; i < text.Length; i++)
            {
                chars[i] = text[i];
            }
            chars[text.Length]     = '.';
            chars[text.Length + 1] = '.';

            DrawTextArgs part = args;

            for (int i = text.Length - 1; i > 0; i--)
            {
                chars[i] = '.';
                if (text[i - 1] == ' ')
                {
                    continue;
                }

                part.Text = new string(chars, 0, i + 2);
                if (TryDraw(ref part, drawer, x, y, maxWidth))
                {
                    return;
                }

                // If down to <= 2 chars, try omit trailing ..
                if (i > 2)
                {
                    continue;
                }
                part.Text = new string(chars, 0, i);
                if (TryDraw(ref part, drawer, x, y, maxWidth))
                {
                    return;
                }
            }
        }
示例#13
0
        static bool TryDraw(ref DrawTextArgs args, IDrawer2D drawer,
                            int x, int y, int maxWidth)
        {
            Size size = drawer.MeasureText(ref args);

            if (size.Width > maxWidth)
            {
                return(false);
            }

            args.SkipPartsCheck = true;
            drawer.DrawText(ref args, x, y);
            return(true);
        }
示例#14
0
        void DrawContent(IDrawer2D drawer, Font font, SpecialInputTab e, int yOffset)
        {
            int          wrap = e.ItemsPerRow;
            DrawTextArgs args = new DrawTextArgs(null, font, false);

            for (int i = 0; i < e.Contents.Length; i += e.CharsPerItem)
            {
                args.Text = e.Contents.Substring(i, e.CharsPerItem);
                int item = i / e.CharsPerItem;

                int x = (item % wrap) * elementSize.Width, y = (item / wrap) * elementSize.Height;
                y += yOffset;
                drawer.DrawText(ref args, x, y);
            }
        }
        void DrawTitles(IDrawer2D drawer, Font font)
        {
            int          x    = 0;
            DrawTextArgs args = new DrawTextArgs(null, font, false);

            for (int i = 0; i < elements.Length; i++)
            {
                args.Text = elements[i].Title;
                FastColour col = i == selectedIndex ? new FastColour(30, 30, 30, 200) :
                                 new FastColour(0, 0, 0, 127);;
                Size size = elements[i].TitleSize;

                drawer.Clear(col, x, 0, size.Width, size.Height);
                drawer.DrawText(ref args, x + titleSpacing / 2, 0);
                x += size.Width;
            }
        }
示例#16
0
        public override void Redraw(IDrawer2D drawer)
        {
            if (Window.Minimised || !Visible)
            {
                return;
            }
            string text = Text;

            if (DarkenWhenInactive && !Active)
            {
                text = "&7" + text;
            }

            DrawTextArgs args = new DrawTextArgs(text, font, true);

            drawer.DrawText(ref args, X, Y);
        }
        unsafe void DrawContent(IDrawer2D drawer, Font font, SpecialInputTab e, int yOffset)
        {
            string       s    = new String('\0', e.CharsPerItem);
            int          wrap = e.ItemsPerRow;
            DrawTextArgs args = new DrawTextArgs(s, font, false);

            fixed(char *ptr = s)
            {
                for (int i = 0; i < e.Contents.Length; i += e.CharsPerItem)
                {
                    for (int j = 0; j < e.CharsPerItem; j++)
                    {
                        ptr[j] = e.Contents[i + j];
                    }
                    int item = i / e.CharsPerItem;

                    int x = (item % wrap) * elementSize.Width, y = (item / wrap) * elementSize.Height;
                    y += yOffset;
                    drawer.DrawText(ref args, x, y);
                }
            }
        }
示例#18
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.MeasureSize(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.DrawText(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));
                }
        }
示例#19
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));
                }
        }