From 86780b5a6c677da2ad66f27215168ee49c665514 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 11 Jun 2024 13:51:14 +0200 Subject: [PATCH] ScalableBitmap: Check if the bitmap has a square shape, when loading from the path --- src/slic3r/GUI/wxExtensions.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 2e70271989..c8e6784c4a 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -475,6 +475,18 @@ ScalableBitmap::ScalableBitmap(wxWindow* parent, boost::filesystem::path& icon_p if (ext == ".png" || ext == ".jpg") { bitmap.LoadFile(path, ext == ".png" ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_JPEG); + // check if the bitmap has a square shape + + if (wxSize sz = bitmap.GetSize(); sz.x != sz.y) { + const int bmp_side = std::min(sz.GetWidth(), sz.GetHeight()); + + wxRect rc = sz.GetWidth() > sz.GetHeight() ? + wxRect(int( 0.5 * (sz.x - sz.y)), 0, bmp_side, bmp_side) : + wxRect(0, int( 0.5 * (sz.y - sz.x)), bmp_side, bmp_side) ; + + bitmap = bitmap.GetSubBitmap(rc); + } + // set mask for circle shape wxBitmapBundle mask_bmps = *get_bmp_bundle("user_mask", bitmap.GetSize().GetWidth());