/// <summary> /// Creates a ScrollBar HUD element with the specified parameters. /// </summary> public ScrollBar(Game game, UIController controller, Vector2? position, float length, ListBoxStateMachine listBox, ScrollBarStateMachine scrollBar, UIElement parent) : base(game, controller, null, position, scrollBar.NumberOfPixelsInHorizontalAxis, scrollBar.NumberOfPixelsInVerticalAxis, parent) { if (scrollBar.Orientation != Orientation.Horizontal) { throw new InvalidOperationException(Properties.Resources.ScrollBarStateMachineShouldBeHorizontal); } this.listBox = listBox; StateMachine = scrollBar; StateMachine.Tag = this; StateMachine.MaximumFlickVelocity = MaximumFlickVelocity; scrollBarLength = length; }
/// <summary> /// Clears an item. /// </summary> internal void ResetItem() { IsPressed = false; IsSelected = false; IsVisible = false; parent = null; }
/// <summary> /// Creates a ScrollBar HUD element with the specified parent UIElement. /// </summary> public ScrollBar(UIElement parent, Vector2? position, float length, ListBoxStateMachine listBox, ScrollBarStateMachine scrollBar) : this(parent.Game, parent.Controller, position, length, listBox, scrollBar, parent) { // Empty. }
/// <summary> /// Creates a Listbox UIElement that may or may not have a parent UIElement. /// </summary> /// <param name="game">XNA Game that contains this ListBox</param> /// <param name="contoller">UIController to associate with the ListBoxStateMachine.</param> /// <param name="x">X-coordinate of elements position (relative or screen).</param> /// <param name="y">Y-coordinate of elements position (relative or screen).</param> /// <param name="width">Width of the ListBox in pixels.</param> /// <param name="height">Height of the ListBox in pixels.</param> /// <param name="parent">UIElement that contains the Listbox.</param> /// <param name="textiles">Textiles UIElement controlled by this list box</param> public ListBox(Game game, UIController contoller, float x, float y, int width, int height, UIElement parent, Textiles textiles) : base(game, contoller, new Vector2(x, y), width, height, parent) { listBoxStateMachine = new ListBoxStateMachine(Controller, (int)width, (int)height) { SelectionMode = SelectionMode.Single, Orientation = Orientation.Horizontal, HorizontalElasticity = 0.0f, VerticalElasticity = 0.0f, HorizontalViewportSize = 1f, VerticalViewportSize = 1f, }; StateMachine = listBoxStateMachine; StateMachine.Tag = this; this.textiles = textiles; listBoxStateMachine.ItemStateChanged += OnItemStateChanged; iconScale = new Vector2((float)iconWidth / itemWidth, (float)iconHeight / itemHeight); UIContainer container = parent as UIContainer; if (container != null) { // Create the scrollbar and position it below the listbox. int offset = Convert.ToInt32(Top - parent.Top + Height); Vector2 position = UIElement.CenterHorizontal(offset, scrollBarBackgroundHeight, container); ScrollBar = new ScrollBar(parent, position, width, listBoxStateMachine, listBoxStateMachine.HorizontalScrollBarStateMachine); // Create the Maximze/Minimize button and position it above the listbox. offset = Convert.ToInt32(Top - parent.Top - buttonHeight); position = UIElement.CenterHorizontal(offset, (float) buttonHeight, Parent); minMaxButton = new Button(parent, position, buttonWidth, buttonHeight); minMaxButton.Name = "button"; minMaxButton.AutoScaleTexture = false; } else { throw new InvalidOperationException(Properties.Resources.ListBoxShouldBeInUIContainer); } }