ConfigWizard: Draw logo inside OnPaint instead of use of wxStaticBitmap

This commit is contained in:
YuSanka 2021-07-23 11:54:15 +02:00
parent c9dffd0c89
commit 9154ebb165
2 changed files with 10 additions and 21 deletions

View file

@ -1606,25 +1606,17 @@ ConfigWizardIndex::ConfigWizardIndex(wxWindow *parent)
, item_hover(NO_ITEM)
, last_page((size_t)-1)
{
#ifndef __WXOSX__
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
#endif //__WXOSX__
SetMinSize(bg.bmp().GetSize());
const wxSize size = GetTextExtent("m");
em_w = size.x;
em_h = size.y;
// Add logo bitmap.
// This could be done in on_paint() along with the index labels, but I've found it tricky
// to get the bitmap rendered well on all platforms with transparent background.
// In some cases it didn't work at all. And so wxStaticBitmap is used here instead,
// because it has all the platform quirks figured out.
auto *sizer = new wxBoxSizer(wxVERTICAL);
logo = new wxStaticBitmap(this, wxID_ANY, bg.bmp());
sizer->AddStretchSpacer();
sizer->Add(logo);
SetSizer(sizer);
logo_height = logo->GetBitmap().GetHeight();
Bind(wxEVT_PAINT, &ConfigWizardIndex::on_paint, this);
Bind(wxEVT_SIZE, [this](wxEvent& e) { e.Skip(); Refresh(); });
Bind(wxEVT_MOTION, &ConfigWizardIndex::on_mouse_move, this);
Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent &evt) {
@ -1769,6 +1761,12 @@ void ConfigWizardIndex::on_paint(wxPaintEvent & evt)
y += yinc;
index_width = std::max(index_width, (int)x + text_size.x);
}
//draw logo
if (int y = size.y - bg.GetBmpHeight(); y>=0) {
dc.DrawBitmap(bg.bmp(), 0, y, false);
index_width = std::max(index_width, bg.GetBmpWidth() + em_w / 2);
}
if (GetMinSize().x < index_width) {
CallAfter([this, index_width]() {
@ -1776,11 +1774,6 @@ void ConfigWizardIndex::on_paint(wxPaintEvent & evt)
Refresh();
});
}
if ((int)y + logo_height > size.GetHeight())
logo->Hide();
else
logo->Show();
}
void ConfigWizardIndex::on_mouse_move(wxMouseEvent &evt)
@ -1806,7 +1799,6 @@ void ConfigWizardIndex::msw_rescale()
bg.msw_rescale();
SetMinSize(bg.bmp().GetSize());
logo->SetBitmap(bg.bmp());
bullet_black.msw_rescale();
bullet_blue.msw_rescale();

View file

@ -512,15 +512,12 @@ private:
ScalableBitmap bullet_black;
ScalableBitmap bullet_blue;
ScalableBitmap bullet_white;
wxStaticBitmap* logo;
std::vector<Item> items;
size_t item_active;
ssize_t item_hover;
size_t last_page;
int logo_height;
int item_height() const { return std::max(bullet_black.bmp().GetSize().GetHeight(), em_w) + em_w; }
void on_paint(wxPaintEvent &evt);