WXHBRUSH wxControl::DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) { HDC hdc = (HDC)pDC; WXHBRUSH hbr = 0; if ( !colBg.IsOk() ) { if ( wxWindow *win = wxFindWinFromHandle(hWnd) ) hbr = win->MSWGetBgBrush(pDC); // if the control doesn't have any bg colour, foreground colour will be // ignored as the return value would be 0 -- so forcefully give it a // non default background brush in this case if ( !hbr && m_hasFgCol ) colBg = GetBackgroundColour(); } // use the background colour override if a valid colour is given: this is // used when the control is disabled to grey it out and also if colBg was // set just above if ( colBg.IsOk() ) { wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBg); hbr = (WXHBRUSH)brush->GetResourceHandle(); } // always set the foreground colour if we changed the background, whether // m_hasFgCol is true or not: if it true, we must do it, of course, but // even if it isn't, we must set the default foreground explicitly as by // default just the simple black is used if ( hbr ) { ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); } // finally also set the background colour for text drawing: without this, // the text in an edit control is drawn using the default background even // if we return a valid brush if ( colBg.IsOk() || m_hasBgCol ) { if ( !colBg.IsOk() ) colBg = GetBackgroundColour(); ::SetBkColor(hdc, wxColourToRGB(colBg)); } return hbr; }
void colorPatternArea::OnMouse(wxMouseEvent &event) { if (mID < kNumPatterns && event.LeftDClick()) { patternSelectDlg selector(this); if (selector.ShowModal() == wxOK) { } } if (mID >= ID_BITMAP_SLT && mID < ID_BITMAP_SLT + kNumPatterns) //exclude color areas in the left panel { if ( mID >= ID_BITMAP_SLT && (event.Entering() || mID == dynamic_cast<patternSelectDlg*>(mParent)->getSltId()) ) { //"distance" of two colors if ( pow((float)(mCurrentColor.Red()-defaultColor.Red()),2.0f) + pow((float)(mCurrentColor.Green()-defaultColor.Green()),2.0f) + pow((float)(mCurrentColor.Blue()-defaultColor.Blue()),2.0f) < 500) SetBackgroundColour(wxColour(68,68,68)); else SetBackgroundColour(defaultColor); } if ( event.Leaving() && mID >= ID_BITMAP_SLT && mPatID != dynamic_cast<patternSelectDlg*>(mParent)->getSltPatId() ) SetBackgroundColour(mCurrentColor); if (event.LeftDown() && mID >= ID_BITMAP_SLT) { dynamic_cast<patternSelectDlg*>(mParent)->setSltId(mID); } } }
void LexerConf::SetDefaultFgColour(const wxColour& colour) { StyleProperty& style = GetProperty(0); if(!style.IsNull()) { style.SetFgColour(colour.GetAsString(wxC2S_HTML_SYNTAX)); } }
wxColor DrawingUtils::DarkColour(const wxColour& color, float percent) { if(percent == 0) { return color; } float h, s, l, r, g, b; RGB_2_HSL(color.Red(), color.Green(), color.Blue(), &h, &s, &l); // reduce the Lum value l -= (float)((percent * 5.0)/100.0); if (l < 0) l = 0.0; HSL_2_RGB(h, s, l, &r, &g, &b); return wxColour((unsigned char)r, (unsigned char)g, (unsigned char)b); }
bool wxVListBox::DoDrawSolidBackground(const wxColour& col, wxDC& dc, const wxRect& rect, size_t n) const { if ( !col.IsOk() ) return false; // we need to render selected and current items differently const bool isSelected = IsSelected(n), isCurrent = IsCurrent(n); if ( isSelected || isCurrent ) { if ( isSelected ) { dc.SetBrush(wxBrush(col, wxBRUSHSTYLE_SOLID)); } else // !selected { dc.SetBrush(*wxTRANSPARENT_BRUSH); } dc.SetPen(*(isCurrent ? wxBLACK_PEN : wxTRANSPARENT_PEN)); dc.DrawRectangle(rect); } //else: do nothing for the normal items return true; }
// Call ParseInner() preserving background colour and mode after any // changes done by it. void CallParseInnerWithBg(const wxHtmlTag& tag, const wxColour& colBg) { const wxColour oldbackclr = m_WParser->GetActualBackgroundColor(); const int oldbackmode = m_WParser->GetActualBackgroundMode(); if ( colBg.IsOk() ) { m_WParser->SetActualBackgroundColor(colBg); m_WParser->SetActualBackgroundMode(wxBRUSHSTYLE_SOLID); m_WParser->GetContainer()->InsertCell( new wxHtmlColourCell(colBg, wxHTML_CLR_BACKGROUND) ); } ParseInner(tag); if ( oldbackmode != m_WParser->GetActualBackgroundMode() || oldbackclr != m_WParser->GetActualBackgroundColor() ) { m_WParser->SetActualBackgroundMode(oldbackmode); m_WParser->SetActualBackgroundColor(oldbackclr); m_WParser->GetContainer()->InsertCell( new wxHtmlColourCell(oldbackclr, oldbackmode == wxBRUSHSTYLE_TRANSPARENT ? wxHTML_CLR_TRANSPARENT_BACKGROUND : wxHTML_CLR_BACKGROUND) ); } }
void wxMenu::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; if (!col.IsOk()) return; if (m_menuWidget) wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col); if (m_buttonWidget) wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { wxMenuItem* item = node->GetData(); if (item->GetButtonWidget()) { // This crashes because it uses gadgets // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col); } if (item->GetSubMenu()) item->GetSubMenu()->SetForegroundColour((wxColour&) col); } }
wxColour GetColourFromUser(wxWindow* parent, const wxColour& colInit) { #ifdef __WXMSW__ const wxString caption = _("Choose color"); #else const wxString caption = _("Choose color (only first 16 will be saved)"); #endif const wxString palette = _T("Default"); wxColourData data; data = sett().GetCustomColors(palette); data.SetChooseFull(true); if (colInit.Ok()) { data.SetColour((wxColour&)colInit); // const_cast } wxColour colRet; wxColourDialog dialog(parent, &data); if (!caption.empty()) dialog.SetTitle(caption); if (dialog.ShowModal() == wxID_OK) { colRet = dialog.GetColourData().GetColour(); } //else: leave it invalid sett().SaveCustomColors(dialog.GetColourData(), palette); return colRet; }
void LexerConf::SetLineNumbersFgColour(const wxColour& colour) { StyleProperty& style = GetProperty(LINE_NUMBERS_ATTR_ID); if(!style.IsNull()) { style.SetFgColour(colour.GetAsString(wxC2S_HTML_SYNTAX)); } }
void PixelBufferClass::Get2ColorBlend(int layer, int coloridx1, int coloridx2, double ratio, wxColour &color) { wxColour c1,c2; palette[layer].GetColor(coloridx1,c1); palette[layer].GetColor(coloridx2,c2); color.Set(ChannelBlend(c1.Red(),c2.Red(),ratio), ChannelBlend(c1.Green(),c2.Green(),ratio), ChannelBlend(c1.Blue(),c2.Blue(),ratio)); }
bool wxColourPickerCtrl::Create( wxWindow *parent, wxWindowID id, const wxColour &col, const wxPoint &pos, const wxSize &size, long style, const wxValidator& validator, const wxString &name ) { if (!wxPickerBase::CreateBase(parent, id, col.GetAsString(), pos, size, style, validator, name)) return false; // we are not interested to the ID of our picker as we connect // to its "changed" event dynamically... m_picker = new wxColourPickerWidget(this, wxID_ANY, col, wxDefaultPosition, wxDefaultSize, GetPickerStyle(style)); // complete sizer creation wxPickerBase::PostCreation(); m_picker->Connect(wxEVT_COMMAND_COLOURPICKER_CHANGED, wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange), NULL, this); return true; }
wxPen::wxPen(const wxColour& col, int width, int style) { m_refData = new wxPenRefData(); M_PENDATA.setWidth(width); M_PENDATA.setStyle(ConvertPenStyle((wxPenStyle)style)); M_PENDATA.setColor(col.GetHandle()); }
void RgbEffects::Get2ColorBlend(int coloridx1, int coloridx2, double ratio, wxColour &color) { wxColour c1,c2; palette.GetColor(coloridx1,c1); palette.GetColor(coloridx2,c2); color.Set(ChannelBlend(c1.Red(),c2.Red(),ratio), ChannelBlend(c1.Green(),c2.Green(),ratio), ChannelBlend(c1.Blue(),c2.Blue(),ratio)); }
wxColour blend50(const wxColour& c1, const wxColour& c2) { unsigned char r,g,b,a; r = c1.Red()/2 + c2.Red()/2; g = c1.Green()/2 + c2.Green()/2; b = c1.Blue()/2 + c2.Blue()/2; a = c1.Alpha()/2 + c2.Alpha()/2; return a << 24 | b << 16 | g << 8 | r; }
wxColour Drawing::darkColour(const wxColour& colour, float percent) { if(percent == 0) { return colour; } // Convert to HSL hsl_t hsl = Misc::rgbToHsl(rgba_t(colour.Red(), colour.Green(), colour.Blue())); // Decrease luminance hsl.l -= (float)((percent * 5.0)/100.0); if (hsl.l < 0) hsl.l = 0; rgba_t rgb = Misc::hslToRgb(hsl); return wxColour(rgb.r, rgb.g, rgb.b); }
void wxMSWOwnerDrawnButtonBase::MSWMakeOwnerDrawnIfNecessary(const wxColour& colFg) { // The only way to change the checkbox foreground colour when using // themes is to owner draw it. if ( wxUxThemeEngine::GetIfActive() ) MSWMakeOwnerDrawn(colFg.IsOk()); }
void OptionsConfig::SetBookmarkBgColour(wxColour c, size_t index) { wxArrayString arr = wxSplit(m_bookmarkBgColours, ';'); if(index < arr.GetCount()) { arr.Item(index) = c.GetAsString(wxC2S_HTML_SYNTAX); m_bookmarkBgColours = wxJoin(arr, ';'); } }
// Change a widget's foreground and background colours. void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) { if (!foregroundColour.IsOk()) return; // When should we specify the foreground, if it's calculated // by wxComputeColours? // Solution: say we start with the default (computed) foreground colour. // If we call SetForegroundColour explicitly for a control or window, // then the foreground is changed. // Therefore SetBackgroundColour computes the foreground colour, and // SetForegroundColour changes the foreground colour. The ordering is // important. XtVaSetValues ((Widget) widget, XmNforeground, foregroundColour.AllocColour(XtDisplay((Widget) widget)), NULL); }
void wxMoColour::UpdateColour( wxColour p_Colour ) { ///internal RGB values m_RGBValue.red = p_Colour.Red(); m_RGBValue.green = p_Colour.Green(); m_RGBValue.blue = p_Colour.Blue(); m_RGBDouble.red = m_RGBValue.red / 255.0; m_RGBDouble.green = m_RGBValue.green / 255.0; m_RGBDouble.blue = m_RGBValue.blue / 255.0; ///internal HSV values m_HSVValue = wxImage::RGBtoHSV( m_RGBValue ); ///assign now m_ColourValue = p_Colour; }
void uwHexCtrl::PaintRectangle( wxDC& dc, wxColour& colour, const wxRect& rect ) { if( !colour.Ok() ) colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); dc.SetBrush(wxBrush(colour)); dc.SetPen(wxPen(colour, 1)); dc.DrawRectangle( rect ); }
template<> void wxStringReadValue(const wxString &s , wxColour &data ) { if ( !data.Set(s) ) { wxLogError(_("String To Colour : Incorrect colour specification : %s"), s.c_str() ); data = wxNullColour; } }
static void bg(GtkStyleContext* sc, wxColour& color, int state = GTK_STATE_FLAG_NORMAL) { GdkRGBA* rgba; cairo_pattern_t* pattern = NULL; gtk_style_context_set_state(sc, GtkStateFlags(state)); gtk_style_context_get(sc, GtkStateFlags(state), "background-color", &rgba, "background-image", &pattern, NULL); color = wxColour(*rgba); gdk_rgba_free(rgba); // "background-image" takes precedence over "background-color". // If there is an image, try to get a color out of it. if (pattern) { if (cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SURFACE) { cairo_surface_t* surf; cairo_pattern_get_surface(pattern, &surf); if (cairo_surface_get_type(surf) == CAIRO_SURFACE_TYPE_IMAGE) { const guchar* data = cairo_image_surface_get_data(surf); const int stride = cairo_image_surface_get_stride(surf); // choose a pixel in the middle vertically, // images often have a vertical gradient const int i = stride * (cairo_image_surface_get_height(surf) / 2); const unsigned* p = reinterpret_cast<const unsigned*>(data + i); const unsigned pixel = *p; guchar r, g, b, a = 0xff; switch (cairo_image_surface_get_format(surf)) { case CAIRO_FORMAT_ARGB32: a = guchar(pixel >> 24); // fallthrough case CAIRO_FORMAT_RGB24: r = guchar(pixel >> 16); g = guchar(pixel >> 8); b = guchar(pixel); break; default: a = 0; break; } if (a != 0) { if (a != 0xff) { // un-premultiply r = guchar((r * 0xff) / a); g = guchar((g * 0xff) / a); b = guchar((b * 0xff) / a); } color.Set(r, g, b, a); } } } cairo_pattern_destroy(pattern); }
wxObject * MaxBannerWindowXmlHandler::DoCreateResource() { XRC_MAKE_INSTANCE(banner, MaxBannerWindow) banner->Create(m_parentAsWindow, GetID(), GetDirection(wxS("direction")), GetPosition(), GetSize(), GetStyle(wxS("style")), GetName()); banner->MaxBind(CB_PREF(wx_wxbannerwindow_wxBannerWindow__xrcNew)(banner)); SetupWindow(banner); const wxColour colStart = GetColour(wxS("gradient-start")); const wxColour colEnd = GetColour(wxS("gradient-end")); if ( colStart.IsOk() || colEnd.IsOk() ) { if ( !colStart.IsOk() || !colEnd.IsOk() ) { ReportError ( "Both start and end gradient colours must be " "specified if either one is." ); } else { banner->SetGradient(colStart, colEnd); } } wxBitmap bitmap = GetBitmap(); if ( bitmap.IsOk() ) { if ( colStart.IsOk() || colEnd.IsOk() ) { ReportError ( "Gradient colours are ignored by wxBannerWindow " "if the background bitmap is specified." ); } banner->SetBitmap(bitmap); } banner->SetText(GetText(wxS("title")), GetText(wxS("message"))); return banner; }
wxString WriteColourAlpha(const wxColour& colour, const unsigned int alpha) { wxASSERT(colour.Ok()); wxASSERT(alpha <= 256); if (alpha) return wxString::Format(wxT("#%02X%02X%02X%02X"), colour.Red(), colour.Green(), colour.Blue(), alpha); else return wxString::Format(wxT("#%02X%02X%02X"), colour.Red(), colour.Green(), colour.Blue()); }
void wxListCtrlBase::EnableAlternateRowColours(bool enable) { if ( enable ) { // This code is copied from wxDataViewMainWindow::OnPaint() // Determine the alternate rows colour automatically from the // background colour. const wxColour bgColour = GetBackgroundColour(); // Depending on the background, alternate row color // will be 3% more dark or 50% brighter. int alpha = bgColour.GetRGB() > 0x808080 ? 97 : 150; SetAlternateRowColour(bgColour.ChangeLightness(alpha)); } else // Disable striping by setting invalid alternative colour. { SetAlternateRowColour(wxColour()); } }
bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) { if (!bitmap.IsOk()) return false; if (m_qtBitmap) delete m_qtBitmap; m_qtBitmap = new QBitmap(bitmap.GetHandle()->createMaskFromColor(colour.GetHandle())); return true; }
// Helper function which blends a colour with the default window text colour, // so that text will be readable in bright and dark colour schemes wxColour BlendTextColour(wxColour col) { wxColour fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); int dist = (fgCol.Red()*fgCol.Red() + fgCol.Green()*fgCol.Green() + fgCol.Blue()*fgCol.Blue()) - (bgCol.Red()*bgCol.Red() + bgCol.Green()*bgCol.Green() + bgCol.Blue()*bgCol.Blue()); if (dist > 0) { // If foreground color is brighter than background color, this is a dark theme, so // brighten the text colour. // I would use wxColour::changeLightness(), but it's only available in v2.9.0 or later. int d = int(sqrt(dist)/4); int r = col.Red() + d; int g = col.Green() + d; int b = col.Blue() + d; return wxColour( r>255 ? 255 : r, g>255 ? 255 : g, b>255 ? 255 : b ); } return col; }
// Creates an image with a solid background color std::unique_ptr<wxImage> CreateBackground(int width, int height, wxColour colour) { auto i = std::make_unique<wxImage>(width, height); unsigned char *ip; int srcVal[3]; int x; srcVal[0] = colour.Red(); srcVal[1] = colour.Green(); srcVal[2] = colour.Blue(); ip = i->GetData(); for(x=0; x<width*height; x++) { *ip++ = srcVal[0]; *ip++ = srcVal[1]; *ip++ = srcVal[2]; } return i; }
bool wxCheckBox::SetForegroundColour(const wxColour& colour) { if ( !wxCheckBoxBase::SetForegroundColour(colour) ) return false; // the only way to change the checkbox foreground colour under Windows XP // is to owner draw it if ( wxUxThemeEngine::GetIfActive() ) MakeOwnerDrawn(colour.Ok()); return true; }
bool wxMask::InitFromColour(const wxBitmap& bitmap, const wxColour& colour) { #if wxUSE_IMAGE const wxColour clr(bitmap.QuantizeColour(colour)); wxImage imgSrc(bitmap.ConvertToImage()); imgSrc.SetMask(false); wxImage image(imgSrc.ConvertToMono(clr.Red(), clr.Green(), clr.Blue())); if ( !image.IsOk() ) return false; m_bitmap = wxBitmap(image, 1); return m_bitmap.IsOk(); #else // !wxUSE_IMAGE wxUnusedVar(bitmap); wxUnusedVar(colour); return false; #endif // wxUSE_IMAGE/!wxUSE_IMAGE }