Пример #1
0
        public void MainLoop()
        {
            while (!Exit && !ProgramInfo.ExitProgram)
            {
                var input = ReadKey();

                if (input.Key == ConsoleKey.Tab)
                {
                    CurrentlySelected.Tab();
                }
                else if (input.Key == ConsoleKey.Enter)
                {
                    CurrentlySelected.Enter();
                }
                else if (input.Key == ConsoleKey.LeftArrow)
                {
                    CurrentlySelected.CursorMoveLeft();
                }
                else if (input.Key == ConsoleKey.RightArrow)
                {
                    CurrentlySelected.CursorMoveRight();
                }
                else if (input.Key == ConsoleKey.UpArrow)
                {
                    CurrentlySelected.CursorMoveUp();
                }
                else if (input.Key == ConsoleKey.DownArrow)
                {
                    CurrentlySelected.CursorMoveDown();
                }
                else if (input.Key == ConsoleKey.Backspace)
                {
                    CurrentlySelected.BackSpace();
                }
                else if (input.Key == ConsoleKey.Home)
                {
                    CurrentlySelected.CursorToStart();
                }
                else if (input.Key == ConsoleKey.End)
                {
                    CurrentlySelected.CursorToEnd();
                }
                else
                {
                    CurrentlySelected.AddLetter((Char)input.KeyChar); // Letter(input.KeyChar);
                }
            }
        }
Пример #2
0
        public virtual bool Update(Keys key, Func <char?> getKey, bool click, int mouseX, int mouseY)
        {
            if (!Visible)
            {
                return(false);
            }
            char?c;

            if (key == Keys.Tab)
            {
                if (CurrentlySelected == null && Inputs.Any())
                {
                    SelectFirstItem();
                }
                else
                {
                    CurrentlySelected?.Tab();
                }
            }
            else if (key == Keys.Escape)
            {
                CurrentlySelected?.Escape();
            }
            else if (key == Keys.PageUp)
            {
                CurrentlySelected?.PageUp();
            }
            else if (key == Keys.PageDown)
            {
                CurrentlySelected?.PageDown();
            }
            else if (key == Keys.Enter)
            {
                CurrentlySelected?.Enter();
            }
            else if (key == Keys.Delete)
            {
                CurrentlySelected?.Delete();
            }
            else if (key == Keys.Left)
            {
                CurrentlySelected?.CursorMoveLeft();
            }
            else if (key == Keys.Right)
            {
                CurrentlySelected?.CursorMoveRight();
            }
            else if (key == Keys.Up)
            {
                CurrentlySelected?.CursorMoveUp();
            }
            else if (key == Keys.Down)
            {
                CurrentlySelected?.CursorMoveDown();
            }
            else if (key == Keys.Back)
            {
                CurrentlySelected?.BackSpace();
            }
            else if (key == Keys.Home)
            {
                CurrentlySelected?.CursorToStart();
            }
            else if (key == Keys.End)
            {
                CurrentlySelected?.CursorToEnd();
            }
            else if ((c = getKey?.Invoke()) != null)
            {
                CurrentlySelected?.AddLetter((char)c);  // Letter(input.KeyChar);
            }
            else if (click)
            {
                var handled = false;
                foreach (var i in Inputs)
                {
                    var rect = new Rectangle(i.PositionX, i.PositionY, i.Width, i.Height);
                    if (rect.Contains(new Point(mouseX, mouseY)))
                    {
                        var mx = mouseX - i.PositionX;
                        var my = mouseY - i.PositionY;
                        if (i.Selectable)
                        {
                            CurrentlySelected = i;
                            SetSelected();
                        }
                        i.Click(mx, my);
                        handled = true;
                    }
                }
                Click(mouseX, mouseY, handled);
            }
            return(true);
        }