示例#1
0
COLORREF AdjustLightness(COLORREF c, float factor)
{
    BYTE R = GetRValueSafe(c), G = GetGValueSafe(c), B = GetBValueSafe(c);
    // cf. http://en.wikipedia.org/wiki/HSV_color_space#Hue_and_chroma
    BYTE M = max(max(R, G), B), m = min(min(R, G), B);
    if (M == m) {
        // for grayscale values, lightness is proportional to the color value
        BYTE X = (BYTE)limitValue((int)floorf(M * factor + 0.5f), 0, 255);
        return RGB(X, X, X);
    }
    BYTE C = M - m;
    BYTE Ha = (BYTE)abs(M == R ? G - B : M == G ? B - R : R - G);
    // cf. http://en.wikipedia.org/wiki/HSV_color_space#Lightness
    float L2 = (float)(M + m);
    // cf. http://en.wikipedia.org/wiki/HSV_color_space#Saturation
    float S = C / (L2 > 255.0f ? 510.0f - L2 : L2);

    L2 = limitValue(L2 * factor, 0.0f, 510.0f);
    // cf. http://en.wikipedia.org/wiki/HSV_color_space#From_HSL
    float C1 = (L2 > 255.0f ? 510.0f - L2 : L2) * S;
    float X1 = C1 * Ha / C;
    float m1 = (L2 - C1) / 2;
    R = (BYTE)floorf((M == R ? C1 : m != R ? X1 : 0) + m1 + 0.5f);
    G = (BYTE)floorf((M == G ? C1 : m != G ? X1 : 0) + m1 + 0.5f);
    B = (BYTE)floorf((M == B ? C1 : m != B ? X1 : 0) + m1 + 0.5f);
    return RGB(R, G, B);
}
示例#2
0
void SetMainWndBgCol(EbookControls *ctrls)
{
    COLORREF bgColor = gGlobalPrefs->ebookUI.backgroundColor;
    if (gGlobalPrefs->useSysColors)
        bgColor = GetSysColor(COLOR_WINDOW);

    Style *styleMainWnd = StyleByName("styleMainWnd");
    CrashIf(!styleMainWnd);
    styleMainWnd->Set(Prop::AllocColorSolid(PropBgColor, GetRValueSafe(bgColor), GetGValueSafe(bgColor), GetBValueSafe(bgColor)));
    ctrls->mainWnd->SetStyle(styleMainWnd);

    Style *styleStatus = StyleByName("styleStatus");
    styleStatus->Set(Prop::AllocColorSolid(PropBgColor, GetRValueSafe(bgColor), GetGValueSafe(bgColor), GetBValueSafe(bgColor)));
    ctrls->status->SetStyle(styleStatus);

    // TODO: should also allow to change text color
    // TODO: also match the colors of progress bar to be based on background color

    // note: callers are expected to update the background of tree control and 
    // other colors that are supposed to match background color
}
示例#3
0
void UpdateBitmapColors(HBITMAP hbmp, COLORREF textColor, COLORREF bgColor)
{
    if ((textColor & 0xFFFFFF) == WIN_COL_BLACK &&
        (bgColor & 0xFFFFFF) == WIN_COL_WHITE)
        return;

    // color order in DIB is blue-green-red-alpha
    int base[4] = { GetBValueSafe(textColor), GetGValueSafe(textColor), GetRValueSafe(textColor), 0 };
    int diff[4] = {
        GetBValueSafe(bgColor) - base[0],
        GetGValueSafe(bgColor) - base[1],
        GetRValueSafe(bgColor) - base[2],
        255
    };

    HDC hDC = GetDC(NULL);
    BITMAPINFO bmi = { 0 };
    SizeI size = GetBitmapSize(hbmp);

    bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
    bmi.bmiHeader.biWidth = size.dx;
    bmi.bmiHeader.biHeight = size.dy;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;

    int bmpBytes = size.dx * size.dy * 4;
    ScopedMem<unsigned char> bmpData((unsigned char *)malloc(bmpBytes));
    CrashIf(!bmpData);
    if (GetDIBits(hDC, hbmp, 0, size.dy, bmpData, &bmi, DIB_RGB_COLORS)) {
        for (int i = 0; i < bmpBytes; i++) {
            int k = i % 4;
            bmpData[i] = (uint8_t)(base[k] + mul255(bmpData[i], diff[k]));
        }
        SetDIBits(hDC, hbmp, 0, size.dy, bmpData, &bmi, DIB_RGB_COLORS);
    }

    ReleaseDC(NULL, hDC);
}
示例#4
0
static inline Color ToColor(COLORREF c)
{
    return Color(GetRValueSafe(c), GetGValueSafe(c), GetBValueSafe(c));
}
示例#5
0
 Pen *LoadPen(Pen &p, COLORREF c, REAL width) {
     p.SetColor(Color(GetRValueSafe(c), GetGValueSafe(c), GetBValueSafe(c)));
     p.SetWidth(width);
     return &p;
 }
示例#6
0
 Brush *LoadBrush(SolidBrush &b, COLORREF c) {
     b.SetColor(Color(GetRValueSafe(c), GetGValueSafe(c), GetBValueSafe(c)));
     return &b;
 }