<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>A5 clipping</title>
		<link>http://www.allegro.cc/forums/view/606493</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 24 Feb 2011 16:51:22 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How do you turn off clipping for a bitmap?</p><p>I tried al_set_clipping_rectangle(0,0,0,0);</p><p>thinking it might do something similar to the old set_clip function but it simply results in nothing being drawn to.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Tue, 22 Feb 2011 21:34:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think you can turn off clipping. Just reset it to 0,0,w,h.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 22 Feb 2011 21:50:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have been considering to add the convenience function:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> al_reset_clipping_rectangle<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Wed, 23 Feb 2011 04:41:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Unrelated to the question at hand, but on the topic of convenience methods:
</p><div class="source-code snippet"><div class="inner"><pre>al_push_state<span class="k2">(</span><span class="k1">int</span> state<span class="k2">)</span><span class="k2">;</span>
al_pop_state<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
I use those a lot.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 23 Feb 2011 05:07:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>^ it&#39;s not really a convenience when it&#39;s additional to what you&#39;re used to with A4 <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>I guess if there&#39;s not much to gain in not having a clipping region then I&#39;ll just chop out the code.</p><p>Carrying on the theme of unrelated but similar observations, I noticed from the early A5 to the current branch, the &#39;image addon&#39; functions have got less and less (now only 3 functions). Why not just bring them into the core given almost everybody wants to load images as it seems odd that you have to call the image initialisation from an add-on to use a core bitmap load method.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 23 Feb 2011 18:43:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No answer will satisfy both sides of that argument. You can search the [AD] mailing list archive if you want to know the reasoning.</p><p>In the end, it comes down to consistency (i.e., either all loaders in core or all in an addon) and slippery slope issues with other addons.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 24 Feb 2011 01:13:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/904783#target">Peter Wang</a> said:</div><div class="quote"><p>I have been considering to add the convenience function:</p><p>void al_reset_clipping_rectangle(void);
</p></div></div><p>

I think an ALLEGRO_CLIP_REGION might be better, with</p><ul><li><p><span class="source-code">ALLEGRO_CLIP_REGION al_compose_clipping_region<span class="k2">(</span><span class="k1">int</span> x, y, w, h<span class="k2">)</span><span class="k2">;</span></span>
</p></li><li><p><span class="source-code"><span class="k1">void</span> al_set_clipping_region<span class="k2">(</span>ALLEGRO_CLIP_REGION region<span class="k2">)</span><span class="k2">;</span></span>
</p></li><li><p><span class="source-code">ALLEGRO_CLIP_REGION al_get_clipping_region<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span></p></li></ul><p>I&#39;ve already come across a few instances where multiple layers of clip regions are necessary.  Specifically, a window widget with a clip region contains child widgets, like a text block that has its own region.  After the text block is drawn, it will need to revert to the previous state before drawing the rest of the children.</p><p>The <a href="http://alleg.sourceforge.net/a5docs/refman/state.html">store/restore</a> states are too much for this particular function, and the existing
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> x, y, w, h<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_get_clipping_rectangle"><span class="a">al_get_clipping_rectangle</span></a><span class="k2">(</span><span class="k3">&amp;</span>x, <span class="k3">&amp;</span>y, <span class="k3">&amp;</span>w, <span class="k3">&amp;</span>h<span class="k2">)</span><span class="k2">;</span>
<span class="c">//</span>
<a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span><span class="k3">&amp;</span>x, <span class="k3">&amp;</span>y, <span class="k3">&amp;</span>w, <span class="k3">&amp;</span>h<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>seems like it could be cleaned up a little.</p><p>Also, my proposed method fits in with the way other allegro components function, eg:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>previous <span class="k3">=</span> al_get_target_bitamp<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>new_target<span class="k2">)</span><span class="k2">;</span>
<span class="c">// draw stuff;</span>
<a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>previous<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Thu, 24 Feb 2011 14:10:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sub bitmaps are better for nesting translations + clipping.</p><p>Edit:</p><p>If you run ex_clip for speed comparisons, you should take note that it also is timing creating and deleting a sub bitmap, which is an unrealistic disadvantage. </p><p>For something like GUI widgets that rarely change, I don&#39;t think it makes sense to use clipping and translations to position the child widgets. A sub bitmap (created once and saved for future use) will be faster than setting clipping all over the place.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 24 Feb 2011 14:40:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm... the biggest problem I have with sub-bitmaps is that they don&#39;t do sub-pixel antialiasing when drawing primitives.  And since all my widgets are drawn with primitives it doesn&#39;t look so hot.</p><p>Also, as it is now, child widgets are not drawn with coordinates relative to their parents.  When a parent is moved, it repositions the children with them.  There are a few benefits to this, including no need to translate or pass relative coordinates between child-parent widgets for mouse events, and it maintains a consistency across all widgets for mouse axes events.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Thu, 24 Feb 2011 15:07:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905051#target">Mark Oates</a> said:</div><div class="quote"><p> the biggest problem I have with sub-bitmaps is that they don&#39;t do sub-pixel antialiasing when drawing primitives
</p></div></div><p>Why don&#39;t they?</p><p>I don&#39;t rely on sampling. It seems to be pretty slow for very little gain in terms of drawing widgets. I simply draw something a bit bigger first with some opacity to it. When you&#39;re dealing with smoothing a single pixel line on a high res monitor, it seems fine to me.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> child widgets are not drawn with coordinates relative to their parents
</p></div></div><p>What is that supposed to mean?</p><p>If I have a 640x480 desktop at (0,0) [relative to the Allegro display] containing a window at (16,16) [relative to the GUI desktop], and if I want to add a button to the window on its top,left corner of its inner panel, I have to call <span class="source-code">move_widget<span class="k2">(</span>btn, <span class="n">16</span>, <span class="n">16</span><span class="k2">)</span></span>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 24 Feb 2011 15:23:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905054#target">Matthew Leverton</a> said:</div><div class="quote"><p>What is that supposed to mean?</p></div></div><p>I take it to mean all widgets are like A4 widgets, they all have their own global coordinates.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 24 Feb 2011 15:27:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905055#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> I take it to mean all widgets are like A4 widgets, they all have their own global coordinates.
</p></div></div><p>Right now I store everything relative, but I have a &quot;get absolute coords&quot; function. If it turns out to be some sort of bottleneck, it would be trivial to store x and abs_x (etc) for each widget. Both systems have uses.</p><p>But how you store it internally doesn&#39;t really matter with regard to sub bitmaps vs clipping. That&#39;s really what I&#39;m asking about: how does using sub bitmaps make that any more difficult?</p><p>Obviously with sub bitmaps, if the &quot;root&quot; bitmap moves, then you have to recreate your sub bitmaps. But moving widgets is not such a common occurrence that it&#39;s problematic. (And if it were, you could give each moving (draggable) framed window its own bitmap.) The code would be hardly any different from repositioning global coordinates.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 24 Feb 2011 15:42:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just assume that everything is drawing to absolute coords rather than relative.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905057#target">Matthew Leverton</a> said:</div><div class="quote"><p>Right now I store everything relative, but I have a &quot;get absolute coords&quot; function. If it turns out to be some sort of bottleneck, it would be trivial to store x and abs_x (etc) for each widget. Both systems have uses.</p></div></div><p>My Canvas lib uses relative positions, but I&#39;ve been thinking about caching the absolute positions like I&#39;ve been caching the transform and other bits.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 24 Feb 2011 15:49:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905054#target">Matthew Leverton</a> said:</div><div class="quote"><p>Why don&#39;t they?</p></div></div><p>

I&#39;m not sure.  It has something to do with <a href="http://www.allegro.cc/forums/thread/604305">a stencil buffer or an FBO or something fancy</a>, I dunno.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I don&#39;t rely on sampling.</p></div></div><p>Not me.  I like my lines smooooth. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905057#target">Matthew Leverton</a> said:</div><div class="quote"><p>how does using sub bitmaps make that any more difficult?</p></div></div><p>More overhead.  Creating an extra bitmap, managing it, x, abs_x, abs_x+w, etc for each child, or mouse axes functions need to pass through a parent widget, or you need to keep it all in check by feeding translations. [edit]If you&#39;re using a sub-bitmap, it seems logical that you would be keeping everything relative to the 0,0 of the bitmap and then drawing the sub-bitmap to a different location, thus requiring a non-absolute child coordinate strategy[/edit].</p><p>Otherwise all you have to do is
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> parent_mouse_axes_move_func<span class="k2">(</span><span class="k1">void</span> <span class="k3">*</span>obj, ALLEGRO_MOUSE_EVENT <span class="k3">*</span>ev<span class="k2">)</span>
<span class="k2">{</span>
    UIParentFrame <span class="k3">*</span>f <span class="k3">=</span> <span class="k1">static_cast</span><span class="k3">&lt;</span>UIParentFrame <span class="k3">*</span><span class="k3">&gt;</span><span class="k2">(</span>obj<span class="k2">)</span><span class="k2">;</span>
    f-&gt;x <span class="k3">+</span><span class="k3">=</span> ev-&gt;dx<span class="k2">;</span>
    f-&gt;y <span class="k3">+</span><span class="k3">=</span> ev-&gt;dy<span class="k2">;</span>
    <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><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span>f-&gt;child.size<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>
    <span class="k2">{</span>
       f-&gt;child<span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>x <span class="k3">+</span><span class="k3">=</span> ev-&gt;dx<span class="k2">;</span>
       f-&gt;child<span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>y <span class="k3">+</span><span class="k3">=</span> ev-&gt;dy<span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>
done. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905054#target">Matthew Leverton</a> said:</div><div class="quote"><p>I have to call move_widget(btn, 16, 16)?</p></div></div><p>I usually compose every parent/child group at (0,0) and then move it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Thu, 24 Feb 2011 15:58:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905059#target">Mark Oates</a> said:</div><div class="quote"><p> I&#39;m not sure. It has something to do with a stencil buffer or an FBO or something, I dunno.
</p></div></div><p>A sub bitmap of the backbuffer should work no differently than clipping. Have you tried?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> More overhead.
</p></div></div><p>One could easily use an absolute coordinate system with a sub bitmap approach. </p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">void</span> parent_mouse_axes_move_func<span class="k2">(</span><span class="k1">void</span> <span class="k3">*</span>obj, ALLEGRO_MOUSE_EVENT <span class="k3">*</span>ev<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>    UIParentFrame <span class="k3">*</span>f <span class="k3">=</span> <span class="k1">static_cast</span><span class="k3">&lt;</span>UIParentFrame <span class="k3">*</span><span class="k3">&gt;</span><span class="k2">(</span>obj<span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>    f-&gt;x <span class="k3">+</span><span class="k3">=</span> ev-&gt;dx<span class="k2">;</span>
<span class="number">  5</span>    f-&gt;y <span class="k3">+</span><span class="k3">=</span> ev-&gt;dy<span class="k2">;</span>
<span class="number">  6</span>    <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><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span>f-&gt;child.size<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>
<span class="number">  7</span>    <span class="k2">{</span>
<span class="number">  8</span>       f-&gt;child<span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>move_rel<span class="k2">(</span>ev-&gt;dx, ev-&gt;dy<span class="k2">)</span>
<span class="number">  9</span>    <span class="k2">}</span>
<span class="number"> 10</span><span class="k2">}</span>
<span class="number"> 11</span>
<span class="number"> 12</span><span class="k1">void</span> widget::move_rel<span class="k2">(</span>x, y<span class="k2">)</span>
<span class="number"> 13</span><span class="k2">{</span>
<span class="number"> 14</span>  this-&gt;x <span class="k3">+</span><span class="k3">=</span> x<span class="k2">;</span>
<span class="number"> 15</span>  this-&gt;y <span class="k3">+</span><span class="k3">=</span> y<span class="k2">;</span>
<span class="number"> 16</span>  <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>this-&gt;canvas<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>  this-&gt;canvas <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sub_bitmap"><span class="a">al_create_sub_bitmap</span></a><span class="k2">(</span>root, this-&gt;x, this-&gt;y, this-&gt;w, this-&gt;h<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span><span class="k2">}</span>
</div></div><p>

And actually, it wouldn&#39;t be too hard to add repositioning sub bitmaps into Allegro core, I don&#39;t think. Then if you made the sub bitmaps relative to the parent, you would never have to create/destroy sub bitmaps. (Only move the single bitmap on the container that moved.)</p><p>So anyway, the point is, I don&#39;t think absolute vs relative has anything to do with sub bitmaps vs clipping.</p><p>And ultimately, they (sub bitmap vs clipping) are probably fairly equivalent in terms of code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 24 Feb 2011 16:23:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606493/905064#target">Matthew Leverton</a> said:</div><div class="quote"><p>A sub bitmap of the backbuffer should work no differently than clipping. Have you tried?</p></div></div><p>I tried back then and something went wrong with drawing from the backbuffer to another bitmap, I&#39;m not sure why.  That&#39;s where I stopped and haven&#39;t worked on it since.  There was also the problem of needing to keep the backbuffer as a freely available drawing surface.  I would have had to get all the renders before drawing the scene, possibly clearing it and needing to redraw the whole thing.  I dunno, there was a lot I didn&#39;t explore.  I&#39;ll look into it some more.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p><span class="source-code"><span class="k1">void</span> widget::move_rel<span class="k2">(</span>x, y<span class="k2">)</span></span></p></div></div><p>

I was going to say you have the extra hit of creating/destroying a bitmap, but I guess with sub-bitmaps it&#39;s not such a big deal.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>And ultimately, they (sub bitmap vs clipping) are probably fairly equivalent in terms of code.</p></div></div><p>Apart from the code I posted before, there is little extra needed to accommodate it in how my system is coming together.</p><p>As it is now, the parent widget <i>contains</i> the children, and the ui_manager only knows of the parent.  So each child is dependent on the events fed through the parent.  Though this isn&#39;t necessary, it keeps things &quot;in the family&quot; <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /><img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>I may change it later, parent/child is still in experimental phase.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Thu, 24 Feb 2011 16:51:22 +0000</pubDate>
	</item>
</rss>
