MeasureString() публичный Метод

public MeasureString ( string text ) : System.Vector2
text string
Результат System.Vector2
Пример #1
1
        /// <summary>
        /// This function loads the content for the lose screen.
        /// </summary>
        /// <param name="texture">texture for the lose screen</param>
        /// <param name="font">font to use for string</param>
        /// <param name="score">exit score</param>
        public void LoadContent(Texture2D texture, SpriteFont font, int score)
        {
            this.texture = texture; //set texture
            rectangle = new Rectangle(0, 0, texture.Width, texture.Height); //set texture bounds

            this.font = font; //set font
            this.scoreString = "SCORE: " + score.ToString(); //set score string to display
            center = new Vector2(800 - font.MeasureString(scoreString).X, 480 - font.MeasureString(scoreString).Y); //set position of score string
        }
Пример #2
0
 private void DrawErrorMessage(SpriteBatch sb, SpriteFont font, String text)
 {
     int width = (int)font.MeasureString(text).X, height = (int)font.MeasureString(text).Y;
     Rectangle r = new Rectangle((game.ScreenWidth - width) / 2, (game.ScreenHeight - height) / 2, width, height);
     Utils.DrawRectangle(sb, game.GraphicsDevice, r, Color.Red);
     game.DrawStringAtCenter(sb, text, Color.White);
 }
        //------------------------------------------------------------------------------
        // Function: ItemText
        // Author: nholmes
        // Summary: item constructor, allows user to specify text, vertical position,
        //          alignment and font as well as whether the text is selectable
        //------------------------------------------------------------------------------
        public ItemText(Menu menu, Game game, string text, int y, Alignment alignment, SpriteFont font, Color fontColor, int textOffset, bool selectable)
            : base(menu, game, textOffset)
        {
            // store the text font and font color to use
            this.text = text;
            this.font = font;
            this.fontColor = fontColor;

            // store whether this item is selectable
            this.selectable = selectable;

            // set the vy position of this text item
            position.Y = y;

            // calculate position based on alignment provided
            switch (alignment)
            {
                case Alignment.left:
                    position.X = 0;
                    break;
                case Alignment.centre:
                    position.X = (int)((menu.ItemArea.Width - font.MeasureString(text).X) / 2);
                    break;
                case Alignment.right:
                    position.X = (int)(menu.ItemArea.Width - font.MeasureString(text).X);
                    break;
                default:
                    position.X = 0;
                    break;
            }

            // store the size of this text item
            size = font.MeasureString(text);
        }
Пример #4
0
        /// <summary>
        /// This function takes a string and a vector2. It splits the string given by spaces
        /// and then for each word it will check the length of it against the length of the
        /// vector2 given in. When the word is passed the edge a new line is put in.
        /// </summary>
        /// <param name="font">The font to use for measuments</param>
        /// <param name="text">Text to be wrapped</param>
        /// <param name="containerDemensions">Dimensions of the container the text is to be wrapped in</param>
        /// <returns>The text including newlines to fit into the container</returns>
        public static String wrapText(SpriteFont font, String text, Vector2 containerDemensions)
        {
            String line = String.Empty;
            String returnString = String.Empty;
            String[] wordArray = text.Split(' ');

            foreach (String word in wordArray)
            {
                if (font.MeasureString(line + word).Length() > containerDemensions.X)
                {
                    returnString += line + '\n';
                    line = String.Empty;

                    // If the string is longer than the box, we need to stop
                    if (font.MeasureString(returnString).Y > containerDemensions.Y)
                    {
                        returnString = returnString.Substring(0, returnString.Length - 3) + "...";
                        break;
                    }
                }

                line += word + ' ';
            }

            return returnString + line;
        }
Пример #5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Wrap text. </summary>
        ///
        /// <remarks>   Frost, 16.11.2010. </remarks>
        ///
        /// <param name="font">                 The font. </param>
        /// <param name="text">                 The text. </param>
        /// <param name="maximumLineLength">    Length of the maximum line. </param>
        ///
        /// <returns>   . </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public static string WrapText(SpriteFont font, string text, float maximumLineLength)
        {
            string[] words = text.Split(' ');

            StringBuilder sb = new StringBuilder();

            float spaceLength = font.MeasureString(" ").X;

            float lineLength = 0;

            foreach (string word in words)
            {
                float wordLength = font.MeasureString(word).X;
                if (wordLength + lineLength < maximumLineLength)
                {
                    sb.Append(word + " ");
                    lineLength += wordLength + spaceLength;
                }

                else
                {
                    sb.Append("\n" + word + " ");
                    lineLength = wordLength + spaceLength;
                }
            }

            return sb.ToString();
        }
Пример #6
0
        public override void LoadContent()
        {
            if (m_content == null)
                m_content = new ContentManager(ScreenManager.Game.Services, "Content");

            m_menu_fnt = m_content.Load<SpriteFont>("Fonts\\atarifont");

            m_selector_txt = m_content.Load<Texture2D>("Pong\\Textures\\selector");

            m_selector_snd = m_content.Load<SoundEffect>("Pong\\Sounds\\paddlehit");

            m_resume = new MenuFontItem(ScreenManager.GraphicsDevice.Viewport.Width / 2 - (int)m_menu_fnt.MeasureString("RESUME").X/2, 150, "RESUME", m_menu_fnt);
            m_restart = new MenuFontItem(ScreenManager.GraphicsDevice.Viewport.Width / 2 - (int)m_menu_fnt.MeasureString("RESTART").X / 2, 155 + m_resume.Height, "RESTART", m_menu_fnt);
            m_quit = new MenuFontItem(ScreenManager.GraphicsDevice.Viewport.Width / 2 - (int)m_menu_fnt.MeasureString("QUIT").X / 2, 155 + m_resume.Height + m_restart.Height, "QUIT", m_menu_fnt);

            m_selector = new Sprite(m_selector_txt);
            m_selector.X_Pos = m_resume.X_Pos - (int)(m_selector.Width*1.5);
            m_selector.Y_Pos = m_resume.Y_Pos + m_resume.Height / 2 - m_selector.Height/2;

            // Hook up menu event handlers.
            m_resume.m_selected_events += OnCancel;
            m_restart.m_selected_events += RestartGameMenuEntrySelected;
            m_quit.m_selected_events += QuitGameMenuEntrySelected;

            // Add entries to the menu.
            MenuEntries.Add(m_resume);
            MenuEntries.Add(m_restart);
            MenuEntries.Add(m_quit);

            m_selected = m_resume;
        }
Пример #7
0
        // Loading the content and setting up said content
        public void LoadContent(ContentManager Content, GraphicsDevice graphicsDevice)
        {
            backgroundManager.LoadContent(Content, graphicsDevice, @"Backgrounds\Clouds\Cloud-Blue-1", @"Backgrounds\Clouds\Cloud-Blue-2");

            HeaderFont = Content.Load<SpriteFont>(@"Fonts\StartMenuHeaderFont");
            HUDFont = Content.Load<SpriteFont>(@"Fonts\HUDFont");

            HeaderPosition = new Vector2(Game1.ViewPortWidth / 2 - (HeaderFont.MeasureString("Levi Challenge").X / 2), Game1.ViewPortHeight / 20);
            MadeByPosition = new Vector2(10, Game1.ViewPortHeight - HUDFont.MeasureString("Made by Nathan Todd").Y);

            boxHeaderLine = new GuiBox(new Vector2(Game1.ViewPortWidth / 2 - (float)((HeaderFont.MeasureString("Levi Challenge").X * 1.3) / 2), Game1.ViewPortHeight / 6), (int)(HeaderFont.MeasureString("Levi Challenge").X * 1.3), 2, 0, Color.White * 0.4f, Color.White, graphicsDevice);

            btnNewGame = new GuiButton(new Vector2(Game1.ViewPortWidth / 2 - 168, Game1.ViewPortHeight / 4), 336, 69, 0, Color.Black * 0.3f, Color.YellowGreen * 0.3f, Color.White, Color.White * 0.6f, "New Game", @"Fonts\StartMenuButtonFont");
            btnContinue = new GuiButton(new Vector2(Game1.ViewPortWidth / 2 - 168, Game1.ViewPortHeight / 4 + 69), 336, 69, 0, Color.Black * 0.15f, Color.YellowGreen * 0.15f, Color.White, Color.White * 0.6f, "Continue", @"Fonts\StartMenuButtonFont");
            btnOptions = new GuiButton(new Vector2(Game1.ViewPortWidth / 2 - 168, Game1.ViewPortHeight / 4 + 138), 336, 69, 0, Color.Black * 0.3f, Color.YellowGreen * 0.3f, Color.White, Color.White * 0.6f, "Options", @"Fonts\StartMenuButtonFont");
            btnExit = new GuiButton(new Vector2(Game1.ViewPortWidth / 2 - 168, Game1.ViewPortHeight / 4 + 207), 336, 69, 0, Color.Black * 0.15f, Color.YellowGreen * 0.15f, Color.White, Color.White * 0.6f, "Exit", @"Fonts\StartMenuButtonFont");

            guiSystem.Add(boxHeaderLine);
            guiSystem.Add(btnNewGame);
            guiSystem.Add(btnContinue);
            guiSystem.Add(btnOptions);
            guiSystem.Add(btnExit);

            guiSystem.LoadContent(Content, graphicsDevice);
            guiSystem.ButtonIndexUpdate(0);
        }
Пример #8
0
        public DetailsView(BohemianArtifact bbshelf, Vector3 position, Vector3 size)
        {
            bookshelf = bbshelf;
            bookshelf.Library.SelectedArtifactChanged += new ArtifactLibrary.SelectedArtifactHandler(library_SelectedArtifactChanged);
            bookshelf.Library.LanguageChanged += new ArtifactLibrary.ChangeLanguageHandler(Library_LanguageChanged);
            this.position = position;
            this.size = size;
            font = bookshelf.Content.Load<SpriteFont>("Arial");

            titleText = new SelectableText(font, "Details", new Vector3(0.4f, 0, 0), bookshelf.GlobalTextColor, Color.White);
            titleText.InverseScale(0.8f, size.X, size.Y);

            boundingBox = new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 0), Color.Black, 0.005f);
            roundedBox = new RoundedBoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 0), new Color(200, 200, 200), 0.008f, this);
            float maxWidth = 0.5f; // as a percentage of the width of the details box

            maxImageBox = new SelectableQuad(new Vector2(0, 0), new Vector2(maxWidth, maxWidth * size.X / size.Y), Color.White);
            rotationRange = new FloatRange(0, 10, 1, (float)(-Math.PI / 24), (float)(Math.PI / 24));

            batch = new SpriteBatch(XNA.GraphicsDevice);
            headerScale = 0.9f;
            subheaderScale = 0.7f;
            bodyScale = 0.55f;

            heightOfBodyLine = font.MeasureString("Eg").Y * bodyScale; // Eg = a high capital letter + low-hanging lowercase to fill the space
            heightofSpaceBetweenLines = font.MeasureString("Eg\nEg").Y * bodyScale - 2 * heightOfBodyLine;

            //setLengths(bbshelf.Library.Artifacts); // for debugging

            maxImageBox.TouchReleased += new TouchReleaseEventHandler(maxImageBox_TouchReleased);
            //bbshelf.SelectableObjects.AddObject(maxImageBox); // for debugging
        }
Пример #9
0
        public string WordWrap(SpriteFont spritefont, string text, float maxWidth)
        {
            string[] words = text.Split(' ');

            StringBuilder stringbuilder = new StringBuilder();
            float linewidth = 0.0f;
            float spacewidth = spritefont.MeasureString(" ").X;

            foreach (var word in words)
            {
                Vector2 size = spritefont.MeasureString(word);

                if (linewidth + size.X < maxWidth)
                {
                    stringbuilder.Append(word + " ");
                    linewidth += size.X + spacewidth;
                }
                else
                {
                    stringbuilder.Append("\n" + word + " ");
                    linewidth = size.X + spacewidth;
                }
            }

            return stringbuilder.ToString();
        }
Пример #10
0
        public JoinNetworkGameScreen(Game game, SpriteBatch spriteBatch, SpriteFont spriteFont, Texture2D background)
            : base(game, spriteBatch)
        {
            this.background = background;
            formBackground = game.Content.Load<Texture2D>("alienmetal");
            Vector2 formSize = new Vector2(350, 350);
            Vector2 center = new Vector2((this.windowSize.Width - formSize.X) / 2, (this.windowSize.Height - formSize.Y) / 2);
            connectionMethodForm = new Form("Connect", "Connection Metod", new Rectangle((int)center.X, (int)center.Y,(int) formSize.X, (int)formSize.Y), formBackground, spriteFont, Color.White);

            buttonTexture = game.Content.Load<Texture2D>("buttonTexture");
            textboxTexture = game.Content.Load<Texture2D>("textboxTexture");

            //figure out the width and heigh of the text on the buttons
            Vector2 lanButtonSize, connectButtonSize;
            lanButtonSize = spriteFont.MeasureString("Scan Lan");
            connectButtonSize = spriteFont.MeasureString("Connect");
            lanButton = new Button("ScanLan", "Scan LAN", new Rectangle(32,30,(int)lanButtonSize.X + 10, (int)lanButtonSize.Y + 10), buttonTexture, spriteFont, Color.White);
            sendButton = new Button("Connect", "Connect", new Rectangle(32,151,(int)connectButtonSize.X + 10, (int)connectButtonSize.Y + 10), buttonTexture, spriteFont, Color.White);
            backButton = new Button("BackButton", @"Back", new Rectangle(32, 192, 95, 23), buttonTexture, spriteFont, Color.White);
            textBoxIP = new TextBox("Address", "",100,new Rectangle(32,110,232,20), textboxTexture, spriteFont, Color.Black);
            textBoxPort = new TextBox("Port", "", 8, new Rectangle(288,110,60,20), textboxTexture, spriteFont, Color.Black);

            connectionMethodForm.AddControl(lanButton);
            connectionMethodForm.AddControl(sendButton);
            connectionMethodForm.AddControl(backButton);
            connectionMethodForm.AddControl(textBoxIP);
            connectionMethodForm.AddControl(textBoxPort);

            lanButton.onClick += new EHandler(ButtonClick);
            sendButton.onClick += new EHandler(ButtonClick);
            backButton.onClick += new EHandler(ButtonClick);

            imageRectangle = new Rectangle(0, 0, Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height);
        }
Пример #11
0
 public static string BreakStringAccoringToLineLength(SpriteFont font, string input, float maxLineLength)
 {
     var words = input.Split(' ');
     var lines = new List<string>();
     var spaceLen = font.MeasureString(" ").X;
     var currentLineLength = 0f;
     StringBuilder currentLine = new StringBuilder();
     foreach (var word in words)
     {
         var wordLen = font.MeasureString(word).X;
         if (currentLineLength > 0)
         {
             if ((currentLineLength + spaceLen + wordLen) > maxLineLength)
             {
                 lines.Add(currentLine.ToString());
                 currentLine.Clear();
                 currentLine.Append(word);
                 currentLineLength = wordLen;
             }
             else
             {
                 currentLine.Append(' ').Append(word);
                 currentLineLength += wordLen + spaceLen;
             }
         }
         else
         {
             currentLine.Append(word);
             currentLineLength += wordLen;
         }
     }
     lines.Add(currentLine.ToString());
     return string.Join("\n", lines);
 }
 public Button(string str, Vector2 SizeandLocation, SpriteFont Font, Color Color)
 {
     text = str;
     font = Font;
     detection = new Rectangle((int)SizeandLocation.X - ((int)font.MeasureString(text).X / 2), (int)SizeandLocation.Y - ((int)font.MeasureString(text).Y / 2), (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y);
     color = Color;
 }
Пример #13
0
 /* word wrapping fr http://www.xnawiki.com/index.php/Basic_Word_Wrapping
  * because I can't be arsed with writing this again */
 public static string WrapText(
     SpriteFont spriteFont,
     string text,
     float maxLineWidth
 )
 {
     string[] words = text.Split(' ');
     StringBuilder sb = new StringBuilder();
     float lineWidth = 0f;
     float spaceWidth = spriteFont.MeasureString(" ").X;
     foreach (string word in words)
     {
         Vector2 size = spriteFont.MeasureString(word);
         if (lineWidth + size.X < maxLineWidth)
         {
             sb.Append(word + " ");
             lineWidth += size.X + spaceWidth;
         }
         else
         {
             sb.Append("\n" + " " + word + " ");
             lineWidth = size.X + spaceWidth;
         }
     }
     return sb.ToString();
 }
Пример #14
0
        public GameState(GraphicsDeviceManager g, ContentManager c, Viewport v)
            : base(g, c, v)
        {
            me = this;
            viewport = v;

            ButtonSize = new Vector2(viewport.Width * 0.34f, viewport.Width * 0.17f);
            btnPlay = content.Load<Texture2D>("btnPlay");
            playLocation = new Vector2((viewport.Width - ButtonSize.X) / 2, viewport.Height * 0.6f);

            score = new Score(v, c);
            score.display = true;

            player = new Player(v);
            player.LoadContent(c);

            obstacles = new Obstacles(viewport);
            obstacles.LoadContent(content);

            spriteFont = content.Load<SpriteFont>("ScoreFont");
            READEsize = spriteFont.MeasureString("Get Ready");
            Menusize = spriteFont.MeasureString("Twerkopter");
            GameOverSize = spriteFont.MeasureString("Game Over");

            GameOverLocation = new Vector2((viewport.Width - spriteFont.MeasureString("Game Over").X) / 2, -GameOverSize.Y);

            Scoreboard = content.Load<Texture2D>("Dashboard");
            ScoreboardSize = new Vector2(viewport.Width * .9f, viewport.Width * 0.545625f);
            ScoreboardLocation = new Vector2((viewport.Width - ScoreboardSize.X) / 2, viewport.Height);

            buttonSound = c.Load<SoundEffect>("swing");
        }
Пример #15
0
        public Menu(SpriteFont TitleFont, SpriteFont menuFont)
        {
            MenuStrings = new List<string>();
            SuitStrings = new List<string>();
            MenuScreens = new Dictionary<string, Texture2D>();

            // add the menu strings
            MenuStrings.Add("Start");
            MenuStrings.Add("Instructions");
            MenuStrings.Add("About");
            MenuStrings.Add("Exit");

            SuitStrings.Add("1. Hearts");
            SuitStrings.Add("2. Diamonds");
            SuitStrings.Add("3. Clubs");
            SuitStrings.Add("4. Spades");

            // add 4 items for now
            MenuStringRectangles = new List<Rectangle>();
            Vector2 FontOrigin;

            string output = "Start";
            FontOrigin = TitleFont.MeasureString(output);
            int optionAnimationCounter = 3;
            float  posX = BOARD_WIDTH / 2 - FontOrigin.X / 4 - optionAnimationCounter * 2;
            float posY = 216 - FontOrigin.Y / 4;
            FontOrigin = TitleFont.MeasureString(output);
            MenuStringRectangles.Add(new Rectangle((int)posX, (int)posY, (int)FontOrigin.X, (int)FontOrigin.Y / 2));

            output = "Instructions";
            FontOrigin = TitleFont.MeasureString(output);
            posY = 344 - FontOrigin.Y / 4;
            posY = 344 - FontOrigin.Y / 4;
            posX -= optionAnimationCounter;
            MenuStringRectangles.Add(new Rectangle((int)posX, (int)posY, (int)FontOrigin.X, (int)FontOrigin.Y / 2));

            output = "About";
            FontOrigin = TitleFont.MeasureString(output);
            posY = 471 - FontOrigin.Y / 4;
            MenuStringRectangles.Add(new Rectangle((int)posX, (int)posY, (int)FontOrigin.X, (int)FontOrigin.Y / 2));

            output = "Exit";
            FontOrigin = TitleFont.MeasureString(output);
            posY = 608 - FontOrigin.Y / 4;
            posX -= optionAnimationCounter * 10;
            MenuStringRectangles.Add(new Rectangle((int)posX, (int)posY, (int)FontOrigin.X + optionAnimationCounter * 10, (int)FontOrigin.Y / 2));

            int startY = 170;
            int startX = 20;
            int increment = 75;
            TrumpStringRectangles = new List<Rectangle>();
            for (int index = 0; index < SuitStrings.Count; index++)
            {
                output = SuitStrings[index];
                FontOrigin = menuFont.MeasureString(output);
                startY += increment;
                TrumpStringRectangles.Add(new Rectangle(startX, startY, (int)(FontOrigin.X * 0.7), (int)(FontOrigin.Y * 0.7)));
            }
        }
Пример #16
0
Файл: Score.cs Проект: k0vl/Pong
 public Score(SpriteFont font, Rectangle gameBoundries)
 {
     this.font = font;
     this.Height = font.MeasureString("0:0").Y*Game1.DeviceScale;
     this.Width =font.MeasureString("0:0").X*Game1.DeviceScale;
     position = new Vector2((gameBoundries.Width /2) - (Width/2), gameBoundries.Height - 100);
     rotation = 0;
 }
Пример #17
0
        public void Draw(SpriteBatch spriteBatch, SpriteFont spriteFont)
        {
            textPos = new Vector2(bounds.X, bounds.Y);
            textPos += new Vector2((bounds.Width / 2) - (spriteFont.MeasureString(text).X / 2), (bounds.Height / 2) - (spriteFont.MeasureString(text).Y / 2));

            spriteBatch.Draw(TextureRefs.menuButton, bounds, Color.White);
            spriteBatch.DrawString(spriteFont, text, textPos, Color.Black);
        }
Пример #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextMultiButton"/> class.
        /// </summary>
        /// <param name="parent">This controls parent control.</param>
        /// <param name="font">The font.</param>
        /// <param name="options">The options.</param>
        /// <param name="focusScope">The focus scope.</param>
        public TextMultiButton(Control parent, SpriteFont font, string[] options)
            : base(parent)
        {
            if (options == null)
                throw new ArgumentNullException("options");
            if (options.Length == 0)
                throw new ArgumentException("There must be at least one option.", "options");

            this.Colour = Color.White;
            this.Highlight = Color.CornflowerBlue;
            this.options = options;
            this.OptionsCount = options.Length;

            this.leftArrow = new Label(this, font);
            this.leftArrow.Text = "<";
            this.leftArrow.SetPoint(Points.TopLeft, 0, 0);
            this.rightArrow = new Label(this, font);
            this.rightArrow.Text = ">";
            this.rightArrow.SetPoint(Points.TopRight, 0, 0);

            this.centreText = new Label(this, font);
            this.centreText.Justification = Justification.Centre;
            this.centreText.SetPoint(Points.TopLeft, leftArrow.Area.Width, 0);
            this.centreText.SetPoint(Points.TopRight, -rightArrow.Area.Width, 0);
            this.centreText.Text = options[0];

            ControlEventHandler recalcSize = delegate(Control c)
            {
                Vector2 maxSize = Vector2.Zero;
                for (int i = 0; i < options.Length; i++)
                {
                    var size = font.MeasureString(options[i]);
                    maxSize.X = Math.Max(maxSize.X, size.X);
                    maxSize.Y = Math.Max(maxSize.Y, size.Y);
                }
                arrowSize = (int)font.MeasureString("<").X;
                maxSize.X += arrowSize * 2;
                SetSize((int)maxSize.X, (int)maxSize.Y);
                leftArrow.SetSize(arrowSize, font.LineSpacing);
                rightArrow.SetSize(arrowSize, font.LineSpacing);
            };

            ControlEventHandler highlight = delegate(Control c)
            {
                (c as Label).Colour = (c.IsFocused || c.IsWarm) ? Highlight : Colour;
            };

            leftArrow.WarmChanged += highlight;
            rightArrow.WarmChanged += highlight;
            recalcSize(this);

            SelectionChanged += delegate(Control c)
            {
                centreText.Text = this[SelectedOption];
            };

            BindGestures();
        }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProgramInformation"/> class.
 /// </summary>
 public ProgramInformation()
 {
     spriteFont = Program.INSTANCE.Content.Load<SpriteFont>("FPS");
     memory = new Vector2(0, spriteFont.LineSpacing);
     npcs = new Vector2(0, spriteFont.LineSpacing * 2);
     projectiles = new Vector2(0, spriteFont.LineSpacing * 3);
     arduino = new Vector2(GameFrame.Width - spriteFont.MeasureString("Arduino Connection: TODO").X, 0);
     database = new Vector2(GameFrame.Width - spriteFont.MeasureString("Database Connection: TODO").X, spriteFont.LineSpacing);
 }
Пример #20
0
        /// <summary>
        /// This function loads the content for the win screen.
        /// </summary>
        /// <param name="texture">win screen texture</param>
        /// <param name="font">font for time string</param>
        /// <param name="time">time of gameplay</param>
        public void LoadContent(Texture2D texture, SpriteFont font, TimeSpan time)
        {
            this.texture = texture; //set the win screen texture
            rectangle = new Rectangle(0, 0, texture.Width, texture.Height); //set the bounds for the texture

            this.font = font; //set the font for the string
            this.timeString = "TIME: " + time.Minutes.ToString("00") + ":" + time.Seconds.ToString("00"); //fill the string
            center = new Vector2(800 - font.MeasureString(timeString).X, 480 - font.MeasureString(timeString).Y); //place the string position
        }
Пример #21
0
        public PlayerStatDisplay(SpriteFont font, int player_index, BoxingPlayer player,Input_Handler input, Rectangle bounds, Texture2D background, Texture2D bar)
        {
            this.player = player;
            this.bounds = bounds;
            this.background = background;
            this.tBar = bar;
            this.health = player.MaxHealth;
            this.stamina = player.MaxStamina;
            this.input = input;
            this.isActive = input.isActive;

            title = "Player " + player_index;

            //===================Initialize positions====================
            int margin = 1; // the whitespace around the entry

            // Dimensions of the strings
            int stringHeight = (int)font.MeasureString("S").Y;
            int stringWidth = (int)font.MeasureString("MMM").X;

            // Dimensions of the bars
            int textX = bounds.X + stringWidth / 2;
            int barHeight = (int)( 1.5f * stringHeight / 3);

            int barX = bounds.X + (int)(1.25f * stringWidth + 2);

            // Portions?
            int vertical_Portion = bounds.Height / 14;
            int textWidth = bounds.Width / 3;
            barWidth = bounds.X + bounds.Width - barX - 4;
            Vector2 start = new Vector2(bounds.X, bounds.Y);

            // Set position of the Title
            vTitle = new Vector2(bounds.X + bounds.Width / 2 - font.MeasureString(title).X, bounds.Y);

            vHealth = new Vector2(textX + margin, start.Y + margin + (1 * (stringHeight) + (1 * 2 * margin)));
            vStamina = new Vector2(textX + margin, start.Y + margin + (2 * (stringHeight) + (2 * 2 * margin)));

            rHealth = new Rectangle(barX, (int)start.Y + margin + (1 * (stringHeight) + (1 * 2 * margin)), barWidth, stringHeight);
            rStamina = new Rectangle(barX, (int)start.Y + margin + (2 * (stringHeight) + (2 * 2 * margin)), barWidth, stringHeight);

            Debug.WriteLine("rHealth.Y = " + rHealth.Y);

            rHealth.Width = (int)(barWidth * (player.CurrentHealth / player.MaxHealth));
            rStamina.Width = (int)(barWidth * (player.CurrentStamina / player.MaxStamina));

            int squarewidth = bounds.Width / 8;

            // Set position of ability cooldown squares
            for (int i = 0; i < 4; i++)
            {
                rAbilities[i] = new Rectangle(((i + 1) * (bounds.X + bounds.Width) / 5) - squarewidth/2,
                    (int)start.Y + margin + (3 * (stringHeight) + (3 * 2 * margin)), squarewidth, squarewidth);
                //Debug.WriteLine("Player " + player_index + " square " + (i + 1) + " initialized");
                Debug.WriteLine("Player " + player_index + " square. X = " + rAbilities[i].X + "square.Y = " + rAbilities[i].Y);
            }
        }
Пример #22
0
        public void BakeTextCentered(SpriteFont font, string text, Vector2 location, Color textColor)
        {
            var shifted = new Vector2 {
                X = (float)Math.Round(location.X - font.MeasureString(text).X / 2),
                Y = (float)Math.Round(location.Y - font.MeasureString(text).Y / 2)
            };

            DrawString(font, text, shifted, textColor);
        }
Пример #23
0
 public static void WriteText(SpriteBatch sb, SpriteFont font, String text, Vector2 position, Color color, int align)
 {
     FontOrigin = Vector2.Zero;
     if (align == 1)
         FontOrigin = font.MeasureString(text) / 2;
     if (align == 2)
         FontOrigin = font.MeasureString(text);
     sb.DrawString(font, text, position, color, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
 }
Пример #24
0
 public override void Draw(SpriteBatch spriteBatch, SpriteFont font)
 {
     string str = "Start";
     base.CollisionMask.Width = (int)font.MeasureString(str).X;
     base.CollisionMask.Height = (int)font.MeasureString(str).Y;
     if (base.hover)
         spriteBatch.DrawString(font, str, new Vector2(CollisionMask.X, CollisionMask.Y), Color.Yellow);
     else
         spriteBatch.DrawString(font, str, new Vector2(CollisionMask.X, CollisionMask.Y), Color.White);
 }
Пример #25
0
Файл: Menu.cs Проект: wico-/Code
 public Button(Texture2D texture, string text)
     : base(new Rectangle(0, 0, texture.Width, texture.Height), texture, ENTITY.UI)
 {
     font = Globals.font;
     this.texture = texture;
     this.text = text;
     this.position = new Vector2();
     textCenter = font.MeasureString(text) / 2;
     boundary = new Rectangle(0, 0, (int)font.MeasureString(text).X + 20, (int)font.MeasureString(text).Y + 20);
 }
 public GenericButton(Vector2 v, string Text, SpriteFont CapitalFont, SpriteFont SmallFont)
 {
     this.Cap = CapitalFont;
     this.Small = SmallFont;
     this.capT = Text[0].ToString();
     this.smallT = Text.Remove(0, 1);
     this.R = new Rectangle((int)v.X - (int)CapitalFont.MeasureString(this.capT).X - (int)SmallFont.MeasureString(Text).X, (int)v.Y, (int)CapitalFont.MeasureString(this.capT).X + (int)SmallFont.MeasureString(Text).X, CapitalFont.LineSpacing);
     this.CapitalPos = new Vector2((float)this.R.X, (float)this.R.Y);
     this.TextPos = new Vector2(this.CapitalPos.X + CapitalFont.MeasureString(this.capT).X + 1f, this.CapitalPos.Y + (float)CapitalFont.LineSpacing - (float)SmallFont.LineSpacing - 3f);
 }
Пример #27
0
 /// <summary>
 /// Constructor for a left aligned message
 /// </summary>
 /// <param name="text">the text for the message</param>
 /// <param name="font">the sprite font for the message</param>
 /// <param name="left">the left of the message</param>
 /// <param name="spotInList">This is used to show a difference between the other constructors</param>
 public Message(string text, SpriteFont font, Vector2 left, int spotInList)
 {
     this.text = text;
     this.font = font;
     this.center = left;
     // calculate position from text and center
     float textWidth = font.MeasureString(text).X;
     float textHeight = font.MeasureString(text).Y;
     position = new Vector2(left.X, left.Y);
 }
Пример #28
0
 public ClickableArea(string texte, SpriteFont font, Vector2 position, Tools.onClickFunction action)
     : base()
 {
     color = Color.Black;
     this.texte = texte;
     this.font = font;
     this.position = position;
     area = new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y), Convert.ToInt32(font.MeasureString(texte).X), Convert.ToInt32(font.MeasureString(texte).Y));
     this.action = action;
 }
Пример #29
0
        public Button(Rectangle location, ContentManager content, string text = "")
        {
            _location = location;
            _texture = content.Load<Texture2D>("Button");
            _font = content.Load<SpriteFont>("ControlFont");
            _text = text;

            _textCenter = new Vector2(_location.X + _location.Width/2 - _font.MeasureString(_text).X /2,
                                      _location.Y + _location.Height / 2 - _font.MeasureString(_text).Y / 2);
        }
Пример #30
0
        public void Dialog(Texture2D dialogBoxTexture, SpriteFont dialogFont, String dialogText, Vector2 dialogPosition)
        {
            DialogBoxTexture = dialogBoxTexture;
            DialogFont = dialogFont;
            DialogText = dialogText;
            DialogPosition = dialogPosition;

            // Creates a rectangel with 15px from text to edge
            DialogBox = new Rectangle((int)DialogPosition.X - 15, (int)DialogPosition.Y - 15, (int)DialogFont.MeasureString(DialogText).X + 30, (int)DialogFont.MeasureString(DialogText).Y + 30);
        }
Пример #31
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font     = Content.Load <Microsoft.Xna.Framework.Graphics.SpriteFont>("SpriteFont1");
            textSize = font.MeasureString("MonoGame");
            textSize = new Vector2(textSize.X / 2, textSize.Y / 2);
        }
Пример #32
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font1    = Content.Load <SpriteFont>("SpriteFont1");
            font2    = Content.Load <SpriteFont>("Arial32");
            textSize = font1.MeasureString("MonoGame");
            textSize = new Vector2(textSize.X / 2, textSize.Y / 2);
        }
Пример #33
0
        public void DrawString(
            SpriteFont spriteFont,
            string text,
            Vector2 position,
            Color color,
            float rotation,
            Vector2 origin,
            Vector2 scale,
            SpriteEffects effects,
            float layerDepth
            )
        {
            /* FIXME: This method is a duplicate of DrawString(StringBuilder)!
             * The only difference is how we iterate through the string.
             * -flibit
             */
            CheckBegin("DrawString");
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (text.Length == 0)
            {
                return;
            }
            effects &= (SpriteEffects)0x03;

            /* We pull all these internal variables in at once so
             * anyone who wants to use this file to make their own
             * SpriteBatch can easily replace these with reflection.
             * -flibit
             */
            Texture2D        textureValue = spriteFont.textureValue;
            List <Rectangle> glyphData    = spriteFont.glyphData;
            List <Rectangle> croppingData = spriteFont.croppingData;
            List <Vector3>   kerning      = spriteFont.kerning;
            List <char>      characterMap = spriteFont.characterMap;

            // FIXME: This needs an accuracy check! -flibit

            // Calculate offset, using the string size for flipped text
            Vector2 baseOffset = origin;

            if (effects != SpriteEffects.None)
            {
                Vector2 size = spriteFont.MeasureString(text);
                baseOffset.X -= size.X * axisIsMirroredX[(int)effects];
                baseOffset.Y -= size.Y * axisIsMirroredY[(int)effects];
            }

            Vector2 curOffset   = Vector2.Zero;
            bool    firstInLine = true;

            foreach (char c in text)
            {
                // Special characters
                if (c == '\r')
                {
                    continue;
                }
                if (c == '\n')
                {
                    curOffset.X  = 0.0f;
                    curOffset.Y += spriteFont.LineSpacing;
                    firstInLine  = true;
                    continue;
                }

                /* Get the List index from the character map, defaulting to the
                 * DefaultCharacter if it's set.
                 */
                int index = characterMap.IndexOf(c);
                if (index == -1)
                {
                    if (!spriteFont.DefaultCharacter.HasValue)
                    {
                        throw new ArgumentException(
                                  "Text contains characters that cannot be" +
                                  " resolved by this SpriteFont.",
                                  "text"
                                  );
                    }
                    index = characterMap.IndexOf(
                        spriteFont.DefaultCharacter.Value
                        );
                }

                /* For the first character in a line, always push the width
                 * rightward, even if the kerning pushes the character to the
                 * left.
                 */
                if (firstInLine)
                {
                    curOffset.X += Math.Abs(kerning[index].X);
                    firstInLine  = false;
                }
                else
                {
                    curOffset.X += spriteFont.Spacing + kerning[index].X;
                }

                // Calculate the character origin
                float offsetX = baseOffset.X + (
                    curOffset.X + croppingData[index].X
                    ) * axisDirectionX[(int)effects];
                float offsetY = baseOffset.Y + (
                    curOffset.Y + croppingData[index].Y
                    ) * axisDirectionY[(int)effects];
                if (effects != SpriteEffects.None)
                {
                    offsetX += glyphData[index].Width * axisIsMirroredX[(int)effects];
                    offsetY += glyphData[index].Height * axisIsMirroredY[(int)effects];
                }

                // Draw!
                float sourceW = Math.Sign(glyphData[index].Width) * Math.Max(
                    Math.Abs(glyphData[index].Width),
                    MathHelper.MachineEpsilonFloat
                    ) / (float)textureValue.Width;
                float sourceH = Math.Sign(glyphData[index].Height) * Math.Max(
                    Math.Abs(glyphData[index].Height),
                    MathHelper.MachineEpsilonFloat
                    ) / (float)textureValue.Height;
                PushSprite(
                    textureValue,
                    glyphData[index].X / (float)textureValue.Width,
                    glyphData[index].Y / (float)textureValue.Height,
                    sourceW,
                    sourceH,
                    position.X,
                    position.Y,
                    glyphData[index].Width * scale.X,
                    glyphData[index].Height * scale.Y,
                    color,
                    offsetX / sourceW / (float)textureValue.Width,
                    offsetY / sourceH / (float)textureValue.Height,
                    (float)Math.Sin(rotation),
                    (float)Math.Cos(rotation),
                    layerDepth,
                    (byte)effects
                    );

                /* Add the character width and right-side
                 * bearing to the line width.
                 */
                curOffset.X += kerning[index].Y + kerning[index].Z;
            }
        }
Пример #34
0
        public void DrawString(
            SpriteFont spriteFont,
            string text,
            Vector2 position,
            Color color,
            float rotation,
            Vector2 origin,
            Vector2 scale,
            SpriteEffects effects,
            float layerDepth
            )
        {
            /* FIXME: This method is a duplicate of DrawString(StringBuilder)!
             * The only difference is how we iterate through the string.
             * -flibit
             */
            CheckBegin("DrawString");
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (text.Length == 0)
            {
                return;
            }
            effects &= (SpriteEffects)0x03;

            // FIXME: This needs an accuracy check! -flibit

            // Calculate offset, using the string size for flipped text
            Vector2 baseOffset = origin;

            if (effects != SpriteEffects.None)
            {
                Vector2 size = spriteFont.MeasureString(text);
                baseOffset.X -= size.X * axisIsMirroredX[(int)effects];
                baseOffset.Y -= size.Y * axisIsMirroredY[(int)effects];
            }

            Vector2 curOffset   = Vector2.Zero;
            bool    firstInLine = true;

            foreach (char c in text)
            {
                // Special characters
                if (c == '\r')
                {
                    continue;
                }
                if (c == '\n')
                {
                    curOffset.X  = 0.0f;
                    curOffset.Y += spriteFont.LineSpacing;
                    firstInLine  = true;
                    continue;
                }

                /* Get the List index from the character map, defaulting to the
                 * DefaultCharacter if it's set.
                 */
                int index = spriteFont.characterMap.IndexOf(c);
                if (index == -1)
                {
                    if (!spriteFont.DefaultCharacter.HasValue)
                    {
                        throw new ArgumentException(
                                  "Text contains characters that cannot be" +
                                  " resolved by this SpriteFont.",
                                  "text"
                                  );
                    }
                    index = spriteFont.characterMap.IndexOf(
                        spriteFont.DefaultCharacter.Value
                        );
                }

                /* For the first character in a line, always push the width
                 * rightward, even if the kerning pushes the character to the
                 * left.
                 */
                if (firstInLine)
                {
                    curOffset.X += Math.Abs(spriteFont.kerning[index].X);
                    firstInLine  = false;
                }
                else
                {
                    curOffset.X += spriteFont.Spacing + spriteFont.kerning[index].X;
                }

                // Calculate the character origin
                Vector2 offset = baseOffset;
                offset.X += (curOffset.X + spriteFont.croppingData[index].X) * axisDirectionX[(int)effects];
                offset.Y += (curOffset.Y + spriteFont.croppingData[index].Y) * axisDirectionY[(int)effects];
                if (effects != SpriteEffects.None)
                {
                    offset.X += spriteFont.glyphData[index].Width * axisIsMirroredX[(int)effects];
                    offset.Y += spriteFont.glyphData[index].Height * axisIsMirroredY[(int)effects];
                }

                // Draw!
                PushSprite(
                    spriteFont.textureValue,
                    spriteFont.glyphData[index],
                    position.X,
                    position.Y,
                    scale.X,
                    scale.Y,
                    color,
                    offset,
                    rotation,
                    layerDepth,
                    (byte)effects,
                    false
                    );

                /* Add the character width and right-side bearing to the line
                 * width.
                 */
                curOffset.X += spriteFont.kerning[index].Y + spriteFont.kerning[index].Z;
            }
        }