<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>vline, etc.</title>
		<link>http://www.allegro.cc/forums/view/589764</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 30 Jan 2007 04:52:34 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yet another text-related question!  I&#39;m trying to create a caret and position it on the screen for input, but vline only has one x position.  I tried different ones (like &quot;line(BITMAP *bmp, int x1, int y1, int x2, int y2, int color);&quot; but all this does is make the program crash for some reason (probably because I don&#39;t know what I&#39;m doing. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />)</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> cTextField::set_text_stats<span class="k2">(</span><span class="k1">int</span> xl1, <span class="k1">int</span> yl1, <span class="k1">int</span> xl2, <span class="k1">int</span> yl2, <span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">int</span> l<span class="k2">)</span>
<span class="k2">{</span>
    x1_line <span class="k3">=</span> xl1<span class="k2">;</span>
    y1_line <span class="k3">=</span> yl1<span class="k2">;</span>
    x2_line <span class="k3">=</span> xl2<span class="k2">;</span>
    y2_line <span class="k3">=</span> yl2<span class="k2">;</span>
    x_text <span class="k3">=</span> x<span class="k2">;</span>
    y_text <span class="k3">=</span> y<span class="k2">;</span>
    l_text <span class="k3">=</span> l<span class="k2">;</span>
<span class="k2">}</span>

<a href="http://www.allegro.cc/manual/line" target="_blank"><span class="a">line</span></a><span class="k2">(</span>buffer, caret <span class="k3">*</span>x1_line, y1_line, x2_line, y2_line, WHITE<span class="k2">)</span><span class="k2">;</span>

<a href="http://www.allegro.cc/manual/textout_ex" target="_blank"><span class="a">textout_ex</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, edittext.c_str<span class="k2">(</span><span class="k2">)</span>, x_text, y_text, WHITE, <span class="k3">-</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

This function is suppose to allow me to position both the text and the caret, and also change the length of the caret and how far ahead it should be placed when inputting.</p><p>(Link to the text input code I&#39;m using) <a href="http://www.gamedev.net/reference/articles/article2130.asp">http://www.gamedev.net/reference/articles/article2130.asp</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (julian_boolean)</author>
		<pubDate>Sun, 28 Jan 2007 05:29:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Umm... what&#39;s with the function? Why not just use xl1 etc. directly? And what are you using for those values?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
but vline only has one x position.
</p></div></div><p><img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kauhiz)</author>
		<pubDate>Sun, 28 Jan 2007 05:56:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>8, 8, 8, 18, 0, 10, 0</p><p>The function is suppose to set the height of the caret, set where it should be placed when you insert a character, set the x coordinate for it, set the x and y coordinates of the text itself, and the max length of the text (which I havn&#39;t got around to doing.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (julian_boolean)</author>
		<pubDate>Sun, 28 Jan 2007 06:16:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
vline only has one x position.
</p></div></div><p>
It&#39;s a vertical line. What other x position would you want to specifiy for it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 28 Jan 2007 06:20:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well in 23yrold3yrold&#39;s code hes using the x value for inputting text. If I wanted to move the caret horizontally (to make it start at a specific x position) and keep the same value when inputting (8) then I&#39;d need a second x.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (julian_boolean)</author>
		<pubDate>Sun, 28 Jan 2007 06:30:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Your question is not at all text-related. Drawing a caret has nothing to do with text, and if your call to line() crashes, my guess would be you a) try to draw to a bitmap that doesn&#39;t exist or b) draw outside a bitmap&#39;s area while clipping is switched off or c) dereference invalid pointer in the process of passing arguments to line().<br />I think you are over-complicating the matter. As far as I can tell, what you are trying to do is display some text on screen, and a caret at the current edit position. The minimum variable set you&#39;d need for that would be:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">unsigned</span> caret_pos<span class="k2">;</span> <span class="c">// the character index into the string the caret is at</span>
<span class="k1">int</span> txt_x<span class="k2">;</span>
<span class="k1">int</span> txt_y<span class="k2">;</span>
std::string txt<span class="k2">;</span>
</pre></div></div><p>
You might want to throw in an extra caret_height int.<br />Then your drawing code might look something like this:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/textout_ex" target="_blank"><span class="a">textout_ex</span></a><span class="k2">(</span>backbuffer, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, txt.c_str<span class="k2">(</span><span class="k2">)</span>, txt_x, txt_y, WHITE, <span class="k3">-</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// please make sure WHITE is defined as something meaningful!</span>
<a href="http://www.allegro.cc/manual/vline" target="_blank"><span class="a">vline</span></a><span class="k2">(</span>backbuffer, txt_x <span class="k3">+</span> <a href="http://www.allegro.cc/manual/text_length" target="_blank"><span class="a">text_length</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, txt.substr<span class="k2">(</span><span class="n">0</span>, caret_pos<span class="k2">)</span><span class="k2">)</span>, txt_y, txt_y <span class="k3">+</span> caret_height, WHITE<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
That&#39;s pretty much it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Sun, 28 Jan 2007 06:59:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Got an error compiling that said: cannot convert `std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&#39; to `const char*&#39; for argument `2&#39; to `int text_length(const FONT*, const char*)&#39;</p><p>Not really sure what it means..  Too tired to think straight. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (julian_boolean)</author>
		<pubDate>Sun, 28 Jan 2007 08:44:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What are you using as <tt>caret_pos</tt>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kauhiz)</author>
		<pubDate>Sun, 28 Jan 2007 17:21:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Got an error compiling that said: cannot convert `std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&#39; to `const char*&#39; for argument `2&#39; to `int text_length(const FONT*, const char*)&#39;</p><p>Not really sure what it means.. Too tired to think straight. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div></div><p>
The text_length() function expects a const char* as its second argument but you are giving it a std::string instead, use:
</p><div class="source-code snippet"><div class="inner"><pre>std::string txt<span class="k2">;</span>
<span class="c">// ...</span>
<a href="http://www.allegro.cc/manual/text_length" target="_blank"><span class="a">text_length</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, txt.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Hano Wair)</author>
		<pubDate>Sun, 28 Jan 2007 19:19:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Figured it out <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> .. Not sure what you guys were trying to tell me, but thanks anywho. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Here&#39;s what I got:</p><p>vline(buffer, textx + caret *8, texty - 2, texty + 8, WHITE);</p><p>Now I just need to the max text length and I should be all set!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (julian_boolean)</author>
		<pubDate>Sun, 28 Jan 2007 21:11:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
textx + caret *8
</p></div></div><p>
What if I go wild and change the font? <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> Just use text_length...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Tue, 30 Jan 2007 02:57:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know how to change the font anyway (as much as I&#39;d like to) and besides I tried to do the text_length thing and it didn&#39;t work for me. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (julian_boolean)</author>
		<pubDate>Tue, 30 Jan 2007 03:49:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I don&#39;t know how to change the font anyway (as much as I&#39;d like to)
</p></div></div><p>
What did you think the FONT* parameter to textout and textprintf() was supposed tobe used for? <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 30 Jan 2007 04:18:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
besides I tried to do the text_length thing and it didn&#39;t work for me
</p></div></div><p>
See the above post. Allegro is a C library, so it expects a C-style string. Thus the .c_str()...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Tue, 30 Jan 2007 04:52:34 +0000</pubDate>
	</item>
</rss>
