コード例 #1
0
        protected void CacheLineNumberTexture()
        {
            Texture2D texture;
            const int textureSize = 64;

            RenderTarget2D rt = UI2D.Shared.RenderTarget64_64;

            InGame.SetRenderTarget(rt);
            SpriteBatch batch = UI2D.Shared.SpriteBatch;

            InGame.Clear(Color.Transparent);

            // Draw line number
            string text = lineNumber.ToString();
            // Center line number horizontally on rt.
            Vector2 pos = new Vector2((rt.Width - UI2D.Shared.GetGameFontLineNumbers().MeasureString(text).X) / 2.0f, 0.0f);

            batch.Begin();
            batch.DrawString(UI2D.Shared.GetGameFontLineNumbers(), text, pos, Color.Black);
            batch.End();

            InGame.RestoreRenderTarget();

            // Copy rendertarget result into texture.
            texture = new Texture2D(BokuGame.bokuGame.GraphicsDevice, textureSize, textureSize, false, SurfaceFormat.Color);
            int[] data = new int[textureSize * textureSize];
            rt.GetData <int>(data);
            texture.SetData <int>(data);

            rtLineNumber.Add(texture);
            Debug.Assert(this.lineNumber <= rtLineNumber.Count);
        }
コード例 #2
0
        }   // end of TextLine c'tor

        /// <summary>
        /// Renders the text string into the texture.
        /// </summary>
        private void RefreshTexture()
        {
            InGame.SetRenderTarget(diffuse);
            InGame.Clear(Color.Transparent);

            Point position = UIGridTextListElement.Margin;

            // Render the checkbox if needed.
            if (checkbox)
            {
                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();
                Vector2         size = new Vector2(40.0f, 40.0f);
                quad.Render(UIGridTextListElement.Checkbox, new Vector2(position.X, position.Y), size, @"TexturedRegularAlpha");
                position.X += (int)size.X;
            }

            // Render the text.
            SpriteBatch batch = UI2D.Shared.SpriteBatch;

            batch.Begin();
            TextHelper.DrawStringWithShadow(Font, batch, position.X, position.Y, text, Color.White, Color.Black, false);
            batch.End();

            // Restore backbuffer.
            InGame.RestoreRenderTarget();

            Size = new Vector2(diffuse.Width, diffuse.Height);
        }   // end of TextLine RefreshTexture()
コード例 #3
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()
コード例 #4
0
        }   // end of Hide()

        public void Update()
        {
            if (texture == null)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                RenderTarget2D rt     = UI2D.Shared.RenderTarget128_128;
                InGame.SetRenderTarget(rt);

                InGame.Clear(Color.Transparent);

                // Background.
                ScreenSpaceQuad quad       = ScreenSpaceQuad.GetInstance();
                Texture2D       background = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\GridElements\BlackSquare");
                quad.Render(background, Vector2.Zero, new Vector2(rt.Width, rt.Height), "TexturedRegularAlpha");

                // Y button
                Vector2 size = new Vector2(64, 64);
                quad.Render(ButtonTextures.BButton, new Vector2(44, 24), size, "TexturedRegularAlpha");

                // Text.
                Color               color    = Color.Yellow;
                SpriteBatch         batch    = UI2D.Shared.SpriteBatch;
                UI2D.Shared.GetFont Font     = UI2D.Shared.GetGameFont24Bold;
                Vector2             position = new Vector2(0, 120 - Font().LineSpacing);
                position.X = 64 - 0.5f * Font().MeasureString(Strings.Localize("editObjectParams.back")).X;
                batch.Begin();
                TextHelper.DrawString(Font, Strings.Localize("editObjectParams.back"), position, color);
                batch.End();

                InGame.RestoreRenderTarget();

                texture = new Texture2D(device, 128, 128, false, SurfaceFormat.Color);

                // Copy rendertarget result into texture.
                int[] data = new int[128 * 128];
                rt.GetData <int>(data);
                texture.SetData <int>(data);
            }

            double now = Time.WallClockTotalSeconds;

            if (now - showTime < delayTime || hide)
            {
                // Still in delay.
                alpha = 0.0f;
            }
            else
            {
                // Either in fade or in full view.
                float t = (float)(now - showTime - delayTime) / fadeTime;
                alpha = Math.Min(t, 1.0f);
            }
        }   // end of Update()
コード例 #5
0
        }   // end of Show()

        public void RefreshTexture()
        {
            if (dirty)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Title.
                quad.Render(title.Texture, title.Position, title.Size, @"TexturedRegularAlpha");

                // The list.  Render these bottom to top so if they overlap we're at least
                // seeing the selected on unobscured.
                for (int i = textList.Count - 1; i >= 0; i--)
                {
                    if (!textList[i].Hidden)
                    {
                        TextLine line = textList[i];
                        quad.Render(line.Texture, line.Position, line.Size, @"TexturedRegularAlpha");
                    }
                }

                // Render the checkmark.
                Vector2 offset = new Vector2(Margin.X + 2, 5);
                Vector2 size   = new Vector2(40.0f, 40.0f);

                quad.Render(Checkmark, textList[curIndex].Position + offset, size, @"TexturedRegularAlpha");

                // Render help button.
                if (ShowHelpButton)
                {
                    int     x   = (int)width * dpi - 54;
                    int     y   = (int)textList[textList.Count - 1].Position.Y; // Align with bottom line of text.
                    Vector2 pos = new Vector2(x, y);
                    size = new Vector2(64, 64);
                    quad.Render(ButtonTextures.YButton, pos, size, "TexturedRegularAlpha");
                    x -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X;

                    SpriteBatch batch = UI2D.Shared.SpriteBatch;
                    batch.Begin();
                    TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editObjectParams.help"), textColor, dropShadowColor, invertDropShadow);
                    batch.End();
                }

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridTextListElement RefreshTexture()
コード例 #6
0
        }   // end of UIGrid2DCheckboxElement Render()

        #endregion

        #region Internal

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        private void RefreshTexture()
        {
            if (dirty)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                int width  = diffuse.Width;
                int height = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Render the checkbox.
                int     margin    = 2;
                Vector2 position  = new Vector2(margin, margin);
                Vector2 size      = new Vector2(height - 2.0f * margin, height - 2.0f * margin);
                Vector4 lightGrey = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
                quad.Render(checkbox, lightGrey, position, size, @"TexturedRegularAlpha");

                // Render the checkmark.
                if (check)
                {
                    quad.Render(checkmark, position, size, @"TexturedRegularAlpha");
                }

                // Render the label text into the texture.
                margin += (int)size.X + 16;
                int x         = 0;
                int y         = (int)((height - Font().LineSpacing) / 2.0f) - 2;
                int textWidth = (int)Font().MeasureString(label).X;

                x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow);
                batch.End();

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGrid2DCheckboxElement Render()
コード例 #7
0
        private void CreateRenderTargets(GraphicsDevice device)
        {
            const int dpi = 128;
            int       w   = (int)(dpi * width);
            int       h   = (int)(dpi * height);

            // Create the diffuse texture.  Leave it null if we have no text to render.
            int originalWidth  = w;
            int originalHeight = h;

            if (BokuGame.RequiresPowerOf2)
            {
                w = MyMath.GetNextPowerOfTwo(w);
                h = MyMath.GetNextPowerOfTwo(h);
            }

            // Create the diffuse texture.  Leave it null if we have no text to render.
            diffuse = new RenderTarget2D(device, w, h, false, SurfaceFormat.Color, DepthFormat.None, 1, RenderTargetUsage.PlatformContents);
            InGame.GetRT("UIGrid2DTextElement", diffuse);

            InGame.SetRenderTarget(diffuse);
            InGame.Clear(Color.Transparent);

            if (label != null && label.Length > 0)
            {
                // Render the label text into the texture.
                int margin    = 24;
                int x         = 0;
                int y         = (int)((originalHeight - Font().LineSpacing) / 2.0f) - 2;
                int textWidth = (int)(Font().MeasureString(label).X);

                x = TextHelper.CalcJustificationOffset(margin, originalWidth, textWidth, justify);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow);
                batch.End();
            }

            // Restore backbuffer.
            InGame.RestoreRenderTarget();
        }
コード例 #8
0
        }   // end of HandleMouseInput()

        private void PreRender()
        {
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            RenderTarget2D rt1k = UI2D.Shared.RenderTarget1024_768;

            CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance();
            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

            Color darkTextColor  = new Color(20, 20, 20);
            Color greyTextColor  = new Color(127, 127, 127);
            Color greenTextColor = new Color(8, 123, 110);
            Color whiteTextColor = new Color(255, 255, 255);

            // Render the text into the 1k rendertarget.
            InGame.SetRenderTarget(rt1k);
            InGame.Clear(Color.Transparent);

            // Set up params for rendering UI with this camera.
            Fx.ShaderGlobals.SetCamera(camera);

            //
            // Text.
            //

            // If we don't have enough text to go into scrolling, center vertically.
            int centering = 0;

            if (blob.NumLines < textVisibleLines)
            {
                centering += (int)(blob.TotalSpacing * (textVisibleLines - blob.NumLines) / 2.0f);
            }

            Vector2 pos;

            pos = new Vector2(textMargin, textTop + textOffset + centering);
            blob.RenderWithButtons(pos, darkTextColor);

            InGame.RestoreRenderTarget();
        }   // end of PreRender()
コード例 #9
0
        }   // end of Render()

        public static void RefreshRT()
        {
            if (Dirty && buttonTexture != null)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                SpriteBatch    batch  = UI2D.Shared.SpriteBatch;

                InGame.SetRenderTarget(buttonPanelRT);

                // If all butttons are dirty (start of game), just clear the whole RT.
                // Else cleart the individual spaces.
                bool allButtonsDirty = true;
                foreach (GUIButton button in buttons)
                {
                    allButtonsDirty &= button.Dirty;
                }

                if (allButtonsDirty)
                {
                    InGame.Clear(Color.Transparent);
                }
                else
                {
                    batch.Begin(SpriteSortMode.Texture, BlendState.Opaque);
                    {
                        for (int i = 0; i < buttons.Length; i++)
                        {
                            if (buttons[i].Dirty)
                            {
                                // Draw over both pressed and unpressed at once.
                                Rectangle dstRect = new Rectangle((int)(i * GUIButton.DefaultSize.X), 0, (int)GUIButton.DefaultSize.X, (int)(GUIButton.DefaultSize.Y * 2));
                                batch.Draw(transparentTexture, dstRect, Color.Transparent);
                            }
                        }
                    }
                    batch.End();
                }

                //
                // Draw main button shapes.
                //
                batch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend);
                {
                    // Render underlying buttons.
                    for (int i = 0; i < buttons.Length; i++)
                    {
                        if (buttons[i].Dirty)
                        {
                            // Normal state.
                            Rectangle rect = new Rectangle((int)(i * GUIButton.DefaultSize.X), 0, (int)GUIButton.DefaultSize.X, (int)GUIButton.DefaultSize.Y);
                            batch.Draw(buttonTexture, rect, buttons[i].Color);

                            // Pressed state.
                            rect.Y = (int)GUIButton.DefaultSize.Y;
                            batch.Draw(buttonPressedTexture, rect, buttons[i].Color);
                        }
                    }
                }
                batch.End();

                // Render labels on top of buttons.
                for (int i = 0; i < kNumButtons; i++)
                {
                    if (buttons[i].Dirty && !string.IsNullOrEmpty(buttons[i].Label))
                    {
                        buttons[i].LabelFits = RenderLabelButton(i);

                        buttons[i].Dirty = false;
                    } // end of label rendering.
                }     // end of loop over buttons.

                InGame.SetRenderTarget(null);

                Dirty = false;
            }
        }   // end of RefreshRT()
コード例 #10
0
        }   // end of PreRender()

        public void Render()
        {
            if (Active)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                RenderTarget2D rtFull = UI2D.Shared.RenderTargetDepthStencil1024_768;   // Rendertarget we render whole display into.
                RenderTarget2D rt1k   = UI2D.Shared.RenderTarget1024_768;

                Vector2 rtSize = new Vector2(rtFull.Width, rtFull.Height);

                CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance();
                ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

                Color darkTextColor  = new Color(20, 20, 20);
                Color greyTextColor  = new Color(127, 127, 127);
                Color greenTextColor = new Color(8, 123, 110);
                Color whiteTextColor = new Color(255, 255, 255);

                // Render the scene to our rendertarget.
                InGame.SetRenderTarget(rtFull);

                // Clear to transparent.
                InGame.Clear(Color.Transparent);

                // Set up params for rendering UI with this camera.
                Fx.ShaderGlobals.SetCamera(camera);

                Vector2 pos;

                // Now render the background tiles.
                Vector2 backgroundSize = new Vector2(backgroundTexture.Width, backgroundTexture.Height);
                pos = (rtSize - backgroundSize) / 2.0f;
                ssquad.Render(backgroundTexture, pos, backgroundSize, @"TexturedRegularAlpha");

                displayPosition = pos;

                // Now render the contents of the rt1k texture but with the edges blended using the mask.
                Vector2 rt1kSize = new Vector2(rt1k.Width, rt1k.Height);
                pos -= new Vector2(40, 70);
                try//minimize bug fix.
                {
                    Vector4 limits = new Vector4(0.095f, 0.112f, 0.57f, 0.64f);
                    ssquad.RenderWithYLimits(rt1k, limits, pos, rt1kSize, @"TexturedPreMultAlpha");
                }
                catch
                {
                    return;
                }

                //
                // Render buttons.
                //

                float margin     = 64.0f;
                float totalWidth = continueButton.GetSize().X + /* margin + backButton.GetSize().X + */ margin + exitTutorialButton.GetSize().X;
                pos    = new Vector2(rtSize.X / 2.0f, rtSize.Y / 2.0f + backgroundSize.Y * 0.28f);
                pos.X -= totalWidth / 2.0f;

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();

                continueButton.Render(pos);
                pos.X += continueButton.GetSize().X + margin;

                /*
                 * backButton.Render(pos);
                 * pos.X += backButton.GetSize().X + margin;
                 */

                exitTutorialButton.Render(pos);

                batch.End();

                // Add left stick if needed.
                Vector2 min;
                Vector2 max;
                if (blob.NumLines >= textVisibleLines)
                {
                    pos = displayPosition + new Vector2(-31, 300);
                    ssquad.Render(leftStick, pos, new Vector2(leftStick.Width, leftStick.Height), "TexturedRegularAlpha");
                    min = pos;
                    max = min + new Vector2(leftStick.Width, leftStick.Height / 2.0f);
                    upBox.Set(min, max);
                    min.Y  = max.Y;
                    max.Y += leftStick.Height / 2.0f;
                    downBox.Set(min, max);
                }

                InGame.RestoreRenderTarget();
                InGame.SetViewportToScreen();

                // No put it all together.
                // Start with the background.
                if (useBackgroundThumbnail)
                {
                    if (!thumbnail.GraphicsDevice.IsDisposed && !thumbnail.IsDisposed)
                    {
                        // Render the blurred thumbnail (if valid) full screen.
                        if (!thumbnail.GraphicsDevice.IsDisposed)
                        {
                            InGame.RestoreViewportToFull();
                            Vector2 screenSize = new Vector2(device.Viewport.Width, device.Viewport.Height);
                            ssquad.Render(thumbnail, Vector2.Zero, screenSize, @"TexturedNoAlpha");
                            InGame.SetViewportToScreen();
                        }
                    }
                    else
                    {
                        // No valid thumbnail, clear to dark.
                        device.Clear(darkTextColor);
                    }
                }

                // Calc scaling and position for rt.
                renderPosition = Vector2.Zero;
                renderScale    = 1.0f;

                // The part of the dialog we care about is 1024x600 so we want to use
                // that as the size to fit to the screen.
                Vector2 dialogSize = new Vector2(1024, 600);
                Vector2 scale      = BokuGame.ScreenSize / dialogSize;
                renderScale = Math.Min(Math.Min(scale.X, scale.Y), 1.0f);
                Vector2 renderSize = rt1kSize * renderScale;

                // Center on screen.
                renderPosition = (BokuGame.ScreenSize - renderSize) / 2.0f;

                ssquad.Render(rtFull, renderPosition, renderSize, @"TexturedRegularAlpha");
            }
        }   // end of ScrollableTextDisplay Render()
コード例 #11
0
        }   // end of UIGridModularMenu Update()

        public void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                int w, h;
                GetWH(out w, out h);

                // If the number of elements has changed, we need a new rendertarget.
                InitDeviceResources(BokuGame.bokuGame.GraphicsDevice);

                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                // The thin margin around the highlight where the normal color shows through.
                int highlightMargin = 5;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Render the white background.  Alpha on normal map is used to round corners.
                Vector2 position = Vector2.Zero;
                Vector2 size     = new Vector2(w, h);

                if (title != null)
                {
                    quad.Render(Vector4.One, position, size);
                    position.Y = 70;
                }

                // And the black parts.
                size.Y = whiteTop.Height;
                quad.Render(whiteTop, new Vector4(0, 0, 0, 1), position, size, "TexturedRegularAlpha");

                position.Y += 16;
                size.Y      = h - position.Y;
                quad.Render(new Vector4(0, 0, 0, 1), position, size);

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Add the highlight/shadow onto the white region.
                if (title != null)
                {
                    position.Y = 25;
                    size.Y     = 48;
                    quad.Render(whiteHighlight, new Vector4(0.6f, 1.0f, 0.8f, 0.2f), position + new Vector2(highlightMargin, 0), size + new Vector2(-2 * highlightMargin, -highlightMargin), "TexturedRegularAlpha");
                }

                // Render the label and value text into the texture.

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();

                // Title.
                UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24Bold;
                if (title != null)
                {
                    position.X = TextHelper.CalcJustificationOffset(margin.X, w, (int)Font().MeasureString(title).X, justify);
                    position.Y = (int)((64 - Font().LineSpacing) / 2.0f) + 4;
                    TextHelper.DrawString(Font, title, position + shadowOffset, shadowColor);
                    TextHelper.DrawString(Font, title, position, titleTextColor);
                }

                // Entries.
                Font       = UI2D.Shared.GetGameFont18Bold;
                position.Y = 8 + (title != null ? 70 : 0);
                Vector2 min = Vector2.Zero;
                Vector2 max = Vector2.One;
                for (int i = 0; i < itemList.Count; i++)
                {
                    // Render bar.
                    Vector4 barColor = active ? new Vector4(1, 1, 1, itemList[i].BarAlpha) : new Vector4(1, 0.5f, 1, itemList[i].BarAlpha);
                    quad.Render(greenBar, barColor, new Vector2(8, position.Y - additionalLineSpacing / 3), new Vector2(w - 16, Font().LineSpacing + additionalLineSpacing), "TexturedRegularAlpha");

                    // Render text.
                    position.X = TextHelper.CalcJustificationOffset(margin.X, w, (int)Font().MeasureString(itemList[i].Text).X, justify);
                    TextHelper.DrawString(Font, itemList[i].Text, position, itemList[i].TextColor);

                    min.Y = position.Y / h;

                    position.Y += Font().LineSpacing + additionalLineSpacing;

                    max.Y = position.Y / h;
                    itemList[i].UVBoundingBox.Set(min, max);
                }

                batch.End();

                // Add the highlight to the black region.
                position = new Vector2(highlightMargin, 1 + (title != null ? 70 : 0));
                size.X   = w - 2 * highlightMargin;
                size.Y   = 60;
                quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), position, size, "AdditiveBlendWithAlpha");

                // Restore write channels.
                device.BlendState = BlendState.NonPremultiplied;

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularMenu RefreshTexture()
コード例 #12
0
        }   // end of UIGridBaseModularSliderElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Render the white background.
                Vector2 position = Vector2.Zero;
                Vector2 size     = new Vector2(w, h);
                quad.Render(sliderWhite, position, size, "TexturedNoAlpha");

                // And the black part.
                int blackHeight = 70;   // From Photoshop...
                position.Y = h - blackHeight;
                size.Y     = blackHeight;
                quad.Render(sliderBlack, position, size, "TexturedRegularAlpha");

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Render the label and value text into the texture.
                int margin = 0;
                position.X = 0;
                position.Y = (int)(((h - blackHeight) - Font().LineSpacing) / 2.0f) - 2;
                int textWidth = (int)(Font().MeasureString(label).X);

                justify    = Justification.Center;
                position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify);

                Color   labelColor   = new Color(127, 127, 127);
                Color   valueColor   = new Color(140, 200, 63);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                TextHelper.DrawString(Font, label, position + shadowOffset, shadowColor);
                TextHelper.DrawString(Font, label, position, labelColor);

                string valueString = GetFormattedValue();
                margin     = 48;
                position.X = w - margin - (int)Font().MeasureString(valueString).X;
                TextHelper.DrawString(Font, valueString, position, valueColor);
                batch.End();

                // Render the value bead.
                int left             = 22;
                int top              = 93;
                int right            = w - left;
                int verticalRadius   = 8;
                int horizontalRadius = 6;

                float percent = GetSliderPercentage();
                int   len     = right - left - horizontalRadius * 2;
                len   = (int)(len * percent);
                len   = Math.Max(len, 7);
                right = len + left + horizontalRadius * 2 - 2;

                quad.Render(sliderBeadEnd, new Vector2(left, top), new Vector2(horizontalRadius, verticalRadius * 2), "TexturedRegularAlpha");
                quad.Render(sliderBeadEnd, new Vector2(right, top), new Vector2(-horizontalRadius, verticalRadius * 2), "TexturedRegularAlpha");
                quad.Render(sliderBeadMiddle, new Vector2(left + horizontalRadius, top), new Vector2(len - 2, verticalRadius * 2), "TexturedRegularAlpha");

                /*
                 * // Render help button.
                 * if (ShowHelpButton)
                 * {
                 *  position.X = w - 54;
                 *  position.Y = h - 54;
                 *  size = new Vector2(64, 64);
                 *  quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha");
                 *  position.X -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X;
                 *  batch.Begin();
                 *  TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position + shadowOffset, shadowColor);
                 *  TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position, fontColor);
                 *  batch.End();
                 * }
                 */

                // Restore default blend state.
                device.BlendState = BlendState.AlphaBlend;

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridIntegerSliderElement RefreshTexture()
コード例 #13
0
            private void CreateRenderTargets(GraphicsDevice device)
            {
                int shadowOffset = Scoreboard.ShadowOffset;

                int surfaceWidth  = MyMath.GetNextPowerOfTwo(charWidth);
                int surfaceHeight = MyMath.GetNextPowerOfTwo(charHeight);

                string str = String.Format("{0}", ch);

                if (surface == null || surface.IsDisposed || surface.GraphicsDevice.IsDisposed)
                {
                    surface = new RenderTarget2D(
                        BokuGame.bokuGame.GraphicsDevice,
                        surfaceWidth,
                        surfaceHeight,
                        false,
                        SurfaceFormat.Color,
                        DepthFormat.None);
                    InGame.GetRT("Scoreboard", surface);
                }

                InGame.SetRenderTarget(surface);
                InGame.Clear(Color.Transparent);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;

                try
                {
                    try
                    {
                        batch.Begin();

                        TextHelper.DrawString(
                            ScoreBoardFont,
                            str,
                            new Vector2(shadowOffset + (surfaceWidth - charWidth) / 2, shadowOffset + (surfaceHeight - charHeight) / 2),
                            Color.Black);
                        TextHelper.DrawString(
                            ScoreBoardFont,
                            str,
                            new Vector2((surfaceWidth - charWidth) / 2, (surfaceHeight - charHeight) / 2),
                            Color.White);
                    }
                    catch (Exception e)
                    {
                        if (e != null)
                        {
                        }
                    }
                    finally
                    {
                        batch.End();
                    }
                }
                catch
                {
                }
                finally
                {
                    InGame.RestoreRenderTarget();
                }
            }
コード例 #14
0
        }   // end of UIGridModularCameraModeElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();


                // Render the white background.
                Vector2 position = Vector2.Zero;
                Vector2 size     = new Vector2(w, white.Height);
                quad.Render(white, position, size, "TexturedNoAlpha");

                // And the black parts.
                position.Y = 70;
                size.Y     = h - 70;
                quad.Render(middleBlack, position, size, "TexturedRegularAlpha");
                position.Y = 64;
                size.Y     = black.Height;
                quad.Render(black, position, size, "TexturedRegularAlpha");

                // The icons.
                position.X = (512 - icons.Width) / 2;
                position.Y = 80;
                size       = new Vector2(icons.Width, icons.Height);
                quad.Render(icons, position, size, "TexturedRegularAlpha");

                // Bounding box
                Vector2 min = new Vector2(position.X / w, position.Y / h);
                Vector2 max = new Vector2((position.X + size.X) / w, (140 + 2.0f * indicatorLit.Height) / h);
                iconButtonBox.Set(min, max);

                // The indicators.
                size     = new Vector2(indicatorLit.Width, indicatorLit.Height);
                position = new Vector2(105, 140);
                quad.Render(CurIndex == 0 ? indicatorLit : indicatorUnlit, position, size, "TexturedRegularAlpha");
                position = new Vector2(512 / 2 - size.X / 2, 140);
                quad.Render(CurIndex == 1 ? indicatorLit : indicatorUnlit, position, size, "TexturedRegularAlpha");
                position = new Vector2(512 - 105 - size.X, 140);
                quad.Render(CurIndex == 2 ? indicatorLit : indicatorUnlit, position, size, "TexturedRegularAlpha");


                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Render the label and value text into the texture.
                string title = label + " : ";
                switch (CurIndex)
                {
                case 0:
                    title += Strings.Localize("editWorldParams.cameraModeFixedPosition");
                    break;

                case 1:
                    title += Strings.Localize("editWorldParams.cameraModeFixedOffset");
                    break;

                case 2:
                    title += Strings.Localize("editWorldParams.cameraModeFree");
                    break;
                }
                int margin = 0;
                position.X = 0;
                position.Y = (int)((64 - Font().LineSpacing) / 2.0f);
                int textWidth = (int)(Font().MeasureString(title).X);

                justify    = Justification.Center;
                position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify);

                Color   labelColor   = new Color(127, 127, 127);
                Color   valueColor   = new Color(140, 200, 63);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();

                // Title.
                TextHelper.DrawString(Font, title, position + shadowOffset, shadowColor);
                TextHelper.DrawString(Font, title, position, labelColor);

                batch.End();

                if (xButtonText != null)
                {
                    UI2D.Shared.GetFont ButtonFont = UI2D.Shared.GetGameFont18Bold;
                    position.X = w - 44;
                    position.Y = h - 44;
                    size       = new Vector2(48, 48);
                    quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha");

                    max.X = (position.X + 44) / w;
                    min.Y = position.Y / h;

                    position.X -= 10 + (int)ButtonFont().MeasureString(Strings.Localize("editWorldParams.setCamera")).X;
                    batch.Begin();
                    TextHelper.DrawString(ButtonFont, Strings.Localize("editWorldParams.setCamera"), position + shadowOffset, shadowColor);
                    TextHelper.DrawString(ButtonFont, Strings.Localize("editWorldParams.setCamera"), position, labelColor);
                    batch.End();

                    min.X = position.X / w;
                    max.Y = min.Y + (float)ButtonFont().LineSpacing / h;

                    xButtonBox.Set(min, max);
                }

                // Restore default blend state.
                device.BlendState = BlendState.AlphaBlend;

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularCameraModeElement Render()
コード例 #15
0
        }   // end of UIGridBaseSliderElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            if (dirty)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                int width  = diffuse.Width;
                int height = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Render the slide under the box.
                int     margin      = 36;
                float   aspectRatio = 5.25f;    // Based on art, should be more flexible.
                Vector4 sliderColor = Color.Red.ToVector4();
                Vector2 position    = new Vector2(margin, margin);
                Vector2 size        = new Vector2(aspectRatio * (height - 2.0f * margin), height - 2.0f * margin);
                // Scale size based on current value and ranges.
                size.X *= GetSliderPercentage();
                quad.Render(sliderColor, position, size);

                // Calc position of text overlay.
                int x = (int)(position.X + aspectRatio * (height - 2.0f * margin) / 2.0f);
                int y = (height - Font().LineSpacing) / 2;

                // Render the slider box over the slider itself.
                margin      = 24;
                aspectRatio = 4.0f;   // Based on art, should be more flexible.
                position    = new Vector2(margin, margin);
                size        = new Vector2(aspectRatio * (height - 2.0f * margin), height - 2.0f * margin);
                Vector4 lightGrey = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
                quad.Render(sliderBox, lightGrey, position, size, @"TexturedRegularAlpha");

                // Render the current slider value in the center of the slider area.
                string valueString = GetFormattedValue();
                x -= (int)(Font().MeasureString(valueString).X) / 2;

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                if (useDropShadow)
                {
                    TextHelper.DrawStringWithShadow(Font, batch, x, y, valueString, textColor, dropShadowColor, false);
                }
                else
                {
                    TextHelper.DrawString(Font, valueString, new Vector2(x, y), textColor);
                }
                batch.End();

                // Render the label text into the texture.
                margin += (int)size.X + 16;
                x       = 0;
                y       = (int)((height - Font().LineSpacing) / 2.0f) - 2;
                int textWidth = (int)(Font().MeasureString(label).X);

                x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify);

                batch.Begin();
                TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow);
                batch.End();

                // Render help button.
                if (ShowHelpButton)
                {
                    x        = width - 54;
                    y        = height - 54;
                    position = new Vector2(x, y);
                    size     = new Vector2(64, 64);
                    quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha");
                    x -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X;
                    batch.Begin();
                    TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editObjectParams.help"), textColor, dropShadowColor, invertDropShadow);
                    batch.End();
                }

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridIntegerSliderElement RefreshTexture()
コード例 #16
0
        }   // end of UIGridModularCheckboxElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Render the white background.
                Vector2 position = Vector2.Zero;
                Vector2 size     = new Vector2(w, nextLevelWhite.Height);
                quad.Render(nextLevelWhite, position, size, "TexturedNoAlpha");

                // And the black parts.
                position.Y = 70;
                size.Y     = h - 70;
                quad.Render(nextLevelMiddleBlack, position, size, "TexturedRegularAlpha");
                position.Y = 64;
                size.Y     = nextLevelBlack.Height;
                quad.Render(nextLevelBlack, position, size, "TexturedRegularAlpha");


                // Render the image.
                position.X = 6;
                position.Y = 70;
                size.X     = size.Y = h - position.Y - 6;
                if (nextLevel != null)
                {
                    //render the thumbnail when "on"
                    quad.Render(nextLevel.Thumbnail.Texture, position, size, "TexturedRegularAlpha");
                }
                else
                {
                    quad.Render(nextLevelNone, position, size, "TexturedRegularAlpha");
                }

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Render the label text into the texture.
                int margin = 16;
                position.X = (int)size.X + margin;
                position.Y = (int)((128 - Font().LineSpacing) / 2.0f);
                TextBlob blob = null;

                if (nextLevel != null)
                {
                    blob = new TextBlob(Font, nextLevel.Name, w - (int)position.X - margin);
                }
                else
                {
                    blob = new TextBlob(Font, Strings.Localize("editWorldParams.noLevelSelected"), w - (int)position.X - margin);
                }

                position.Y = (int)((h - blob.TotalSpacing) / 2.0f) - 2;

                Color   fontColor    = new Color(127, 127, 127);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                //render the main label
                string label = Strings.Localize("editWorldParams.nextLevel");

                // prepare the label position
                int     labelWidth    = (int)(Font().MeasureString(label).X);
                Vector2 labelPosition = Vector2.Zero;
                labelPosition.X = TextHelper.CalcJustificationOffset(0, w, labelWidth, Justification.Center);
                labelPosition.Y = (int)((64 - Font().LineSpacing) / 2.0f);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                //render the main label
                TextHelper.DrawString(Font, label, labelPosition + shadowOffset, shadowColor);
                TextHelper.DrawString(Font, label, labelPosition, fontColor);
                batch.End();

                //render the world name
                blob.RenderWithButtons(position, fontColor, shadowColor, shadowOffset, maxLines: 3);

                //only render X button if we have a level
                if (nextLevel != null)
                {
                    float clearLabelLength = Font().MeasureString(Strings.Localize("editWorldParams.clearNextLevel")).X;
                    //render the X button
                    position.X = w - 54;
                    position.Y = h - 54;
                    size       = new Vector2(64, 64);

                    quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha");

                    //prepare position for "clear" label
                    position.X -= 10 + (int)clearLabelLength;

                    float hitBoxU = (float)(w - clearLabelLength - 64) / (float)w;
                    float hitBoxV = (float)(h - 64) / (float)h;
                    //update the hit box for "clear" - basically bottom right corner
                    clearHitBox.Set(new Vector2(hitBoxU, hitBoxV), new Vector2(1.0f, 1.0f));

                    //render the clear button text
                    batch.Begin();
                    TextHelper.DrawString(Font, Strings.Localize("editWorldParams.clearNextLevel"), position + shadowOffset, shadowColor);
                    TextHelper.DrawString(Font, Strings.Localize("editWorldParams.clearNextLevel"), position, fontColor);
                    batch.End();
                }
                else
                {
                    //no clear hit box if it's not being rendered
                    clearHitBox.Set(Vector2.Zero, Vector2.Zero);
                }


                // Restore write channels
                device.BlendState = BlendState.AlphaBlend;

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularCheckboxElement Render()
コード例 #17
0
        }   // end of PartInfo GetColor()

        /// <summary>
        /// Create the localized WHEN and DO textures for the programming UI.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private Texture2D CreateProgrammingClauseTexture(string str)
        {
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            string label = Strings.Localize(str);

            Texture2D result = new Texture2D(device, 128, 128);

            SpriteBatch batch = UI2D.Shared.SpriteBatch;

            // Use the 256x256 rendertarget to pre-render our text label.
            // This gives us the chance to compress it if we need to if
            // the label is too long to naturally fit on the tile.
            RenderTarget2D rt = UI2D.Shared.RenderTarget256_256;

            InGame.SetRenderTarget(rt);

            InGame.Clear(Color.Transparent);

            UI2D.Shared.GetFont Font      = UI2D.Shared.GetGameFont30Bold;
            Vector2             labelSize = Vector2.Zero;

            if (label != null)
            {
                labelSize = Font().MeasureString(label) + new Vector2(3, 2);
                batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
                TextHelper.DrawString(Font, label, new Vector2(1, 1), Color.White);
                batch.End();
            }

            // Restore backbuffer.
            InGame.RestoreRenderTarget();

            // Now render the texture to the 128x128 rt.
            RenderTarget2D renderTarget = UI2D.Shared.RenderTarget128_128;

            Rectangle destRect = new Rectangle(0, 0, renderTarget.Width, renderTarget.Height);

            InGame.SetRenderTarget(renderTarget);

            InGame.Clear(Color.Black);

            batch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);

            // Draw label
            if (label != null)
            {
                Rectangle srcRect = new Rectangle(0, 0, (int)labelSize.X, (int)labelSize.Y);
                Rectangle dstRect;
                // Center vertically.
                int yPos = (int)((renderTarget.Height - labelSize.Y) / 2.0f);
                if (labelSize.X > renderTarget.Width)
                {
                    // Label is wider than tile, shrink to fit.
                    dstRect = new Rectangle(0, yPos, renderTarget.Width, srcRect.Height);
                }
                else
                {
                    // Label fits on tile, center location.
                    dstRect = new Rectangle((int)((renderTarget.Width - srcRect.Width) / 2.0f), yPos, srcRect.Width, srcRect.Height);
                }
                batch.Draw(rt, dstRect, srcRect, Color.White);
            }

            batch.End();

            // Restore backbuffer.
            InGame.RestoreRenderTarget();

            // Copy rendertarget result into texture.
            int[] data = new int[128 * 128];
            renderTarget.GetData <int>(data);
            result.SetData <int>(data);

            return(result);
        }
コード例 #18
0
        }   // end of Clear()

        private static void RefreshTexture()
        {
            bool lores = BokuGame.ScreenSize.Y <= 480;

            UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24Bold;
            if (lores)
            {
                Font = UI2D.Shared.GetGameFont30Bold;
            }
            blob.Font = Font;

            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
            RenderTarget2D  rt     = UI2D.Shared.RenderTarget512_302;

            InGame.SetRenderTarget(rt);

            InGame.Clear(Color.Transparent);

            ssquad.Render(background, Vector2.Zero, new Vector2(512, 302), "TexturedRegularAlpha");

            // Tile name.
            SpriteBatch batch = UI2D.Shared.SpriteBatch;
            Vector2     pos   = new Vector2(margin, margin);

            /*
             * batch.Begin();
             * TextHelper.DrawString(Font, curTip, pos, Color.Yellow);
             * batch.End();
             */
            string desc = blob.RawText; // Save string we're displaying.

            blob.RawText = curTip;
            if (blob.HasRtoL)
            {
                blob.Justification = Boku.UI2D.UIGridElement.Justification.Right;
            }
            blob.RenderWithButtons(pos, Color.Yellow);
            blob.RawText = desc;        // Restore

            // We need to special case groups since they don't have any data.  For groups
            // we just display a string that says "press <a> for more..."
            if (curTip == Strings.Localize("toolTips.group"))
            {
                blob = new TextBlob(Font, Strings.Localize("toolTips.groupDesc"), 512 - margin * 2);
                blob.Justification = Boku.UI2D.UIGridElement.Justification.Center;
                pos = new Vector2(0, (302 - Font().LineSpacing) / 2);
                blob.RenderWithButtons(pos, Color.White);
            }
            else
            {
                // Normal ToolTip.

                // Text description.
                if (blob != null)
                {
                    int maxLines = showButtons ? (lores ? 3 : 4) : (lores ? 4 : 6);

                    // Modify final line to end with ellipsis.
                    blob.AddEllipsisToLine(maxLines - 1);

                    // Move down to account for title.
                    pos.Y += Font().LineSpacing;

                    // If less than maxLines of text, center on texture.
                    int spareLines = maxLines - blob.NumLines - 1;
                    if (spareLines > 0)
                    {
                        pos.Y += spareLines * 0.5f * Font().LineSpacing;
                    }

                    // Right justify if RtoL
                    if (blob.HasRtoL)
                    {
                        blob.Justification = Boku.UI2D.UIGridElement.Justification.Right;
                    }

                    blob.RenderWithButtons(pos, Color.White, maxLines: maxLines);
                }

                // Buttons @ bottom
                if (showButtons)
                {
                    string aText = useAdd ? Strings.Localize("toolTips.add") : Strings.Localize("toolTips.change");

                    int     buttonWidth = 40;                   // For spacing.
                    Vector2 buttonSize  = new Vector2(64, 64);  // For rendering.
                    pos.Y = 302 - margin - Font().LineSpacing;
                    int aTextWidth = (int)Font().MeasureString(aText).X;
                    int yTextWidth = (int)Font().MeasureString(Strings.Localize("toolTips.examples")).X;
                    int width      = 3 * buttonWidth + aTextWidth + yTextWidth;
                    pos.X = (512 - width) / 2;

                    batch.Begin();

                    ssquad.Render(ButtonTextures.AButton, pos, buttonSize, "TexturedRegularAlpha");
                    pos.X += buttonWidth;
                    TextHelper.DrawString(Font, aText, pos, Color.White);

                    pos.X += buttonWidth + aTextWidth;
                    ssquad.Render(ButtonTextures.YButton, pos, buttonSize, "TexturedRegularAlpha");
                    pos.X += buttonWidth;
                    TextHelper.DrawString(Font, Strings.Localize("toolTips.examples"), pos, Color.White);

                    batch.End();
                }
            }

            InGame.RestoreRenderTarget();

            //
            // Copy result to local texture.
            //
            int[] data = new int[512 * 302];
            rt.GetData <int>(data);
            texture.SetData <int>(data);

            // Scale size to 1/4 screen height.
            int   w     = (int)BokuGame.ScreenSize.X;
            int   h     = (int)BokuGame.ScreenSize.Y;
            float scale = h / 4.0f / 302.0f;

            size  = new Vector2(512, 302);
            size *= scale;

            // Check position to keep on screen within 10% safe area.
            // Horizontal
            int safe = (int)(w * 0.05f);

            if (pendingPosition.X < safe)
            {
                pendingPosition.X = safe;
            }
            else if (pendingPosition.X > w - safe - size.X)
            {
                pendingPosition.X = w - safe - size.X;
            }
            // Vertical
            safe = (int)(h * 0.05f);
            if (pendingPosition.Y < safe)
            {
                pendingPosition.Y = safe;
            }
            else if (pendingPosition.Y > h - safe - size.Y)
            {
                pendingPosition.Y = h - safe - size.Y;
            }

            dirty = false;
        }   // end of RefreshTexture()
コード例 #19
0
        private void CreateRenderTargets(GraphicsDeviceManager graphics)
        {
            GraphicsDevice device = graphics.GraphicsDevice;

            const int margin = 24;
            int       w      = (int)width;
            int       h      = (int)height;

            int backgroundWidth  = w;
            int backgroundHeight = h;

            // Create the diffuse texture.
            if (BokuGame.RequiresPowerOf2)
            {
                w = MyMath.GetNextPowerOfTwo(w);
                h = MyMath.GetNextPowerOfTwo(h);
            }

            diffuse = new RenderTarget2D(
                device,
                w, h,
                1,
                SurfaceFormat.Color,
                MultiSampleType.None, 0,
                RenderTargetUsage.PlatformContents);
            InGame.GetRT("MessageBoxElement", diffuse);

            // Save off the current depth buffer.
            InGame.SetRenderTarget(diffuse);
            InGame.Clear(Color.Transparent);

            // Render the backdrop.
            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();

            ssquad.Render(background, Vector2.Zero, new Vector2(512, 512), @"TexturedPreMultAlpha");

            SpriteFont font = Font();

            List <string> lineList = new List <string>();

            TextHelper.SplitMessage(label, backgroundWidth - margin * 2, font, false, lineList);

            // Calc center of display.
            int y  = (int)((backgroundHeight - font.LineSpacing) / 2.0f) - 2;
            int dy = font.LineSpacing;

            // Offset based on number of lines.
            y -= (int)(dy * (lineList.Count - 1) / 2.0f);

            SpriteBatch batch = UI2D.Shared.SpriteBatch;

            batch.Begin();

            for (int i = 0; i < lineList.Count; i++)
            {
                string line = lineList[i];

                // Render the label text into the texture.
                int     x        = 0;
                Vector2 textSize = font.MeasureString(line);

                x = TextHelper.CalcJustificationOffset(margin, backgroundWidth, (int)textSize.X, justify);

                if (useDropShadow)
                {
                    TextHelper.DrawStringWithShadow(font, batch, x, y, line, textColor, dropShadowColor, invertDropShadow);
                }
                else
                {
                    batch.DrawString(font, line, new Vector2(x, y), textColor);
                }

                y += dy;
            }   // end of i loop over lines in list.

            // Load button textures.
            Texture BButton = ButtonTextures.BButton;

            // Render the 'B' button.
            Vector2 size     = new Vector2(56.0f, 56.0f);
            Vector2 position = new Vector2(w - 150, h - 40 - margin);

            // Hack for X600 compat.
            if (BokuGame.RequiresPowerOf2)
            {
                position = new Vector2(backgroundWidth - 350, backgroundHeight - size.Y - margin);
            }
            ssquad.Render(BButton, position, size, @"TexturedRegularAlpha");

            // And the text with it.
            {
                int x = (int)(position.X + 40);
                y = (int)(position.Y);
                String buttonLabel = @"Back";
                if (useDropShadow)
                {
                    TextHelper.DrawStringWithShadow(font, batch, x, y, buttonLabel, textColor, dropShadowColor, false);
                }
                else
                {
                    batch.DrawString(font, buttonLabel, new Vector2(x, y), textColor);
                }
            }

            batch.End();


            // Restore backbuffer and depth buffer.
            InGame.RestoreRenderTarget();
        }
コード例 #20
0
        }   // end of UIGridModularButtonElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            // dirty = true;  // Debug only.

            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();


                // Render the white region with highlight.
                Vector2 position = new Vector2(h - 2, 0);
                Vector2 size     = new Vector2(w, h) - position;
                quad.Render(checkboxWhite, position, size, "TexturedNoAlpha");

                // Render the black box.
                position = Vector2.Zero;
                size.X   = size.Y;
                quad.Render(blackSquare, position, size, "TexturedRegularAlpha");

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Render the label text into the texture.
                int margin = 16;
                position.X = (int)size.X + margin;

                string text = label + "\n";
                if (aButtonText != null)
                {
                    text += "    <A> " + aButtonText + "\n";
                }
                if (xButtonText != null)
                {
                    text += "    <X> " + xButtonText;
                }

                TextBlob blob = new TextBlob(Font, text, w - (int)position.X - margin);

                position.Y = (int)((h - blob.TotalSpacing) / 2.0f) - 2;
                if (blob.NumLines == 2)
                {
                    position.Y -= blob.TotalSpacing / 2.0f;
                }
                else if (blob.NumLines == 3)
                {
                    position.Y -= blob.TotalSpacing;
                }

                Color   fontColor    = new Color(127, 127, 127);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                blob.RenderWithButtons(position, fontColor, shadowColor, shadowOffset, maxLines: 3);

                // Restore default blending.
                device.BlendState = BlendState.AlphaBlend;

                int line = blob.NumLines - 1;   // Which line in the text has the button.

                // Calc bounding boxes in UV space for A and X buttons/labels.
                if (onXButton != null)
                {
                    Vector2 min = new Vector2(position.X / w, (position.Y + line * blob.TotalSpacing) / h);
                    Vector2 max = min + new Vector2((float)blob.GetLineWidth(line) / w, (float)blob.TotalSpacing / h);
                    xButtonBox.Set(min, max);
                    --line;
                }

                if (onAButton != null)
                {
                    Vector2 min = new Vector2(position.X / w, (position.Y + line * blob.TotalSpacing) / h);
                    Vector2 max = min + new Vector2((float)blob.GetLineWidth(line) / w, (float)blob.TotalSpacing / h);
                    aButtonBox.Set(min, max);
                }

                // DEBUG Show hit box for a button as overlay.

                /*
                 * if (onAButton != null)
                 * {
                 *  position = new Vector2(diffuse.Width * aButtonBox.Min.X, diffuse.Height * aButtonBox.Min.Y);
                 *  size = new Vector2(diffuse.Width * (aButtonBox.Size.X), diffuse.Height * aButtonBox.Size.Y);
                 *  quad.Render(new Vector4(1, 0, 0, 0.5f), position, size);
                 * }
                 * if (onXButton != null)
                 * {
                 *  position = new Vector2(diffuse.Width * xButtonBox.Min.X, diffuse.Height * xButtonBox.Min.Y);
                 *  size = new Vector2(diffuse.Width * (xButtonBox.Size.X), diffuse.Height * xButtonBox.Size.Y);
                 *  quad.Render(new Vector4(0, 1, 0, 0.5f), position, size);
                 * }
                 */

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularButtonElement Render()
コード例 #21
0
        }   // end of TwitchPick()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        private void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();


                // Render the white background.
                Vector2 position = Vector2.Zero;
                Vector2 size     = new Vector2(w, white.Height);
                quad.Render(white, position, size, "TexturedNoAlpha");

                // And the black parts.
                position.Y = 70;
                size.Y     = h - 70;
                quad.Render(middleBlack, position, size, "TexturedRegularAlpha");
                position.Y = 64;
                size.Y     = black.Height;
                quad.Render(black, position, size, "TexturedRegularAlpha");

                // The arrows.
                position.X = 20;
                position.Y = 90;
                size       = new Vector2(arrow.Width, arrow.Height);
                quad.Render(arrow, position, size, "TexturedRegularAlpha");
                position.X = w - position.X;
                size.X     = -size.X;
                quad.Render(arrow, position, size, "TexturedRegularAlpha");

                // The indicator.
                size     = new Vector2(indicatorLit.Width, indicatorLit.Height);
                position = new Vector2(512 / 2 - size.X / 2, 140);
                quad.Render(indicatorLit, position, size, "TexturedRegularAlpha");

                // The pictures.  Render them from the outside-in so that they
                // ovelap correctly.
                Vector2 border = new Vector2(3, 3);
                int     index;
                for (int i = limit; i > 0; i--)
                {
                    index    = (CurIndex + i) % pics.Count;
                    size     = new Vector2(pics[index].size);
                    position = pics[index].position - 0.5f * size;
                    quad.Render(new Vector4(0, 0, 0, 1), position, size);
                    quad.Render(pics[index].texture, position + border, size - 2.0f * border, "TexturedRegularAlpha");

                    index    = (CurIndex - i + pics.Count) % pics.Count;
                    size     = new Vector2(pics[index].size);
                    position = pics[index].position - 0.5f * size;
                    quad.Render(new Vector4(0, 0, 0, 1), position, size);
                    quad.Render(pics[index].texture, position + border, size - 2.0f * border, "TexturedRegularAlpha");
                }
                index    = CurIndex;
                size     = new Vector2(pics[index].size);
                position = pics[index].position - 0.5f * size;
                quad.Render(new Vector4(0, 0, 0, 1), position, size);
                quad.Render(pics[index].texture, position + border, size - 2.0f * border, "TexturedRegularAlpha");

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Render the label and value text into the texture.
                string title  = label + " : " + pics[CurIndex].label;
                int    margin = 0;
                position.X = 0;
                position.Y = (int)((64 - Font().LineSpacing) / 2.0f);
                int textWidth = (int)(Font().MeasureString(title).X);

                justify    = Justification.Center;
                position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify);

                Color   labelColor   = new Color(127, 127, 127);
                Color   valueColor   = new Color(140, 200, 63);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();

                // Title.
                TextHelper.DrawString(Font, title, position + shadowOffset, shadowColor);
                TextHelper.DrawString(Font, title, position, labelColor);

                batch.End();

                // Restore default blend state.
                device.BlendState = BlendState.AlphaBlend;


                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularPictureListElement Render()
コード例 #22
0
        }   // end of UIGridModularCheckboxElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();


                // Render the white region with highlight.
                Vector2 position = new Vector2(h - 2, 0);
                Vector2 size     = new Vector2(w, h) - position;
                quad.Render(checkboxWhite, position, size, "TexturedNoAlpha");

                // Render the checkbox.
                position = Vector2.Zero;
                size.X   = size.Y;
                if (check)
                {
                    quad.Render(checkOn, position, size, "TexturedRegularAlpha");
                }
                else
                {
                    quad.Render(checkOff, position, size, "TexturedRegularAlpha");
                }

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Render the label text into the texture.
                int margin = 16;
                position.X = (int)size.X + margin;

                TextBlob blob = new TextBlob(Font, label, w - (int)position.X - margin);

                position.Y = (int)((h - blob.TotalSpacing) / 2.0f) - 2;

                if (blob.NumLines == 2)
                {
                    position.Y -= blob.TotalSpacing / 2.0f;
                }
                else if (blob.NumLines == 3)
                {
                    position.Y -= blob.TotalSpacing;
                }

                Color   fontColor    = new Color(127, 127, 127);
                Color   shadowColor  = new Color(0, 0, 0, 20);
                Vector2 shadowOffset = new Vector2(0, 6);

                blob.RenderWithButtons(position, fontColor, shadowColor, shadowOffset, maxLines: 3);

                // Render help button.

                /*
                 * if (ShowHelpButton)
                 * {
                 *  position.X = w - 54;
                 *  position.Y = h - 54;
                 *  size = new Vector2(64, 64);
                 *  quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha");
                 *  position.X -= 10 + (int)font.MeasureString(Strings.Localize("editObjectParams.help")).X;
                 *  batch.Begin();
                 *  TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position + shadowOffset, shadowColor);
                 *  TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position, fontColor);
                 *  batch.End();
                 *
                 *  if (xButtonText != null)
                 *  {
                 *      position.X = w - 54;
                 *      position.Y = h - 54 - Font().LineSpacing - 6;
                 *      size = new Vector2(64, 64);
                 *      quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha");
                 *      position.X -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X;
                 *      batch.Begin();
                 *      TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position + shadowOffset, shadowColor);
                 *      TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position, fontColor);
                 *      batch.End();
                 *  }
                 * }
                 */

                if (xButtonText != null)
                {
                    position.X = w - 54;
                    position.Y = h - 54;
                    size       = new Vector2(64, 64);
                    quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha");

                    Vector2 min = Vector2.Zero;
                    Vector2 max = Vector2.Zero;

                    max.X = (position.X + 54) / w;
                    min.Y = position.Y / h;

                    position.X -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X;
                    SpriteBatch batch = UI2D.Shared.SpriteBatch;
                    batch.Begin();
                    TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position + shadowOffset, shadowColor);
                    TextHelper.DrawString(Font, Strings.Localize("editWorldParams.setCamera"), position, fontColor);
                    batch.End();

                    min.X = position.X / w;
                    max.Y = min.Y + (float)Font().LineSpacing / h;

                    xButtonBox.Set(min, max);
                }

                // Restore default blend state.
                device.BlendState = BlendState.AlphaBlend;

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularCheckboxElement Render()
コード例 #23
0
        }   // end of Clear()

        private static void RefreshTexture()
        {
            // TODO (****) *** Does this make sense any more since we require a min height of 600?
            bool lores = BokuGame.ScreenSize.Y <= 480;

            UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24Bold;
            if (lores)
            {
                Font = UI2D.Shared.GetGameFont30Bold;
            }
            blob.Font = Font;

            ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance();
            RenderTarget2D  rt     = UI2D.Shared.RenderTarget512_302;

            InGame.SetRenderTarget(rt);

            InGame.Clear(Color.Transparent);

            ssquad.Render(background, Vector2.Zero, new Vector2(512, 302), "TexturedRegularAlpha");

            // Text description.
            if (blob != null)
            {
                Vector2 pos      = new Vector2(margin, margin);
                int     maxLines = showYButton ? (lores ? 3 : 4) : (lores ? 4 : 6);

                // Modify final line to end with ellipsis.
                blob.AddEllipsisToLine(maxLines - 1);

                // If less than maxLines of text, center on texture.
                int spareLines = maxLines - blob.NumLines - 1;
                if (spareLines > 0)
                {
                    pos.Y += spareLines * 0.5f * Font().LineSpacing;
                }

                blob.RenderWithButtons(pos, Color.Yellow, maxLines: maxLines);
            }


            InGame.RestoreRenderTarget();

            //
            // Copy result to local texture.
            //
            int[] data = new int[512 * 302];
            rt.GetData <int>(data);
            texture.SetData <int>(data);

            // Scale size to 1/4 screen height.
            int   w     = (int)BokuGame.ScreenSize.X;
            int   h     = (int)BokuGame.ScreenSize.Y;
            float scale = h / 4.0f / 302.0f;

            size  = new Vector2(512, 302);
            size *= scale;

            // Position in lower right hand corner.
            targetPosition  = new Vector2(w, h);
            targetPosition -= size;

            dirty = false;
        }   // end of RefreshTexture()
コード例 #24
0
        }   // end of UIGridPictureListElement RecalPositions().

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        private void RefreshTexture()
        {
            if (!dirty)
            {
                // Check if any of the owned pictures are dirty.
                for (int i = 0; i < pictures.Count; i++)
                {
                    if (pictures[i].dirty)
                    {
                        dirty             = true;
                        pictures[i].dirty = false;
                    }
                }
            }

            if (dirty)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                int width  = backgroundWidth;
                int height = backgroundHeight;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();



                // Render the label text into the texture in the upper left-hand corner.
                int margin = 32;
                int x      = 0;
                int y      = 12;

                string fancyLabel = label;
                if (pictures[curIndex].label != null)
                {
                    fancyLabel = fancyLabel + " : " + pictures[curIndex].label;
                }
                int textWidth = (int)(Font().MeasureString(fancyLabel).X);

                x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                TextHelper.DrawStringWithShadow(Font, batch, x, y, fancyLabel, textColor, dropShadowColor, invertDropShadow);
                batch.End();


                // Render the arrows.
                if (showLeftArrow)
                {
                    quad.Render(leftArrow, leftArrowPosition, arrowSize, @"TexturedRegularAlpha");
                }
                if (showRightArrow)
                {
                    quad.Render(rightArrow, rightArrowPosition, arrowSize, @"TexturedRegularAlpha");
                }

                // Render the PictureList.
                for (int i = 0; i < pictures.Count; i++)
                {
                    if (pictures[i].alpha > 0.0f)
                    {
                        quad.Render(pictures[i].Texture, pictures[i].position, pictures[i].scale * arrowSize, @"TexturedRegularAlpha");
                    }
                }

                // Render help button.
                if (ShowHelpButton)
                {
                    x = width - 54;
                    y = height - 54;
                    Vector2 pos  = new Vector2(x, y);
                    Vector2 size = new Vector2(64, 64);
                    quad.Render(ButtonTextures.YButton, pos, size, "TexturedRegularAlpha");
                    x -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X;
                    batch.Begin();
                    TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editObjectParams.help"), textColor, dropShadowColor, invertDropShadow);
                    batch.End();

                    if (xButtonText != null)
                    {
                        x    = width - 54;
                        y    = height - 54 - Font().LineSpacing - 6;
                        pos  = new Vector2(x, y);
                        size = new Vector2(64, 64);
                        quad.Render(ButtonTextures.XButton, pos, size, "TexturedRegularAlpha");
                        x -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X;
                        batch.Begin();
                        TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editWorldParams.setCamera"), textColor, dropShadowColor, invertDropShadow);
                        batch.End();
                    }
                }

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridPictureListElement RefreshTexture()
コード例 #25
0
        }   // end of UIGridModularRadioBoxElement Update()

        public void RefreshTexture()
        {
            if (dirty || diffuse.IsContentLost)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.White);

                int w = diffuse.Width;
                int h = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                // Render the white background.
                Vector2 position = Vector2.Zero;
                Vector2 size     = new Vector2(w, radioWhite.Height);
                quad.Render(radioWhite, position, size, "TexturedNoAlpha");

                // And the black parts.
                position.Y = 70;
                size.Y     = h - 70;
                quad.Render(middleBlack, position, size, "TexturedRegularAlpha");
                position.Y = 64;
                size.Y     = radioBlack.Height;
                quad.Render(radioBlack, position, size, "TexturedRegularAlpha");

                // Disable writing to alpha channel.
                // This prevents transparent fringing around the text.
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                device.BlendState = UI2D.Shared.BlendStateColorWriteRGB;

                // Render the label and value text into the texture.
                int margin = 0;
                position.X = 0;
                position.Y = (int)((64 - Font().LineSpacing) / 2.0f);
                int textWidth = (int)(Font().MeasureString(label).X);

                justify    = Justification.Center;
                position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify);

                Color   labelColor    = new Color(127, 127, 127);
                Color   valueColor    = new Color(140, 200, 63);
                Color   shadowColor   = new Color(0, 0, 0, 20);
                Vector2 shadowOffset  = new Vector2(0, 6);
                Color   entryColor    = new Color(200, 200, 200);
                Color   selectedColor = new Color(0, 255, 12);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();

                // Title.
                TextHelper.DrawString(Font, label, position + shadowOffset, shadowColor);
                TextHelper.DrawString(Font, label, position, labelColor);

                // Entries.
                UI2D.Shared.GetFont entryFont = UI2D.Shared.GetGameFont18Bold;

                if (numColumns == 1)
                {
                    position.Y = 70;
                    Vector2 min = Vector2.Zero;
                    Vector2 max = Vector2.One;

                    for (int i = 0; i < list.Count; i++)
                    {
                        position.X = (512 - entryFont().MeasureString(list[i].Text).X) / 2;
                        TextHelper.DrawString(entryFont, list[i].Text, position, curIndex == i ? selectedColor : entryColor);

                        if (showIndicators)
                        {
                            int vert = 5;
                            if (curIndex == i)
                            {
                                quad.Render(indicatorLit, new Vector2(30, position.Y + vert), new Vector2(indicatorLit.Width, indicatorLit.Height), "TexturedRegularAlpha");
                                quad.Render(indicatorLit, new Vector2(512 - 30 - indicatorLit.Width, position.Y + vert), new Vector2(indicatorLit.Width, indicatorLit.Height), "TexturedRegularAlpha");
                            }
                            else
                            {
                                quad.Render(indicatorUnlit, new Vector2(30, position.Y + vert), new Vector2(indicatorUnlit.Width, indicatorUnlit.Height), "TexturedRegularAlpha");
                                quad.Render(indicatorUnlit, new Vector2(512 - 30 - indicatorLit.Width, position.Y + vert), new Vector2(indicatorUnlit.Width, indicatorUnlit.Height), "TexturedRegularAlpha");
                            }
                        }

                        min.Y = position.Y / h;

                        position.Y += entryFont().LineSpacing + 4;

                        max.Y = position.Y / h;
                        if (list[i].Box == null)
                        {
                            list[i].Box = new AABB2D(min, max);
                        }
                        else
                        {
                            list[i].Box.Set(min, max);
                        }
                    }
                }
                else if (numColumns == 2)
                {
                    // Probably not as general as we'd like but I think this only
                    // get used for the language options so just do what we need
                    // to get all the languages to fit.
                    // For column 0, left justify.
                    // For column 1, right justify.
                    for (int column = 0; column < numColumns; column++)
                    {
                        position.Y = 70;

                        int width          = 512 / numColumns;
                        int center         = width / 2 + column * width;
                        int itemsPerColumn = (list.Count + (numColumns - 1)) / numColumns;
                        int minIndex       = column * itemsPerColumn;
                        int maxIndex       = Math.Min(list.Count, (column + 1) * itemsPerColumn);

                        // Min/max values ine 0..1 range across rt.
                        Vector2 min = new Vector2((center - width / 2.0f) / w, 0);
                        Vector2 max = new Vector2((center + width / 2.0f) / w, 1);

                        for (int i = minIndex; i < maxIndex; i++)
                        {
                            position.X = (int)(center - (entryFont().MeasureString(list[i].Text).X) / 2);
                            int edgeMargin = 8;
                            if (column == 0)
                            {
                                position.X = edgeMargin;
                            }
                            else
                            {
                                position.X = (int)(512 - edgeMargin - entryFont().MeasureString(list[i].Text).X);
                            }
                            TextHelper.DrawString(entryFont, list[i].Text, position, curIndex == i ? selectedColor : entryColor);

                            min.Y = position.Y / h;

                            position.Y += entryFont().LineSpacing + 4;

                            max.Y = position.Y / h;
                            if (list[i].Box == null)
                            {
                                list[i].Box = new AABB2D(min, max);
                            }
                            else
                            {
                                list[i].Box.Set(min, max);
                            }
                        }
                    }
                }
                else
                {
                    Debug.Assert(false, "numColumns must be 1 or 2, nothing else is supported.");
                }


                batch.End();

                // Restore default blend state.
                device.BlendState = BlendState.AlphaBlend;

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridModularRadioBoxElement RefreshTexture()
コード例 #26
0
        }   // end of UIGridCheckboxElement Render()

        /// <summary>
        /// If the state of the element has changed, we may need to re-create the texture.
        /// </summary>
        public void RefreshTexture()
        {
            if (dirty)
            {
                InGame.SetRenderTarget(diffuse);
                InGame.Clear(Color.Transparent);

                int width  = diffuse.Width;
                int height = diffuse.Height;

                ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();


                // Render the checkbox.
                int     margin    = 24;
                Vector2 position  = new Vector2(margin, margin);
                Vector2 size      = new Vector2(height - 2.0f * margin, height - 2.0f * margin);
                Vector4 lightGrey = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
                quad.Render(checkbox, lightGrey, position, size, @"TexturedRegularAlpha");

                // Render the checkmark.
                if (check)
                {
                    quad.Render(checkmark, position, size, @"TexturedRegularAlpha");
                }

                // Render the label text into the texture.
                margin += (int)size.X + 16;
                int x         = 0;
                int y         = (int)((height - Font().LineSpacing) / 2.0f) - 2;
                int textWidth = (int)(Font().MeasureString(label).X);

                x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;
                batch.Begin();
                TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow);
                batch.End();

                // Render help button.
                if (ShowHelpButton)
                {
                    x        = width - 54;
                    y        = height - 54;
                    position = new Vector2(x, y);
                    size     = new Vector2(64, 64);
                    quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha");
                    x -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X;
                    batch.Begin();
                    TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editObjectParams.help"), textColor, dropShadowColor, invertDropShadow);
                    batch.End();

                    if (xButtonText != null)
                    {
                        x        = width - 54;
                        y        = height - 54 - Font().LineSpacing - 6;
                        position = new Vector2(x, y);
                        size     = new Vector2(64, 64);
                        quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha");
                        x -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X;
                        batch.Begin();
                        TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editWorldParams.setCamera"), textColor, dropShadowColor, invertDropShadow);
                        batch.End();
                    }
                }

                // Restore backbuffer.
                InGame.RestoreRenderTarget();

                dirty = false;
            }
        }   // end of UIGridCheckboxElement Render()