// Evaluates the colors for the tab's elements. void EvaluateColors(bool force=false) { COLORREF bg, txt; if (inTitlebar) { WindowInfo *win = FindWindowInfoByHwnd(hwnd); bg = win->caption->bgColor; txt = win->caption->textColor; } else { bg = GetSysColor(TAB_COLOR_BG); txt = GetSysColor(TAB_COLOR_TEXT); } if (!force && bg == color.bar && txt == color.text) return; color.bar = bg; color.text = txt; int sign = GetLightness(color.text) > GetLightness(color.bar) ? -1 : 1; color.current = AdjustLightness2(color.bar, sign * 25.0f); color.highlight = AdjustLightness2(color.bar, sign * 15.0f); color.background = AdjustLightness2(color.bar, -sign * 15.0f); color.outline = AdjustLightness2(color.bar, -sign * 60.0f); color.x_line = COL_CLOSE_X_HOVER; color.x_highlight = COL_CLOSE_HOVER_BG; color.x_click = AdjustLightness2(color.x_highlight, -10.0f); if (currBgCol != DEFAULT_CURRENT_BG_COL) { color.current = currBgCol; } }
// Adjusts lightness by 1/255 units. COLORREF AdjustLightness2(COLORREF c, float units) { float lightness = GetLightness(c); units = limitValue(units, -lightness, 255.0f - lightness); if (0.0f == lightness) return RGB(BYTE(units + 0.5f), BYTE(units + 0.5f), BYTE(units + 0.5f)); return AdjustLightness(c, 1.0f + units / lightness); }
void UpdateTocColors(WindowInfo *win) { COLORREF labelBgCol = GetSysColor(COLOR_BTNFACE); COLORREF labelTxtCol = GetSysColor(COLOR_BTNTEXT); COLORREF treeBgCol = (DWORD)-1; COLORREF splitterCol = GetSysColor(COLOR_BTNFACE); bool flatTreeWnd = false; if (win->AsEbook() && !gGlobalPrefs->useSysColors) { labelBgCol = gGlobalPrefs->ebookUI.backgroundColor; labelTxtCol = gGlobalPrefs->ebookUI.textColor; treeBgCol = labelBgCol; float factor = 14.f; int sign = GetLightness(labelBgCol) + factor > 255 ? 1 : -1; splitterCol = AdjustLightness2(labelBgCol, sign * factor); flatTreeWnd = true; } TreeView_SetBkColor(win->hwndTocTree, treeBgCol); SetBgCol(win->tocLabelWithClose, labelBgCol); SetTextCol(win->tocLabelWithClose, labelTxtCol); SetBgCol(win->sidebarSplitter, splitterCol); ToggleWindowStyle(win->hwndTocTree, WS_EX_STATICEDGE, !flatTreeWnd, GWL_EXSTYLE); SetWindowPos(win->hwndTocTree, nullptr, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); // TODO: if we have favorites in ebook view, we'll need this //SetBgCol(win->favLabelWithClose, labelBgCol); //SetTextCol(win->favLabelWithClose, labelTxtCol); //SetBgCol(win->favSplitter, labelTxtCol); // TODO: more work needed to to ensure consistent look of the ebook window: // - tab bar should match the color // - change the tree item text color // - change the tree item background color when selected (for both focused and non-focused cases) // - ultimately implement owner-drawn scrollbars in a simpler style (like Chrome or VS 2013) // and match their colors as well }
// Paints the tabs that intersect the window's update rectangle. void Paint(HDC hdc, RECT &rc) { IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom); // paint the background bool isTranslucentMode = inTitlebar && dwm::IsCompositionEnabled(); if (isTranslucentMode) PaintParentBackground(hwnd, hdc); else { HBRUSH brush = CreateSolidBrush(color.bar); FillRect(hdc, &rc, brush); DeleteObject(brush); } // TODO: GDI+ doesn't seem to cope well with SetWorldTransform XFORM ctm = { 1.0, 0, 0, 1.0, 0, 0 }; SetWorldTransform(hdc, &ctm); Graphics graphics(hdc); graphics.SetCompositingMode(CompositingModeSourceCopy); graphics.SetCompositingQuality(CompositingQualityHighQuality); graphics.SetSmoothingMode(SmoothingModeHighQuality); graphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit); graphics.SetPageUnit(UnitPixel); GraphicsPath shapes(data->Points, data->Types, data->Count); GraphicsPath shape; GraphicsPathIterator iterator(&shapes); SolidBrush br(Color(0, 0, 0)); Pen pen(&br, 2.0f); Font f(hdc, GetDefaultGuiFont()); // TODO: adjust these constant values for DPI? RectF layout((REAL)DpiScaleX(hwnd,3), 1.0f, REAL(width - DpiScaleX(hwnd,20)), (REAL)height); StringFormat sf(StringFormat::GenericDefault()); sf.SetFormatFlags(StringFormatFlagsNoWrap); sf.SetLineAlignment(StringAlignmentCenter); sf.SetTrimming(StringTrimmingEllipsisCharacter); REAL yPosTab = inTitlebar ? 0.0f : REAL(ClientRect(hwnd).dy - height - 1); for (int i = 0; i < Count(); i++) { graphics.ResetTransform(); graphics.TranslateTransform(1.f + (REAL)(width + 1) * i - (REAL)rc.left, yPosTab - (REAL)rc.top); if (!graphics.IsVisible(0, 0, width + 1, height + 1)) continue; // in firefox style we only paint current and highlighed tabs // all other tabs only show bool onlyText = g_FirefoxStyle && !((current == i) || (highlighted == i)); if (onlyText) { #if 0 // we need to first paint the background with the same color as caption, // otherwise the text looks funny (because is transparent?) // TODO: what is the damn bg color of caption? bar is too light, outline is too dark Color bgColTmp; bgColTmp.SetFromCOLORREF(color.bar); { SolidBrush bgBr(bgColTmp); graphics.FillRectangle(&bgBr, layout); } bgColTmp.SetFromCOLORREF(color.outline); { SolidBrush bgBr(bgColTmp); graphics.FillRectangle(&bgBr, layout); } #endif // TODO: this is a hack. If I use no background and cleartype, the // text looks funny (is bold). // CompositingModeSourceCopy doesn't work with clear type // another option is to draw background before drawing text, but // I can't figure out what is the actual color of caption graphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit); graphics.SetCompositingMode(CompositingModeSourceCopy); //graphics.SetCompositingMode(CompositingModeSourceOver); br.SetColor(ToColor(color.text)); graphics.DrawString(text.At(i), -1, &f, layout, &sf, &br); graphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit); continue; } COLORREF bgCol = color.background;; if (current == i) { bgCol = color.current; } else if (highlighted == i) { bgCol = color.highlight; } // ensure contrast between text and background color // TODO: adjust threshold (and try adjusting both current/background tabs) COLORREF textCol = color.text; float bgLight = GetLightness(bgCol), textLight = GetLightness(textCol); if (textLight < bgLight ? bgLight < 0x70 : bgLight > 0x90) textCol = textLight ? AdjustLightness(textCol, 255.0f / textLight - 1.0f) : RGB(255, 255, 255); if (fabs(textLight - bgLight) < 0x40) textCol = bgLight < 0x80 ? RGB(255, 255, 255) : RGB(0, 0, 0); // paint tab's body graphics.SetCompositingMode(CompositingModeSourceCopy); iterator.NextMarker(&shape); br.SetColor(ToColor(bgCol)); graphics.FillPath(&br, &shape); // draw tab's text graphics.SetCompositingMode(CompositingModeSourceOver); br.SetColor(ToColor(textCol)); graphics.DrawString(text.At(i), -1, &f, layout, &sf, &br); // paint "x"'s circle iterator.NextMarker(&shape); if (xClicked == i || xHighlighted == i) { br.SetColor(ToColor(i == xClicked ? color.x_click : color.x_highlight)); graphics.FillPath(&br, &shape); } // paint "x" iterator.NextMarker(&shape); if (xClicked == i || xHighlighted == i) pen.SetColor(ToColor(color.x_line)); else pen.SetColor(ToColor(color.outline)); graphics.DrawPath(&pen, &shape); iterator.Rewind(); } }