Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » textprintf_ex

This thread is locked; no one can reply to it. rss feed Print
textprintf_ex
Sylvarant
Member #7,886
October 2006

how do you divide an output in two lines using textprintf_ex.
I tried something like this :
textprintf_ex(window_bitmap,font,0,0,makecol(0,0,0),-1," testline 1 \n testline 2);
but that just gave me testline 1 ^ testline 2

miran
Member #2,407
June 2002

You call it twice with different y.

Btw, are you sure you want to be a programmer?

--
sig used to be here

LennyLen
Member #5,313
December 2004
avatar

Quote:

Btw, are you sure you want to be a programmer?

Ouch.

A multi-line text_printf function would be good though.

Sylvarant
Member #7,886
October 2006

Quote:

Btw, are you sure you want to be a programmer?

that hurt.
I'm only into programming for like a month, I can't help it I'm not always on top of things.

miran
Member #2,407
June 2002

Hehe, I'm only messing with you. :)

The point is, for programming you need a different way of thinking than for most other things in life. Otherwise you can bang your head against the desk for a whole day when the solution is really obvious... :)

--
sig used to be here

TeamTerradactyl
Member #7,733
September 2006
avatar

Adriaan Larmuseau said:

textprintf_ex(window_bitmap,font,0,0,makecol(0,0,0),-1," testline 1 \n testline 2");


As miran and LennyLen suggest, you will probably want to do something like this:

  textprintf_ex(window_bitmap,font,0,0,makecol(0,0,0),-1," testline 1");
  textprintf_ex(window_bitmap,font,0,12,makecol(0,0,0),-1," testline 2");

That would put what you want on separate lines. At this time, I'm not aware of multi-line textprintf_ex's.

-TeamTerradactyl

LennyLen
Member #5,313
December 2004
avatar

Quote:

As miran and LennyLen suggest, you will probably want to do something like this:

  textprintf_ex(window_bitmap,font,0,0,makecol(0,0,0),-1," testline 1");
  textprintf_ex(window_bitmap,font,0,12,makecol(0,0,0),-1," testline 2");

That would put what you want on separate lines. At this time, I'm not aware of multi-line textprintf_ex's.

Well, it was only Miran that suggested it. ;)

In any case, I'd probably change that code slightly to be more like this:

#define LINE_SPACING 3
...
textprintf_ex(window_bitmap,font,0,0,makecol(0,0,0),-1," testline 1");
textprintf_ex(window_bitmap,font,0,(text_height(font) + LINE_SPACING),makecol(0,0,0),-1," testline 1");


If you're not using the default font, then change it to text_height(insert_your_font_name_here).

TeamTerradactyl
Member #7,733
September 2006
avatar

Quote:

Well, it was only Miran that suggested it.


You were the first to suggest -- and I quote:

Quote:

A multi-line text_printf function would be good though.


So you basically deserve some of the credit. ;)

miran
Member #2,407
June 2002

You can easily make your own multiline textprintf function. Just use printf to print to a buffer, parse it with ustrtok with '\n' as the delimiter and use textprintf_ex to print individual lines, incrementing y at each step. If you also know how to use text_length, you can even implement different alignment methods, and if you want something extra, you can do wordwrapping as well. That last one is a little trickier though...

--
sig used to be here

Go to: