* @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);
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);
BAR_YAREA, /**< Y-Coord in bar area */
};
-const COLORREF clrBackground = RGB(0xe4, 0xe4, 0xf4);
-
/////////////////////////////////////////////////////////////////////////////
// CLocationView
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.
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);
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);
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());
}