[AD] Fwd: [PATCH] newline in drawing text ...

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]



----------  Forwarded Message  ----------

Subject: [PATCH] newline in drawing text ...
Date: Thu, 8 Jan 2004 10:19:35 +0100
From: Franjo Stipanovic <fr1c@xxxxxxxxxx>
To: alleg-developers@xxxxxxxxxx

Hello!
I've made patch which adds small, but nice feature ...
Ability to use '\n' in textout functions ...
All textout functions are supported except textout_justify_ex ... (which will
soon be done).

--
Franjo Stipanovic, Fritz
Security & Developing

-------------------------------------------------------



-- 
Franjo Stipanovic, Fritz
Security & Developing
diff -ur ../alleg-old/src/font.c src/font.c
--- ../alleg-old/src/font.c	Mon Jun 30 01:27:03 2003
+++ src/font.c	Thu Jan  8 09:58:23 2004
@@ -464,6 +464,8 @@
     ASSERT(f);
 
     while( (ch = ugetxc(&p)) ) {
+	if (ch == '\n')	
+		return w;
         w += f->vtable->char_length(f, ch);
     }
 
@@ -537,13 +539,19 @@
  */
 static void mono_render(AL_CONST FONT* f, AL_CONST char* text, int fg, int bg, BITMAP* bmp, int x, int y)
 {
-    int ch = 0;
+    int ch = 0, x_ = x, fh = 0;
     AL_CONST char* p = text;
 
     acquire_bitmap(bmp);
 
     while( (ch = ugetxc(&p)) ) {
-        x += f->vtable->render_char(f, ch, fg, bg, bmp, x, y);
+	if (ch == '\n') {
+		fh = font_height(f);
+		y += fh + 2;
+		x = x_;
+	}
+	else
+ 	       x += f->vtable->render_char(f, ch, fg, bg, bmp, x, y);
     }
 
     release_bitmap(bmp);
Only in src/i386: asmdef
diff -ur ../alleg-old/src/text.c src/text.c
--- ../alleg-old/src/text.c	Mon Jun 30 01:27:03 2003
+++ src/text.c	Thu Jan  8 09:57:26 2004
@@ -48,13 +48,26 @@
  */
 void textout_centre_ex(BITMAP *bmp, AL_CONST FONT *f, AL_CONST char *str, int x, int y, int color, int bg)
 {
-   int len;
+   int len, ch = 0, x_ = x;
    ASSERT(bmp);
    ASSERT(f);
    ASSERT(str);
 
    len = text_length(f, str);
-   f->vtable->render(f, str, color, bg, bmp, x - len/2, y);
+   /*
+    * f->vtable->render(f, str, color, bg, bmp, x - len/2, y);
+    */
+   while( (ch = ugetxc(&str)) ) {
+	   if (ch != '\n')
+		   x += f->vtable->render_char(f, ch, color, bg, bmp, x - len/2, y);
+	   else {
+		   x = x_;
+		   len = text_length(f, str);
+		   y += f->vtable->font_height(f) + 2;
+	   }
+		   
+   }
+    
 }
 
 
@@ -65,13 +78,24 @@
  */
 void textout_right_ex(BITMAP *bmp, AL_CONST FONT *f, AL_CONST char *str, int x, int y, int color, int bg)
 {
-   int len;
+   int len, ch = 0, x_ = x;
    ASSERT(bmp);
    ASSERT(f);
    ASSERT(str);
 
    len = text_length(f, str);
-   f->vtable->render(f, str, color, bg, bmp, x - len, y);
+   /*
+    * f->vtable->render(f, str, color, bg, bmp, x - len, y);
+    */
+   while( (ch = ugetxc(&str)) ) {
+	   if (ch != '\n')
+		   x += f->vtable->render_char(f, ch, color, bg, bmp, x - len, y);
+	   else {
+		   x = x_;
+		   len = text_length(f, str);
+		   y += f->vtable->font_height(f) + 2;
+	   }
+   }
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/