<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Text Wrapping in Allegro</title>
		<link>http://www.allegro.cc/forums/view/581296</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 27 Apr 2006 23:21:28 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there anything in the allegro libraries the allows text to be drawn within a specified box? I just spent three weeks developing my own class that uses strings to draw, but I would like to know if there was an easier way.:&#39;(  <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cadatoiva)</author>
		<pubDate>Mon, 24 Apr 2006 21:14:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Is there anything in the allegro libraries the allows text to be drawn within a specified box?
</p></div></div><p>
Yes. Take a look at these:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/text_length" target="_blank"><span class="a">text_length</span></a><span class="k2">(</span><span class="k2">)</span>
<a href="http://www.allegro.cc/manual/text_height" target="_blank"><span class="a">text_height</span></a><span class="k2">(</span><span class="k2">)</span>
textout<span class="k2">(</span><span class="k2">)</span>
textprintf<span class="k2">(</span><span class="k2">)</span>
</pre></div></div><p>
There are more functions like that, for working with strings, copying, splitting, finding delimiters, etc. All in the manual...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Mon, 24 Apr 2006 21:18:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But is there something like<br />textout_rect(BITMAP *, FONT *, const char *, int x, int y, int width, int height, color)?</p><p>That is what I am looking for.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cadatoiva)</author>
		<pubDate>Mon, 24 Apr 2006 22:21:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not until your write it. You might find it if you search the forums though. This has probably been asked a few times before.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Mon, 24 Apr 2006 22:24:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can achieve the same effect by adjusting the clipping rectangle of the bitmap or by using a subbitmap.<br />Depending on how you want to use it, one or the other might be more appropriate. If you&#39;re writing text to the same area of the bitmap regularly, a subbitmap will be better (create it once and reuse it). If it&#39;s just once, then adjusting the clipping rectangle is a little cleaner.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 24 Apr 2006 22:27:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Adjusting the clipping rectangle turns word wrapping on in Allegro? Wow, I didn&#39;t know that!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Mon, 24 Apr 2006 22:29:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, but it keeps the text from flowing out of the specified region.<br />Reading the original post (`allows text to be drawn within a specified box&#39;), I assumed that was what he meant, but taking another look at the topic, I was probably wrong.</p><p>One way to do it, using only plain Allegro functions, is by using the d_text_proc function. This can be a bit messy and hackish, but it can be done.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 24 Apr 2006 22:33:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This <i>might</i> work...
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> draw_wrapping_text<span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp, <a href="http://www.allegro.cc/manual/FONT" target="_blank"><span class="a">FONT</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>str, <span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">int</span> w, <span class="k1">int</span> h, <span class="k1">int</span> color<span class="k2">)</span>
<span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/DIALOG" target="_blank"><span class="a">DIALOG</span></a> d <span class="k3">=</span> <span class="k2">{</span> <a href="http://www.allegro.cc/manual/d_text_proc" target="_blank"><span class="a">d_text_proc</span></a>, x, y, w, h, color, <span class="n">0</span><span class="c">/*unused?*/</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="k2">(</span><span class="k1">void</span><span class="k3">*</span><span class="k2">)</span>str, <span class="k2">(</span><span class="k1">void</span><span class="k3">*</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, NULL <span class="k2">}</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>old_bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/gui_get_screen" target="_blank"><span class="a">gui_get_screen</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>

   <a href="http://www.allegro.cc/manual/gui_set_screen" target="_blank"><span class="a">gui_set_screen</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
   d.proc<span class="k2">(</span>MSG_START, <span class="k3">&amp;</span>d, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
   d.proc<span class="k2">(</span>MSG_DRAW, <span class="k3">&amp;</span>d, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
   d.proc<span class="k2">(</span>MSG_END, <span class="k3">&amp;</span>d, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/gui_set_screen" target="_blank"><span class="a">gui_set_screen</span></a><span class="k2">(</span>old_bmp<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Mon, 24 Apr 2006 23:53:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In addition to the functions that Miran pointed out, you would need a function for finding the length of each character. Unfortunately, the only way you can do this in the Allegro public API is by converting each character into a string (copying it to a buffer that is followed by a terminating \0) and using text_length() on the string. However, the internal API has a char_length() method for the font, which will come in useful as we need to measure each character. To make use if it, add the line <tt>#include &lt;allegro/internal/aintern.h&gt;</tt> to the file where the multiline text-out code is stored.</p><p>It just so happens that I&#39;ve written some code to do just that, so I thought I&#39;d share it (see attatchment). The code can handle unicode characters (although this is currently untested).<br />[EDIT]The code can also handle newline characters, and prints the wrapped lines justified.[/EDIT]</p><p>Use the function <tt>aeGetNumTextLinesWithLengthLimit()</tt> to get the number of lines that the rendered text will take up, and <tt>aeTextoutMultiline()</tt> to actually render the text. The code is well commented (it even uses Doxygen-style comments so it can automatically generate docs if passed through Doxygen).</p><p>There are still a few things I could do to improve the code. Currently, the code uses a static buffer for the output of each line. This is determined by AEMULTILINEBUFSIZE (currently 512). Also, the code does not do tabs or hyphens, and the helper-function <tt>aeAdvanceToStartOfCurrentLineandGetNextLine()</tt> could be split into two separate functions.</p><p>Anyway, let me know if this is what you&#39;re after.</p><p>AE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrei Ellman)</author>
		<pubDate>Tue, 25 Apr 2006 00:52:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Easiest way: Download OpenLayer and turn on word wrapping. It even allows for several text alignments, like centered or justified text. Also line breaks inside text are supported.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Tue, 25 Apr 2006 00:53:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Fladimir da Gorf said:</div><div class="quote"><p>

Also line breaks inside text are supported.
</p></div></div><p>
See edit to my previous post.</p><p>AE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrei Ellman)</author>
		<pubDate>Tue, 25 Apr 2006 01:25:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">tfm said:</div><div class="quote"><p>
int d_textbox_proc(int msg, DIALOG *d, int c);</p><p>A text box object. The dp field points to the text which is to be displayed in the box. If the text is long, there will be a vertical scrollbar on the right hand side of the object which can be used to scroll through the text. The default is to print the text with word wrapping, but if the D_SELECTED flag is set, the text will be printed with character wrapping. The d1 field is used internally to store the number of lines of text, and d2 is used to store how far it has scrolled through the text.
</p></div></div><p>

I would use this one. I would create my text box function, which would create a simple Allegro dialog with only one item, d_my_textbox_proc(), which would call d_textbox_proc() with the proper parameters and then return D_CLOSE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Tue, 25 Apr 2006 01:50:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
aeAdvanceToStartOfCurrentLineandGetNextLine
</p></div></div><p>
<img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> I guess your IDE has auto-complete...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Tue, 25 Apr 2006 02:29:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried the auto-complete thing on all my projects, but it didn&#39;t work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Tue, 25 Apr 2006 02:38:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
One way to do it, using only plain Allegro functions, is by using the d_text_proc function. This can be a bit messy and hackish, but it can be done.
</p></div></div><p>
Yeah I&#39;ve done this before.  You have to use an internal function that d_text_proc uses and hack it a bit and then you can kind of use it to do it.  Its all very messy and hacky though, probably only a little bit harder and way cleaner to just write your own word wrapping method.  I have one laying around somewhere, maybe I&#39;ll come back and paste it sometime if I can find the thing.</p><p>[edit]<br />Ok, heres some code i just ripped from a really really old project.  You know what the variables are as well as I do...
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>        <span class="k1">int</span> y_i <span class="k3">=</span> <span class="k2">(</span>state <span class="k3">&amp;</span> inputing<span class="k2">)</span> ? <span class="n">2</span> <span class="k2">:</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">2</td><td>                <span class="c">// Start above line of input</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td>        <span class="k2">{</span></td></tr><tr><td class="number">5</td><td>                std::list<span class="k3">&lt;</span>string&gt;::const_reverse_iterator itr <span class="k3">=</span> text.rbegin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td>                <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> scroll <span class="k3">&amp;</span><span class="k3">&amp;</span> itr <span class="k3">!</span><span class="k3">=</span> text.rend<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">8</td><td>                        itr<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td>                <span class="k1">for</span><span class="k2">(</span><span class="k2">;</span> itr <span class="k3">!</span><span class="k3">=</span> text.rend<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>itr, <span class="k3">+</span><span class="k3">+</span>y_i<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">11</td><td>                        <span class="k1">if</span><span class="k2">(</span><span class="k2">(</span>y <span class="k3">+</span> h<span class="k2">)</span> <span class="k3">-</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/text_height" target="_blank"><span class="a">text_height</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a><span class="k2">)</span> <span class="k3">+</span> vert_spacing<span class="k2">)</span> <span class="k3">*</span> y_i <span class="k3">&lt;</span> y <span class="k3">+</span> horz_spacing<span class="k2">)</span></td></tr><tr><td class="number">12</td><td>                                <span class="k1">break</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>                        text_mode<span class="k2">(</span><span class="k3">-</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>                        textout<span class="k2">(</span>dest, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>,</td></tr><tr><td class="number">16</td><td>                                itr-&gt;c_str<span class="k2">(</span><span class="k2">)</span>,</td></tr><tr><td class="number">17</td><td>                                x <span class="k3">+</span> horz_spacing,</td></tr><tr><td class="number">18</td><td>                                <span class="k2">(</span>y <span class="k3">+</span> h<span class="k2">)</span> <span class="k3">-</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/text_height" target="_blank"><span class="a">text_height</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a><span class="k2">)</span> <span class="k3">+</span> vert_spacing<span class="k2">)</span> <span class="k3">*</span> y_i,</td></tr><tr><td class="number">19</td><td>                                <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">0xff</span>, <span class="n">0xff</span>, <span class="n">0xff</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>                <span class="k2">}</span></td></tr><tr><td class="number">21</td><td>        <span class="k2">}</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Tue, 25 Apr 2006 10:40:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My idea wouldn&#39;t be very ugly hacking. Inside this function:
</p><div class="source-code snippet"><div class="inner"><pre>textout_rect<span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp, <a href="http://www.allegro.cc/manual/FONT" target="_blank"><span class="a">FONT</span></a> <span class="k3">*</span>fnt, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>str, <span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">int</span> width, <span class="k1">int</span> height, color<span class="k2">)</span>
</pre></div></div><p>

...I&#39;d create a DIALOG,
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/DIALOG" target="_blank"><span class="a">DIALOG</span></a> <span class="k3">*</span>dlg<span class="k2">[</span><span class="k2">]</span> <span class="k3">=</span>
<span class="k2">{</span>
  <span class="k2">{</span> d_mytextbox_proc, x, y, width, height, color, bgcolor, <span class="k3">-</span><span class="n">1</span>, D_EXIT, <span class="n">0</span>, <span class="n">0</span>, str, NULL, NULL <span class="k2">}</span>,
  <span class="k2">{</span> NULL, <span class="n">0</span>, <span class="c">// etc</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>
...then I&#39;d run it. d_mytextbox_proc would do the following:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> d_mytextbox_proc<span class="k2">(</span><span class="k1">int</span> msg, <a href="http://www.allegro.cc/manual/DIALOG" target="_blank"><span class="a">DIALOG</span></a> <span class="k3">*</span>d, <span class="k1">int</span> c<span class="k2">)</span>
<span class="k2">{</span>
   <span class="k1">int</span> hlp<span class="k2">;</span>
   hlp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/d_textbox_proc" target="_blank"><span class="a">d_textbox_proc</span></a><span class="k2">(</span>msg, d, c<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">if</span> <span class="k2">(</span>msg <span class="k3">=</span><span class="k3">=</span> MSG_DRAW <span class="k3">&amp;</span><span class="k3">&amp;</span> hlp <span class="k3">=</span><span class="k3">=</span> D_O_K<span class="k2">)</span>
        <span class="k1">return</span> D_CLOSE<span class="k2">;</span>
   <span class="k1">return</span> hlp<span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
That is, it should in all aspects behave like d_textbox_proc, but as soon as it has been drawn, it closes the dialog, leaving the drawn textbox on the screen. I haven&#39;t tested that, but the idea should work. You get your text box sith word wrapped text. You need the background colour parameter, too. If your text doesn&#39;t fit in the given box size, you get automatic scrollbars, but you can&#39;t use them. If you want usable scrollbars, you simply have to do the whole thing as a dialog.</p><p>What I don&#39;t have there is a way to draw to bmp instead of screen, which is the Allegro dialog system&#39;s standard output. I haven&#39;t tested it but I guess one could start with:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>restore_bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a> <span class="k3">=</span> bmp<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/FONT" target="_blank"><span class="a">FONT</span></a> <span class="k3">*</span>restore_fnt <span class="k3">=</span> <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a> <span class="k3">=</span> fnt<span class="k2">;</span>

<span class="c">// Do the stuff</span>

<a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a> <span class="k3">=</span> restore_bmp<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a> <span class="k3">=</span> restore_fnt<span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Tue, 25 Apr 2006 16:53:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What I don&#39;t have there is a way to draw to bmp instead of screen, which is the Allegro dialog system&#39;s standard output. I haven&#39;t tested it but I guess one could start with:
</p></div></div><p>
Yeach.<br />That&#39;s what gui_set_screen() and gui_get_screen() were created for. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 25 Apr 2006 20:59:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
My idea wouldn&#39;t be very ugly hacking. Inside this function:<br /> <br />...I&#39;d create a DIALOG,</p><p>...then I&#39;d run it.
</p></div></div><p>
Which is basically what my function does, just a lot cleaner and more straight-forward. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> Create a single dialog object (no need for a two-object array), send it MSG_START to init itself, then MSG_DRAW to draw itself using its given parameters, then MSG_END to deinit itself. Then the function returns.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Tue, 25 Apr 2006 21:44:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;ll proably want to be able to scroll the box up and down.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Tue, 25 Apr 2006 22:17:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you&#39;re not using Allegro&#39;s GUI for anything else than drawing wrapped text, then doing so will bloat your program. Use my solution instead, and keep your EXEs small.</p><p>AE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrei Ellman)</author>
		<pubDate>Tue, 25 Apr 2006 22:54:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What I did to accomplish this was to create a class that understood simple markups.</p><p>The way it worked was you passed the class your modifiers:<br />  Suggested max width, Suggested max height. Base Font. Color.</p><p>Then, you could pass it your display string, with markups, and it would return you a transparent BITMAP with your text.</p><p>I think that is your best solution. I coded for center, left, right, bold, underline, and italic markups.  </p><p>For the bold/underline/italic markups, you will need to create a &quot;Smart&quot; Font library that can correctly upgrade your base font to the appropriate style based on the markups.</p><p>Good luck!</p><p>Mae
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mae Mutts)</author>
		<pubDate>Tue, 25 Apr 2006 23:10:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>All of your ideas really helped. My Text Wrapping functions weren&#39;t as good as I thought they were. I think that Andrei&#39;s idea was best and will use it. But I have one question, how does nMaxLength (width of each line?) and npMaxLineLength(number of lines to draw?) work?;D
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cadatoiva)</author>
		<pubDate>Thu, 27 Apr 2006 03:11:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><tt>nMaxLength</tt> is the maximum length you are permitting your line to be (although this will be exceded if one line consists of only one character who&#39;se width is greater than <tt>nMaxLength</tt>).</p><p><tt>npMaxLineLength</tt> is a running count of the longest length we have so far. This is useful so we can find out the actual length of the longest line that will be printed. Often, this is shorter than <tt>nMaxLength</tt>, so we may want to shrink the horizontal size of the text-area to take this into account. aeGetNumTextLinesWithLengthLimit() and aeTextoutMultiline() both update the value pointed to by the <tt>npMaxLineLength</tt> paramater (although in practice, you will usually end up passing in NULL to <tt>aeTextoutMultiline()</tt>). Note that <tt>npMaxLineLength</tt> is optional, and you can pass in NULL if you don&#39;t want to print your text as compactly as possible.</p><p>Below is an example of the usage of the code.</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>&#160;</td></tr><tr><td class="number">2</td><td><span class="k1">char</span> <span class="k3">*</span>szText1 <span class="k3">=</span> <span class="s">"A short line"</span>.</td></tr><tr><td class="number">3</td><td><span class="k1">char</span> <span class="k3">*</span>szText2 <span class="k3">=</span> <span class="s">"Testing...\nThis is an example of some text that we want to be able to print accross multiple lines. It is a long line of text so it is almost certainly going to be broken up."</span></td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td><span class="k1">unsigned</span> <span class="k1">int</span> nNumLines1, nNumLines2<span class="k2">;</span> <span class="c">/* Number of lines each string will take up when it will be printed */</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td><span class="k1">unsigned</span> <span class="k1">int</span> nMaxLength <span class="k3">=</span> SCREEN_W-150<span class="k2">;</span> <span class="c">/* The maximum length (in pixels) we are letting our lines of text be */</span></td></tr><tr><td class="number">8</td><td><span class="k1">unsigned</span> <span class="k1">int</span> nMaxLineLength <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> <span class="c">/* A running count of the longest line we have so far. Start off at 0. We could start off at some higher value if we want a minimum text-area width */</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td>nNumLines1 <span class="k3">=</span> aeGetNumTextLinesWithLengthLimit<span class="k2">(</span>szText1, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, nMaxLength, <span class="k3">&amp;</span>nMaxLineLength<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td><span class="c">/* nMaxLineLength is now the length of the longest line in szText1 */</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>nNumLines2 aeGetNumTextLinesWithLengthLimit<span class="k2">(</span>szText2, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, nMaxLength, <span class="k3">&amp;</span>nMaxLineLength<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td><span class="c">/* nMaxLineLength is now the length of the longest line in both szText1 and szText2 */</span></td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td><span class="c">/* We have now calculated the longest line length, so in order to print our text as compactly as possible, we are using nMaxLineLength as the right-most boundry instead of nMaxLength. We could of course pass in nMaxLength instead if we want the text to fit nicely in the original text-area */</span></td></tr><tr><td class="number">18</td><td><span class="c">/* We are no longer interested in finding the maximum line-length (we already have it), so pass in NULL to npMaxLineLength */</span></td></tr><tr><td class="number">19</td><td>aeTextoutMultiline<span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, szText1, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="n">20</span>, <span class="n">10</span>, <span class="n">1</span>, <span class="k3">-</span><span class="n">1</span>, nMaxLineLength, NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>aeTextoutMultiline<span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, szText2, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="n">20</span>, <span class="n">10</span><span class="k3">+</span>nNumLines1<span class="k3">*</span><a href="http://www.allegro.cc/manual/text_height" target="_blank"><span class="a">text_height</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a><span class="k2">)</span>, <span class="n">2</span>, <span class="k3">-</span><span class="n">1</span>, nMaxLineLength, NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td><span class="c">/* And finally, draw a rectangle around our text */</span></td></tr><tr><td class="number">23</td><td><a href="http://www.allegro.cc/manual/rect" target="_blank"><span class="a">rect</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">10</span><span class="k3">-</span><span class="n">2</span>, <span class="n">10</span><span class="k3">-</span><span class="n">2</span>, <span class="n">10</span><span class="k3">+</span>nMaxLineLength<span class="k3">+</span><span class="n">2</span>, <span class="n">10</span><span class="k3">+</span><span class="k2">(</span>nNumLines1<span class="k3">+</span>nNumLines2<span class="k2">)</span><span class="k3">*</span><a href="http://www.allegro.cc/manual/text_height" target="_blank"><span class="a">text_height</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a><span class="k2">)</span><span class="k3">+</span><span class="n">2</span>, <span class="n">3</span><span class="k2">)</span><span class="k2">;</span></td></tr></tbody></table></div></div><p>
<i>note: this code is untested</i></p><p>The two strings will be printed. Both strings will have the same right-most border when they are justified. If the longest line-length is shorter than the maximum line-length, then the right-most border will be moved to the left to make the string more compact.</p><p>AE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrei Ellman)</author>
		<pubDate>Thu, 27 Apr 2006 20:33:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Below is an example of the usage of the code.
</p></div></div><p>
<img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>What about just implementing a print( font, text, width, alignment ) -function?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Thu, 27 Apr 2006 22:34:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What about just implementing a print( font, text, width, alignment ) -function?
</p></div></div><p>
You can do that with <span class="source-code">aeTextoutMultiline<span class="k2">(</span>bitmapdest, text, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, x, y, fgcol, bgcol, width, NULL<span class="k2">)</span><span class="k2">;</span></span> The only reason why you need all the rest of the code in my example is if you want to find out how long the longest line is going to be and adjust the right-boundry accordingly. My code lacs the ability to set the alignment (the text always justified, except for the last line before each newline or \0 which are left-aligned).</p><p>AE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrei Ellman)</author>
		<pubDate>Thu, 27 Apr 2006 23:21:28 +0000</pubDate>
	</item>
</rss>
