private void RenderItems() { Sprites.RemoveAll(x => x is ItemSprite); var spriteFactory = new SpriteFactory(ScreenManager.Game); var prevPos = GetRelative(0.05f, 0.30f); foreach (var item in _items) { var textSprite = new TextSpriteTexture2D(_itemFont); var s = spriteFactory.Create <ItemSprite>(item, textSprite); var textureSize = GetRelative(0.9f / _items.Count, 0.40f); //var borderSize = textureSize.GetRelative(0.1f / _items.Count, 0.1f).ToPoint(); var borderSize = new Point(5, 5); var defaultTexture = spriteFactory.CreateFilledRectangle(textureSize.ToPoint(), Utils.RandomColor()); var focusedTexture = spriteFactory.CreateFilledRectangleWithBorder(textureSize.ToPoint(), Color.Orange, defaultTexture.Color, borderSize.Inflate(2)); //var onHoverTexture = spriteFactory.CreateFilledRectangle(textureSize, Color.LightYellow); var onHoverTexture = spriteFactory.CreateFilledRectangleWithBorder(textureSize.ToPoint(), Color.LightYellow, defaultTexture.Color, borderSize); var onFocusedHoverTexture = spriteFactory.CreateFilledRectangleWithBorder(textureSize.ToPoint(), Color.LightYellow, Color.Orange, borderSize); //s.SpriteTexture = defaultTexture; s.SpriteTexture = new MultiStateSpriteTexture2D <string>(new Dictionary <string, ISpriteTexture> { { "default", defaultTexture }, { "focused", focusedTexture }, { "hover", onHoverTexture }, { "focused-hover", onFocusedHoverTexture }, }); //s.SpriteTexture = new MultiStateSpriteTexture2D<string>(new Dictionary<string, ISpriteTexture> //{ // { "default", new TextSpriteTexture2D(itemFont) { Text = item.Title } }, // { "focused", new TextSpriteTexture2D(itemFont) { Text = item.Title } }, // { "hover", new TextSpriteTexture2D(itemFont) { Text = item.Title } }, // { "focused-hover", new TextSpriteTexture2D(itemFont) { Text = item.Title } }, //}); s.OnClicked += Item_OnClick; s.OnMouseEntered += Item_OnMouseEntered; s.OnMouseLeft += Item_OnMouseLeft; s.Position = prevPos; prevPos = new Vector2(prevPos.X + s.Bounds.Width, prevPos.Y); Sprites.Add(s); } }
public ItemSprite(Item item, TextSpriteTexture2D textSprite) { Item = item; TextSprite = textSprite; }