1 registered members (Ayumi),
662
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
str_width improvements
#241666
12/18/08 01:12
12/18/08 01:12
|
Joined: Mar 2002
Posts: 1,774 Magdeburg
FlorianP
OP
Serious User
|
OP
Serious User
Joined: Mar 2002
Posts: 1,774
Magdeburg
|
It would be really helpful to have the following functions in addition to str_width
foo(string, font, len) Gives the width of the first [len] chars of string
and
foo(string, font, width) Gives the number of chars that fit in [width] pixels
I know that this can be done quite easy with str_width but i think an intern solution would be much faster
I <3 LINQ
|
|
|
Re: str_width improvements
[Re: FlorianP]
#241720
12/18/08 12:22
12/18/08 12:22
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
int str_widthpart( STRING* str, FONT* font, int len ) {
STRING* temp="";
str_cpy(temp, str);
str_trunc( temp, str_len(str) - len );
return str_width( temp, font );
}
int str_fit( STRING* str, FONT* font, int width ) {
STRING* temp="";
str_cpy(temp, str);
var length=str_width(st, font);
while( length > width && str_len( temp ) > 0) {
str_trunc (temp, 1);
length = str_width( temp, font );
}
return str_len( temp );
}
I don't have the option to use str_width, so I can't test. But that should work.
Last edited by Joozey; 12/18/08 12:23.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: str_width improvements
[Re: Joozey]
#241735
12/18/08 13:50
12/18/08 13:50
|
Joined: Mar 2002
Posts: 1,774 Magdeburg
FlorianP
OP
Serious User
|
OP
Serious User
Joined: Mar 2002
Posts: 1,774
Magdeburg
|
Thats not the point. These functions are terribly slow and both should need less calculations than one str_width command - So it is like going from NY to LA with a stop in Moscow
I <3 LINQ
|
|
|
Re: str_width improvements
[Re: jcl]
#241781
12/18/08 20:26
12/18/08 20:26
|
Joined: Mar 2002
Posts: 1,774 Magdeburg
FlorianP
OP
Serious User
|
OP
Serious User
Joined: Mar 2002
Posts: 1,774
Magdeburg
|
The way i think str_width works (simplified):
function str_width(string, font) { while (i < str_len(string) ) { width += Char_Size[ string[i] ] //Adding the width of each char of the string i++ } return width }
so an internal solution could do the following
Give the number of chars that fit in [max_width]: function str_widthanything (string, font, max_width) { while (width < max_width && i < str_len(string) ) { width += Char_Size[ string[i] ] //Adding the width of each char of the string i++ } return i - 1 }
Adds the sizes of the first [char_num] chars: function str_widthanything (string, font, char_num) { while ( i < char_num ) { width += Char_Size[ string[i] ] //Adding the width of each char of the string i++ } return width }
So, if str_width works this way - don't u think it would be senseless calling str_width that many times instead of adding two modified versions of it? Tell me if im wrong...
Last edited by FlorianP; 12/18/08 20:28.
I <3 LINQ
|
|
|
Re: str_width improvements
[Re: Joozey]
#241790
12/18/08 21:37
12/18/08 21:37
|
Joined: Mar 2002
Posts: 1,774 Magdeburg
FlorianP
OP
Serious User
|
OP
Serious User
Joined: Mar 2002
Posts: 1,774
Magdeburg
|
What you can do to maximize speed; Store the width's of all the characters (e.g. via their ascii value) once at game start, and read the values out when nessecary. Of course - i can also write my own engine. I just thought it to be a useful feature and didnt ask for workarounds. Please dont get me wrong, i appreciate that you want to help me, but it was just a suggestion to 'improve' a7
I <3 LINQ
|
|
|
|