Ejemplo n.º 1
0
        public override void Update(GUIControlContext Context, double Time)
        {
            // Mouse navigation.
            Rectangle inner = new Rectangle(this.Size).Margin(this._Style.Margin);
            MouseState ms = Context.MouseState;
            this._MouseDown = false;
            if (ms != null)
            {
                Point mousepos = ms.Position;
                foreach (_Item i in this._Items)
                {
                    Rectangle irect = this._ItemRect(inner, i);
                    if (irect.In(mousepos))
                    {
                        if (ms.IsButtonDown(MouseButton.Left))
                        {
                            this._MouseDown = true;
                        }
                        if ((mousepos - this._LastMouse).SquareLength > 1.0 || this._MouseDown)
                        {
                            if (this._Select(i))
                            {
                                this._UpdateSubmenu(irect);
                            }
                        }
                        if (ms.HasReleasedButton(MouseButton.Left))
                        {
                            this._Click();
                        }
                    }
                }
                this._LastMouse = mousepos;
            }

            // Keyboard navigation
            KeyboardState ks = Context.KeyboardState;
            if (ks != null && !this._MouseDown)
            {
                foreach (KeyEvent ke in ks.Events)
                {
                    _Item nitem = this._Active;
                    if (ke.Type == ButtonEventType.Down)
                    {
                        if (ke.Key == Key.Down)
                        {
                            // Navigate down
                            if (this._Active == null)
                            {
                                nitem = this._Items[0];
                            }
                            else
                            {
                                nitem = this._ItemAtOffsetIndex(this._Active, 1);
                            }
                        }
                        if (ke.Key == Key.Up)
                        {
                            // Navigate up
                            if (this._Active == null)
                            {
                                nitem = this._Items[this._Items.Count - 1];
                            }
                            else
                            {
                                nitem = this._ItemAtOffsetIndex(this._Active, -1);
                            }
                        }
                        if (ke.Key == Key.Left)
                        {
                            if (this._Parent != null)
                            {
                                this._Parent._Submenu = null;
                            }
                            this.Dismiss();
                            return;
                        }
                        if (ke.Key == Key.Right)
                        {
                            if (this._Active != null)
                            {
                                this._UpdateSubmenu(_ItemRect(inner, this._Active));
                                return;
                            }
                        }
                        if (ke.Key == Key.Enter)
                        {
                            this._Click();
                            return;
                        }
                    }
                    if (nitem != this._Active)
                    {
                        this._Select(nitem);
                    }
                }

                // Super quick number navigation
                foreach (char c in ks.Presses)
                {
                    int n = (int)c - 49;
                    if (n >= 0 && n < 9)
                    {
                        if (n < this._Items.Count)
                        {
                            _Item item = this._Items[n];
                            if (this._Select(item))
                            {
                                this._UpdateSubmenu(this._ItemRect(inner, item));
                                this._Click();
                            }
                        }
                    }
                }
            }
            if (this._Submenu == null && !Context.HasKeyboard)
            {
                Context.CaptureKeyboard();
            }
        }
Ejemplo n.º 2
0
 public override void Update(GUIControlContext Context, double Time)
 {
     // Handle mouse selection.
     MouseState ms = Context.MouseState;
     if (ms != null)
     {
         if (this._MouseDrag)
         {
             if(ms.IsButtonDown(MouseButton.Left))
             {
                 this._Selection.End = this._SelectedIndex(ms.Position);
             }
             else
             {
                 Context.ReleaseMouse();
                 this._MouseDrag = false;
             }
         }
         if (ms.HasPushedButton(MouseButton.Left))
         {
             Context.CaptureMouse();
             Context.CaptureKeyboard();
             this._Selection = new TextSelection(this._SelectedIndex(ms.Position));
             this._MouseDrag = true;
         }
     }
 }
Ejemplo n.º 3
0
        public override void Update(GUIControlContext Context, double Time)
        {
            // Handle mouse selection.
            MouseState ms = Context.MouseState;
            if (ms != null)
            {
                if (this._MouseDrag)
                {
                    if(ms.IsButtonDown(MouseButton.Left))
                    {
                        this._Selection.End = this._SelectedIndex(ms.Position);
                    }
                    else
                    {
                        Context.ReleaseMouse();
                        this._MouseDrag = false;
                    }
                }
                if (ms.HasPushedButton(MouseButton.Left))
                {
                    Context.CaptureMouse();
                    Context.CaptureKeyboard();
                    this._Selection = new TextSelection(this._SelectedIndex(ms.Position));
                    this._MouseDrag = true;
                }
            }
            TextSelection ts = this._Selection;
            if (ts != null && !Context.HasKeyboard)
            {
                this._Selection = ts = null;
                if (this.TextEntered != null)
                {
                    this.TextEntered(this._Text);
                }
            }

            // Flash the cursor
            this._CursorFlashTime += Time;
            double cfr = this._Style.CursorFlashRate;
            while (this._CursorFlashTime > cfr)
            {
                this._CursorFlashTime -= cfr * 2.0;
            }

            // Update text
            KeyboardState ks = Context.KeyboardState;
            if (ks != null && ts != null)
            {
                bool changed = false;
                foreach (char c in ks.Presses)
                {
                    int starti;
                    int endi;
                    ts.Order(out starti, out endi);

                    if (c == '\b')
                    {
                        if (endi - starti > 0)
                        {
                            if(this._TryChangeText(this._Text.Substring(0, starti) + this._Text.Substring(endi, this._Text.Length - endi)))
                            {
                                this._Selection = new TextSelection(starti);
                                changed = true;
                            }
                        }
                        else
                        {
                            if (starti > 0)
                            {
                                if (this._TryChangeText(this._Text.Substring(0, starti - 1) + this._Text.Substring(starti, this._Text.Length - starti)))
                                {
                                    this._Selection = new TextSelection(starti - 1);
                                    changed = true;
                                }
                            }
                        }
                        continue;
                    }

                    if (ValidChar(c))
                    {
                        if (this._TryChangeText(this._Text.Substring(0, starti) + c + this._Text.Substring(endi, this._Text.Length - endi)))
                        {
                            this._Selection = new TextSelection(starti + 1);
                            changed = true;
                        }
                    }
                }
                if (changed)
                {
                    this._CursorFlashTime = 0.0;
                    this._TextSample.Dispose();
                    this._MakeTextSample();
                }

                // Navigation
                foreach (KeyEvent ke in ks.Events)
                {
                    if (ke.Type == ButtonEventType.Down)
                    {
                        int ss = this._Selection.Start;
                        if (ke.Key == Key.Left)
                        {
                            if (ss > 0)
                            {
                                this._Selection = new TextSelection(ss - 1);
                            }
                        }
                        if (ke.Key == Key.Right)
                        {
                            if (ss < this._Text.Length)
                            {
                                this._Selection = new TextSelection(ss + 1);
                            }
                        }
                    }
                }

                // Enter?
                if (ks.IsKeyDown(Key.Enter))
                {
                    this._Selection = null;
                    Context.ReleaseKeyboard();

                    if (this.TextEntered != null)
                    {
                        this.TextEntered(this._Text);
                    }
                }
            }
        }