Changeset 62


Ignore:
Timestamp:
Feb 22, 2006, 10:17:33 AM (19 years ago)
Author:
dmik
Message:

Fixed QPainter::drawRoundRect(): the background of rectangles with rounded corners was 1 pixel taller than the frame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel/qpainter_pm.cpp

    r61 r62  
    11431143        }
    11441144        qt_geom_line_handle gh;
    1145         qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
     1145        qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()),
     1146                            cpen.style() == NoPen, &gh );
    11461147
    11471148        GpiMove( hps, &sptl );
     
    13091310}
    13101311
     1312static void doDrawRect( HPS hps, int x, int y, int w, int h, int axr, int ayr )
     1313{
     1314    const FIXED RightAngle = MAKEFIXED(90,0);
     1315    const FIXED One = MAKEFIXED(1,0);
     1316   
     1317    // top/right coordinates are inclusive
     1318    -- w;
     1319    -- h;
     1320   
     1321    // beginning of the bottom side
     1322    POINTL ptl = { x + axr, y };
     1323    GpiMove( hps, &ptl );
     1324    // center of the bottom-right arc
     1325    ptl.x = x + w - axr; ptl.y = y + ayr;
     1326    GpiPartialArc( hps, &ptl, One, MAKEFIXED(270,0), RightAngle );
     1327    // center of the top-right arc
     1328    /* ptl.x = x + w - axr; */ ptl.y = y + h - ayr;
     1329    GpiPartialArc( hps, &ptl, One, MAKEFIXED(0,0), RightAngle );
     1330    // center of the top-left arc
     1331    ptl.x = x + axr; /* ptl.y = y + h - ayr; */
     1332    GpiPartialArc( hps, &ptl, One, RightAngle, RightAngle );
     1333    // center of the bottom-left arc
     1334    /* ptl.x = x + axr; */ ptl.y = y + ayr;
     1335    GpiPartialArc( hps, &ptl, One, MAKEFIXED(180,0), RightAngle );
     1336}
    13111337
    13121338void QPainter::drawRectInternal(
     
    13191345    }
    13201346
    1321     POINTL ptl1 = { x, y };
    1322     if ( devh ) ptl1.y = devh - ( ptl1.y + h );
    1323     POINTL ptl2 = { x + w - 1, ptl1.y + h - 1 };
    1324 
     1347    // GpiBox API is buggy when it comes to rounded corners
     1348    // combined with filling the interior (see ticket:16).
     1349    // The fix is to draw rounded corners ourselves.
     1350
     1351    if ( wRnd == 0 || hRnd == 0 ) {
     1352        POINTL ptl1 = { x, y };
     1353        if ( devh ) ptl1.y = devh - ( ptl1.y + h );
     1354        POINTL ptl2 = { x + w - 1, ptl1.y + h - 1 };
     1355        if ( cpen.width() > 1 ) {
     1356            GpiMove( hps, &ptl1 );
     1357            GpiBox( hps, DRO_FILL, &ptl2, wRnd, hRnd );
     1358            qt_geom_line_handle gh;
     1359            qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()),
     1360                                cpen.style() == NoPen, &gh );
     1361            GpiMove( hps, &ptl1 );
     1362            GpiBox( hps, DRO_OUTLINE, &ptl2, 0, 0 );
     1363            qt_end_geom_line( hps, &gh );
     1364        } else {
     1365            GpiMove( hps, &ptl1 );
     1366            GpiBox( hps, DRO_FILL | DRO_OUTLINE, &ptl2, 0, 0 );
     1367        }
     1368        return;
     1369    }
     1370   
     1371    // flip y coordinate
     1372    if ( devh ) y = devh - ( y + h );
     1373
     1374    int axr = (wRnd - 1) / 2;
     1375    int ayr = (hRnd - 1) / 2;
     1376    ARCPARAMS arcparams = { axr, ayr, 0, 0 };
     1377    GpiSetArcParams( hps, &arcparams );
     1378   
    13251379    if ( cpen.width() > 1 ) {
    1326         GpiMove( hps, &ptl1 );
    1327         GpiBox( hps, DRO_FILL, &ptl2, wRnd, hRnd );
     1380        GpiBeginArea( hps, BA_NOBOUNDARY | BA_ALTERNATE );
     1381        doDrawRect( hps, x, y, w, h, axr, ayr );
     1382        GpiEndArea( hps );
    13281383        qt_geom_line_handle gh;
    1329         qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()), cpen.style() == NoPen, &gh );
    1330         GpiMove( hps, &ptl1 );
    1331         GpiBox( hps, DRO_OUTLINE, &ptl2, wRnd, hRnd );
     1384        qt_begin_geom_line( hps, COLOR_VALUE(cpen.color()),
     1385                            cpen.style() == NoPen, &gh );
     1386        doDrawRect( hps, x, y, w, h, axr, ayr );
     1387        GpiCloseFigure( hps );
    13321388        qt_end_geom_line( hps, &gh );
    13331389    } else {
    1334         GpiMove( hps, &ptl1 );
    1335         GpiBox( hps, DRO_FILL | DRO_OUTLINE, &ptl2, wRnd, hRnd );
     1390        GpiBeginArea( hps, BA_BOUNDARY | BA_ALTERNATE );
     1391        doDrawRect( hps, x, y, w, h, axr, ayr );
     1392        GpiEndArea( hps );
    13361393    }
    13371394}
     
    14671524            if ( w <= 0 || h <= 0 )
    14681525                fix_neg_rect( &x, &y, &w, &h );
    1469             w--;
    1470             h--;
    14711526            int rxx = w*xRnd/200;
    14721527            int ryy = h*yRnd/200;
     
    14991554    }
    15001555
    1501     drawRectInternal( x, y, w, h, w*xRnd/100, h*yRnd/100 );
     1556    drawRectInternal( x, y, w, h, w*xRnd/99, h*yRnd/99 );
    15021557}
    15031558
Note: See TracChangeset for help on using the changeset viewer.