From 8db62d179c2da4fd6bb7aa243e6771b769ddcbf5 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sun, 29 Dec 2019 09:08:40 -0800 Subject: [PATCH] Move code for creating a disabled bitmap to wxBitmap To allow using it from multiple places --- include/wx/gtk/bitmap.h | 1 + src/gtk/bitmap.cpp | 26 ++++++++++++++++++++++++++ src/gtk/toolbar.cpp | 15 +-------------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 993c71dbae..3d1f249e46 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -136,6 +136,7 @@ public: cairo_t* CairoCreate() const; void Draw(cairo_t* cr, int x, int y, bool useMask = true, const wxColour* fg = NULL, const wxColour* bg = NULL) const; void SetSourceSurface(cairo_t* cr, int x, int y, const wxColour* fg = NULL, const wxColour* bg = NULL) const; + wxBitmap CreateDisabled() const; #else GdkPixmap *GetPixmap() const; bool HasPixmap() const; diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 79d5a4ede1..b7d883cc98 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -1372,6 +1372,32 @@ void wxBitmap::Draw(cairo_t* cr, int x, int y, bool useMask, const wxColour* fg, else cairo_paint(cr); } + +wxBitmap wxBitmap::CreateDisabled() const +{ + wxBitmap disabled; + if (m_refData == NULL) + return disabled; + + const wxBitmapRefData* bmpData = M_BMPDATA; + wxBitmapRefData* newRef = new wxBitmapRefData(bmpData->m_width, bmpData->m_height, 32); + newRef->m_scaleFactor = bmpData->m_scaleFactor; + disabled.m_refData = newRef; + + cairo_t* cr = disabled.CairoCreate(); + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgba(cr, 0, 0, 0, 0); + // clear to transparent + cairo_paint(cr); + // draw in this bitmap + Draw(cr, 0, 0); + cairo_set_source_rgba(cr, 0, 0, 0, 0); + // create disabled appearance + cairo_paint_with_alpha(cr, 0.5); + cairo_destroy(cr); + + return disabled; +} #else GdkPixbuf* wxBitmap::GetPixbufNoMask() const { diff --git a/src/gtk/toolbar.cpp b/src/gtk/toolbar.cpp index a4fa9e3e29..f58958f8ce 100644 --- a/src/gtk/toolbar.cpp +++ b/src/gtk/toolbar.cpp @@ -189,20 +189,7 @@ image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool) if (!disabled.IsOk() && bitmap.IsOk() && bitmap.GetScaleFactor() > 1) { // make scaled disabled bitmap from normal one - - disabled.CreateScaled(bitmap.GetScaledHeight(), bitmap.GetScaledWidth(), - 32, bitmap.GetScaleFactor()); - cairo_t* cr2 = disabled.CairoCreate(); - // clear to transparent - cairo_set_operator(cr2, CAIRO_OPERATOR_SOURCE); - cairo_set_source_rgba(cr2, 0, 0, 0, 0); - cairo_paint(cr2); - // draw in normal bitmap - bitmap.Draw(cr2, 0, 0); - // create disabled appearance, this seems to be how GTK does it - cairo_set_source_rgba(cr2, 0, 0, 0, 0); - cairo_paint_with_alpha(cr2, 0.5); - cairo_destroy(cr2); + disabled = bitmap.CreateDisabled(); } bitmap = disabled; }