From 82ed0aa199512e5e5e586aac68bce6f4a3ea35df Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Tue, 18 Feb 2020 08:01:23 +0900 Subject: [PATCH] LocationView: Make the color close to the background color of the editor the background color of the location pane --- Src/Common/Bitmap.cpp | 97 ++++++++++++++++++++++++++++++++++++--------------- Src/Common/Bitmap.h | 2 +- Src/LocationView.cpp | 30 +++++++++++++--- Src/LocationView.h | 1 + 4 files changed, 95 insertions(+), 35 deletions(-) diff --git a/Src/Common/Bitmap.cpp b/Src/Common/Bitmap.cpp index 945cad439..657a0e93b 100644 --- a/Src/Common/Bitmap.cpp +++ b/Src/Common/Bitmap.cpp @@ -56,9 +56,10 @@ void DrawBitmap(CDC *pDC, int x, int y, CBitmap *pBitmap) * @brief Duplicate a bitmap and make it dark * @param pDC [in] Device context * @param pBitmap [in] the bitmap to darken + * @param lighten [in] make bitmap lighten if ligthen is true * @return The bitmap object */ -CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap) +CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap, bool lighten) { CDC dcMem; dcMem.CreateCompatibleDC(pDC); @@ -85,39 +86,77 @@ CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap) std::unique_ptr pbuf(new BYTE[bi.bmiHeader.biSizeImage]); GetDIBits(dcMem.m_hDC, (HBITMAP)*pBitmapDarkened, 0, bm.bmHeight, pbuf.get(), &bi, DIB_RGB_COLORS); - int x; - for (x = 0; x < bm.bmWidth; x++) + if (!lighten) { - double b = 0.85 + (0.10 * sin(acos((double)x/bm.bmWidth*2.0-1.0))); - for (int y = 1; y < bm.bmHeight-1; y++) + for (int x = 0; x < bm.bmWidth; x++) { - int i = x * 4 + y * bm.bmWidth * 4; - pbuf[i ] = (BYTE)(pbuf[i] * 0.95); - pbuf[i+1] = (BYTE)(pbuf[i+1] * b); - pbuf[i+2] = (BYTE)(pbuf[i+2] * b); + double b = 0.85 + (0.10 * sin(acos((double)x / bm.bmWidth*2.0 - 1.0))); + for (int y = 1; y < bm.bmHeight - 1; y++) + { + int i = x * 4 + y * bm.bmWidth * 4; + pbuf[i] = (BYTE)(pbuf[i] * 0.95); + pbuf[i + 1] = (BYTE)(pbuf[i + 1] * b); + pbuf[i + 2] = (BYTE)(pbuf[i + 2] * b); + } + } + for (int x = 0; x < bm.bmWidth; x++) + { + int i = x * 4 + 0 * bm.bmWidth * 4; + pbuf[i] = (BYTE)(pbuf[i] * 0.95); + pbuf[i + 1] = (BYTE)(pbuf[i + 1] * 0.9); + pbuf[i + 2] = (BYTE)(pbuf[i + 2] * 0.9); + i = x * 4 + (bm.bmHeight - 1) * bm.bmWidth * 4; + pbuf[i] = (BYTE)(pbuf[i] * 0.95); + pbuf[i + 1] = (BYTE)(pbuf[i + 1] * 0.9); + pbuf[i + 2] = (BYTE)(pbuf[i + 2] * 0.9); + } + for (int y = 0; y < bm.bmHeight; y++) + { + int i = 0 * 4 + y * bm.bmWidth * 4; + pbuf[i] = (BYTE)(pbuf[i] * 0.95); + pbuf[i + 1] = (BYTE)(pbuf[i + 1] * 0.9); + pbuf[i + 2] = (BYTE)(pbuf[i + 2] * 0.9); + i = (bm.bmWidth - 1) * 4 + y * bm.bmWidth * 4; + pbuf[i] = (BYTE)(pbuf[i] * 0.95); + pbuf[i + 1] = (BYTE)(pbuf[i + 1] * 0.9); + pbuf[i + 2] = (BYTE)(pbuf[i + 2] * 0.9); } } - for (x = 0; x < bm.bmWidth; x++) - { - int i = x * 4 + 0 * bm.bmWidth * 4; - pbuf[i ] = (BYTE)(pbuf[i] * 0.95); - pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.9); - pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.9); - i = x * 4 + (bm.bmHeight-1) * bm.bmWidth * 4; - pbuf[i ] = (BYTE)(pbuf[i] * 0.95); - pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.9); - pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.9); - } - for (int y = 0; y < bm.bmHeight; y++) + else { - int i = 0 * 4 + y * bm.bmWidth * 4; - pbuf[i ] = (BYTE)(pbuf[i] * 0.95); - pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.9); - pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.9); - i = (bm.bmWidth-1) * 4 + y * bm.bmWidth * 4; - pbuf[i ] = (BYTE)(pbuf[i] * 0.95); - pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.9); - pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.9); + for (int x = 0; x < bm.bmWidth; x++) + { + int b = static_cast(12.0 + (20.0 * sin(acos((double)x / bm.bmWidth*2.0 - 1.0)))); + for (int y = 1; y < bm.bmHeight - 1; y++) + { + int i = x * 4 + y * bm.bmWidth * 4; + pbuf[i] = (BYTE)((std::min)(pbuf[i] + 40, 255)); + pbuf[i + 1] = (BYTE)((std::min)(pbuf[i + 1] + b, 255)); + pbuf[i + 2] = (BYTE)((std::min)(pbuf[i + 2] + b, 255)); + } + } + for (int x = 0; x < bm.bmWidth; x++) + { + int i = x * 4 + 0 * bm.bmWidth * 4; + pbuf[i] = (BYTE)((std::min)(pbuf[i] + 40, 255)); + pbuf[i + 1] = (BYTE)((std::min)(pbuf[i + 1] + 32, 255)); + pbuf[i + 2] = (BYTE)((std::min)(pbuf[i + 2] + 32, 255)); + i = x * 4 + (bm.bmHeight - 1) * bm.bmWidth * 4; + pbuf[i] = (BYTE)((std::min)(pbuf[i] + 40, 255)); + pbuf[i + 1] = (BYTE)((std::min)(pbuf[i + 1] + 32, 255)); + pbuf[i + 2] = (BYTE)((std::min)(pbuf[i + 2] + 32, 255)); + } + for (int y = 0; y < bm.bmHeight; y++) + { + int i = 0 * 4 + y * bm.bmWidth * 4; + pbuf[i] = (BYTE)((std::min)(pbuf[i] + 40, 255)); + pbuf[i + 1] = (BYTE)((std::min)(pbuf[i + 1] + 32, 255)); + pbuf[i + 2] = (BYTE)((std::min)(pbuf[i + 2] + 32, 255)); + i = (bm.bmWidth - 1) * 4 + y * bm.bmWidth * 4; + pbuf[i] = (BYTE)((std::min)(pbuf[i] + 40, 255)); + pbuf[i + 1] = (BYTE)((std::min)(pbuf[i + 1] + 32, 255)); + pbuf[i + 2] = (BYTE)((std::min)(pbuf[i + 2] + 32, 255)); + } } SetDIBits(dcMem.m_hDC, (HBITMAP)*pBitmapDarkened, 0, bm.bmHeight, pbuf.get(), &bi, DIB_RGB_COLORS); diff --git a/Src/Common/Bitmap.h b/Src/Common/Bitmap.h index ac16fc68a..b127382af 100644 --- a/Src/Common/Bitmap.h +++ b/Src/Common/Bitmap.h @@ -13,6 +13,6 @@ namespace ATL { class CImage; } CBitmap *CopyRectToBitmap(CDC *pDC, const CRect & rect); void DrawBitmap(CDC *pDC, int x, int y, CBitmap *pBitmap); -CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap); +CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap, bool lighten = false); bool GrayScale(CBitmap *pBitmap); bool LoadImageFromResource(ATL::CImage& image, const TCHAR *pName, const TCHAR *pType); diff --git a/Src/LocationView.cpp b/Src/LocationView.cpp index aa504fb2c..94d0fd611 100644 --- a/Src/LocationView.cpp +++ b/Src/LocationView.cpp @@ -73,8 +73,6 @@ enum LOCBAR_TYPE BAR_YAREA, /**< Y-Coord in bar area */ }; -const COLORREF clrBackground = RGB(0xe4, 0xe4, 0xf4); - ///////////////////////////////////////////////////////////////////////////// // CLocationView @@ -175,6 +173,28 @@ BOOL CLocationView::OnEraseBkgnd(CDC* pDC) return FALSE; } +static bool IsColorDark(COLORREF clrBackground) +{ + return !(GetRValue(clrBackground) >= 0x80 || GetGValue(clrBackground) >= 0x80 || GetBValue(clrBackground) >= 0x80); + +} + +COLORREF CLocationView::GetBackgroundColor() +{ + COLORREF clrBackground = GetDocument()->GetView(0, 0)->GetColor(COLORINDEX_WHITESPACE); + if (!IsColorDark(clrBackground)) + { + return RGB( + (std::max)(GetRValue(clrBackground) - 24, 0), + (std::max)(GetGValue(clrBackground) - 24, 0), + (std::max)(GetBValue(clrBackground) - 12, 0)); + } + return RGB( + (std::min)(GetRValue(clrBackground) + 20, 255), + (std::min)(GetGValue(clrBackground) + 20, 255), + (std::min)(GetBValue(clrBackground) + 32, 255)); +} + /** * @brief Draw custom (non-white) background. * @param [in] pDC Pointer to draw context. @@ -182,7 +202,7 @@ BOOL CLocationView::OnEraseBkgnd(CDC* pDC) void CLocationView::DrawBackground(CDC* pDC) { // Set brush to desired background color - CBrush backBrush(clrBackground); + CBrush backBrush(GetBackgroundColor()); // Save old brush CBrush* pOldBrush = pDC->SelectObject(&backBrush); @@ -389,7 +409,7 @@ void CLocationView::OnDraw(CDC* pDC) CalculateBars(); DrawBackground(&dc); - COLORREF clrFace = clrBackground; + COLORREF clrFace = GetBackgroundColor(); COLORREF clrShadow = GetSysColor(COLOR_BTNSHADOW); COLORREF clrShadow2 = GetIntermediateColor(clrFace, clrShadow, 0.9f); COLORREF clrShadow3 = GetIntermediateColor(clrFace, clrShadow2, 0.5f); @@ -961,7 +981,7 @@ void CLocationView::DrawVisibleAreaRect(CDC *pClientDC, int nTopLine, int nBotto CRect rcVisibleArea(2, m_visibleTop, rc.right - 2, m_visibleBottom); std::unique_ptr pBitmap(CopyRectToBitmap(pClientDC, rcVisibleArea)); - std::unique_ptr pDarkenedBitmap(GetDarkenedBitmap(pClientDC, pBitmap.get())); + std::unique_ptr pDarkenedBitmap(GetDarkenedBitmap(pClientDC, pBitmap.get(), IsColorDark(GetBackgroundColor()))); DrawBitmap(pClientDC, rcVisibleArea.left, rcVisibleArea.top, pDarkenedBitmap.get()); } diff --git a/Src/LocationView.h b/Src/LocationView.h index a5708fad2..7f139d675 100644 --- a/Src/LocationView.h +++ b/Src/LocationView.h @@ -92,6 +92,7 @@ protected: void CalculateBlocks(); void CalculateBlocksPixel(int nBlockStart, int nBlockEnd, int nBlockLength, int &nBeginY, int &nEndY); + COLORREF GetBackgroundColor(); void DrawBackground(CDC* pDC); private: -- 2.11.0