Пример #1
0
        public virtual void Draw(GameTime gameTime)
        {
            var         font     = Game.GetFont(FontName);
            var         solid    = Game.GetTexture("solid");
            var         n        = Messages.First;
            float       y        = Position.Y;
            const float vspacing = 4.0f;
            const float hspacing = 10.0f;
            Effect      crop     = Game.GetEffect("crop");

            while (n != null)
            {
                Vector2 size      = font.MeasureString(n.Value.Text);
                float   rectWidth = (size.X + 2 * hspacing);
                float   coef      = (float)n.Value.Life * 10 / (float)ElegantMessage.TTL;
                rectWidth = Math.Min(rectWidth, rectWidth * coef);
                if (coef < 1.0f && !n.Value.Dead)
                {
                    n.Value.Dead = true;
                    PlayDeathSound();
                }
                Rectangle bounds = new Rectangle(
                    (int)((Align == ElegantMessageAlignModes.Left ? 0 : -size.X) - hspacing + Position.X),
                    (int)(y),
                    (int)(rectWidth),
                    (int)(size.Y + 2.0f * vspacing));

                Game.SpriteBatch.Draw(solid,
                                      bounds, BackColor);
                y += vspacing;

                Game.SpriteBatch.End();
                Game.PushTarget(target);
                Game.GraphicsDevice.Clear(Color.Transparent);
                Game.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                Game.SpriteBatch.DrawString(font, n.Value.Text,
                                            new Vector2((Align == ElegantMessageAlignModes.Left ? 0 : -size.X) + Position.X,
                                                        y),
                                            ForeColor);
                Game.SpriteBatch.End();
                Game.PopTarget();
                Game.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
                                       null, DepthStencilState.None, RasterizerState.CullNone, crop);
                crop.Parameters["top"].SetValue((float)bounds.Top / (float)Game.GameHeight);
                crop.Parameters["down"].SetValue((float)bounds.Bottom / (float)Game.GameHeight);
                crop.Parameters["left"].SetValue((float)bounds.Left / (float)Game.GameWidth);
                crop.Parameters["right"].SetValue((float)bounds.Right / (float)Game.GameWidth);
                Game.SpriteBatch.Draw(target, Vector2.Zero, ForeColor);

                /*Game.SpriteBatch.DrawString(font, n.Value.Text,
                 *  new Vector2((Align == ElegantMessageAlignModes.Left ? 0 : -size.X) + Position.X,
                 *      y),
                 *  ForeColor);*/
                Game.RestartBatch();
                y += vspacing + size.Y;
                n  = n.Next;
            }
        }
Пример #2
0
            public void Render(GameTime gameTime)
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    Color drawColor  = Items[i].GetForeColor();
                    bool  isSelected = (SelectedItem == i);
                    //if (selectedItem == i) drawColor = selectedItemForeground;
                    if (!Items[i].Enabled)
                    {
                        drawColor = GraphicsHelper.GetColorWithAlpha(DisabledItemForeground, Items[i].Alpha);
                    }

                    GraphicsHelper.DrawShadowedString(game.SpriteBatch,
                                                      font,
                                                      (Items[i].Caption),
                                                      (Position - centerOffset) + i * ItemsOffset + (isSelected?SelectedItemOffset:Vector2.Zero),
                                                      (isSelected?SelectedItemForeground :drawColor),
                                                      (DrawShadow ? (isSelected ? Color.Black : GraphicsHelper.GetColorWithAlpha(ShadowColor, Items[i].Alpha)) : Color.Transparent)
                                                      );
                    if (isSelected)
                    {
                        game.SpriteBatch.DrawString(
                            font,
                            "| ",
                            ((Position - centerOffset) + i * ItemsOffset + (isSelected ? SelectedItemOffset : Vector2.Zero)) -
                            new Vector2(font.MeasureString("| ").X + bracketDistance, 0),
                            Color.Brown);
                        game.SpriteBatch.DrawString(
                            font,
                            " |",
                            ((Position - centerOffset) + i * ItemsOffset + (isSelected ? SelectedItemOffset : Vector2.Zero)) +
                            (new Vector2(longestItem + bracketDistance, 0)),
                            Color.Brown);
                    }
                }

                game.SpriteBatch.Draw(
                    game.GetTexture("menuFocus"),
                    itemSelector,
                    Color.White);
            }
Пример #3
0
        public override void Draw(GameTime gameTime)
        {
            if (alpha > 0)
            {
                game.SpriteBatch.Begin();
                game.SpriteBatch.Draw(game.GetTexture("mediaHUD"),
                                      DrawPosition, GraphicsHelper.GetColorWithAlpha(Color.White, alpha));

                //text
                try
                {
                    GraphicsHelper.DrawShadowedString(game.SpriteBatch,
                                                      game.GetFont(FontName),
                                                      trackName,
                                                      DrawPosition + trackNameOffset,
                                                      GraphicsHelper.GetColorWithAlpha(Color.White, alpha),
                                                      GraphicsHelper.GetColorWithAlpha(Color.Black, alpha));

                    GraphicsHelper.DrawShadowedString(game.SpriteBatch, game.GetFont(FontName),
                                                      trackAlbum,
                                                      DrawPosition + trackAlbumOffset,
                                                      GraphicsHelper.GetColorWithAlpha(Color.White, alpha),
                                                      GraphicsHelper.GetColorWithAlpha(Color.Black, alpha));

                    GraphicsHelper.DrawShadowedString(game.SpriteBatch, game.GetFont(FontName),
                                                      trackArtist,
                                                      DrawPosition + trackArtistOffset,
                                                      GraphicsHelper.GetColorWithAlpha(Color.White, alpha),
                                                      GraphicsHelper.GetColorWithAlpha(Color.Black, alpha));
                }
                catch
                { alpha = 0; }
                game.SpriteBatch.End();
            }
            base.Draw(gameTime);
        }