コード例 #1
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()
コード例 #2
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()
コード例 #3
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();
        }
コード例 #4
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()
コード例 #5
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()
コード例 #6
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()
コード例 #7
0
        public override void Update(ref Matrix parentMatrix)
        {
            // Do we need to render the gradients?
            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
            RenderTarget2D rt     = UI2D.Shared.RenderTarget64_64;

            for (int i = 0; i < pics.Count; i++)
            {
                if (pics[i].texture == null)
                {
                    if (pics[i].gradient >= 0)
                    {
                        // Create the texture gradient.
                        InGame.SetRenderTarget(rt);
                        ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();
                        quad.RenderGradient(SkyBox.Gradient(pics[i].gradient));
                        InGame.RestoreRenderTarget();

                        pics[i].texture = new Texture2D(device, 64, 64, false, SurfaceFormat.Color);

                        // Copy rendertarget result into texture.
                        int[] data = new int[64 * 64];
                        rt.GetData <int>(data);
                        pics[i].texture.SetData <int>(data);
                    }
                    else
                    {
                        // Load the texture image.
                        pics[i].texture = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\" + pics[i].picName);
                    }
                    dirty = true;
                }
            }

            // Check for input but only if selected.
            if (selected)
            {
                GamePadInput pad = GamePadInput.GetGamePad0();

                if (Actions.ComboRight.WasPressedOrRepeat)
                {
                    curIndex = (curIndex + 1) % pics.Count;
                    Foley.PlayClickUp();
                    recalcPositions = true;
                    dirty           = true;
                }

                if (Actions.ComboLeft.WasPressedOrRepeat)
                {
                    curIndex = (curIndex + pics.Count - 1) % pics.Count;
                    Foley.PlayClickDown();
                    recalcPositions = true;
                    dirty           = true;
                }
            }

            if (recalcPositions)
            {
                if (onChange != null)
                {
                    OnChange(CurIndex);
                }
                RefreshPositions();
            }
            RefreshTexture();

            base.Update(ref parentMatrix);
        }   // end of UIGridModularPictureListElement Update()
コード例 #8
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()
コード例 #9
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);
        }
コード例 #10
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()
コード例 #11
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()
コード例 #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
        }   // 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()