 |
DrawStrWidthP |
Function (ROM Call 0x3EE) |
Returns the width of the first len characters of a string.
DrawStrWidthP returns the length in pixels of the first len characters of the string str displayed with font Font.
The difference between DrawStrWidthP and DrawStrWidth is that DrawStrWidth gives the length in pixels of the full string str displayed with font Font.
Be careful: len must be less or equal to strlen (str)
!
This function is interesting only for the F_4x6
font; for the F_6x8 and
F_8x10 fonts, DrawStrWidthP will return
6*len and 8*len, respectively.
Also, it is faster to use DrawStrWidth than to use:
DrawStrWidthP (str, strlen (str), font);
Example:
// This line is equivalent to:
// printf_xy (0, 0, "%hu", DrawStrWidth ("DEFGHIJK", F_4x6));
printf_xy (0, 0, "%hu",
DrawStrWidthP ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + 3, 8, F_4x6));
On AMS versions lower than 2.00, you can emulate DrawStrWidthP with:
unsigned short DrawStrWidthP(const char *str, short len, short Font)
{
char s[len+1];
short i;
// Calling memcpy is slower than copying the string by-hand...
for (i = 0; i < len; i++)
s[i] = str[i];
s[len] = 0;
return DrawStrWidth (s, font);
}
This function is about 1% slower than the original implementation.
Uses: sf_width
Used by: Dialog, WinStrXYWrap
See also: DrawStrWidth