Exemple #1
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;
        }
 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);
 }