Hey guys, so in my app I have a toolbar which in lightmode looks like this:
This is how those icons have been created:
The code for setting the red color as a mask:
wxBitmap bmpfilter("filterbmp", wxBITMAP_TYPE_RESOURCE); wxMask* maskfilter = new wxMask(bmpfilter, wxColour(255, 0, 0)); bmpfilter.SetMask(maskfilter); m_menuItem6->SetBitmaps(bmpfilter);
Now, when switching to darkmode I get this result:
Something is clearly happening with the mask, but it's not transparent but black instead.
Expected result would be transparency as in light mode.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Could you please attach the bitmap you use here?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
How do I do that? It says bitmap not allowed when just dragging it in and when using the Paste button below, .bmp is not in the list of files. I'll make a .png out of it and paste that.
filter_16x16_redbg_desaturated.png (view on web)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Is the bug reproducible with the bitmap created from PNG? If yes, this is fine. If not, please put the BMP into a ZIP and upload it instead. TIA!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I'm not sure what you mean with the first part of the sentence, so I made the zip with the original bitmap and will attach that here.
filter_16x16_redbg_desaturated.zip
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Can someone reproduce this? Is it a problem with the bitmap somehow, even though it works in light mode? Is there another way to achieve the transparent background with the toolbar icons?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Why you did not provide a repro code, as expected? That could significantly increase the chances of someone looking into it (soon).
FWIW, I cannot reproduce it with patched toolbar sample, but I can in a minimal sample (both using same manifest):
toolbar-bmp-msw-dark.png (view on web)
Minimal sample
#include <wx/wx.h> class MyFrame : public wxFrame { public: MyFrame(wxWindow* parent = nullptr) : wxFrame(parent, wxID_ANY, "Test") { wxToolBar* toolBar = CreateToolBar(); wxBitmap bmpfilter("filterbmp", wxBITMAP_TYPE_RESOURCE); wxMask* maskfilter = new wxMask(bmpfilter, wxColour(255, 0, 0)); bmpfilter.SetMask(maskfilter); toolBar->AddTool(wxID_ANY, "", bmpfilter); toolBar->Realize(); } }; class MyApp : public wxApp { bool OnInit() override { (new MyFrame)->Show(); return true; } }; wxIMPLEMENT_APP(MyApp);
The workaround is to convert to image and back to 32bpp bitmap:
toolBar->AddTool(..., wxBitmap(bmpfilter.ConvertToImage(), 32));TBH, this seems a bit odd procedure to create a transparent bitmap. I would just convert the bitmaps to PNGs (or better yet, recreate in SVG) and adjusted the code.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
So, I tried to exchange the filterbmp with a png version with transparency instead of the red bg, putting it as RCDATA into the .rc file and loading it as wxBITMAP_TYPE_PNG_RESOURCE. Further I commented out the two lines creating and setting the mask.
The result is that the filter icon has now a transparent background, not the black one anymore.
However, the other symbols that are still using bitmaps with red and the setmask command, are also working properly now?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
However, the other symbols that are still using bitmaps with red and the setmask command, are also working properly now?
So that is why it worked in the toolbar sample and not my minimal code. Once a toolbar is assigned a bitmap with alpha, the masked bitmaps start working. Just verified it with a minimal code sample.
toolbar-bmp-msw-dark2.png (view on web)
#include <wx/wx.h> #include <wx/artprov.h>
class MyFrame : public wxFrame { public: MyFrame(wxWindow* parent = nullptr) : wxFrame(parent, wxID_ANY, "Test") { wxToolBar* toolBar = CreateToolBar
();
wxBitmap bmpfilter("filterbmp", wxBITMAP_TYPE_RESOURCE);
bmpfilter.SetMask(new wxMask(bmpfilter, *wxRED));
toolBar->AddTool(wxID_ANY, "", bmpfilter);
toolBar->AddTool(wxID_ANY, "", wxArtProvider::GetBitmapBundle(wxART_INFORMATION, wxART_OTHER, bmpfilter.GetSize()));
toolBar->Realize();
}
};
class MyApp : public wxApp { bool OnInit() override { (new MyFrame)->Show(); return true; } }; wxIMPLEMENT_APP(MyApp);
But I have no idea why it works like that (I did not investigate) and whether it is a Windows or wxWidgets issue...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
But wouldn't it be related to the dark mode somehow, as it works just fine in light mode?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
But wouldn't it be related to the dark mode somehow, as it works just fine in light mode?
Yes, the whole Issue is about dark mode, see its "dark mode" and "MSW" labels.
I have realized that the issue can be reproduced with XPM-based wxArt shipped with wxWidgets, so here is the patch to the minimal sample:
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp index 5f32257c6b..ad27a582e9 100644 --- a/samples/minimal/minimal.cpp +++ b/samples/minimal/minimal.cpp @@ -25,6 +25,7 @@ #ifndef WX_PRECOMP #include "wx/wx.h" #endif +#include "wx/artprov.h" // ---------------------------------------------------------------------------- // resources @@ -175,6 +176,13 @@ MyFrame::MyFrame(const wxString& title) CreateStatusBar(2); SetStatusText("Welcome to wxWidgets!"); #endif // wxUSE_STATUSBAR + + wxToolBar* toolBar = CreateToolBar(); + + toolBar->AddTool(wxID_ANY, "", wxArtProvider::GetBitmapBundle(wxART_TIP, wxART_TOOLBAR)); + // uncomment the line below to make bitmap masks work + // toolBar->AddTool(wxID_ANY, "", wxArtProvider::GetBitmapBundle(wxART_WX_LOGO, wxART_TOOLBAR)); + toolBar->Realize(); }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Uh.. well my last comment was in regards to you questioning if it might be a windows or wxwidgets problem. Since it is dark mode related, ( and i know this topic is about darkmode since I named it that way ^^ ), I just assumed that it then would be a wxwidgets problem?
Does your finding that it also happens with the XPMs reinforce that then?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Sorry, I have no idea where the problem could be. I am not a developer, just a nosy user.
As said before, until the bug is fixed, I would use the workaround I provided in my first post here. It changes just a single line of code, no other changes needed. And of course added a comment explaining the need for it and linking to this issue.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Ah I see, no problem, hope someone will look into it then =)
As for a temporary workaround, I opted for just using PNGs because i had to rework all the icons to look well in dark mode anyway.
Thanks for you help with this matter!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Should be fixed by #25598, thanks for providing a nice way to reproduce this!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #25547 as completed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Thank you, will close this then.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()