Пример #1
0
        public override void Update(GameTime gameTime)
        {
            if (!Enabled || !Game.IsActive)
            {
                return;
            }

            _mouseDown = ScrollableGame.CheckLeftDown() || ScrollableGame.CheckLeftPressed();

            bool newMouseOver = MouseCollide();

            // Se antes não estava com o MouseOver e agora esta
            if (!IsMouseOver && newMouseOver)
            {
                if (MouseOver != null)
                {
                    MouseOver(this, EventArgs.Empty);
                }
            }
            // Se antes estava com o MouseOver e agora não esta
            if (!newMouseOver && IsMouseOver)
            {
                if (MouseOut != null)
                {
                    MouseOut(this, EventArgs.Empty);
                }
            }

            IsMouseOver = newMouseOver;

            Hits = Hits && _mouseDown && IsMouseOver;

            if (IsMouseOver && ScrollableGame.CheckLeftPressed())
            {
                _pressedOver = true;
                Hits         = true;
            }

            if (ScrollableGame.CheckLeftReleased())
            {
                if (IsMouseOver && _pressedOver)
                {
                    OnClick();
                    Hits = true;
                }
                _pressedOver = false;
            }

            base.Update(gameTime);
        }
Пример #2
0
        public override void Update(GameTime gameTime)
        {
            if (!Enabled || !Game.IsActive)
            {
                return;
            }

            // Select for Drag
            if (ScrollableGame.CheckLeftPressed(true))
            {
                if (Rect.Contains(ScrollableGame.MousePoint))
                {
                    Draging     = true;
                    Hits        = true;
                    _draggedDif = ScrollableGame.MousePos;
                }
            }

            // Dragging
            if (Draging && ScrollableGame.CheckLeftDown())
            {
                var pos = ScrollableGame.MousePos - _draggedDif;
                _draggedDif = ScrollableGame.MousePos;

                if (Horizontal)
                {
                    PosX += (int)pos.X;
                    var widthDif = Width - BarWidth;
                    if (widthDif <= 0 || PosX < 0)
                    {
                        PosX = 0;
                    }
                    else if (widthDif > 0 && PosX > widthDif)
                    {
                        PosX = widthDif;
                    }
                    if (widthDif > 0)
                    {
                        PercentageX = PosX / widthDif;
                    }
                    else
                    {
                        UpdateRec();
                    }
                }

                if (Vertical)
                {
                    PosY += (int)pos.Y;
                    var heightDif = Height - BarHeight;
                    if (heightDif <= 0 || PosY < 0)
                    {
                        PosY = 0;
                    }
                    else if (heightDif > 0 && PosY > heightDif)
                    {
                        PosY = heightDif;
                    }
                    if (heightDif > 0)
                    {
                        PercentageY = PosY / heightDif;
                    }
                    else
                    {
                        UpdateRec();
                    }
                }
            }

            // Drop
            if (ScrollableGame.CheckLeftReleased())
            {
                Draging = false;
                Hits    = false;
            }

            base.Update(gameTime);
        }
Пример #3
0
        protected bool MouseCollide()
        {
            Point point;

            if (UseScrolling)
            {
                point = new Point(ScrollableGame.MousePoint.X - (int)ScrollableGame.Scrolling.X, ScrollableGame.MousePoint.Y - (int)ScrollableGame.Scrolling.Y);
            }
            else
            {
                point = ScrollableGame.MousePoint;
            }
            return(Rec.Contains(point) && ScrollableGame.InScrollableRenderTarget(point) && (ScrollableGame.CheckValidTouchLocation() || ScrollableGame.CheckLeftReleased()));
        }
        public override void Update(GameTime gameTime)
        {
            if (!Enabled || !Game.IsActive)
            {
                return;
            }

            UpdateRec();

            // Select for Drag
            if (ScrollableGame.CheckLeftPressed(true))
            {
                if (Rect.Contains(ScrollableGame.MousePoint))
                {
                    Draging     = true;
                    _draggedDif = ScrollableGame.MousePos;
                }
                if (_rec2.Contains(ScrollableGame.MousePoint))
                {
                    Hits = true;
                }
            }

            // Dragging
            if (Draging && ScrollableGame.CheckLeftDown())
            {
                var pos = ScrollableGame.MousePos - _draggedDif;
                _draggedDif = ScrollableGame.MousePos;

                if (Vertical)
                {
                    PosY += (int)pos.Y;
                    var heightDif = Height - BarHeight;
                    if (heightDif <= 0 || PosY < 0)
                    {
                        PosY = 0;
                    }
                    else if (heightDif > 0 && PosY > heightDif)
                    {
                        PosY = heightDif;
                    }
                    if (heightDif > 0)
                    {
                        PercentageY = PosY / heightDif;
                    }
                    UpdateRec();

                    ScrollContainer.Percentage = PercentageY;
                }
            }

            // Drop
            if (ScrollableGame.CheckLeftReleased())
            {
                Draging = false;
                Hits    = false;
            }

            _barraUp.Position   = Position + new Vector2(0, PosY);
            _barraDown.Position = Position;

            base.Update(gameTime);
        }
Пример #5
0
        public override void Update(GameTime gameTime)
        {
            if (!Enabled)
            {
                return;
            }

            bool scrollDrag = false;

            if (_scroll != null)
            {
                _scroll.Update(gameTime);
                scrollDrag = _scroll.Draging || _scroll.Hits;
            }

            if (!scrollDrag)
            {
                // Select for Drag
                if (ScrollableGame.CheckLeftPressed(true))
                {
                    if (_rect.Contains(ScrollableGame.MousePoint))
                    {
                        _draging           = true;
                        _draggedDifInicial = _draggedDif = ScrollableGame.MousePos;
                    }
                }

                // Dragging
                if (_draging && ScrollableGame.CheckLeftDown())
                {
                    if (Horizontal)
                    {
                        var pos = ScrollableGame.MousePos.X - _draggedDif.X;
                        _draggedDif = ScrollableGame.MousePos;
                        PosDif     -= (int)pos;

                        if (Math.Abs(ScrollableGame.MousePos.X - _draggedDifInicial.X) > 5)
                        {
                            Button.CancelClick = true;
                        }

                        var widthDif = ContentSize - Width;

                        if (widthDif <= 0 || PosDif < 0)
                        {
                            PosDif = 0;
                        }
                        else if (widthDif > 0 && PosDif > widthDif)
                        {
                            PosDif = widthDif;
                        }

                        if (widthDif > 0)
                        {
                            Percentage = PosDif / widthDif;
                        }
                    }
                    else
                    {
                        var pos = ScrollableGame.MousePos.Y - _draggedDif.Y;
                        _draggedDif = ScrollableGame.MousePos;
                        PosDif     -= (int)pos;

                        if (Math.Abs(ScrollableGame.MousePos.Y - _draggedDifInicial.Y) > 5)
                        {
                            Button.CancelClick = true;
                        }

                        var heightDif = ContentSize - Height;

                        if (heightDif <= 0 || PosDif < 0)
                        {
                            PosDif = 0;
                        }
                        else if (heightDif > 0 && PosDif > heightDif)
                        {
                            PosDif = heightDif;
                        }

                        if (heightDif > 0)
                        {
                            Percentage = PosDif / heightDif;
                        }
                    }
                }

                // Drop
                if (ScrollableGame.CheckLeftReleased()
#if SILVERLIGHT
                    || !_rect.Contains(ScrollableGame.MousePoint)
#endif
                    )
                {
                    _draging = false;
#if SILVERLIGHT
                    Microsoft.Xna.Framework.Input.Mouse.LeftButtonDown = false;
#endif
                }

                ScrollableGame.Begin(this);

                if (_scrollable != null)
                {
                    _scrollable.Update(gameTime);
                }

                ScrollableGame.End(this);
            }

            UpdateContentSize();

            base.Update(gameTime);
        }