<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Does not draw</title>
		<link>http://www.allegro.cc/forums/view/587901</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 06 Oct 2006 11:24:28 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am trying to teach myself how to use objects.</p><p>I created a window with about 4 objects.</p><p>I want it to look something like this:
</p><pre>
+--------------------------------------+
|                                      |
| +----------------------------------+ |
| | MENU                             | |
| +----------------------------------+ |
|                                      |
| +-----------------------+ +--------+ |
| | MAIN                  | | SIDE   | |
| |                       | |        | |
| |                       | |        | |
| |                       | |        | |
| |                       | |        | |
| |                       | |        | |
| +-----------------------+ +--------+ |
|                                      |
| +----------------------------------+ |
| | STAT                             | |
| |                                  | |
| +----------------------------------+ |
|                                      |
+--------------------------------------+

</pre><p>

The problem I&#39;m getting is that it looks like the attachment (<i>image.png</i>), which isn&#39;t really what I want at all.</p><p>I&#39;m thinking that the <b>WindowObject.draw()</b> function in the <b>mapObjects.hpp</b> is where the problem is occurring, as it&#39;s the only thing that calls <b>blit()</b> (other than the <b>blit2screen()</b> function), but if anyone could take a look at my sources (I&#39;ve included them all) and let me know where I&#39;ve got the error...  <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Thanks!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeamTerradactyl)</author>
		<pubDate>Fri, 06 Oct 2006 08:33:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That is possible. Check this:</p><pre>
(gdb) n
330        blit(surface, double_buffer, 0, 0, x1, y1, objectWidth, objectHeight);
(gdb) p surface-&gt;x
There is no member named x.
(gdb) p surface-&gt;w
$23 = 27
(gdb) p surface-&gt;h
$24 = 390
(gdb) p objectWidth
$25 = 390
(gdb) p objectHeight
$26 = 27
(gdb)
</pre><p>

Note that the width and height of the surface are exactly the opposite from the object properties. The other mistake I found is that you are positioning the object within the surface, when it is the surface the one you should move. In example:</p><div class="source-code snippet"><div class="inner"><pre>   x1 <span class="k3">=</span> HORZ_BUFFER<span class="k2">;</span>          <span class="c">// 5</span>
   y1 <span class="k3">=</span> VERT_BUFFER<span class="k2">;</span>          <span class="c">// 5</span>
   x2 <span class="k3">=</span> SW <span class="k3">-</span> HORZ_BUFFER<span class="k2">;</span>     <span class="c">// 395</span>
   y2 <span class="k3">=</span> SH <span class="k3">/</span> <span class="n">8</span> <span class="k3">-</span> VERT_BUFFER<span class="k2">;</span> <span class="c">// 32</span>
   WindowObject MenuObject<span class="k2">(</span><span class="s">"Menu"</span>, x1, y1, x2, y2<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The WindowObject class will call calculate size:</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">void</span> WindowObject::calculateSize<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span></td></tr><tr><td class="number">2</td><td><span class="k2">{</span></td></tr><tr><td class="number">3</td><td>   objectHeight <span class="k3">=</span> y2 <span class="k3">-</span> y1<span class="k2">;</span></td></tr><tr><td class="number">4</td><td>   <span class="k1">if</span> <span class="k2">(</span>objectHeight <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">5</td><td>      objectHeight <span class="k3">=</span> <span class="k3">-</span>objectHeight<span class="k2">;</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td>   objectWidth <span class="k3">=</span> x2 <span class="k3">-</span> x1<span class="k2">;</span></td></tr><tr><td class="number">8</td><td>   <span class="k1">if</span> <span class="k2">(</span>objectWidth <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">9</td><td>      objectWidth <span class="k3">=</span> <span class="k3">-</span>objectWidth<span class="k2">;</span></td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td>   <span class="k1">if</span> <span class="k2">(</span>objectHeight <span class="k3">&gt;</span> <span class="n">0</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> objectWidth <span class="k3">&gt;</span> <span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">12</td><td>   <span class="k2">{</span></td></tr><tr><td class="number">13</td><td>      surface <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span>objectHeight, objectWidth<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>      clear<span class="k2">(</span>surface<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>   <span class="k2">}</span></td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

(Note that you twisted the height and width, the arguments should be width and then height). Here, you create a bitmap with a determine width and height. If you pass 5, 5, 10, 10, it will create a 5x5 bitmap. However, your draw method:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> WindowObject::draw<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/ASSERT" target="_blank"><span class="a">ASSERT</span></a> <span class="k2">(</span>surface <span class="k3">!</span><span class="k3">=</span> NULL<span class="k2">)</span><span class="k2">;</span>

   <a href="http://www.allegro.cc/manual/clear_to_color" target="_blank"><span class="a">clear_to_color</span></a><span class="k2">(</span>surface, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">0</span>,<span class="n">128</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/rectfill" target="_blank"><span class="a">rectfill</span></a><span class="k2">(</span>surface, x1, y1, x2, y2, bgcolor<span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/rectfill" target="_blank"><span class="a">rectfill</span></a><span class="k2">(</span>surface, x1 <span class="k3">+</span> <span class="n">5</span>, y1 <span class="k3">+</span> <span class="n">5</span>, x2 <span class="k3">-</span> <span class="n">5</span>, y2 <span class="k3">-</span> <span class="n">5</span>, fgcolor<span class="k2">)</span><span class="k2">;</span>
   print_sfont<span class="k2">(</span>x1 <span class="k3">+</span> <span class="n">3</span>, y1 <span class="k3">+</span> <span class="n">3</span>, name.c_str<span class="k2">(</span><span class="k2">)</span>, surface<span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>surface, double_buffer, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, surface-&gt;w, surface-&gt;h<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

will draw in the surface taking into account the offsets. So, mathematically:</p><ul><li><p> Create a bitmap with the coordenates (x1, y1) = (5, 5); (x2, y2) = (10, 10).</p></li><li><p> now rectfill a rectangle with coordenates (x1, y1) = (5, 5); (x2, y2) = (10, 10):</p></li></ul><p>

Where is the rectangle? Nowhere, because the rectangle begins at (5,5), and your surface has coordenates (0,4) only. So, you basically need to turn the height and width arguments when creating the bitmap, then changing your draw code to draw the rectfill always at (0, 0); (x2-x1, y2-y1), and then move the surface in the bitmap.</p><p>(Edited: In mapobjects.hpp, change the <i>create_bitmap</i> line to <i>surface = create_bitmap(objectWidth, objectHeight);</i>, and change your draw method to</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> WindowObject::draw<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/ASSERT" target="_blank"><span class="a">ASSERT</span></a> <span class="k2">(</span>surface <span class="k3">!</span><span class="k3">=</span> NULL<span class="k2">)</span><span class="k2">;</span>

   <a href="http://www.allegro.cc/manual/clear_to_color" target="_blank"><span class="a">clear_to_color</span></a><span class="k2">(</span>surface, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">0</span>,<span class="n">128</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/rectfill" target="_blank"><span class="a">rectfill</span></a><span class="k2">(</span>surface, <span class="n">0</span>, <span class="n">0</span>, x2-x1, y2-y1, bgcolor<span class="k2">)</span><span class="k2">;</span>
<span class="c">//   rectfill(surface, x1 + 5, y1 + 5, x2 - 5, y2 - 5, fgcolor);</span>
   print_sfont<span class="k2">(</span>x1 <span class="k3">+</span> <span class="n">3</span>, y1 <span class="k3">+</span> <span class="n">3</span>, name.c_str<span class="k2">(</span><span class="k2">)</span>, surface<span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>surface, double_buffer, <span class="n">0</span>, <span class="n">0</span>, x1, y1, objectWidth, objectHeight<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

That should do)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Fri, 06 Oct 2006 10:49:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you!</p><p>I love these allegro gurus; they&#39;re so sweet :-)!</p><p>That works beautifully.  I carried that one further and figured out why my bottom object (STAT) had disappeared, and why the names of the objects were all off-mark.  It looks great now; thanks so much.</p><p>Does this mean that my objects should not hold their own sizes and coordinates?  If I need to do any mouse detection, I would need 0..size instead of (x1,y1)..(x2,y2), correct?</p><p>I&#39;ll mull this over, but in the meantime, thank you again for the in-depth help!</p><p>-TeamTerradactyl
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeamTerradactyl)</author>
		<pubDate>Fri, 06 Oct 2006 11:24:28 +0000</pubDate>
	</item>
</rss>
