/// <summary> /// Draws a list box item. /// </summary> /// <param name="batch">SpriteBatch to use for drawing.</param> /// <param name="item">ListBoxStateMachineItem to draw.</param> private void DrawItem(SpriteBatch batch, ListBoxItem item) { Rectangle source; Rectangle destination; int clipLeft, clipRight; GetDrawingRectangles(item, out source, out destination, out clipLeft, out clipRight); // Draw the list box item icon. DrawIcon(batch, item.Icon, CenterOf(destination), clipLeft, clipRight); // Draw the list box item frame texture. batch.Draw(itemDefault, destination, source, SpriteColor, ActualRotation, Vector2.Zero, SpriteEffects, LayerDepth); }
/// <summary> /// Draws a list box item that is pressed. /// </summary> /// <param name="batch"></param> /// <param name="item"></param> private void DrawPressedItem(SpriteBatch batch, ListBoxItem item) { Rectangle source; Rectangle destination; int clipLeft, clipRight; GetDrawingRectangles(item, out source, out destination, out clipLeft, out clipRight); Rectangle frameSource = new Rectangle(0, 0, itemHit.Width, itemHit.Height); Vector2 origin = CenterOf(frameSource); Vector2 center = CenterOf(destination); if (clipRight > 0) { frameSource = new Rectangle(0, 0, itemHit.Width - clipLeft - clipRight - glowSize, itemHit.Height); center.X += Convert.ToInt32(clipRight/2f); } if (clipLeft > 0) { frameSource = new Rectangle(clipLeft + glowSize, 0, itemHit.Width - clipLeft - clipRight - glowSize, itemHit.Height); center.X += Convert.ToInt32(clipLeft/2f) + glowSize; } // Draw the list box item icon. DrawIcon(batch, item.Icon, CenterOf(destination), clipLeft, clipRight); // Draw the list box item frame texture. float zOrder = MathHelper.Clamp(LayerDepth - layerOffset, 0f, 1f); batch.Draw(itemHit, center, frameSource, SpriteColor, ActualRotation, origin, item.AnimationScale * ActualScale, SpriteEffects, zOrder); }
/// <summary> /// Load all of the content for the list box. /// </summary> protected override void LoadContent() { itemDefault = TextureFromFile(@"Content\ItemDefault.png"); itemHit = TextureFromFile(@"Content\ItemHit.png"); minBackground = TextureFromFile(@"Content\MinBackground.png"); maxBackground = TextureFromFile(@"Content\MaxBackground.png"); textiles.Initialize(); animationSteps = (float)(animationDuration.TotalMilliseconds/Game.TargetElapsedTime.TotalMilliseconds); widthStep = (float) (maxBackground.Width - minBackground.Width)/animationSteps; listBoxStateMachine.Items.Clear(); // Populate the listbox. float horizontalSize = (float)itemWidth/listBoxStateMachine.NumberOfPixelsInHorizontalAxis; float verticalSize = (float)itemHeight/listBoxStateMachine.NumberOfPixelsInVerticalAxis; foreach (Textiles.Theme theme in Enum.GetValues(typeof(Textiles.Theme))) { Texture2D icon = textiles.GetIcon(theme); ListBoxStateMachineItem item = new ListBoxItem(icon, theme, horizontalSize, verticalSize); listBoxStateMachine.Items.Add(item); } // Initialize button images maximizeDefault = TextureFromFile(@"Content\MaximizeDefault.png"); maximizeHit = TextureFromFile(@"Content\MaximizeHit.png"); minimizeDefault = TextureFromFile(@"Content\MinimizeDefault.png"); minimizeHit = TextureFromFile(@"Content\MinimizeHit.png"); minMaxButton.DefaultImage = maximizeDefault; minMaxButton.PressedImage = maximizeHit; base.LoadContent(); }