/// <summary> /// Calculates the width of a string. /// </summary> /// <param name="text">The text to measure.</param> /// <param name="font">Game font used for measurements.</param> /// <param name="scale">The scale of the characters.</param> /// <returns>The width of the string based on the font and scale.</returns> public static float GetTextWidth(string text, CitizenFX.Core.UI.Font font, float scale) { // Start by requesting the game to start processing a width measurement SetTextEntryForWidth("CELL_EMAIL_BCON"); // _BEGIN_TEXT_COMMAND_WIDTH // Add the text string UIResText.AddLongString(text); // Set the properties for the text SetTextFont((int)font); SetTextScale(1f, scale); // Ask the game for the relative string width float width = GetTextScreenWidth(true); // And return the literal result return(ResolutionMaintainRatio.Width * width); }
/// <summary> /// Calculates the width of a string. /// </summary> /// <param name="text">The text to measure.</param> /// <param name="font">Game font used for measurements.</param> /// <param name="scale">The scale of the characters.</param> /// <returns>The width of the string based on the font and scale.</returns> public static float GetTextWidth(string text, GTA.Font font, float scale) { // Start by requesting the game to start processing a width measurement Function.Call(Hash._SET_TEXT_ENTRY_FOR_WIDTH, "CELL_EMAIL_BCON"); // _BEGIN_TEXT_COMMAND_WIDTH // Add the text string UIResText.AddLongString(text); // Set the properties for the text Function.Call(Hash.SET_TEXT_FONT, (int)font); Function.Call(Hash.SET_TEXT_SCALE, 1f, scale); // Ask the game for the relative string width float width = Function.Call <float>(Hash._GET_TEXT_SCREEN_WIDTH, true); // And return the literal result return(ResolutionMaintainRatio.Width * width); }