Ticket #7330: 0002-ControlLook-Add-side-parameter-to-tab-drawing-functi.patch

File 0002-ControlLook-Add-side-parameter-to-tab-drawing-functi.patch, 9.4 KB (added by KapiX, 2 years ago)
  • headers/os/interface/ControlLook.h

    From b01dc52bc06dbc47bf33cc30d313ff3a639a711b Mon Sep 17 00:00:00 2001
    From: Kacper Kasper <kacperkasper@gmail.com>
    Date: Sat, 21 Jan 2017 17:22:16 +0100
    Subject: [PATCH 2/2] ControlLook: Add side parameter to tab drawing functions.
    
    * This allows drawing tabs on any side of the view.
    ---
     headers/os/interface/ControlLook.h |   6 +-
     src/kits/interface/ControlLook.cpp | 169 ++++++++++++++++++++++++++++++-------
     2 files changed, 141 insertions(+), 34 deletions(-)
    
    diff --git a/headers/os/interface/ControlLook.h b/headers/os/interface/ControlLook.h
    index 0908256..2f2472d 100644
    a b public: 
    288288    virtual void                DrawActiveTab(BView* view, BRect& rect,
    289289                                    const BRect& updateRect,
    290290                                    const rgb_color& base, uint32 flags = 0,
    291                                     uint32 borders = B_ALL_BORDERS);
     291                                    uint32 borders = B_ALL_BORDERS,
     292                                    uint32 side = B_TOP_BORDER);
    292293
    293294    virtual void                DrawInactiveTab(BView* view, BRect& rect,
    294295                                    const BRect& updateRect,
    295296                                    const rgb_color& base, uint32 flags = 0,
    296                                     uint32 borders = B_ALL_BORDERS);
     297                                    uint32 borders = B_ALL_BORDERS,
     298                                    uint32 side = B_TOP_BORDER);
    297299
    298300    /*virtual*/ void            DrawSplitter(BView* view, BRect& rect,
    299301                                    const BRect& updateRect,
  • src/kits/interface/ControlLook.cpp

    diff --git a/src/kits/interface/ControlLook.cpp b/src/kits/interface/ControlLook.cpp
    index 8e38fbb..7a00152 100644
    a b BControlLook::DrawSliderHashMarks(BView* view, BRect& rect, 
    13551355
    13561356void
    13571357BControlLook::DrawActiveTab(BView* view, BRect& rect, const BRect& updateRect,
    1358     const rgb_color& base, uint32 flags, uint32 borders)
     1358    const rgb_color& base, uint32 flags, uint32 borders, uint32 side)
    13591359{
    13601360    if (!rect.IsValid() || !rect.Intersects(updateRect))
    13611361        return;
    BControlLook::DrawActiveTab(BView* view, BRect& rect, const BRect& updateRect, 
    14091409    BRect leftTopCorner(rect);
    14101410    leftTopCorner.right = floorf(leftTopCorner.left + kRoundCornerRadius);
    14111411    leftTopCorner.bottom = floorf(rect.top + kRoundCornerRadius);
    1412     clipping.Exclude(leftTopCorner);
    1413 
    1414     // draw the left top corner
    1415     _DrawRoundCornerLeftTop(view, leftTopCorner, updateRect, base,
    1416         edgeShadowColor, frameLightColor, bevelLightColor,
    1417         fillGradient);
    14181412
    14191413    // right top corner dimensions
    14201414    BRect rightTopCorner(rect);
    1421     rightTopCorner.right = floorf(rect.right);
    14221415    rightTopCorner.left = floorf(rightTopCorner.right - kRoundCornerRadius);
    14231416    rightTopCorner.bottom = floorf(rect.top + kRoundCornerRadius);
    1424     clipping.Exclude(rightTopCorner);
    14251417
    1426     // draw the right top corner
    1427     _DrawRoundCornerRightTop(view, rightTopCorner, updateRect, base,
    1428         edgeShadowColor, edgeLightColor, frameLightColor,
    1429         frameShadowColor, bevelLightColor, bevelShadowColor,
    1430         fillGradient);
     1418    // left bottom corner dimensions
     1419    BRect leftBottomCorner(rect);
     1420    leftBottomCorner.right = floorf(leftBottomCorner.left + kRoundCornerRadius);
     1421    leftBottomCorner.top = floorf(rect.bottom - kRoundCornerRadius);
     1422
     1423    // right bottom corner dimensions
     1424    BRect rightBottomCorner(rect);
     1425    rightBottomCorner.left = floorf(rightBottomCorner.right
     1426        - kRoundCornerRadius);
     1427    rightBottomCorner.top = floorf(rect.bottom - kRoundCornerRadius);
     1428
     1429    switch (side) {
     1430        case B_TOP_BORDER:
     1431            clipping.Exclude(leftTopCorner);
     1432            clipping.Exclude(rightTopCorner);
     1433
     1434            // draw the left top corner
     1435            _DrawRoundCornerLeftTop(view, leftTopCorner, updateRect, base,
     1436                edgeShadowColor, frameLightColor, bevelLightColor,
     1437                fillGradient);
     1438            // draw the right top corner
     1439            _DrawRoundCornerRightTop(view, rightTopCorner, updateRect, base,
     1440                edgeShadowColor, edgeLightColor, frameLightColor,
     1441                frameShadowColor, bevelLightColor, bevelShadowColor,
     1442                fillGradient);
     1443            break;
     1444        case B_BOTTOM_BORDER:
     1445            clipping.Exclude(leftBottomCorner);
     1446            clipping.Exclude(rightBottomCorner);
     1447
     1448            // draw the left top corner
     1449            _DrawRoundCornerLeftBottom(view, leftBottomCorner, updateRect, base,
     1450                edgeShadowColor, edgeLightColor, frameLightColor,
     1451                frameShadowColor, bevelLightColor, bevelShadowColor,
     1452                fillGradient);
     1453            // draw the right top corner
     1454            _DrawRoundCornerRightBottom(view, rightBottomCorner, updateRect,
     1455                base, edgeLightColor, frameShadowColor, bevelShadowColor,
     1456                fillGradient);
     1457            break;
     1458        case B_LEFT_BORDER:
     1459            clipping.Exclude(leftTopCorner);
     1460            clipping.Exclude(leftBottomCorner);
     1461
     1462            // draw the left top corner
     1463            _DrawRoundCornerLeftTop(view, leftTopCorner, updateRect, base,
     1464                edgeShadowColor, frameLightColor, bevelLightColor,
     1465                fillGradient);
     1466            // draw the left top corner
     1467            _DrawRoundCornerLeftBottom(view, leftBottomCorner, updateRect, base,
     1468                edgeShadowColor, edgeLightColor, frameLightColor,
     1469                frameShadowColor, bevelLightColor, bevelShadowColor,
     1470                fillGradient);
     1471            break;
     1472        case B_RIGHT_BORDER:
     1473            clipping.Exclude(rightTopCorner);
     1474            clipping.Exclude(rightBottomCorner);
     1475
     1476            // draw the right top corner
     1477            _DrawRoundCornerRightTop(view, rightTopCorner, updateRect, base,
     1478                edgeShadowColor, edgeLightColor, frameLightColor,
     1479                frameShadowColor, bevelLightColor, bevelShadowColor,
     1480                fillGradient);
     1481            // draw the right top corner
     1482            _DrawRoundCornerRightBottom(view, rightBottomCorner, updateRect,
     1483                base, edgeLightColor, frameShadowColor, bevelShadowColor,
     1484                fillGradient);
     1485            break;
     1486    }
    14311487
    14321488    // clip out the corners
    14331489    view->ConstrainClippingRegion(&clipping);
    14341490
     1491    uint32 bordersToDraw = 0;
     1492    switch (side) {
     1493        case B_TOP_BORDER:
     1494            bordersToDraw = (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER);
     1495            break;
     1496        case B_BOTTOM_BORDER:
     1497            bordersToDraw = (B_LEFT_BORDER | B_BOTTOM_BORDER | B_RIGHT_BORDER);
     1498            break;
     1499        case B_LEFT_BORDER:
     1500            bordersToDraw = (B_LEFT_BORDER | B_BOTTOM_BORDER | B_TOP_BORDER);
     1501            break;
     1502        case B_RIGHT_BORDER:
     1503            bordersToDraw = (B_RIGHT_BORDER | B_BOTTOM_BORDER | B_TOP_BORDER);
     1504            break;
     1505    }
     1506
    14351507    // draw the rest of frame and fill
    14361508    _DrawFrame(view, rect, edgeShadowColor, edgeShadowColor, edgeLightColor,
    1437         edgeLightColor,
    1438         borders & (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER));
    1439     if ((borders & B_LEFT_BORDER) == 0)
    1440         rect.left++;
    1441     if ((borders & B_RIGHT_BORDER) == 0)
    1442         rect.right--;
     1509        edgeLightColor, borders & bordersToDraw);
     1510    if (side == B_TOP_BORDER || side == B_BOTTOM_BORDER) {
     1511        if ((borders & B_LEFT_BORDER) == 0)
     1512            rect.left++;
     1513        if ((borders & B_RIGHT_BORDER) == 0)
     1514            rect.right--;
     1515    } else if (side == B_LEFT_BORDER || side == B_RIGHT_BORDER) {
     1516        if ((borders & B_TOP_BORDER) == 0)
     1517            rect.top++;
     1518        if ((borders & B_BOTTOM_BORDER) == 0)
     1519            rect.bottom--;
     1520    }
    14431521
    14441522    _DrawFrame(view, rect, frameLightColor, frameLightColor, frameShadowColor,
    1445         frameShadowColor, B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER);
     1523        frameShadowColor, bordersToDraw);
    14461524
    14471525    _DrawFrame(view, rect, bevelLightColor, bevelLightColor, bevelShadowColor,
    14481526        bevelShadowColor);
    BControlLook::DrawActiveTab(BView* view, BRect& rect, const BRect& updateRect, 
    14561534
    14571535void
    14581536BControlLook::DrawInactiveTab(BView* view, BRect& rect, const BRect& updateRect,
    1459     const rgb_color& base, uint32 flags, uint32 borders)
     1537    const rgb_color& base, uint32 flags, uint32 borders, uint32 side)
    14601538{
    14611539    if (!rect.IsValid() || !rect.Intersects(updateRect))
    14621540        return;
    BControlLook::DrawInactiveTab(BView* view, BRect& rect, const BRect& updateRect, 
    14911569        fillGradient.AddColor(tint_color(base, 1.08), 255);
    14921570    }
    14931571
     1572    uint32 bordersToDraw = 0;
     1573    switch (side) {
     1574        case B_TOP_BORDER:
     1575            bordersToDraw = (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER);
     1576            rect.top += 4;
     1577            break;
     1578        case B_BOTTOM_BORDER:
     1579            bordersToDraw = (B_LEFT_BORDER | B_BOTTOM_BORDER | B_RIGHT_BORDER);
     1580            rect.bottom -= 4;
     1581            break;
     1582        case B_LEFT_BORDER:
     1583            bordersToDraw = (B_LEFT_BORDER | B_BOTTOM_BORDER | B_TOP_BORDER);
     1584            rect.left += 4;
     1585            break;
     1586        case B_RIGHT_BORDER:
     1587            bordersToDraw = (B_RIGHT_BORDER | B_BOTTOM_BORDER | B_TOP_BORDER);
     1588            rect.right -= 4;
     1589        break;
     1590    }
     1591
    14941592    // active tabs stand out at the top, but this is an inactive tab
    14951593    view->SetHighColor(base);
    1496     view->FillRect(BRect(rect.left, rect.top, rect.right, rect.top + 4));
    1497     rect.top += 4;
     1594    view->FillRect(rect);
    14981595
    14991596    // frame and fill
    15001597    _DrawFrame(view, rect, edgeShadowColor, edgeShadowColor, edgeLightColor,
    1501         edgeLightColor,
    1502         borders & (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER));
     1598        edgeLightColor, borders & bordersToDraw);
    15031599
    15041600    _DrawFrame(view, rect, frameLightColor, frameLightColor, frameShadowColor,
    1505         frameShadowColor,
    1506         borders & (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER));
     1601        frameShadowColor, borders & bordersToDraw);
    15071602
    15081603    if (rect.IsValid()) {
    1509         _DrawFrame(view, rect, bevelShadowColor, bevelShadowColor,
    1510             bevelLightColor, bevelLightColor, B_LEFT_BORDER & ~borders);
     1604        if (side == B_TOP_BORDER || side == B_BOTTOM_BORDER) {
     1605            _DrawFrame(view, rect, bevelShadowColor, bevelShadowColor,
     1606                bevelLightColor, bevelLightColor, B_LEFT_BORDER & ~borders);
     1607        } else if (side == B_LEFT_BORDER || side == B_RIGHT_BORDER) {
     1608            _DrawFrame(view, rect, bevelShadowColor, bevelShadowColor,
     1609                bevelLightColor, bevelLightColor, B_TOP_BORDER & ~borders);
     1610        }
    15111611    } else {
    1512         if ((B_LEFT_BORDER & ~borders) != 0)
    1513             rect.left++;
     1612        if (side == B_TOP_BORDER || side == B_BOTTOM_BORDER) {
     1613            if ((B_LEFT_BORDER & ~borders) != 0)
     1614                rect.left++;
     1615        } else if (side == B_LEFT_BORDER || side == B_RIGHT_BORDER) {
     1616            if ((B_TOP_BORDER & ~borders) != 0)
     1617                rect.top++;
     1618        }
    15141619    }
    15151620
    15161621    view->FillRect(rect, fillGradient);