}   // end of LabelButton()

        /// <summary>
        /// Returns true if line fits with reasonable compression.  False if compressed too much.
        /// </summary>
        /// <param name="Font"></param>
        /// <param name="pos"></param>
        /// <param name="line"></param>
        /// <param name="size"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        static bool RenderLine(UI2D.Shared.GetFont Font, Vector2 pos, string line, Vector2 size, int width)
        {
            Vector2 scale = Vector2.One;

            if (size.X > width)
            {
                // Need to compress.
                scale.X = width / size.X;
            }
            else
            {
                // No compression, just center.
                pos.X += (int)((width - size.X) / 2.0f);
            }

            RectangleF rect = new RectangleF(pos.X, pos.Y, width, 96);

            SysFont.DrawString(line, pos, rect, Font().systemFont, Color.Black, scale, outlineColor: Color.White, outlineWidth: 1.5f);
            pos.Y  += GUIButton.DefaultSize.Y;
            rect.Y += GUIButton.DefaultSize.Y;
            SysFont.DrawString(line, pos, rect, Font().systemFont, Color.Black, scale, outlineColor: Color.White, outlineWidth: 1.5f);

            return(scale.X > 0.5f);
        }   // end of RenderLine()
Exemplo n.º 2
0
            }   // end of UpdateTextColor()

            /// <summary>
            /// Render our UI to the screen, but only if now is appropriate.
            /// </summary>
            public static void Render()
            {
                // In mouse mode, don't render undo/redo icons if pickers are active.
                bool mouseEdit = inGame.CurrentUpdateMode == UpdateMode.MouseEdit &&
                                 !InGame.inGame.touchEditUpdateObj.PickersActive;

                if ((inGame.CurrentUpdateMode == UpdateMode.ToolMenu || mouseEdit) &&
                    HaveAnything)
                {
                    GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                    // Calc position for undo/redo text.
                    int x          = 0;
                    int y          = (int)(BokuGame.ScreenSize.Y * 0.66f);
                    int buttonSize = 40;

                    UI2D.Shared.GetFont Font  = UI2D.Shared.GetGameFont18Bold;
                    SpriteBatch         batch = UI2D.Shared.SpriteBatch;

                    // Handle small screens.
                    if (BokuGame.ScreenSize.Y < 720)
                    {
                        Font       = UI2D.Shared.GetGameFont15_75;
                        buttonSize = (int)(buttonSize * 0.8f);
                    }

                    if (HaveReDo)
                    {
                        ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance();

                        Texture2D texture = GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad ? ButtonTextures.YButton : ButtonTextures.Redo;
                        quad.Render(texture,
                                    Vector4.One,
                                    new Vector2(x, y),
                                    new Vector2(buttonSize),
                                    @"TexturedRegularAlpha");

                        redoHitBox.Set(new Vector2(x, y), new Vector2(x, y) + new Vector2(buttonSize - 12));
                    }
                    else
                    {
                        redoHitBox.Set(Vector2.Zero, Vector2.Zero);
                    }

                    if (HaveUnDo)
                    {
                        ScreenSpaceQuad quad    = ScreenSpaceQuad.GetInstance();
                        Texture2D       texture = GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad ? ButtonTextures.XButton : ButtonTextures.Undo;
                        quad.Render(texture,
                                    Vector4.One,
                                    new Vector2(x, y + buttonSize - 12),
                                    new Vector2(buttonSize),
                                    @"TexturedRegularAlpha");

                        undoHitBox.Set(new Vector2(x, y + buttonSize - 12), new Vector2(x, y + buttonSize - 12) + new Vector2(buttonSize - 12));
                    }
                    else
                    {
                        undoHitBox.Set(Vector2.Zero, Vector2.Zero);
                    }

                    Color darkGrey = new Color(10, 10, 10);

#if NETFX_CORE
                    batch.Begin();
                    if (HaveReDo)
                    {
                        string str = Strings.Localize("undoStack.redo") + "(" + NumReDo.ToString() + ")";
                        TextHelper.DrawStringWithShadow(Font,
                                                        batch,
                                                        x + buttonSize - 12,
                                                        y - 4,
                                                        str,
                                                        redoTextColor, darkGrey, false);
                        Vector2 max = redoHitBox.Max;
                        max.X += Font().MeasureString(str).X;
                        redoHitBox.Set(redoHitBox.Min, max);
                    }

                    if (HaveUnDo)
                    {
                        string str = Strings.Localize("undoStack.undo") + "(" + NumUnDo.ToString() + ")";
                        TextHelper.DrawStringWithShadow(Font,
                                                        batch,
                                                        x + buttonSize - 12,
                                                        y + buttonSize - 16,
                                                        str,
                                                        undoTextColor, darkGrey, false);
                        Vector2 max = undoHitBox.Max;
                        max.X += Font().MeasureString(str).X;
                        undoHitBox.Set(undoHitBox.Min, max);
                    }
                    batch.End();
#else
                    SysFont.StartBatch(null);
                    if (HaveReDo)
                    {
                        string str = Strings.Localize("undoStack.redo") + "(" + NumReDo.ToString() + ")";
                        SysFont.DrawString(str, new Vector2(x + buttonSize - 12, y - 4), new RectangleF(), Font().systemFont, redoTextColor, outlineColor: Color.Black, outlineWidth: 1.5f);
                        Vector2 max = redoHitBox.Max;
                        max.X += Font().MeasureString(str).X;
                        redoHitBox.Set(redoHitBox.Min, max);
                    }

                    if (HaveUnDo)
                    {
                        string str = Strings.Localize("undoStack.undo") + "(" + NumUnDo.ToString() + ")";
                        SysFont.DrawString(str, new Vector2(x + buttonSize - 12, y + buttonSize - 16), new RectangleF(), Font().systemFont, undoTextColor, outlineColor: Color.Black, outlineWidth: 1.5f);
                        Vector2 max = undoHitBox.Max;
                        max.X += Font().MeasureString(str).X;
                        undoHitBox.Set(undoHitBox.Min, max);
                    }
                    SysFont.EndBatch();
#endif
                }
            }