fit font into a circle

RizbIT

Member
Can the size of a font be dynamically or programaticaly be changed during runtime to fit a variable string into a set sized circle or square?
 
R

Red Phantom

Guest
AS FAR AS I KNOW, THE ANSWER TO YOUR QUESTION IS NO, HOWEVER

So I have textboxes in my game which are rectangular. (When it comes to solving this problem rectangular and square are the same, however a circle textbox is more difficult). I of course have text inside the textboxes.

Here is a script I made for creating a textbox in the centre of the current view in the room
Code:
textbox_height = 64 (refers to heigh of Text_box background resource)
textbox_top = view_yview - 8 + ((view_hview - textbox_height)/2)
textbox_width = 196 (refers to width of Text_box background resource)
textbox_left = view_xview + ((view_wview - textbox_width)/2)

draw_background(Text_box, textbox_left, textbox_top)
draw_set_font(fnt_standard)
draw_text_ext(textbox_left + 5, textbox_top + 3, argument0,-1,187)
/*
NOTE: TEXTBOXES ARE CENTRED HORIZONTALLY, BUT IN TERMS OF VERTICAL (Y) POSITION,
THEY ARE SLIGHTLY above the mid-y-position of the screen’s view.
Within the draw event of my text object I call the script with the given arguments:\
Code:
script_execute(scr_Draw_Text_and_Box, "The door is locked.")
SOLUTION 1
Create different fonts of different sizes, and to set the different fonts(with the different sizes) for each different variable string.
Using the
Code:
draw_set_font(argument0)
function you can set the font to different sizes so that it fits your textbox. You will have to start off with a font size that will cause the text to not fit in your square then keep setting the font smalller by 1 each time until you reached the biggest possible size to have your text for the particular variable string.
for instance argument0, the fonts should be named after the font size of the font: font_size_8 OR font_size_10 OR font_size_12
where font_size_8 refers to the font that is sized as 8 and so on...

SOLUTION 2
Use 1 font with 1 font size.
Fit as much of the text in the textbox as you can.
With the rest of the text that you could not fit, there will be a second identical textbox (but with different string) which is created upon the destruction of the previous textbox.
E.g. pressing down destroys text 1 and creates text 2 while maintaing the same textbox and font size.
Using as many text objects as you need to get through all of your string.
If you want to see the code for my text objects which I figured out how to run smoothly let me know and I will give you all the code you need.
 
Last edited by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
No, because font resources are pre-rendered as sprites, put on texture pages as graphics and then drawn from there.

You can scale drawn text, but this comes with the same downsides as scaling any other graphic.


What you can do is include a font as an included file, then dynamically add font resources of the desired font and size at run time. Note that this requires you to have permission to distribute the font with the game, which may not always be possible or expensive.
 
D

dannyjenn

Guest
I'm not sure I understand your question.

Are you asking whether it's possible to wrap the text to fit within the bounds of a circular-shaped text box? Or are you asking whether it's possible to scale the text such that it actually becomes circular (like WordArt)?

Both these things are possible, though it would require writing your own script (i.e. there's no built-in function that can do either of these sorts of things).
 

RizbIT

Member
oh so we can scale the font.... that would work thought yes im sure it would not look as good as real sized font
 
Top