Applied part of #10034: wxImage::ConvertToDisabled()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62099 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -149,6 +149,97 @@ wxString wxColourBase::GetAsString(long flags) const
|
||||
return colName;
|
||||
}
|
||||
|
||||
// static
|
||||
void wxColourBase::MakeMono(unsigned char* r, unsigned char* g, unsigned char* b,
|
||||
bool on)
|
||||
{
|
||||
*r = *g = *b = on ? 255 : 0;
|
||||
}
|
||||
|
||||
// static
|
||||
void wxColourBase::MakeGrey(unsigned char* r, unsigned char* g, unsigned char* b
|
||||
/*, unsigned char brightness */
|
||||
)
|
||||
{
|
||||
*r = *g = *b = (wxByte)(((*b)*117UL + (*g)*601UL + (*r)*306UL) >> 10);
|
||||
}
|
||||
|
||||
// static
|
||||
void wxColourBase::MakeGrey(unsigned char* r, unsigned char* g, unsigned char* b,
|
||||
double weight_r, double weight_g, double weight_b)
|
||||
{
|
||||
double luma = (*r) * weight_r + (*g) * weight_g + (*b) * weight_b;
|
||||
*r = *g = *b = (wxByte)wxRound(luma);
|
||||
}
|
||||
|
||||
// static
|
||||
void wxColourBase::MakeDisabled(unsigned char* r, unsigned char* g, unsigned char* b,
|
||||
unsigned char brightness)
|
||||
{
|
||||
//MakeGrey(r, g, b, brightness); // grey no-blend version
|
||||
*r = AlphaBlend(*r, brightness, 0.4);
|
||||
*g = AlphaBlend(*g, brightness, 0.4);
|
||||
*b = AlphaBlend(*b, brightness, 0.4);
|
||||
}
|
||||
|
||||
// AlphaBlend is used by ChangeLightness and MakeDisabled
|
||||
|
||||
// static
|
||||
unsigned char wxColourBase::AlphaBlend(unsigned char fg, unsigned char bg,
|
||||
double alpha)
|
||||
{
|
||||
double result = bg + (alpha * (fg - bg));
|
||||
result = wxMax(result, 0.0);
|
||||
result = wxMin(result, 255.0);
|
||||
return (unsigned char)result;
|
||||
}
|
||||
|
||||
// ChangeLightness() is 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
|
||||
|
||||
// static
|
||||
void wxColourBase::ChangeLightness(unsigned char* r, unsigned char* g, unsigned char* b,
|
||||
int ialpha)
|
||||
{
|
||||
if (ialpha == 100) return;
|
||||
|
||||
// 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 = wxMax(ialpha, 0);
|
||||
ialpha = wxMin(ialpha, 200);
|
||||
double alpha = ((double)(ialpha - 100.0))/100.0;
|
||||
|
||||
unsigned char bg;
|
||||
if (ialpha > 100)
|
||||
{
|
||||
// blend with white
|
||||
bg = 255;
|
||||
alpha = 1.0 - alpha; // 0 = transparent fg; 1 = opaque fg
|
||||
}
|
||||
else
|
||||
{
|
||||
// blend with black
|
||||
bg = 0;
|
||||
alpha = 1.0 + alpha; // 0 = transparent fg; 1 = opaque fg
|
||||
}
|
||||
|
||||
*r = AlphaBlend(*r, bg, alpha);
|
||||
*g = AlphaBlend(*g, bg, alpha);
|
||||
*b = AlphaBlend(*b, bg, alpha);
|
||||
}
|
||||
|
||||
wxColour wxColourBase::ChangeLightness(int ialpha) const
|
||||
{
|
||||
wxByte r = Red();
|
||||
wxByte g = Green();
|
||||
wxByte b = Blue();
|
||||
ChangeLightness(&r, &g, &b, ialpha);
|
||||
return wxColour(r,g,b);
|
||||
}
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
// static
|
||||
|
||||
Reference in New Issue
Block a user