Write flickering free code
From AbiWiki
m (moved DoubleBuffering to Write flickering free code) |
|||
(2 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
+ | The double buffering in AbiWord is meant to be managed by a FV_ViewDoubleBuffering object. One may find ways to avoid using FV_ViewDoubleBuffering and directly call the double buffering code in GR_Graphics / GR_Painter, but '''this isn't recommended'''. | ||
+ | To enable double buffering for a certain section, you will first create a FV_ViewDoubleBuffering object (eg. dblBuffObj) and then enclose the code between dblBuffObj.beginDoubleBuffering() and dblBuffObj.endDoubleBuffering(). Now, let's take a look at those 3 parameters passed to the constructor: | ||
+ | |||
+ | #FV_View *pView<br />This is a reference to the current view. It is used to determine the GR_Graphics object used for drawing and to record any FV_View::_draw calls that take place. | ||
+ | #bool suspendDirectDrawing<br />This tells the object to discard any drawing that takes place between beginDoubleBuffering() and endDoubleBuffering() calls. Yes, I said discard. There are many functions (like insertSpan, for example) which have "drawing side effects": insertSpan() inserts a span and then draws something on the screen. When this is followed by a updateScreen(false), it is really useless. | ||
+ | #bool callDrawOnlyAtTheEnd<br />This tells the object to record FV_View::_draw calls between beginDoubleBuffering() and endDoubleBuffering() and call _draw only once, inside endDoubleBuffering() with the cumulative effect of all previous calls. | ||
+ | |||
+ | For most functions, the following code works well enough: | ||
+ | |||
+ | <tt> | ||
+ | FV_ViewDoubleBuffering dblBuffObj(?, true, true);<br /> | ||
+ | dblBuffObj.beginDoubleBuffering(); | ||
+ | </tt> | ||
+ | |||
+ | On the other side, sometimes, you will need to call dblBuffObj.endDoubleBuffering(); before the function returns and / or set suspendDirectDrawing / callDrawOnlyAtTheEnd to false. However, the combination <tt>FV_ViewDoubleBuffering dblBuffObj(?, true, false);</tt> is wrong, because it has no effect at all: it discards the _draw calls as well, resulting in no drawing (if you don't draw, what do you want to double buffer?). |
Current revision as of 16:44, 19 July 2011
The double buffering in AbiWord is meant to be managed by a FV_ViewDoubleBuffering object. One may find ways to avoid using FV_ViewDoubleBuffering and directly call the double buffering code in GR_Graphics / GR_Painter, but this isn't recommended.
To enable double buffering for a certain section, you will first create a FV_ViewDoubleBuffering object (eg. dblBuffObj) and then enclose the code between dblBuffObj.beginDoubleBuffering() and dblBuffObj.endDoubleBuffering(). Now, let's take a look at those 3 parameters passed to the constructor:
- FV_View *pView
This is a reference to the current view. It is used to determine the GR_Graphics object used for drawing and to record any FV_View::_draw calls that take place. - bool suspendDirectDrawing
This tells the object to discard any drawing that takes place between beginDoubleBuffering() and endDoubleBuffering() calls. Yes, I said discard. There are many functions (like insertSpan, for example) which have "drawing side effects": insertSpan() inserts a span and then draws something on the screen. When this is followed by a updateScreen(false), it is really useless. - bool callDrawOnlyAtTheEnd
This tells the object to record FV_View::_draw calls between beginDoubleBuffering() and endDoubleBuffering() and call _draw only once, inside endDoubleBuffering() with the cumulative effect of all previous calls.
For most functions, the following code works well enough:
FV_ViewDoubleBuffering dblBuffObj(?, true, true);
dblBuffObj.beginDoubleBuffering();
On the other side, sometimes, you will need to call dblBuffObj.endDoubleBuffering(); before the function returns and / or set suspendDirectDrawing / callDrawOnlyAtTheEnd to false. However, the combination FV_ViewDoubleBuffering dblBuffObj(?, true, false); is wrong, because it has no effect at all: it discards the _draw calls as well, resulting in no drawing (if you don't draw, what do you want to double buffer?).