From 4cd1d196791755519f2a8024cdb6b91bdf05fa08 Mon Sep 17 00:00:00 2001 From: Benjamin Williams Date: Thu, 16 Nov 2006 08:25:09 +0000 Subject: [PATCH] use real alpha blending algorithm to avoid sickly looking colors on some platforms git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43440 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/aui/dockart.cpp | 53 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 5b94972ed5..b03d8ac28e 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -56,14 +56,57 @@ // wxAuiManager::SetDockArt() -wxColor wxAuiStepColour(const wxColor& c, int percent) +// wxAuiBlendColour is used by wxAuiStepColour +double wxAuiBlendColour(double fg, double bg, double alpha) { - int r = c.Red(), g = c.Green(), b = c.Blue(); - return wxColour((unsigned char)wxMin((r*percent)/100,255), - (unsigned char)wxMin((g*percent)/100,255), - (unsigned char)wxMin((b*percent)/100,255)); + double result = bg + (alpha * (fg - bg)); + if (result < 0.0) + result = 0.0; + if (result > 255) + result = 255; + return result; } +// wxAuiStepColour() it a utility function that simply darkens +// or lightens a color, based on the specified percentage +// ialpha of 0 would be completely black, 100 completely white +// an ialpha of 100 returns the same colour +wxColor wxAuiStepColour(const wxColor& c, int ialpha) +{ + if (ialpha == 100) + return c; + + double r = c.Red(), g = c.Green(), b = c.Blue(); + double bg; + + // ialpha is 0..200 where 0 is completely black + // and 200 is completely white and 100 is the same + // convert that to normal alpha 0.0 - 1.0 + ialpha = wxMin(ialpha, 200); + ialpha = wxMax(ialpha, 0); + double alpha = ((double)(ialpha - 100.0))/100.0; + + if (ialpha > 100) + { + // blend with white + bg = 255.0; + alpha = 1.0 - alpha; // 0 = transparent fg; 1 = opaque fg + } + else + { + // blend with black + bg = 0.0; + alpha = 1.0 + alpha; // 0 = transparent fg; 1 = opaque fg + } + + r = wxAuiBlendColour(r, bg, alpha); + g = wxAuiBlendColour(g, bg, alpha); + b = wxAuiBlendColour(b, bg, alpha); + + return wxColour((int)r, (int)g, (int)b); +} + + wxColor wxAuiLightContrastColour(const wxColour& c) { int amount = 120;