Ejemplo n.º 1
0
 public TextInput(BMFont font, string s = "")
     : base(new Point(0, 0), new Point(200, font.Height), "TextEntry" + (object)UserInterface.GetUniqueElementID())
 {
     this.text              = new Text(Shaders.FontShader, font, s, BMFont.Justification.Left);
     this.text.RelativeTo   = Corner.Fill;
     this.text.Padding      = new Point(5, 0);
     this.OnMouseClick      = (OnMouse)((o, e) => this.text.OnMouseClick(o, e));
     this.text.OnMouseClick = (OnMouse)((o, e) =>
     {
         if (this.hasFocus)
         {
             return;
         }
         this.hasFocus = true;
         Input.PushKeyBindings();
         Input.SubscribeAll(new Event((Event.KeyEvent)((key, state) =>
         {
             if (!state || this.text.TextSize.X > this.Size.X - 16)
             {
                 return;
             }
             this.text.String += key.ToString();
             if (this.OnTextEntry == null)
             {
                 return;
             }
             this.OnTextEntry(this, this.String);
         })));
         Input.Subscribe('\b', new Event((Action)(() =>
         {
             if (this.text.String.Length == 0)
             {
                 return;
             }
             this.text.String = this.text.String.Substring(0, this.text.String.Length - 1);
             if (this.OnTextEntry == null)
             {
                 return;
             }
             this.OnTextEntry(this, this.String);
         })));
         Input.Subscribe('\r', new Event((Action)(() =>
         {
             if (this.OnCarriageReturn == null)
             {
                 return;
             }
             this.OnCarriageReturn(this, this.String);
         })));
         Input.Subscribe('\x001B', new Event((Action)(() => this.text.OnLoseFocus((object)null, (IMouseInput)null))));
         this.text.OnLoseFocus = (OnFocus)((sender, newFocus) =>
         {
             if (!this.hasFocus)
             {
                 return;
             }
             this.hasFocus = false;
             Input.PopKeyBindings();
         });
     });
     this.AddElement((UIElement)this.text);
 }
Ejemplo n.º 2
0
        public TextBox(BMFont font, Texture scrollTexture, int selectedLine = -1)
        {
            this.Font          = font;
            this.SelectedColor = new Vector4(0.3f, 0.9f, 0.3f, 1f);

            this.OnMouseDown = new OnMouse((sender, eventArgs) =>
            {
                // find which line we're on
                int y        = (CorrectedPosition.Y + Size.Y) - (UserInterface.Height - eventArgs.Location.Y);
                SelectedLine = currentLine + (int)(y / (Font.Height * 1.2));
            });

            // set up the scroll bar
            if (scrollbarTexture == null)
            {
                scrollbarTexture = scrollTexture;
            }
            this.scrollBar = new Button(scrollbarTexture);
            this.scrollBar.BackgroundColor = new Vector4(0, 0, 0, 0);
            this.scrollBar.Size            = new Point(scrollBar.Size.X, scrollBar.Size.Y / 2);

            scrollBar.OnMouseUp   = new OnMouse((sender, eventArgs) => scrollBarMouseDown = false);
            scrollBar.OnMouseDown = new OnMouse((sender, eventArgs) =>
            {
                scrollBarMouseDown = (eventArgs.Button == MouseButton.Left);
                scrollBarDown      = eventArgs.Location.Y;
            });
            scrollBar.OnMouseMove = new OnMouse((sender, eventArgs) =>
            {
                if (!scrollBarMouseDown)
                {
                    return;
                }

                int dy = scrollBarDown - eventArgs.Location.Y;

                int ymin = CorrectedPosition.Y - Parent.CorrectedPosition.Y;
                int ymax = ymin + Size.Y - ScrollBar.Size.Y;
                int y    = Math.Min(ymax, Math.Max(ymin, scrollBar.Position.Y + dy));

                if (y == scrollBar.Position.Y)
                {
                    return;
                }

                scrollBarDown      = eventArgs.Location.Y;
                scrollBar.Position = new Point(scrollBar.Position.X, y);
                scrollBar.OnResize();

                double percent = ((ymax - y) / ((double)Size.Y - scrollBar.Size.Y));
                CurrentLine    = (int)Math.Round((LineCount - MaximumLines) * percent);
            });
            scrollBar.OnLoseFocus = new OnFocus((o, e) =>
            {
                if (this.OnLoseFocus != null)
                {
                    this.OnLoseFocus(o, e);
                }
            });
            this.OnMouseMove = (sender, eventArgs) => scrollBar.OnMouseMove(sender, eventArgs);
        }
Ejemplo n.º 3
0
 public void Write(Vector3 color, string message, BMFont customFont)
 {
     this.textBox.Write(color, message, customFont);
 }
Ejemplo n.º 4
0
 public Text(ShaderProgram program, BMFont font, string text, BMFont.Justification justification = BMFont.Justification.Left)
     : this(program, font, text, new Vector3(1, 1, 1), justification)
 {
 }
Ejemplo n.º 5
0
        public TextInput(BMFont font, string s = "")
            : base(new Point(0, 0), new Point(200, font.Height), "TextEntry" + UserInterface.GetUniqueElementID())
        {
            text            = new Text(Shaders.FontShader, font, s, BMFont.Justification.Left);
            text.RelativeTo = Corner.Fill;
            text.Padding    = new Point(5, 0);

            this.OnMouseClick = new OnMouse((o, e) => text.OnMouseClick(o, e));

            text.OnMouseClick = new OnMouse((o, e) =>
            {
                if (hasFocus)
                {
                    return;
                }
                hasFocus = true;

                // take control of the key bindings
                Input.PushKeyBindings();

                Input.SubscribeAll(new Event((key, state) =>
                {
                    // give 16 pixels of padding on the right
                    if (!state || text.TextSize.X > Size.X - 16)
                    {
                        return;
                    }

                    text.String += key;

                    if (OnTextEntry != null)
                    {
                        OnTextEntry(this, String);
                    }
                }));

                // delete key
                Input.Subscribe((char)8, new Event(() =>
                {
                    if (text.String.Length == 0)
                    {
                        return;
                    }
                    else
                    {
                        text.String = text.String.Substring(0, text.String.Length - 1);
                    }

                    if (OnTextEntry != null)
                    {
                        OnTextEntry(this, String);
                    }
                }));

                // carriage return
                Input.Subscribe((char)13, new Event(() =>
                {
                    if (OnCarriageReturn != null)
                    {
                        OnCarriageReturn(this, String);
                    }
                }));

                // escape key
                Input.Subscribe((char)27, new Event(() => text.OnLoseFocus(null, null)));

                // restore the key bindings when we lose focus
                text.OnLoseFocus = new OnFocus((sender, newFocus) =>
                {
                    if (!hasFocus)
                    {
                        return;
                    }
                    hasFocus = false;

                    Input.PopKeyBindings();
                });
            });

            this.AddElement(text);
        }
Ejemplo n.º 6
0
 public Text(Material program, BMFont font, string text, BMFont.Justification justification = BMFont.Justification.Left)
     : this(program, font, text, new Vector3(1f, 1f, 1f), justification)
 {
 }