<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - DrawingArea Internal Behaviour
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../doc+en">Up</a>&nbsp;
<a href="dragndrop+en">Previous</a>&nbsp;
<a href="faq+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
DrawingArea Internal Behaviour
</h1>
Here is more information about the <a href="../comp/gb.qt/drawingarea+en">DrawingArea</a> internal stuffs.
<p>
It is related to the way Qt manages draw events sent by the X Server.
<p>
First, you must know that a draw event is a rectangle in your window that you
must redraw.
<p>
Then there is two ways:
<p>
<ol>
<li>All X11 draw events are merged by QT into a Region <a href="../def/object+en">object</a>, that is not rectangular, and then the QT paint event is called, and thus the <a href="../def/gambas+en">Gambas</a> <a href="../comp/gb.qt/drawingarea/_draw+en">Draw</a> event. All drawings during the draw event handler will be clipped by this region.<br><br>It worked like that before my modifications.
<p>
<li>QT merges nothing, and you get one <a href="../def/gambas+en">Gambas</a> draw event for each X11 draw event. The drawing is clipped by the rectangle.<br><br>It works like that now.
<p>
</ol>

<h2>Why doing that ?</h2>
<p>
Logically, during the drawing event handler, you have to draw the less
possible things to speed up the drawing.
<p>
The only way in <a href="../def/gambas+en">Gambas</a> to know what to draw is using the <a href="../comp/gb.qt/draw/clip+en">Clip</a> property.
of the <a href="../comp/gb.qt/draw+en">Draw</a> class.
<p>
In the first case, as drawing is clipped by the region, <a href="../comp/gb.qt/draw+en">Draw</a>.<a href="../comp/gb.qt/draw/clip+en">Clip</a>.[X/Y/W/H] returns
the smallest rectangle that includes the region.
<p>
But, for example, when you enlarge a little a window, the region contains two
rectangles: one at the right of the window, the other at the bottom. And so,
the including rectangle is the entire window!
<p>
<pre class="code">+--------------------------------+---+
|                                | x |      xxx = The region used by Qt
|                                | x |
|                                | x |
|                                | x |
|                                | x |
|                                | x |
|                                | x |
|                    Old size    | x |
|                                | x |
+--------------------------------+ x |
|xxxxxxxxxxxxxxxxxxxxx New size xxxx |
+------------------------------------+
</pre><p><p>
When you can easily draw any sub-rectangle of your drawing area, the second
way is the better.
<p>
When you can't easily do that, i.e. when your drawing is too complex to be
easily splitted into a rectangle, you prefer drawing everything each time you
receive a <a href="../comp/gb.qt/draw+en">Draw</a> event. And so, you do the job twice or more times comparing to
the first way. So it is twice or ore slower.
<p>
The solution is having a property in the <a href="../comp/gb.qt/drawingarea+en">DrawingArea</a> to tell it merging
or not drawing events.
<p>
This is the <a href="../comp/gb.qt/drawingarea/merge+en">Merge</a> property.

</div>
</body>
</html>

