Esempio n. 1
0
        public override void LoadContent()
        {
            //font = Game.Content.Load<SpriteFont>("GameFont");


            var spriteFactory = new SpriteFactory(Game);
            var bounds        = Game.GraphicsDevice.Viewport.Bounds;

            componentCenter = new Vector2(bounds.Width / 2, bounds.Height / 2);
            componentCenter = GetRelative(0.5f, 0.5f);
            componentCenter = GetRelative(0.75f, 0.75f);
            dialRadius      = (int)(Game.GraphicsDevice.Viewport.Width * 0.4f);
            dialRadius      = (int)GetRelative(0.1f, 0).X;
            var full   = GetRelative(1, 1);
            var margin = GetRelative(0.11f, 0.15f);

            componentCenter = new Vector2(full.X - margin.X, full.Y - margin.Y);



            // Draw contant sprites
            var circlePos     = componentCenter - (new Vector2(dialRadius) / 2);
            var circleTexture = spriteFactory.CreateFilledCircle(dialRadius, Color.Gray);

            circleSprite          = spriteFactory.Create <Sprite>(circleTexture);
            circleSprite.Position = circlePos;
            Sprites.Add(circleSprite);


            var rectTexture = spriteFactory.CreateFilledRectangle(3, 3, Color.Orange);

            rectSprite          = spriteFactory.Create <Sprite>(rectTexture);
            rectSprite.Position = componentCenter;
            Sprites.Add(rectSprite);


            var cPos          = componentCenter + (cursorPos * dialRadius * 0.5f);
            var cursorTexture = spriteFactory.CreateFilledRectangle(5, 5, Color.Blue);

            cursorSprite          = spriteFactory.Create <Sprite>(cursorTexture);
            cursorSprite.Position = cPos;
            Sprites.Add(cursorSprite);


            base.LoadContent();
        }
Esempio n. 2
0
        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);
            }
        }