コード例 #1
0
ファイル: InputWidget.cs プロジェクト: dhtdht020/GTTMCube
        /// <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 = GetLastCol(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;
        }
コード例 #2
0
ファイル: Drawer2DExt.cs プロジェクト: dhtdht020/GTTMCube
        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;
                }
            }
        }
コード例 #3
0
        void DrawGrid(IDrawer2D drawer)
        {
            if (!game.ClassicBackground)
            {
                drawer.Clear(LauncherSkin.BackgroundCol,
                             table.X, table.Y + headerHeight + 5, table.Width, 2);
            }
            headerStartY = table.Y;

            headerEndY = table.Y + headerHeight + 5;
            int startY = headerEndY + 3;

            numEntries = (table.Y + table.Height - startY) / (entryHeight + 3);
        }
コード例 #4
0
ファイル: Drawer2DExt.cs プロジェクト: dhtdht020/GTTMCube
        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);
        }
コード例 #5
0
        public void SetDrawData(IDrawer2D drawer, string text)
        {
            Text = text;
            if (Password)
            {
                text = new String('*', text.Length);
            }

            DrawTextArgs args = new DrawTextArgs(text, font, true);
            Size         size = drawer.MeasureSize(ref args);

            RealWidth  = Math.Max(ButtonWidth, size.Width + 15);
            textHeight = size.Height;
        }
コード例 #6
0
        string GetPart(string line, int start, int end)
        {
            string part    = line.Substring(start, end - start);
            int    lastCol = line.LastIndexOf('&', start, start);

            // We may split up a line into say %e<word><url>
            // url and word both need to have %e at the start.

            if (lastCol >= 0 && IDrawer2D.ValidColCode(line, lastCol + 1))
            {
                part = "&" + line[lastCol + 1] + part;
            }
            return(part);
        }
コード例 #7
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;
            }
        }
コード例 #8
0
        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( 60, 60, 60, 200 );
                Size size = elements[i].TitleSize;

                drawer.Clear( col, x, 0, size.Width, size.Height );
                drawer.DrawChatText( ref args, x + titleSpacing / 2, 0 );
                x += size.Width;
            }
        }
コード例 #9
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);
            }
        }
コード例 #10
0
        public override void Redraw(IDrawer2D drawer)
        {
            if (Window.Minimised || !Visible)
            {
                return;
            }
            using (FastBitmap bmp = Window.LockBits()) {
                Rectangle r = new Rectangle(X, Y, Width, Height);
                DrawBoxBounds(bmp, r);
                DrawBox(bmp, r);

                r.Width = (int)(Width * Value / MaxValue);
                Drawer2DExt.Clear(bmp, r, ProgressColour);
            }
        }
コード例 #11
0
        void LoadSavedInfo(IDrawer2D drawer)
        {
            Dictionary <string, object> metadata;

            // restore what user last typed into the various fields
            if (game.ScreenMetadata.TryGetValue("screen-CC", out metadata))
            {
                Set(0, (string)metadata["user"]);
                Set(1, (string)metadata["pass"]);
            }
            else
            {
                LoadFromOptions();
            }
        }
コード例 #12
0
        public void RedrawData(IDrawer2D drawer)
        {
            int x = table.X + 5;

            DrawGrid(drawer);
            x += DrawColumn(drawer, false, font, titleFont,
                            "Name", table.ColumnWidths[0], x, e => e.Name) + 5;
            x += DrawColumn(drawer, true, font, titleFont,
                            "Players", table.ColumnWidths[1], x, e => e.Players) + 5;
            x += DrawColumn(drawer, true, font, titleFont,
                            "Uptime", table.ColumnWidths[2], x, e => e.Uptime) + 5;
            x += DrawColumn(drawer, true, font, titleFont,
                            "Software", table.ColumnWidths[3], x, e => e.Software) + 5;
            DrawScrollbar(drawer);
        }
コード例 #13
0
        void AddChat(string text)
        {
            text = text.TrimEnd().Replace('%', '&');
            if (!IDrawer2D.IsWhiteColour(lastCol))
            {
                text = "&" + lastCol + text;
            }

            char col = game.Drawer2D.LastColour(text, text.Length);

            if (col != '\0')
            {
                lastCol = col;
            }
            game.Chat.Add(text, MessageType.Normal);
        }
コード例 #14
0
        void DrawGrid(IDrawer2D drawer, Font font, Font titleFont)
        {
            DrawTextArgs args = new DrawTextArgs("I", titleFont, true);
            Size         size = drawer.MeasureSize(ref args);

            if (!Window.ClassicMode)
            {
                drawer.Clear(LauncherSkin.BackgroundCol, X, Y + size.Height + 5, Width, 2);
            }
            headerStartY = Y;

            headerEndY = Y + size.Height + 5;
            int startY = headerEndY + 3;

            numEntries = (Y + Height - startY) / (defaultInputHeight + 3);
        }
コード例 #15
0
        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;
            }
        }
コード例 #16
0
 public override void Redraw(IDrawer2D drawer)
 {
     if (Window.Minimised)
     {
         return;
     }
     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);
 }
コード例 #17
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);
        }
コード例 #18
0
        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;
            }
        }
コード例 #19
0
        public GameView2D(IDrawer2D <IGameBitmap> drawer, int width, int height, int xScale, int yScale, Color bgColor, int buffers = 1)
        {
            Bounds = new Rectangle(0, 0, width, height);

            this.drawer = drawer;
            this.xScale = xScale;
            this.yScale = yScale;
            this.drawer.Init(width, height, xScale, yScale);

            ScrollTop          = 20;
            ScrollBottom       = 20;
            ScrollLeft         = 20;
            ScrollRight        = 20;
            LockViewToLocation = true;
            backgroundColor    = bgColor;
            this.buffers       = buffers;
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        public unsafe override void Redraw(IDrawer2D drawer)
        {
            if (Window.Minimised || !Visible)
            {
                return;
            }
            int *palette = stackalloc int[Palette.Length];

            CalculatePalette(palette);

            using (FastBitmap bmp = Window.LockBits()) {
                int i = 0;
                for (int yy = 0; yy < Height; yy++)
                {
                    if ((Y + yy) < 0)
                    {
                        continue;
                    }
                    if ((Y + yy) >= bmp.Height)
                    {
                        break;
                    }
                    int *row = bmp.GetRowPtr(Y + yy);

                    for (int xx = 0; xx < Width; xx++)
                    {
                        int index    = Indices[i >> 1];                      // each byte has even and odd 4bits
                        int selector = 4 * ((i + 1) & 1);
                        index = (index >> selector) & 0xF;
                        i++;

                        int col = palette[index];
                        if (col == 0)
                        {
                            continue;                                   // transparent pixel
                        }
                        if ((X + xx) < 0 || (X + xx) >= bmp.Width)
                        {
                            continue;
                        }
                        row[X + xx] = col;
                    }
                }
            }
        }
コード例 #22
0
ファイル: Player.cs プロジェクト: adtyn/ClassicalSharp
        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));
                }
        }
コード例 #23
0
        unsafe void DrawContent( IDrawer2D drawer, Font font, Element 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.DrawChatText( ref args, x, y );
                }
            }
        }
コード例 #24
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;
        }
コード例 #25
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);
            }
        }
コード例 #26
0
        protected char GetLastColour(int indexX, int indexY)
        {
            int x = indexX;

            for (int y = indexY; y >= 0; y--)
            {
                string part = lines[y];
                char   code = IDrawer2D.LastCol(part, x);
                if (code != '\0')
                {
                    return(code);
                }
                if (y > 0)
                {
                    x = lines[y - 1].Length;
                }
            }
            return('\0');
        }
コード例 #27
0
        char GetLastColour(int indexX, int indexY)
        {
            int       x      = indexX;
            IDrawer2D drawer = game.Drawer2D;

            for (int y = indexY; y >= 0; y--)
            {
                string part = parts[y];
                char   code = drawer.LastColour(part, x);
                if (code != '\0')
                {
                    return(code);
                }
                if (y > 0)
                {
                    x = parts[y - 1].Length;
                }
            }
            return('\0');
        }
コード例 #28
0
        public void SetText(string text)
        {
            game.Graphics.DeleteTexture(ref texture);
            if (IDrawer2D.EmptyText(text))
            {
                texture = default(Texture);
                Width   = 0; Height = defaultHeight;
            }
            else
            {
                DrawTextArgs args = new DrawTextArgs(text, font, true);
                texture = game.Drawer2D.MakeTextTexture(ref args, 0, 0);
                Width   = Math.Max(texture.Width, MinWidth);
                Height  = Math.Max((int)texture.Height, minHeight);

                Reposition();
                texture.X1 = X + (Width / 2 - texture.Width / 2);
                texture.Y1 = Y + (Height / 2 - texture.Height / 2);
            }
        }
コード例 #29
0
ファイル: Player.cs プロジェクト: Dirfiend1324/ClassicalSharp
        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));
                }
        }
コード例 #30
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);
                }
        }
コード例 #31
0
        public void SetDrawData(IDrawer2D drawer, string text, Font font, Font hintFont,
                                Anchor horAnchor, Anchor verAnchor, int width, int height, int x, int y)
        {
            ButtonWidth = width; ButtonHeight = height;
            Width       = width; Height = height;
            CalculateOffset(x, y, horAnchor, verAnchor);

            Text = text;
            if (Password)
            {
                text = new String('*', text.Length);
            }
            this.font     = font;
            this.hintFont = hintFont;

            DrawTextArgs args = new DrawTextArgs(text, font, true);
            Size         size = drawer.MeasureSize(ref args);

            Width      = Math.Max(ButtonWidth, size.Width + 15);
            textHeight = size.Height;
        }
コード例 #32
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);
                }
        }