Simple way to calculate pixel width of a string?

BlitzMax Forums/BlitzMax Beginners Area/Simple way to calculate pixel width of a string?

Apollonius(Posted 2007) [#1]
I'm trying to calculate the width of a string with default font. I was thinking of assigning a width value for each characters but I have a question:

How to calculate how many of a character you have in a string? Like how many "e" or what not.

I tried doing this:
Local length:Int = Len text:string
width = length*9

hmm or maybe there's an easier way?


TomToad(Posted 2007) [#2]
Width = TextWidth(text)


xlsior(Posted 2007) [#3]
Width = TextWidth(text)


Do note that this does not take any scale into consideration, so if you've done a setscale 2,2 then you'll also need to multiply the result of TextWidth with that '2' to get the true width if you were to draw it at that point.


Perturbatio(Posted 2007) [#4]
for scale: