Example #1
0
        public void Render <TSurface, TSource>(ScreenRenderer <TSurface, TSource> r, DirectGraphicsContext <TSurface, TSource> layer, Point destination, int fontScale = 1)
        {
            var font = r.SpriteManager["font"];

            byte[] asciiBytes = Encoding.ASCII.GetBytes(Text);

            int destX = destination.X;

            if (Icon != null)
            {
                Rectangle iconDestination = new Rectangle(Icon.Destination);
                iconDestination.X += destination.X;
                iconDestination.Y += destination.Y;
                layer.Draw(r.SpriteManager[Icon.Texture], iconDestination.ToDrawing(), Icon.Source != Rectangle.Empty ? Icon.Source.ToDrawing() : (System.Drawing.Rectangle?)null);

                destX += (int)iconDestination.Width + 4;
            }

            foreach (byte c in asciiBytes)
            {
                int srcX = (c % 16) * 8;
                int srcY = (c / 16) * 8;

                layer.Draw(font, new System.Drawing.Rectangle(destX, destination.Y, 8 * fontScale, 8 * fontScale), new System.Drawing.Rectangle(srcX, srcY, 8, 8), new DrawInfo()
                {
                    Color = Color
                });
                destX += char_sizes[c] * fontScale;
            }
        }
Example #2
0
        public virtual void Render <TSurface, TSource>(ScreenRenderer <TSurface, TSource> r, DirectGraphicsContext <TSurface, TSource> layer, Vector2D offset)
        {
            if (!Enabled)
            {
                return;
            }
            layer.FillRect((Bounds + (Position + offset)).ToDrawing(), Highlighted ? Focused ? Color.CornflowerBlue : Color.FromArgb(63, 63, 70) : Color.FromArgb(37, 37, 38));
            TextUnit  label         = new TextUnit(Display);
            Rectangle displayBounds = (Bounds + (Position + offset));

            System.Drawing.Size labelSize = label.GetSize(TextSize);
            label.Render(r, layer, new Point((int)(displayBounds.X + displayBounds.Width / 2 - labelSize.Width / 2), (int)(displayBounds.Y + displayBounds.Height / 2 - labelSize.Height / 2)), TextSize);
        }
Example #3
0
        public TextInputSystem()
        {
            Pad = new List <GUIButton>();

            int       btnSize      = 36;
            Rectangle btnBounds    = new Rectangle(-btnSize / 2, -btnSize / 2, btnSize, btnSize);
            int       spacebarSize = (btnSize + 4) * 7 - 4;
            Rectangle spaceBounds  = new Rectangle(-spacebarSize / 2, -btnSize / 2, spacebarSize, btnSize);

            int y = 0;

            for (int i = 0; i < rows.Length; i++)
            {
                string row = rows[i];
                int    x   = 0;
                for (int j = 0; j < row.Length; j++)
                {
                    char c = row[j];
                    if (c != ' ')
                    {
                        Pad.Add(new GUIKeyboardButton(this, new Vector2D(x, y), c + "", shiftRows[i][j] + "", btnBounds)
                        {
                            Repeating = true
                        });
                    }
                    x += btnSize + 4;
                }
                y += btnSize + 4;
            }
            y -= btnSize + 4;
            Pad.Add(new GUIButton(new Vector2D((btnSize + 4) * 5, y), " ", spaceBounds)
            {
                Repeating = true
            });

            //Pad.Add(new GUIButton(new Vector2D(-(btnSize + 4), 0), "\b", btnBounds));
            //Pad.Add(new GUIButton(new Vector2D(-(btnSize + 4), btnSize + 4), "\u0018", btnBounds));

            //Pad.Add(new GUIButton(new Vector2D(-(btnSize + 4), (btnSize + 4) * 5 / 2), "\u0007", new Rectangle(-btnSize / 2, -btnSize - 2, btnSize, btnSize * 2 + 4)));
        }
Example #4
0
        public NumberInputSystem()
        {
            Pad = new List <GUIButton>();

            int       btnSize   = 36;
            Rectangle btnBounds = new Rectangle(-btnSize / 2, -btnSize / 2, btnSize, btnSize);

            Pad.Add(new GUIButton(new Vector2D(0, 0), "1", btnBounds)
            {
                Highlighted = true
            });
            Pad.Add(new GUIButton(new Vector2D(btnSize + 4, 0), "2", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(btnSize + 4 + btnSize + 4, 0), "3", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(0, btnSize + 4), "4", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(btnSize + 4, btnSize + 4), "5", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(btnSize + 4 + btnSize + 4, btnSize + 4), "6", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(0, (btnSize + 4) * 2), "7", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(btnSize + 4, (btnSize + 4) * 2), "8", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(btnSize + 4 + btnSize + 4, (btnSize + 4) * 2), "9", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(0, (btnSize + 4) * 3), "-", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(btnSize + 4, (btnSize + 4) * 3), "0", btnBounds));
            Pad.Add(DotButton = new GUIButton(new Vector2D(btnSize + 4 + btnSize + 4, (btnSize + 4) * 3), ".", btnBounds));

            Pad.Add(new GUIButton(new Vector2D(-btnSize - 4, -2 * (btnSize * 3 / 4 - 4)), "^", new Rectangle(-btnSize / 2, -btnSize / 4, btnSize, btnSize / 2))
            {
                TextSize = 2, Repeating = true
            });
            Pad.Add(new GUIButton(new Vector2D(-btnSize - 4, -btnSize * 3 / 4 - 4), "v", new Rectangle(-btnSize / 2, -btnSize / 4, btnSize, btnSize / 2))
            {
                TextSize = 2, Repeating = true
            });

            Pad.Add(new GUIButton(new Vector2D(-(btnSize + 4), 0), "\b", btnBounds));
            Pad.Add(new GUIButton(new Vector2D(-(btnSize + 4), btnSize + 4), "\u0018", btnBounds));

            Pad.Add(new GUIButton(new Vector2D(-(btnSize + 4), (btnSize + 4) * 5 / 2), "\u0007", new Rectangle(-btnSize / 2, -btnSize - 2, btnSize, btnSize * 2 + 4)));
        }
Example #5
0
 public GUIButton(Vector2D position, string display, Rectangle bounds)
 {
     Position = position;
     Display  = display;
     Bounds   = bounds;
 }
Example #6
0
 public GUIKeyboardButton(TextInputSystem owner, Vector2D position, string display, string altDisplay, Rectangle bounds) : base(position, display, bounds)
 {
     Owner         = owner;
     NormalDisplay = display;
     ShiftDisplay  = altDisplay;
 }