mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-12-11 16:00:17 -07:00
update BitmapComboBox
This commit is contained in:
parent
77a143a8ff
commit
eba3fe207f
2 changed files with 4 additions and 88 deletions
|
|
@ -54,17 +54,6 @@ using Slic3r::GUI::format_wxstr;
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
/* For PresetComboBox we use bitmaps that are created from images that are already scaled appropriately for Retina
|
|
||||||
* (Contrary to the intuition, the `scale` argument for Bitmap's constructor doesn't mean
|
|
||||||
* "please scale this to such and such" but rather
|
|
||||||
* "the wxImage is already sized for backing scale such and such". )
|
|
||||||
* Unfortunately, the constructor changes the size of wxBitmap too.
|
|
||||||
* Thus We need to use unscaled size value for bitmaps that we use
|
|
||||||
* to avoid scaled size of control items.
|
|
||||||
* For this purpose control drawing methods and
|
|
||||||
* control size calculation methods (virtual) are overridden.
|
|
||||||
**/
|
|
||||||
|
|
||||||
BitmapComboBox::BitmapComboBox(wxWindow* parent,
|
BitmapComboBox::BitmapComboBox(wxWindow* parent,
|
||||||
wxWindowID id/* = wxID_ANY*/,
|
wxWindowID id/* = wxID_ANY*/,
|
||||||
const wxString& value/* = wxEmptyString*/,
|
const wxString& value/* = wxEmptyString*/,
|
||||||
|
|
@ -90,72 +79,6 @@ BitmapComboBox::~BitmapComboBox()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
bool BitmapComboBox::OnAddBitmap(const wxBitmap& bitmap)
|
|
||||||
{
|
|
||||||
if (bitmap.IsOk())
|
|
||||||
{
|
|
||||||
// we should use scaled! size values of bitmap
|
|
||||||
int width = (int)bitmap.GetScaledWidth();
|
|
||||||
int height = (int)bitmap.GetScaledHeight();
|
|
||||||
|
|
||||||
if (m_usedImgSize.x < 0)
|
|
||||||
{
|
|
||||||
// If size not yet determined, get it from this image.
|
|
||||||
m_usedImgSize.x = width;
|
|
||||||
m_usedImgSize.y = height;
|
|
||||||
|
|
||||||
// Adjust control size to vertically fit the bitmap
|
|
||||||
wxWindow* ctrl = GetControl();
|
|
||||||
ctrl->InvalidateBestSize();
|
|
||||||
wxSize newSz = ctrl->GetBestSize();
|
|
||||||
wxSize sz = ctrl->GetSize();
|
|
||||||
if (newSz.y > sz.y)
|
|
||||||
ctrl->SetSize(sz.x, newSz.y);
|
|
||||||
else
|
|
||||||
DetermineIndent();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxCHECK_MSG(width == m_usedImgSize.x && height == m_usedImgSize.y,
|
|
||||||
false,
|
|
||||||
"you can only add images of same size");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BitmapComboBox::OnDrawItem(wxDC& dc,
|
|
||||||
const wxRect& rect,
|
|
||||||
int item,
|
|
||||||
int flags) const
|
|
||||||
{
|
|
||||||
const wxBitmap& bmp = *(static_cast<wxBitmap*>(m_bitmaps[item]));
|
|
||||||
if (bmp.IsOk())
|
|
||||||
{
|
|
||||||
// we should use scaled! size values of bitmap
|
|
||||||
wxCoord w = bmp.GetScaledWidth();
|
|
||||||
wxCoord h = bmp.GetScaledHeight();
|
|
||||||
|
|
||||||
const int imgSpacingLeft = 4;
|
|
||||||
|
|
||||||
// Draw the image centered
|
|
||||||
dc.DrawBitmap(bmp,
|
|
||||||
rect.x + (m_usedImgSize.x - w) / 2 + imgSpacingLeft,
|
|
||||||
rect.y + (rect.height - h) / 2,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString text = GetString(item);
|
|
||||||
if (!text.empty())
|
|
||||||
dc.DrawText(text,
|
|
||||||
rect.x + m_imgAreaWidth + 1,
|
|
||||||
rect.y + (rect.height - dc.GetCharHeight()) / 2);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
int BitmapComboBox::Append(const wxString& item)
|
int BitmapComboBox::Append(const wxString& item)
|
||||||
|
|
@ -166,18 +89,11 @@ int BitmapComboBox::Append(const wxString& item)
|
||||||
//2. But then set width to 0 value for no using of bitmap left and right spacing
|
//2. But then set width to 0 value for no using of bitmap left and right spacing
|
||||||
//3. Set this empty bitmap to the at list one item and BitmapCombobox will be recreated correct
|
//3. Set this empty bitmap to the at list one item and BitmapCombobox will be recreated correct
|
||||||
|
|
||||||
wxBitmap bitmap(1, int(1.6 * wxGetApp().em_unit() + 1));
|
wxBitmapBundle bitmap = *get_empty_bmp_bundle(1, 16);
|
||||||
{
|
|
||||||
// bitmap.SetWidth(0); is depricated now
|
|
||||||
// so, use next code
|
|
||||||
bitmap.UnShare();// AllocExclusive();
|
|
||||||
bitmap.GetGDIImageData()->m_width = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
OnAddBitmap(bitmap);
|
OnAddBitmap(bitmap);
|
||||||
|
|
||||||
const int n = wxComboBox::Append(item);
|
const int n = wxComboBox::Append(item);
|
||||||
if (n != wxNOT_FOUND)
|
|
||||||
DoSetItemBitmap(n, bitmap);
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ BitmapComboBox(wxWindow* parent,
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int Append(const wxString& item);
|
int Append(const wxString& item);
|
||||||
#endif
|
#endif
|
||||||
int Append(const wxString& item, const wxBitmap& bitmap)
|
int Append(const wxString& item, const wxBitmapBundle& bitmap)
|
||||||
{
|
{
|
||||||
return wxBitmapComboBox::Append(item, bitmap);
|
return wxBitmapComboBox::Append(item, bitmap);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue