diff options
author | B Stack <bgstack15@gmail.com> | 2020-07-22 16:56:03 +0000 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-07-22 16:56:03 +0000 |
commit | e5633fb1c0db91f01ab967330b76baf4ecdb0512 (patch) | |
tree | 10260e25ae905564f7978b83fc4e316670f987c6 /wx+/bitmap_button.h | |
parent | Merge branch '10.25' into 'master' (diff) | |
parent | add upstream 11.0 (diff) | |
download | FreeFileSync-e5633fb1c0db91f01ab967330b76baf4ecdb0512.tar.gz FreeFileSync-e5633fb1c0db91f01ab967330b76baf4ecdb0512.tar.bz2 FreeFileSync-e5633fb1c0db91f01ab967330b76baf4ecdb0512.zip |
Merge branch '11.0' into 'master'11.0
add upstream 11.0
See merge request opensource-tracking/FreeFileSync!24
Diffstat (limited to 'wx+/bitmap_button.h')
-rw-r--r-- | wx+/bitmap_button.h | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/wx+/bitmap_button.h b/wx+/bitmap_button.h index b40d8dd3..508a72fc 100644 --- a/wx+/bitmap_button.h +++ b/wx+/bitmap_button.h @@ -8,6 +8,7 @@ #define BITMAP_BUTTON_H_83415718945878341563415 #include <wx/bmpbuttn.h> +#include <wx/settings.h> #include "image_tools.h" #include "dc.h" @@ -26,17 +27,20 @@ public: long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr) : - wxBitmapButton(parent, id, wxNullBitmap, pos, size, style | wxBU_AUTODRAW, validator, name) { SetLabel(label); } + wxBitmapButton(parent, id, wxNullBitmap, pos, size, style, validator, name) + { + SetLabel(label); + } }; //wxButton::SetBitmap() also supports "image + text", but screws up proper gap and border handling void setBitmapTextLabel(wxBitmapButton& btn, const wxImage& img, const wxString& text, int gap = fastFromDIP(5), int border = fastFromDIP(5)); //set bitmap label flicker free: -void setImage(wxBitmapButton& button, const wxBitmap& bmp); - - +void setImage(wxBitmapButton& button, const wxImage& bmp); +wxBitmap renderSelectedButton(const wxSize& sz); +wxBitmap renderPressedButton(const wxSize& sz); @@ -53,34 +57,80 @@ void setBitmapTextLabel(wxBitmapButton& btn, const wxImage& img, const wxString& gap = std::max(0, gap); border = std::max(0, border); - wxImage dynImage = createImageFromText(text, btn.GetFont(), btn.GetForegroundColour()); + wxImage imgTxt = createImageFromText(text, btn.GetFont(), btn.GetForegroundColour()); if (img.IsOk()) - dynImage = btn.GetLayoutDirection() != wxLayout_RightToLeft ? - stackImages(img, dynImage, ImageStackLayout::horizontal, ImageStackAlignment::center, gap) : - stackImages(dynImage, img, ImageStackLayout::horizontal, ImageStackAlignment::center, gap); + imgTxt = btn.GetLayoutDirection() != wxLayout_RightToLeft ? + stackImages(img, imgTxt, ImageStackLayout::horizontal, ImageStackAlignment::center, gap) : + stackImages(imgTxt, img, ImageStackLayout::horizontal, ImageStackAlignment::center, gap); //SetMinSize() instead of SetSize() is needed here for wxWindows layout determination to work correctly const int defaultHeight = wxButton::GetDefaultSize().GetHeight(); - btn.SetMinSize({dynImage.GetWidth () + 2 * border, - std::max(dynImage.GetHeight() + 2 * border, defaultHeight)}); + btn.SetMinSize({imgTxt.GetWidth () + 2 * border, + std::max(imgTxt.GetHeight() + 2 * border, defaultHeight)}); - btn.SetBitmapLabel(wxBitmap(dynImage)); + btn.SetBitmapLabel(imgTxt); //SetLabel() calls confuse wxBitmapButton in the disabled state and it won't show the image! workaround: - btn.SetBitmapDisabled(wxBitmap(dynImage.ConvertToDisabled())); + btn.SetBitmapDisabled(imgTxt.ConvertToDisabled()); } inline -void setImage(wxBitmapButton& button, const wxBitmap& bmp) +void setImage(wxBitmapButton& button, const wxImage& img) { - if (!button.GetBitmapLabel().IsSameAs(bmp)) + if (!img.IsOk()) { - button.SetBitmapLabel(bmp); + button.SetBitmapLabel (wxNullBitmap); + button.SetBitmapDisabled(wxNullBitmap); + return; + } - //wxWidgets excels at screwing up consistently once again: - //the first call to SetBitmapLabel() *implicitly* sets the disabled bitmap, too, subsequent calls, DON'T! - button.SetBitmapDisabled(bmp.ConvertToDisabled()); //inefficiency: wxBitmap::ConvertToDisabled() implicitly converts to wxImage! + button.SetBitmapLabel(img); + + //wxWidgets excels at screwing up consistently once again: + //the first call to SetBitmapLabel() *implicitly* sets the disabled bitmap, too, subsequent calls, DON'T! + button.SetBitmapDisabled(img.ConvertToDisabled()); //inefficiency: wxBitmap::ConvertToDisabled() implicitly converts to wxImage! +} + + +inline +wxBitmap renderSelectedButton(const wxSize& sz) +{ + wxBitmap bmp(sz); //seems we don't need to pass 24-bit depth here even for high-contrast color schemes + { + wxMemoryDC dc(bmp); + dc.SetBrush(wxColor(0xcc, 0xe4, 0xf8)); //light blue + dc.SetPen (wxColor(0x79, 0xbc, 0xed)); //medium blue + dc.DrawRectangle(wxRect(bmp.GetSize())); + } + return bmp; +} + + +inline +wxBitmap renderPressedButton(const wxSize& sz) +{ + wxBitmap bmp(sz); //seems we don't need to pass 24-bit depth here even for high-contrast color schemes + { + //draw rectangle border with gradient + const wxColor colFrom = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); + const wxColor colTo(0x11, 0x79, 0xfe); //light blue + + wxMemoryDC dc(bmp); + dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + wxRect rect(bmp.GetSize()); + + const int borderSize = fastFromDIP(3); + for (int i = 1 ; i <= borderSize; ++i) + { + const wxColor colGradient((colFrom.Red () * (borderSize - i) + colTo.Red () * i) / borderSize, + (colFrom.Green() * (borderSize - i) + colTo.Green() * i) / borderSize, + (colFrom.Blue () * (borderSize - i) + colTo.Blue () * i) / borderSize); + dc.SetPen(colGradient); + dc.DrawRectangle(rect); + rect.Deflate(1); + } } + return bmp; } } |