Logo Search packages:      
Sourcecode: yzis version File versions  Download package

void YView::guiPaintEvent ( const YSelection drawMap  )  [virtual]

default implementation for guiPaintEvent

Reimplemented in NYView, and QYView.

Definition at line 1781 of file view.cpp.

References drawChar(), drawColor(), drawHeight(), drawLength(), drawLineNumber(), drawNextCol(), drawNextLine(), getColumnsVisible(), getDrawCurrentLeft(), getLinesVisible(), getLocalBooleanOption(), getSelectionPool(), YViewIface::guiDrawClearToEOL(), YViewIface::guiDrawSetLineNumber(), YViewIface::guiDrawSetMaxLineNumber(), YViewIface::guiEndPaintEvent(), YViewIface::guiPreparePaintEvent(), YSelection::isEmpty(), lineHeight(), YSelection::map(), myBuffer(), and YViewCursor::screen().

Referenced by QYView::guiPaintEvent(), and NYView::guiPaintEvent().

{
    if ( drawMap.isEmpty() )
        return ;
    //dbg() << "YView::guiPaintEvent" << drawMap;

    bool number = getLocalBooleanOption( "number" );
    if ( number ) {
        guiDrawSetMaxLineNumber( myBuffer()->lineCount() );
    }
    if ( m_paintAll ) {
        /* entire screen has been updated already */
        return ;
    }

    /* to calculate relative position */
    int shiftY = getDrawCurrentTop();
    int shiftX = getDrawCurrentLeft();
    int maxX = shiftX + getColumnsVisible() - 1;

    YSelectionMap map = drawMap.map();
    int size = map.size();

    int fromY = map[ 0 ].fromPos().y(); /* first line */
    int toY = map[ size - 1 ].toPos().y(); /* last line */

    /* where the draw begins */
    int curY = initDrawContents( fromY );
    int curX = 0;

    /* inform the view we want to paint from line <fromY> to <toY> */
    guiPreparePaintEvent( curY - shiftY, toY - shiftY );

    int mapIdx = 0; /* first interval */

    int fX = map[ mapIdx ].fromPos().x(); /* first col of interval */
    int fY = map[ mapIdx ].fromPos().y(); /* first line of interval */
    int tX = map[ mapIdx ].toPos().x(); /* last col of interval */
    int tY = map[ mapIdx ].toPos().y(); /* last line of interval */

    bool drawIt; /* if we are inside the interval */

    bool drawLine; /* if we have to paint a part of line */
    bool drawEntireLine; /* if we have to paint the entire line */

    bool drawStartAfterSOL; /* if we don't have to draw from the begin of line */
    bool drawStopBeforeEOL; /* if we don't have to draw until the end of line */

    bool clearToEOL; /* if we have to clear the rest of line */

    bool interval_changed = true;

    /* set selection layouts */
    m_drawBuffer.setSelectionLayout( YSelectionPool::Search, *getSelectionPool()->search() - scrollCursor.screen() ); //XXX: search map is buffer only
    m_drawBuffer.setSelectionLayout( YSelectionPool::Visual, getSelectionPool()->visual()->screen() - scrollCursor.screen() );

    while ( curY <= toY && drawNextLine() ) {
        curX = shiftX;

        while ( tY < curY ) { /* next interval */
            ++mapIdx;
            fX = map[ mapIdx ].fromPos().x();
            fY = map[ mapIdx ].fromPos().y();
            tX = map[ mapIdx ].toPos().x();
            tY = map[ mapIdx ].toPos().y();
            interval_changed = true;
        }
        //yzDebug("painting") << curX << "," << curY << ":painting interval " << map[ mapIdx ]
        //      << " (changed=" << interval_changed << ")" << endl;
        if ( interval_changed ) {
            m_drawBuffer.replace( map[ mapIdx ] - scrollCursor.screen() );
                  //dbg() << "replacing " << (map[mapIdx] - scrollCursor.screen()) << endl;
            interval_changed = false;
        }

        drawStartAfterSOL = ( curY == fY && fX > shiftX );
        drawStopBeforeEOL = ( curY == tY && tX < maxX );

        drawLine = fY <= curY; // curY <= tY always true */
        drawIt = drawLine && !drawStartAfterSOL;
        drawEntireLine = drawIt && !drawStopBeforeEOL;

        clearToEOL = drawEntireLine || (drawIt && curY != tY);

        if ( drawLine && number ) {
            guiDrawSetLineNumber( curY - shiftY, drawLineNumber(), lineHeight() - 1 );
        }

        if ( drawIt && curY > fY ) {
            m_drawBuffer.newline( curY - shiftY );
        }
        while ( drawNextCol() ) {
            if ( !drawEntireLine ) { /* we have to care of starting/stopping to draw on that line */
                if ( !drawIt && curY == fY ) { // start drawing 
                    drawIt = ( curX == fX );
                    clearToEOL = drawIt && curY != tY;
                } else if ( drawIt && curY == tY ) { // stop drawing ?
                    drawIt = !( curX > tX );
                    if ( ! drawIt ) {
                        ++mapIdx;
                        if ( mapIdx != size ) {
                            fX = map[ mapIdx ].fromPos().x();
                            fY = map[ mapIdx ].fromPos().y();
                            tX = map[ mapIdx ].toPos().x();
                            tY = map[ mapIdx ].toPos().y();
                            m_drawBuffer.replace( map[ mapIdx ] - scrollCursor.screen() );
                        } else {
                            fX = fY = tX = tY = 0;
                        }
                    }
                }
            }
            if ( drawIt ) {
                QString disp = QString( drawChar() );
                disp = disp.leftJustified( drawLength(), fillChar() );
                        if ( curY == tY && curX + drawLength() > tX+1 ) { /* overlap */
                              disp = disp.left(tX - curX + 1);
                        }

                m_drawBuffer.setColor( drawColor() );

                m_drawBuffer.push( disp );
            }
            curX += drawLength();
        }
        if ( clearToEOL ) {
            guiDrawClearToEOL( QPoint (curX - shiftX, curY - shiftY), drawLineFiller() );
        }
        curY += drawHeight();
    }

    /* out of file lines (~) */
    int fh = shiftY + getLinesVisible();
    toY = qMin( toY, fh - 1 );
    m_drawBuffer.setColor( Qt::cyan );
    for ( ; curY <= toY; ++curY ) {
        m_drawBuffer.newline( curY - shiftY );
        if ( number ) guiDrawSetLineNumber( curY - shiftY, 0, 0 );
        m_drawBuffer.push( "~" );
        guiDrawClearToEOL( QPoint(1, curY - shiftY), ' ' );
    }

    m_drawBuffer.flush();

    //dbg() << "after drawing: " << endl << m_drawBuffer << "--------" << endl;

    guiEndPaintEvent();
}


Generated by  Doxygen 1.6.0   Back to index