Exemplo n.º 1
0
 /// <summary>
 /// Down Scroll Button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void ScrollDown(GUIComponent sender, OnMouseClickEventArgs args)
 {
     if (topItem < Items.Count - numItems)
     {
         topItem++;
         UpdateList();
         PosBar.UpdateLocation(PosBar.Location + new Vector2(0, barIntervals));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            // TODO: Add your initialization code here
            batch     = new SpriteBatch(Game.GraphicsDevice);
            font      = Game.Content.Load <SpriteFont>(@"Fonts\Console");
            primBatch = new PrimitiveBatch(Game.GraphicsDevice);

            // Set up visible items
            if (numItems > Items.Count)
            {
                numItems = Items.Count;
            }


            // Initialise the buttons
            foreach (GUIListBoxItem lbi in Items)
            {
                lbi.Initialize();
                lbi.Parent = this;

                if (font.MeasureString(lbi.Name).X > maxWidth)
                {
                    maxWidth = font.MeasureString(lbi.Name).X;
                }
                lbi.OnMouseClick += new GUIListBoxItem.MouseClickHandler(SelectItem);
            }

            maxWidth += 20;

            foreach (GUIListBoxItem lbi in Items)
            {
                lbi.boxDimensions.X = maxWidth;
            }

            // And set the initial locations
            UpdateList();

            components = new List <GUIComponent>();

            // Get width of the listbox
            float boxHeight = (numItems - 1) * Items[0].Bounds.Height;

            // Display Down button
            DownButton = new GUIButton(Game, new Vector2(maxWidth, boxHeight + 20), new Vector2(20, 20), "down", "+");
            DownButton.Initialize();
            DownButton.OnMouseClick += new GUIButton.MouseClickHandler(ScrollDown);
            DownButton.UpdateLocation(DownButton.Location + new Vector2(Location.X, Location.Y));
            components.Add(DownButton);

            // Display Up button
            UpButton = new GUIButton(Game, new Vector2(maxWidth, 20), new Vector2(20, 20), "up", "-");
            UpButton.Initialize();
            UpButton.OnMouseClick += new GUIButton.MouseClickHandler(ScrollUp);
            UpButton.UpdateLocation(UpButton.Location + new Vector2(Location.X, Location.Y));
            components.Add(UpButton);

            // Calculate bar intervals
            barIntervals = ((boxHeight - 20) / Items.Count);

            PosBar = new GUIButton(Game, new Vector2(maxWidth, 40), new Vector2(20, barIntervals * numItems), "bar", "");
            PosBar.BackgroundColor = HighlightColor;
            PosBar.AllowHold       = true;
            PosBar.Initialize();
            PosBar.OnMouseHold += new GUIButton.MouseClickHandler(DragScroll);
            PosBar.UpdateLocation(PosBar.Location + new Vector2(Location.X, Location.Y));
            components.Add(PosBar);

            currentItem = new GUILabel(Game, new Vector2(0, 0), new Vector2(maxWidth, 20), "label", "Select ...");
            currentItem.Initialize();
            currentItem.BackgroundColor = Color.AntiqueWhite;
            currentItem.UpdateLocation(currentItem.Location + new Vector2(Location.X, Location.Y));
            components.Add(currentItem);

            OpenCloseList = new GUIButton(Game, new Vector2(maxWidth, 0), new Vector2(20, 20), "openclose", "+");
            OpenCloseList.Initialize();
            OpenCloseList.OnMouseClick += new GUIButton.MouseClickHandler(OCList);
            OpenCloseList.UpdateLocation(OpenCloseList.Location + new Vector2(Location.X, Location.Y));
            components.Add(OpenCloseList);
        }