示例#1
0
 public ScrollPanel(Vector2 position, Vector2 size, Control control) : base()
 {
     this.Position   = position;
     Size            = size;
     Bounds          = new Rectangle(Position.ToPoint(), Size.ToPoint());
     rasterizerState = new RasterizerState();
     rasterizerState.ScissorTestEnable = true;
     this.control   = control;
     control.Bounds = new Rectangle((Position + control.Position + scrollPosition).ToPoint(), control.Bounds.Size);
     offset         = Position - control.Position;
     KeyboardManager.GetInstance().KeyPressed += HandleKeyPressed;
     HandlePos       = new Vector2(Position.X + Size.X - scollbarPos.X + 2, Position.Y) + scrollPosition;
     HandleStartPos  = HandlePos;
     ScrollbarHandle = new Rectangle(HandleStartPos.ToPoint(), new Vector2(scollbarPos.X - 2, 50).ToPoint());
     Scrollbar       = new Rectangle(new Vector2(Position.X + Size.X - scollbarPos.X, Position.Y).ToPoint(), new Vector2(scollbarPos.X, Bounds.Height - control.MarginBR.Y / 2).ToPoint());
     control.Parent  = this;
     controlScale    = new Vector2(control.Bounds.Height / Bounds.Height, control.Bounds.Width / Bounds.Width);
 }
示例#2
0
        public override void Update(GameTime gameTime)
        {
            KeyboardManager.GetInstance().Update(gameTime);
            mouseState = Mouse.GetState();

            if (lastState != mouseState)
            {
                if (lastState.LeftButton != mouseState.LeftButton || lastState.RightButton != mouseState.RightButton)
                {
                    if (mouseState.LeftButton == ButtonState.Pressed || mouseState.RightButton == ButtonState.Pressed)
                    {
                        handleMouseDown();
                    }
                    else if (mouseState.LeftButton == ButtonState.Released || mouseState.RightButton == ButtonState.Released)
                    {
                        handleMouseUp();
                    }
                }
                else
                {
                    handleMouseMove();
                }

                lastState = mouseState;
            }

            foreach (Window w in windows)
            {
                w.Update(gameTime);
            }

            foreach (Control c in children)
            {
                c.Update(gameTime);
            }
            // UpdateChildren(mouseDelta);
        }