So I have a project that draws a string that the player types on the screen, this is drawn on top of a box that I'd like to match the size of the string + a buffer.
The text that is drawn does not use a font resource so by default GameMaker uses the Arial font to draw it on the screen.
The issue is: How do I get the the exact Hight and width of my string at all times so that I can change the size of the background box?
for an example lets use the sentence:
" The Quick Brown Fox Jumped Over The Lazy Dog "
My code can get this information from that string:
[*]How many Characters are in the string
[*]Where the current input is in the string ( the blinking bar when you type 's location in the string)
My code for this already
text is the string we want to get the size of
input_suggestion_text is a different string, if we can figure out the size of the Text string we dont need to worry about this one
Currently im using string width but that is only returning the amount of characters not the exact size in pixels we need
we add 30 to that to get a nice buffer, then times it by the width of "A" ,
which works for small strings but as the string gets longer the background box breaks and becomes to long for its needed use
Any help is appreciated, Thanks
The text that is drawn does not use a font resource so by default GameMaker uses the Arial font to draw it on the screen.
The issue is: How do I get the the exact Hight and width of my string at all times so that I can change the size of the background box?
for an example lets use the sentence:
" The Quick Brown Fox Jumped Over The Lazy Dog "
My code can get this information from that string:
[*]How many Characters are in the string
[*]Where the current input is in the string ( the blinking bar when you type 's location in the string)
My code for this already
GML:
//DRAW BACKGROUND BOX
draw_set_alpha(0.65);
var background_width = 500;
//AUTO RESIZE BACKGROUND WITH TEXT LENGTH
if (string_width(text) > 500)
{
var background_width = string_width(text)+30*string_width("A");
}
if (string_width(input_suggestion_text) > 500)
{
var background_width = string_width(input_suggestion_text)+30*string_width("A");
}
//DEFAULT SIZE
if (input_suggestion_text == "")
{
draw_rectangle(x-10,y-10,x+background_width,y+30,false);
}else{
//SIZE FOR AUTO TAB COMPLETE TEXT
draw_rectangle(x-10,y-10,x+background_width,y+50,false);
}
draw_set_alpha(1);
input_suggestion_text is a different string, if we can figure out the size of the Text string we dont need to worry about this one
Currently im using string width but that is only returning the amount of characters not the exact size in pixels we need
we add 30 to that to get a nice buffer, then times it by the width of "A" ,
which works for small strings but as the string gets longer the background box breaks and becomes to long for its needed use
Any help is appreciated, Thanks