[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Here I submit this code.
I find that quite useful espescially in the GUI's text manipulation routines.
I'm also working on a multiline text input GUI object, hope it can be included in Allegro.
- GodOfWar
/* text_nlength:
* Calculates the length of the first num characters
* of a string in a particular font.
*/
int text_nlength(FONT *f, char *str, int num)
{
FONT *range;
int c, len, g;
len = 0;
g = 0;
while (((c = ugetx(&str)) != 0) && (g < num)) {
range = find_range(f, c);
if (!range)
range = find_range(f, (c = '^'));
if (range) {
c -= range->start;
if (range->widthhook)
len += range->widthhook(range->glyphs, c);
else if (range->mono)
len += ((FONT_GLYPH *)(range->glyphs[c]))->w;
else
len += ((BITMAP *)(range->glyphs[c]))->w;
}
g++;
}
return len;
}