private void initialize(Rectangle Bounds, bool Vertical = false) { this.scrollerTexture = StandardTexture; ScrollerLabels = new List <Label>(); this.Vertical = Vertical; if (Vertical) { ButtonHeight = Bounds.Width / 2; upperButton = new Button(new Rectangle(Bounds.X, Bounds.Y, Bounds.Width, ButtonHeight)); lowerButton = new Button(new Rectangle(Bounds.X, Bounds.Bottom - ButtonHeight, Bounds.Width, ButtonHeight)); ScrollBounds = new Rectangle(Bounds.X, Bounds.Y + ButtonHeight, Bounds.Width, Bounds.Height - 2 * ButtonHeight); scrollButton = new Button(ScrollBounds); } else { ButtonHeight = Bounds.Height / 2; upperButton = new Button(new Rectangle(Bounds.X, Bounds.Y, ButtonHeight, Bounds.Height)); lowerButton = new Button(new Rectangle(Bounds.Right - ButtonHeight, Bounds.Y, ButtonHeight, Bounds.Height)); ScrollBounds = new Rectangle(Bounds.X + ButtonHeight, Bounds.Y, Bounds.Width - 2 * ButtonHeight, Bounds.Height); scrollButton = new Button(ScrollBounds); } upperButton.buttonTexture = scrollerTexture.upButton; lowerButton.buttonTexture = scrollerTexture.downButton; scrollButton.buttonTexture = scrollerTexture.scrollButton; upperButton.LeftClicked += delegate(object s, ButtonEventArgs e) { if (Value > 0) { Value--; } }; lowerButton.LeftClicked += delegate(object s, ButtonEventArgs e) { if (Value < itemCount) { Value++; } }; scrollButton.LeftClickedPressed += delegate(object s, ButtonEventArgs e) { if (!scrolling) { if (Vertical) { itemHeight = (((ScrollBounds.Height - ButtonHeight) * Increment) / (itemCount - MinimumCount)); startPos = (int)((Mouse.GetState().Position.Y - (scrollButton.ButtonBounds.Y - ScrollBounds.Y))); } else { itemHeight = (((ScrollBounds.Width - ButtonHeight) * Increment) / (float)(itemCount - MinimumCount)); startPos = (Mouse.GetState().Position.X - (scrollButton.ButtonBounds.X - ScrollBounds.X)); } } scrolling = true; }; scrollButton.Disable(); }
private void Initialize(int x, int y, int height, int thickness, bool Vertical = false) { scrollerTexture = StandardTexture; this.Vertical = Vertical; buttonUp = ButtonSize; buttonDown = ButtonSize; scrollBounds = height - buttonUp - buttonDown; normalizedBounds = new Rectangle(x, y, thickness, height); upperButton = new Button(new Rectangle()); lowerButton = new Button(new Rectangle()); scrollButton = new Button(new Rectangle()); SetButtonSizes(); upperButton.buttonTexture = scrollerTexture.upButton; lowerButton.buttonTexture = scrollerTexture.downButton; scrollButton.buttonTexture = scrollerTexture.scrollButton; scrollButton.Disable(); upperButton.LeftClicked += delegate(object s, ButtonEventArgs e) { if (Value > 0) { Value--; } }; lowerButton.LeftClicked += delegate(object s, ButtonEventArgs e) { if (Value < itemCount) { Value++; } }; scrollButton.LeftClickedPressed += delegate(object s, ButtonEventArgs e) { ScrollPress(Vertical ? e.MousePos.Y : e.MousePos.X); }; }
//------------------------------------------------------ //------------------------Constructors------------------ //------------------------------------------------------ public Scroller(int x, int y, int height, int thickness, ScrollerTexture scrollerTexture, bool Vertical = false) { this.scrollerTexture = scrollerTexture; Initialize(x, y, height, thickness, Vertical); }
//------------------------------------------------------ //------------------------Constructors------------------ //------------------------------------------------------ public ScrollerOld(Rectangle Bounds, ScrollerTexture scrollerTexture, bool Vertical = false) { this.scrollerTexture = scrollerTexture; initialize(Bounds, Vertical); }