Пример #1
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;
         }
     }
 }
Пример #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;
                }
            }
            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);
                    }
                }
            }
        }
Пример #3
0
        public override void Update(GUIControlContext Context, double Time)
        {
            this._TopLeftButton.Update(Context.CreateChildContext(this._TopLeftButton, new Point(0.0, 0.0)), Time);
            this._BottomRightButton.Update(Context.CreateChildContext(this._BottomRightButton, this._BottomRightButtonOffset), Time);

            // Handle mouse
            MouseState ms = Context.MouseState;
            if (this._Enabled && ms != null)
            {
                bool oldmousedown = this._MouseDown;
                this._MouseDown = ms.IsButtonDown(MouseButton.Left);

                double areastart;
                double areaend;
                double areasize;
                double sliderstart;
                double slidersize;
                this._GetScrollMeasurements(out areastart, out areaend, out areasize, out sliderstart, out slidersize);
                double mouse = ms.Position.SwapIf(this._Direction == Axis.Vertical).X;

                // Dragging
                if (this._DragOffset != null)
                {
                    this.Value = (mouse - this._DragOffset.Value - areastart) / (areasize - slidersize);
                    if (!this._MouseDown)
                    {
                        this._DragOffset = null;
                        Context.ReleaseMouse();
                    }
                }

                // Check for press
                if (!oldmousedown && this._MouseDown)
                {
                    // See if its in one of the empty regions to either end of the scrollbar.
                    if (mouse > areastart && mouse < sliderstart)
                    {
                        this.Value = this._Value - this._MajorIncrement;
                    }
                    if (mouse < areaend && mouse > sliderstart + slidersize)
                    {
                        this.Value = this._Value + this._MajorIncrement;
                    }

                    // Perhaps the user intends to drag?
                    if (mouse > sliderstart && mouse < sliderstart + slidersize)
                    {
                        Context.CaptureMouse();
                        this._DragOffset = mouse - sliderstart;
                    }
                }
            }
        }
Пример #4
0
        public override void Update(GUIControlContext Context, double Time)
        {
            this._Client.Update(Context.CreateChildContext(this._Client, this.ClientRectangle.Location), Time);
            this._RightTitleBar.Update(Context.CreateChildContext(this._RightTitleBar, this._RightTitleBarOffset), Time);

            // Form needs to be dragged?
            MouseState ms = Context.MouseState;
            if (ms != null)
            {
                Point mousepos = ms.Position;
                if (this._FormDragOffset == null)
                {
                    if (new Rectangle(
                        this._Style.TitleBarLeftRightMargin,
                        0.0,
                        this.Size.X - this._RightTitleBar.Size.X - this._Style.TitleBarLeftRightMargin,
                        this._Style.TitleBarSize).In(mousepos))
                    {
                        if (ms.HasPushedButton(MouseButton.Left))
                        {
                            Context.CaptureMouse();
                            this.Container.BringToTop(this);
                            this._FormDragOffset = mousepos;
                        }
                    }
                }
                else
                {
                    this.Position = this.Position + mousepos - this._FormDragOffset.Value;
                    if (!ms.IsButtonDown(MouseButton.Left))
                    {
                        Context.ReleaseMouse();
                        this._FormDragOffset = null;
                    }
                }
            }
        }