wxBitmap ConvertTo24Bit( wxColor bgColor, wxBitmap front ) { if( front.GetDepth() == 24 ) return front; wxBitmap result( front.GetWidth(), front.GetHeight(), 24 ); front.UseAlpha(); wxImage im_front = front.ConvertToImage(); wxImage im_result = result.ConvertToImage(); unsigned char *presult = im_result.GetData(); unsigned char *pfront = im_front.GetData(); unsigned char *afront = NULL; if( im_front.HasAlpha() ) afront = im_front.GetAlpha(); for( int i = 0; i < result.GetWidth(); i++ ) { for( int j = 0; j < result.GetHeight(); j++ ) { double alphaF = (double) ( *afront++ ) / 256.0; unsigned char r = *pfront++ * alphaF + bgColor.Red() * ( 1.0 - alphaF ); *presult++ = r; unsigned char g = *pfront++ * alphaF + bgColor.Green() * ( 1.0 - alphaF ); *presult++ = g; unsigned char b = *pfront++ * alphaF + bgColor.Blue() * ( 1.0 - alphaF ); *presult++ = b; } } result = wxBitmap( im_result ); return result; }
// StepColour() it a utility function that simply darkens // or lightens a color, based on the specified percentage static wxColor StepColour(const wxColor& c, int percent) { 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)); }
static wxColor wxStepColour(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 = wxBlendColour(r, bg, alpha); g = wxBlendColour(g, bg, alpha); b = wxBlendColour(b, bg, alpha); return wxColour((unsigned char)r, (unsigned char)g, (unsigned char)b); }
void Overlay::bg_color_updated(const wxColor& bg) { if (0.299*bg.Red() + 0.587*bg.Green() + 0.114*bg.Blue() < 128) color_.Set(192, 192, 192); else color_.Set(64, 64, 64); }
wxColor TextColorFromBG(const wxColor& bg) { int gray = 77 * bg.Red() + 151 * bg.Green() + 28 * bg.Blue(); gray >>= 8; gray = gray < 128 ? 255 : 0; return wxColor(gray, gray, gray); }
String entityColorAsString(const wxColor& color, const Assets::ColorRange::Type colorRange) { StringStream result; if (colorRange == Assets::ColorRange::Byte) { result << int(color.Red()) << " " << int(color.Green()) << " " << int(color.Blue()); } else if (colorRange == Assets::ColorRange::Float) { result << float(color.Red()) / 255.0f << " " << float(color.Green()) / 255.0f << " "<< float(color.Blue()) / 255.0f; } return result.str(); }
wxColor CodeEdit::GetInverse(const wxColor& color) { unsigned char r = color.Red(); unsigned char g = color.Green(); unsigned char b = color.Blue(); return wxColor( r ^ 0xFF, g ^ 0xFF, b ^ 0xFF ); }
wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const wxColor& col) { //wxDC::DrawLabel() doesn't respect alpha channel => calculate alpha values manually: if (text.empty()) return wxImage(); wxBitmap newBitmap(getTextExtent(text, font)); //seems we don't need to pass 24-bit depth here even for high-contrast color schemes { wxMemoryDC dc(newBitmap); dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); dc.SetTextForeground(*wxBLACK); //for use in calcAlphaForBlackWhiteImage dc.SetTextBackground(*wxWHITE); // dc.SetFont(font); //assert(!contains(text, L"&")); //accelerator keys not supported here; see also getTextExtent() wxString textFmt = replaceCpy(text, L"&", L"", false); //for some reason wxDC::DrawText messes up "weak" bidi characters even when wxLayout_RightToLeft is set! (--> arrows in hebrew/arabic) //=> use mark characters instead: const wchar_t rtlMark = L'\u200F'; if (wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft) textFmt = rtlMark + textFmt + rtlMark; dc.DrawText(textFmt, wxPoint()); } wxImage output(newBitmap.ConvertToImage()); output.SetAlpha(); //calculate alpha channel calcAlphaForBlackWhiteImage(output); //apply actual text color unsigned char* dataPtr = output.GetData(); const int pixelCount = output.GetWidth() * output.GetHeight(); for (int i = 0; i < pixelCount; ++ i) { *dataPtr++ = col.Red(); *dataPtr++ = col.Green(); *dataPtr++ = col.Blue(); } return output; }
bool readColor(const Json::Value& json, const std::string& prop, wxColor& color) { if(json.isMember(prop)) { wxString tempStr = json[prop].asString(); color.Set(tempStr); return true; } return false; }
void MadHighlightingDialog::SetPanelBC(const wxColor &color) { if(color==wxNullColour) { WxStaticTextBCName->SetLabel(wxT("(Automatic)")); WxPanelBC->SetBackgroundColour(WxListCtrlBC->GetItemBackgroundColour(0)); WxPanelBC->ClearBackground(); } else { wxString cname=wxTheColourDatabase->FindName(color); if(cname.IsEmpty()) { cname.Printf(wxT("#%02X%02X%02X"), color.Red(), color.Green(), color.Blue()); } WxStaticTextBCName->SetLabel(cname); WxPanelBC->SetBackgroundColour(color); WxPanelBC->ClearBackground(); } }
wxColor wxGradient::lerp(wxColor c1, wxColor c2, double value) { unsigned char R = (1.0 - value)*c1.Red() + value*c2.Red(); unsigned char G = (1.0 - value)*c1.Green() + value*c2.Green(); unsigned char B = (1.0 - value)*c1.Blue() + value*c2.Blue(); return wxColor(R,G,B); }
void wxAuiDefaultDockArt::SetColour(int id, const wxColor& colour) { switch (id) { case wxAUI_DOCKART_BACKGROUND_COLOUR: m_backgroundBrush.SetColour(colour); break; case wxAUI_DOCKART_SASH_COLOUR: m_sashBrush.SetColour(colour); break; case wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR: m_inactiveCaptionColour = colour; break; case wxAUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR: m_inactiveCaptionGradientColour = colour; break; case wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR: m_inactiveCaptionTextColour = colour; break; case wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR: m_activeCaptionColour = colour; break; case wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR: m_activeCaptionGradientColour = colour; break; case wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR: m_activeCaptionTextColour = colour; break; case wxAUI_DOCKART_BORDER_COLOUR: m_borderPen.SetColour(colour); break; case wxAUI_DOCKART_GRIPPER_COLOUR: m_gripperBrush.SetColour(colour); m_gripperPen1.SetColour(colour.ChangeLightness(40)); m_gripperPen2.SetColour(colour.ChangeLightness(60)); break; default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break; } InitBitmaps(); }
PMSColor::PMSColor(wxColor col) : blue{col.Blue()}, green{col.Green()}, red{col.Red()}, alpha{col.Alpha()} { }
static wxColour TransparentColor(wxColor c) { return wxColor(c.Red(), c.Green(), c.Blue(), c.Alpha()*7/24); }
wxColor CamArtProvider::DarkenColour(const wxColor& c, INT32 amount) { INT32 r = c.Red(), g = c.Green(), b = c.Blue(); return wxColour((r*amount)/100, (g*amount)/100, (b*amount)/100); }
wxColor CamArtProvider::LightenColour(const wxColor& c, INT32 amount) { INT32 r = 255-c.Red(), g = 255-c.Green(), b = 255-c.Blue(); return wxColour(255-(r*amount)/100, 255-(g*amount)/100, 255-(b*amount)/100); }
std::string colorAsString(const wxColor& c) { return c.GetAsString().ToStdString(); }