DrawingArea内部行为

这是关于 DrawingArea 内部的更多信息。

它与 qt 处理X服务器发送的绘制事件的方式有关。

首先,你必须知道draw事件是窗口中必须重新绘制的矩形。

Then there is two ways:

  1. All X11 draw events are merged by QT into a Region 对象, that is not rectangular, and then the QT paint event is called, and thus the Gambas Draw event. All drawings during the draw event handler will be clipped by this region.

    It worked like that before my modifications.

  2. QT merges nothing, and you get one Gambas draw event for each X11 draw event. The drawing is clipped by the rectangle.

    It works like that now.

Why doing that ?

Logically, during the drawing 事件 handler, you have to draw the less possible things to speed up the drawing.

The only way in Gambas to know what to draw is using the Clip 属性. of the Draw 类.

In the first case, as drawing is clipped by the region, Draw.Clip.[X/Y/W/H] returns the smallest rectangle that includes the region.

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!

+--------------------------------+---+
|                                | x |      xxx = The region used by Qt
|                                | x |
|                                | x |
|                                | x |
|                                | x |
|                                | x |
|                                | x |
|                    Old size    | x |
|                                | x |
+--------------------------------+ x |
|xxxxxxxxxxxxxxxxxxxxx New size xxxx |
+------------------------------------+

When you can easily draw any sub-rectangle of your drawing area, the second way is the better.

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 Draw event. And so, you do the job twice or more times comparing to the first way. So it is twice or more slower.

The solution is having a property in the DrawingArea to tell it merging or not drawing events.

This is the merge ? property.