Rendering Engine

From Yzis Wiki

Jump to: navigation, search

The goal of the rendering engine is to display the content of the YBuffer attached to the current YView.

User may configure it through some options like wrap, tabstop, etc...

Contents

Buffer / View separation

Image:Buffer view separation.png There may be a big difference between buffer and view coordinates

Cursors

To handle buffer/view synchronization, we use a YViewCursor. YViewCursor contains the buffer and view coordinates, and a list of counters indicating different kind of positions (line height, current column, etc...). When performing operations on a YView, you have to create a YViewCursor and ask the view to move it where you want. For example :

 YView::gotodxdy(YViewCursor* cursor, QPoint pos, bool) will move cursor to pos on view 
 YView::gotoxy(YViewCursor* cursor, QPoint pos, bool) will move cursor to pos on buffer

Please note the last bool argument is always ignored when cursor is not the main cursor.

The main cursor is the cursor refering to the current position of the user in the file.

Moving a cursor may be an heavy operation, especially when the wrap mode is enabled. So to minimize the deplacement of the cursor, it is a good practice to move a cursor which is not so far from the targeted position. That's why we provide two methods for creating a new YViewCursor :

  • by calling YViewCursor::YViewCursor(YView*), it will create a cursor at (0,0)
  • by calling YView::viewCursor(), it will copy the main cursor

In almost every case of use, we perform operations around the main cursor.

The following example will calculate the total height of the buffer on view :

 YViewCursor myCursor = view->viewCursor();
 view->gotoxy(&myCursor, buffer->textline(buffer->lineCount()-1).length()-1, buffer->lineCount()-1);
 int totalHeight = myCursor->screenY() + 1;

Important cursors

  • YView::mainCursor : the main cursor, the one which is displayed
  • YView::scrollCursor : view top-left cursor
  • YView::workCursor : pointer to the current moving cursor
  • YView::keepCursor : pending position for the main cursor (set with *YView::sendCursor(YViewCursor*)) : will become the main cursor when YView::commitPaintEvent will be called.

Low level operations

TODO (drawNextLine, etc, gotox, etc, )

The draw buffer

TODO


Updating a view

When modifing buffer, resizing a window, etc.. the view has to be re-synchronized with the buffer.

Disable autocommit

You may want to group update requests (aka paint events) for the view (to avoid flickering) :

  • YView::setPaintAutoCommit( bool enable ) : if enable is false, it will wait for an explicit commit
  • YView::commitPaintEvent() : commit update requests

It supports recursion :

 view->setPaintAutoCommit(false);
 //.. do some stuff ..
    view->setPaintAutoCommit(false);
    //.. other stuff ..
    view->commitPaintEvent(); // nothing is commited
 view->commitPaintEvent(); // changes are applied

TODO : sendPaintEvent, buffer operations auto update the views