git » fp-git.git » commit a1365f2

add some useful functions

author gazer
2005-01-17 00:06:49 UTC
committer gazer
2005-01-17 00:06:49 UTC
parent 8cd65ca028e5b79ce434fb9200420f9708e8e404

add some useful functions

FP/src/out/output.c +27 -3
stuff/modtools/font/test.c +1 -1

diff --git a/FP/src/out/output.c b/FP/src/out/output.c
index c5d00fd..5670b51 100644
--- a/FP/src/out/output.c
+++ b/FP/src/out/output.c
@@ -52,8 +52,8 @@ SDL_Surface *screen;
 
 typedef struct _valid_chars {
 	char is_valid; // Is character valid ?
-	int x;         // X pos in font image
-	int w;         // Width of letter
+	unsigned int x;         // X pos in font image
+	unsigned int w;         // Width of letter
 } vChar;
 
 vChar valid_chars[255];
@@ -70,7 +70,7 @@ void initText ()
 	int pos_x[92] = {0, 7, 14, 21, 28, 34, 40, 47, 54, 59, 66, 74, 80,
 		89, 96, 103, 110, 117, 124, 131, 138, 145, 152, 161, 168, 175, 184,
 		191, 198, 205, 212, 219, 225, 232, 239, 242, 247, 254, 257, 266, 
-		237, 280, 287, 294, 301, 308, 314, 321, 328, 337, 344, 351, 358,
+		273, 280, 287, 294, 301, 308, 314, 321, 328, 337, 344, 351, 358,
 		365, 372, 379, 387, 394, 401, 408, 415, 422, 429, 433, 438, 441,
 		444, 448, 452, 458, 464, 473, 482, 490, 493, 499, 507, 516, 525,
 		534, 539, 544, 549, 556, 563, 568, 573, 578, 582, 588, 593, 600};
@@ -94,6 +94,30 @@ void initText ()
 	font_init = 1;
 }
 
+/* Use vararg's too?? */
+unsigned int outputGetTextWidth (const char *txt)
+{
+	const char *s;
+	unsigned int l = 0;
+
+	s = txt;
+	while ((*s) != '\0') {
+		if (valid_chars[*s].is_valid) {
+			l += valid_chars[*s].w;
+		}
+		s++;
+	}
+
+	return l;
+}
+
+unsigned int outputGetTextHeight (const char *txt)
+{
+	if (!font) return 0;
+	
+	return font->h;
+}
+
 /* Text Primitives*/
 void outputDrawText(int x, int y, const char *fmt, ...)
 {
diff --git a/stuff/modtools/font/test.c b/stuff/modtools/font/test.c
index 29176aa..1971e8a 100644
--- a/stuff/modtools/font/test.c
+++ b/stuff/modtools/font/test.c
@@ -12,7 +12,7 @@ int main (int argc, char *argv[])
 	initText ();
 
 	outputInit ();
-	outputDrawText (10, 0, "Feliz Cumple %d, Gazer", 26);
+	outputDrawText (10, 0, "Texto \"Hola\" tiene %d pixels de largo", outputGetTextWidth("Hola"));
 	
 	outputDrawText (55, 20, "ABCD 123456 &/$#    000", 26);