Move code for creating a disabled bitmap to wxBitmap

To allow using it from multiple places
This commit is contained in:
Paul Cornett 2019-12-29 09:08:40 -08:00
parent dda052d38a
commit 8db62d179c
3 changed files with 28 additions and 14 deletions

View File

@ -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;

View File

@ -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
{

View File

@ -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;
}