OSDN Git Service

LocationView: Make the color close to the background color of the editor the backgrou...
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Mon, 17 Feb 2020 23:01:23 +0000 (08:01 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Mon, 17 Feb 2020 23:05:05 +0000 (08:05 +0900)
Src/Common/Bitmap.cpp
Src/Common/Bitmap.h
Src/LocationView.cpp
Src/LocationView.h

index 945cad4..657a0e9 100644 (file)
@@ -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<BYTE[]> 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<int>(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);
index ac16fc6..b127382 100644 (file)
@@ -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);
index aa504fb..94d0fd6 100644 (file)
@@ -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<CBitmap> pBitmap(CopyRectToBitmap(pClientDC, rcVisibleArea));
-       std::unique_ptr<CBitmap> pDarkenedBitmap(GetDarkenedBitmap(pClientDC, pBitmap.get()));
+       std::unique_ptr<CBitmap> pDarkenedBitmap(GetDarkenedBitmap(pClientDC, pBitmap.get(), IsColorDark(GetBackgroundColor())));
        DrawBitmap(pClientDC, rcVisibleArea.left, rcVisibleArea.top, pDarkenedBitmap.get());
 }
 
index a5708fa..7f139d6 100644 (file)
@@ -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: