* @brief Draws rect indicating visible area in file views. * * @param [in] nTopLine New topline for indicator * @param [in] nBottomLine New bottomline for indicator * @todo This function duplicates too much DrawRect() code. */
| 875 | * @todo This function duplicates too much DrawRect() code. |
| 876 | */ |
| 877 | void CLocationView::DrawVisibleAreaRect(CDC *pClientDC, int nTopLine, int nBottomLine) |
| 878 | { |
| 879 | CMergeDoc* pDoc = GetDocument(); |
| 880 | int nGroup = pDoc->GetActiveMergeView()->m_nThisGroup; |
| 881 | |
| 882 | if (nTopLine == -1) |
| 883 | nTopLine = pDoc->GetView(nGroup, 0)->GetTopSubLine(); |
| 884 | |
| 885 | if (nBottomLine == -1) |
| 886 | { |
| 887 | const int nScreenLines = pDoc->GetView(nGroup, 1)->GetScreenLines(); |
| 888 | nBottomLine = nTopLine + nScreenLines; |
| 889 | } |
| 890 | |
| 891 | const int lpx = pClientDC->GetDeviceCaps(LOGPIXELSX); |
| 892 | auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; |
| 893 | |
| 894 | CRect rc; |
| 895 | GetClientRect(rc); |
| 896 | int nbLines = INT_MAX; |
| 897 | pDoc->ForEachActiveGroupView([&](auto& pView) { |
| 898 | nbLines = min(nbLines, pView->GetSubLineCount()); |
| 899 | }); |
| 900 | |
| 901 | int nTopCoord = static_cast<int>(Y_OFFSET + |
| 902 | (static_cast<double>(nTopLine * m_lineInPix))); |
| 903 | int nBottomCoord = static_cast<int>(Y_OFFSET + |
| 904 | (static_cast<double>(nBottomLine * m_lineInPix))); |
| 905 | |
| 906 | double xbarBottom = min(nbLines / m_pixInLines + Y_OFFSET, rc.Height() - Y_OFFSET); |
| 907 | int barBottom = (int)xbarBottom; |
| 908 | // Make sure bottom coord is in bar range |
| 909 | nBottomCoord = min(nBottomCoord, barBottom); |
| 910 | |
| 911 | // Ensure visible area is at least minimum height |
| 912 | if (nBottomCoord - nTopCoord < INDICATOR_MIN_HEIGHT) |
| 913 | { |
| 914 | // If area is near top of file, add additional area to bottom |
| 915 | // of the bar and vice versa. |
| 916 | if (nTopCoord < Y_OFFSET + 20) |
| 917 | nBottomCoord += INDICATOR_MIN_HEIGHT - (nBottomCoord - nTopCoord); |
| 918 | else |
| 919 | { |
| 920 | // If we have a high number of lines, it may be better |
| 921 | // to keep the topline, otherwise the cursor can |
| 922 | // jump up and down unexpected |
| 923 | nBottomCoord = nTopCoord + INDICATOR_MIN_HEIGHT; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | // Store current values for later use (to check if area changes) |
| 928 | m_visibleTop = nTopCoord; |
| 929 | m_visibleBottom = nBottomCoord; |
| 930 | |
| 931 | CRect rcVisibleArea(2, m_visibleTop, rc.right - 2, m_visibleBottom); |
| 932 | std::unique_ptr<CBitmap> pBitmap(CopyRectToBitmap(pClientDC, rcVisibleArea)); |
| 933 | std::unique_ptr<CBitmap> pDarkenedBitmap(GetDarkenedBitmap(pClientDC, pBitmap.get(), pointToPixel(3), IsColorDark(GetBackgroundColor()))); |
| 934 | DrawBitmap(pClientDC, rcVisibleArea.left, rcVisibleArea.top, pDarkenedBitmap.get()); |
nothing calls this directly
no test coverage detected