<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Clipping rectangle and text in allegro5</title>
		<link>http://www.allegro.cc/forums/view/617100</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 24 Oct 2017 19:37:01 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello,</p><p>I&#39;m writing a GUI using allegro 5. When composed, I iterate for all widgets from child to parents and call drawing routines for each, so this way I ensure the foreground widget is draw the last.</p><p>To avoid drawing outside their parent, each child widget, and before drawing it, sets a clipping rectangle with the dimensions of their parent with <tt>al_set_clipping_rectangle</tt>. This is working fine except for the text widget, as I can see all the text when a fraction of widget is presented (I suppose text don&#39;t support half drawing and is just a draw or not draw solution).</p><p>Can you give a hint to resolve this issue? (I was thinking in drawing text to a bitmap and clip this bitmap, but I think this would be expensive, maybe I&#39;m wrong).</p><p>Also, I don&#39;t want to do checks in each child to test his position if possible, and I like the method of simple clipping away the widgets outside his parent.</p><p>Thank you in advance
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bungow)</author>
		<pubDate>Mon, 23 Oct 2017 04:40:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am surprised that it doesn&#39;t work, I also thought clipping works with the text output functions.Do you use a bitmap font or a TTF font?  Do you have some code demonstrating the issue? Otherwise I will investigate myself later.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 23 Oct 2017 10:10:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello,</p><p>I&#39;m using TTF fonts, the code I have is a bit huge, but here I left the relevant parts:</p><p>The drawing routine calls this code recursively over each widget, from the background widget to the top.</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><a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span>widget-&gt;parent-&gt;x <span class="k3">-</span> mk_dpi<span class="k2">(</span><span class="n">2</span><span class="k2">)</span>,
<span class="number">  2</span>              widget-&gt;parent-&gt;y <span class="k3">-</span> mk_dpi<span class="k2">(</span><span class="n">2</span><span class="k2">)</span>,
<span class="number">  3</span>              widget-&gt;parent-&gt;width <span class="k3">+</span> mk_dpi<span class="k2">(</span><span class="n">2</span><span class="k2">)</span>,
<span class="number">  4</span>              widget-&gt;parent-&gt;height <span class="k3">+</span> mk_dpi<span class="k2">(</span><span class="n">2</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>      <span class="c">// Clipping rectangle. All draws outside this rectangle are</span>
<span class="number">  6</span>      <span class="c">// ignored</span>
<span class="number">  7</span>  <span class="k2">}</span>
<span class="number">  8</span>  widget-&gt;f.draw<span class="k2">(</span>widget, NULL<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>  al_reset_clipping_rectangle<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

The draw code for text is simply:
</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">if</span> <span class="k2">(</span>widget-&gt;p.text.text<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 2</span>  al_draw_multiline_text<span class="k2">(</span>widget-&gt;root-&gt;p.root.ctx-&gt;asset.gui_font,
<span class="number"> 3</span>             widget-&gt;style-&gt;foreground, widget-&gt;x, widget-&gt;y,
<span class="number"> 4</span>             widget-&gt;width, <span class="n">0</span>, <span class="n">0</span>, widget-&gt;p.text.text<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 5</span>    <span class="k2">}</span>
</div></div><p>

The widget text is always nested to another widgets like buttons or text labels but I think it&#39;s not relevant.</p><p>Result:<br />This is a huge grid of tilemaps (stolen from another game for testing purpose only), when all the widget is clipped the text don&#39;t appear.</p><p><span class="remote-thumbnail"><span class="json">{"name":"611086","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/3\/c3ee16d6932cfbd96cf1149f9c613f5b.png","w":1333,"h":862,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/3\/c3ee16d6932cfbd96cf1149f9c613f5b"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/c/3/c3ee16d6932cfbd96cf1149f9c613f5b-240.jpg" alt="611086" width="240" height="155" /></span></p><p>But when the right widgets start to draw the text appear without clipping in the window (the rectangle in the middle of screen)</p><p><span class="remote-thumbnail"><span class="json">{"name":"611087","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/1\/61c5f563509e7117cd4056dce81613ad.png","w":1366,"h":858,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/1\/61c5f563509e7117cd4056dce81613ad"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/6/1/61c5f563509e7117cd4056dce81613ad-240.jpg" alt="611087" width="240" height="150" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bungow)</author>
		<pubDate>Mon, 23 Oct 2017 13:58:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>TTF fonts are drawn using al_draw_bitmap, so there is no reason clipping would work any differently.</p><p>I can try myself later - but if you create a minimal example, can you reproduce this behavior? E.g. just add a clipping rectangle to the ex_ttf example.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 23 Oct 2017 18:45:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Humm you are right, the clipping is working fine in a simple example, sorry for no test this first, but it&#39;s seems I made some mistake calculating the clipping rectangle :/</p><p>I will investigate on this, and come here if I need more help.</p><p>Thanks you all for your help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bungow)</author>
		<pubDate>Mon, 23 Oct 2017 19:48:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It looks the mk_dpi function is not correct, and so the clipping rectangle is miscalculated bigger than expected. You can debug this visually by drawing the clipping rectangle with al_draw_rectangle before setting it.</p><p>And don&#39;t worry about asking, we all get stuck at times and we all can use some help, at times. 😎
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 23 Oct 2017 22:21:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What is mk_dpi? I see you are adjusting the position by mk_dpi, but why are you also adjusting the width and height?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Tue, 24 Oct 2017 00:26:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello, I finally manage to solve the issue, I was miscalculating the clipping rectangle only in some cases, and I almost go crazy finding the issue, but now is working (Maybe I need to open another tread with performance issues).</p><p>mk_dpi is a function returning a DPI scale, so for example mk_dpi(1) return 1 when no scale, but return 4 id DPI is set to 4. I need this to scale all GUI drawing to high DPI screens.</p><p><span class="remote-thumbnail"><span class="json">{"name":"611103","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/9\/0950dbafe3f743b7896f0923ffb28ad1.png","w":1399,"h":800,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/9\/0950dbafe3f743b7896f0923ffb28ad1"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/0/9/0950dbafe3f743b7896f0923ffb28ad1-240.jpg" alt="611103" width="240" height="137" /></span></p><p>Thank you for your help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bungow)</author>
		<pubDate>Tue, 24 Oct 2017 19:37:01 +0000</pubDate>
	</item>
</rss>
