Beispiel #1
0
        }   // TwitchedOrientation()

        public void RenderToTexture()
        {
            dirty = false;

            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            InGame.SetRenderTarget(rt);
            InGame.Clear(Color.Black);

            ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

            // Render the thumbnail.
            if (Thumbnail != null)
            {
                // Figure out how much of the thumbnail to crop off since the tiles are square.
                int crop = (Thumbnail.Width - Thumbnail.Height) / 2;

                try
                {
                    quad.Render(Thumbnail, new Vector2(-crop, 0.0f), new Vector2(rt.Width + crop, rt.Height), @"TexturedNoAlpha");
                }
                catch
                {
                    // At this point what has probably happened is that the thumbnail data has been lost or corrupted
                    // so we need to force it to reload and then set the dirty flag on this element so the rt is redone.

                    // Note:  for now setting dirty to true is commented out since it won't cause the thumbnail texture to
                    // reload and just causes perf to die.  Probably related to bug #2221

                    //dirty = true;
                }
            }

            // Render the title.
            {
                const int kTextMargin = 10;
                const int kTextPosY   = 150;

                string  title     = TextHelper.AddEllipsis(Font, Title, rt.Width - kTextMargin * 2);
                Vector2 titleSize = Font().MeasureString(title);

                // Render the title background.
                quad.Render(
                    new Vector4(0, 0, 0, 0.25f),
                    new Vector2(0, kTextPosY),
                    new Vector2(rt.Width, titleSize.Y));

                // Render the title text.
                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                TextHelper.DrawString(Font, title, new Vector2((rt.Width - titleSize.X) / 2f, kTextPosY), textColor);
                batch.End();
            }

            InGame.RestoreRenderTarget();
        }   // end of UIGridLevelElement RenderToTexture()