mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-20 20:03:47 +00:00
Simplify drawing splash screen using wxPaintDC and Fix scaling & blank rendering issues (#12586)
* Update GUI_App.cpp * Update GUI_App.cpp * make splash screen parentless
This commit is contained in:
@@ -276,8 +276,8 @@ bool is_associate_files(std::wstring extend)
|
|||||||
class SplashScreen : public wxSplashScreen
|
class SplashScreen : public wxSplashScreen
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxPoint pos = wxDefaultPosition)
|
SplashScreen(wxPoint pos = wxDefaultPosition)
|
||||||
: wxSplashScreen(bitmap, splashStyle, milliseconds, static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
: wxSplashScreen(wxBitmap(FromDIP(wxSize(480,480),nullptr)), wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT, 1500, nullptr, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
wxBORDER_NONE | wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP
|
wxBORDER_NONE | wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP
|
||||||
#else
|
#else
|
||||||
@@ -285,51 +285,53 @@ public:
|
|||||||
#endif // !__APPLE__
|
#endif // !__APPLE__
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int init_dpi = get_dpi_for_window(this);
|
|
||||||
this->SetPosition(pos);
|
this->SetPosition(pos);
|
||||||
this->CenterOnScreen();
|
this->CenterOnScreen();
|
||||||
int new_dpi = get_dpi_for_window(this);
|
|
||||||
|
|
||||||
m_scale = (float)(new_dpi) / (float)(init_dpi);
|
scale_font(m_font_version, 1.65f); // only scale this one since it hasnt a preloaded font like Label::Body_24;
|
||||||
|
|
||||||
m_main_bitmap = bitmap;
|
m_bg_color = StateColor::darkModeColorFor(wxColour("#FFFFFF"));
|
||||||
|
m_fg_color = StateColor::darkModeColorFor(wxColour("#6B6A6A"));
|
||||||
|
bool dark_mode = m_fg_color != wxColour("#6B6A6A");
|
||||||
|
wxSize sz = m_window->GetClientSize();
|
||||||
|
BitmapCache bmp_cache;
|
||||||
|
m_logo_bmp = *bmp_cache.load_svg(dark_mode ? "splash_logo_dark" : "splash_logo", sz.GetWidth(), sz.GetHeight());
|
||||||
|
|
||||||
scale_bitmap(m_main_bitmap, m_scale);
|
m_window->Bind(wxEVT_PAINT, &SplashScreen::OnPaint, this);
|
||||||
|
m_window->Refresh();
|
||||||
|
m_window->Update();
|
||||||
|
}
|
||||||
|
|
||||||
// init constant texts and scale fonts
|
void OnPaint(wxPaintEvent& evt)
|
||||||
m_constant_text.init(Label::Body_16);
|
{
|
||||||
|
wxPaintDC dc(m_window);
|
||||||
|
wxSize c_sz = m_window->GetClientSize();
|
||||||
|
|
||||||
// ORCA scale all fonts with monitor scale
|
dc.SetBackground(wxBrush(m_bg_color));
|
||||||
scale_font(m_constant_text.version_font, m_scale * 2);
|
dc.Clear();
|
||||||
scale_font(m_constant_text.based_on_font, m_scale * 1.5f);
|
if (m_logo_bmp.IsOk())
|
||||||
scale_font(m_constant_text.credits_font, m_scale * 2);
|
dc.DrawBitmap(m_logo_bmp, 0, 0, true);
|
||||||
|
|
||||||
// this font will be used for the action string
|
wxRect rc = wxRect(0, 0, c_sz.GetWidth(), 0);
|
||||||
m_action_font = m_constant_text.credits_font;
|
dc.SetTextForeground(m_fg_color);
|
||||||
|
|
||||||
// draw logo and constant info text
|
dc.SetFont(m_font_version);
|
||||||
Decorate(m_main_bitmap);
|
rc.y = c_sz.GetHeight() * 0.72;
|
||||||
wxGetApp().UpdateFrameDarkUI(this);
|
rc.height = dc.GetTextExtent(m_text_version).GetHeight();
|
||||||
|
dc.DrawLabel(m_text_version, rc, wxALIGN_CENTER);
|
||||||
|
|
||||||
|
dc.SetFont(m_font_action);
|
||||||
|
rc.y = c_sz.GetHeight() * 0.88;
|
||||||
|
rc.height = dc.GetTextExtent(m_text_action).GetHeight();
|
||||||
|
dc.DrawLabel(m_text_action, rc, wxALIGN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetText(const wxString& text)
|
void SetText(const wxString& text)
|
||||||
{
|
{
|
||||||
set_bitmap(m_main_bitmap);
|
|
||||||
if (!text.empty()) {
|
if (!text.empty()) {
|
||||||
wxBitmap bitmap(m_main_bitmap);
|
m_text_action = text;
|
||||||
|
m_window->Refresh();
|
||||||
wxMemoryDC memDC;
|
m_window->Update();
|
||||||
memDC.SelectObject(bitmap);
|
|
||||||
memDC.SetFont(m_action_font);
|
|
||||||
memDC.SetTextForeground(StateColor::darkModeColorFor(wxColour(144, 144, 144)));
|
|
||||||
int width = bitmap.GetWidth();
|
|
||||||
int text_height = memDC.GetTextExtent(text).GetHeight();
|
|
||||||
int text_width = memDC.GetTextExtent(text).GetWidth();
|
|
||||||
wxRect text_rect(wxPoint(0, m_action_line_y_position), wxPoint(width, m_action_line_y_position + text_height));
|
|
||||||
memDC.DrawLabel(text, text_rect, wxALIGN_CENTER);
|
|
||||||
|
|
||||||
memDC.SelectObject(wxNullBitmap);
|
|
||||||
set_bitmap(bitmap);
|
|
||||||
#ifdef __WXOSX__
|
#ifdef __WXOSX__
|
||||||
// without this code splash screen wouldn't be updated under OSX
|
// without this code splash screen wouldn't be updated under OSX
|
||||||
wxYield();
|
wxYield();
|
||||||
@@ -337,77 +339,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Decorate(wxBitmap& bmp)
|
|
||||||
{
|
|
||||||
if (!bmp.IsOk())
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool is_dark = wxGetApp().app_config->get("dark_color_mode") == "1";
|
|
||||||
|
|
||||||
// use a memory DC to draw directly onto the bitmap
|
|
||||||
wxMemoryDC memDc(bmp);
|
|
||||||
|
|
||||||
int width = bmp.GetWidth();
|
|
||||||
int height = bmp.GetHeight();
|
|
||||||
|
|
||||||
// Logo
|
|
||||||
BitmapCache bmp_cache;
|
|
||||||
wxBitmap logo_bmp = *bmp_cache.load_svg(is_dark ? "splash_logo_dark" : "splash_logo", width, height); // use with full width & height
|
|
||||||
memDc.DrawBitmap(logo_bmp, 0, 0, true);
|
|
||||||
|
|
||||||
// Version
|
|
||||||
memDc.SetFont(m_constant_text.version_font);
|
|
||||||
memDc.SetTextForeground(StateColor::darkModeColorFor(wxColor(134, 134, 134)));
|
|
||||||
wxSize version_ext = memDc.GetTextExtent(m_constant_text.version);
|
|
||||||
wxRect version_rect(
|
|
||||||
wxPoint(0, int(height * 0.70)),
|
|
||||||
wxPoint(width, int(height * 0.70) + version_ext.GetHeight())
|
|
||||||
);
|
|
||||||
memDc.DrawLabel(m_constant_text.version, version_rect, wxALIGN_CENTER);
|
|
||||||
|
|
||||||
// Dynamic Text
|
|
||||||
m_action_line_y_position = int(height * 0.83);
|
|
||||||
}
|
|
||||||
|
|
||||||
static wxBitmap MakeBitmap()
|
|
||||||
{
|
|
||||||
int width = FromDIP(480, nullptr);
|
|
||||||
int height = FromDIP(480, nullptr);
|
|
||||||
|
|
||||||
wxImage image(width, height);
|
|
||||||
wxBitmap new_bmp(image);
|
|
||||||
|
|
||||||
wxMemoryDC memDC;
|
|
||||||
memDC.SelectObject(new_bmp);
|
|
||||||
memDC.SetBrush(StateColor::darkModeColorFor(*wxWHITE));
|
|
||||||
memDC.DrawRectangle(-1, -1, width + 2, height + 2);
|
|
||||||
memDC.DrawBitmap(new_bmp, 0, 0, true);
|
|
||||||
return new_bmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_bitmap(wxBitmap& bmp)
|
|
||||||
{
|
|
||||||
m_window->SetBitmap(bmp);
|
|
||||||
m_window->Refresh();
|
|
||||||
m_window->Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void scale_bitmap(wxBitmap& bmp, float scale)
|
|
||||||
{
|
|
||||||
if (scale == 1.0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
wxImage image = bmp.ConvertToImage();
|
|
||||||
if (!image.IsOk() || image.GetWidth() == 0 || image.GetHeight() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int width = int(scale * image.GetWidth());
|
|
||||||
int height = int(scale * image.GetHeight());
|
|
||||||
image.Rescale(width, height, wxIMAGE_QUALITY_BILINEAR);
|
|
||||||
|
|
||||||
bmp = wxBitmap(std::move(image));
|
|
||||||
}
|
|
||||||
|
|
||||||
void scale_font(wxFont& font, float scale)
|
void scale_font(wxFont& font, float scale)
|
||||||
{
|
{
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
@@ -425,47 +356,16 @@ public:
|
|||||||
#endif //__WXMSW__
|
#endif //__WXMSW__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxStaticText* m_staticText_slicer_name;
|
wxBitmap m_logo_bmp;
|
||||||
wxStaticText* m_staticText_slicer_version;
|
wxColour m_fg_color;
|
||||||
wxStaticBitmap* m_bitmap;
|
wxColour m_bg_color;
|
||||||
wxStaticText* m_staticText_loading;
|
|
||||||
|
|
||||||
wxBitmap m_main_bitmap;
|
wxString m_text_version = GUI_App::format_display_version();
|
||||||
wxFont m_action_font;
|
wxString m_text_action = _L("Loading configuration") + dots;
|
||||||
int m_action_line_y_position;
|
|
||||||
float m_scale {1.0};
|
|
||||||
|
|
||||||
struct ConstantText
|
wxFont m_font_version = Label::Body_16;
|
||||||
{
|
wxFont m_font_action = Label::Body_16;
|
||||||
wxString title;
|
|
||||||
wxString version;
|
|
||||||
wxString credits;
|
|
||||||
|
|
||||||
wxFont title_font;
|
|
||||||
wxFont version_font;
|
|
||||||
wxFont credits_font;
|
|
||||||
wxFont based_on_font;
|
|
||||||
|
|
||||||
void init(wxFont init_font)
|
|
||||||
{
|
|
||||||
// title
|
|
||||||
//title = wxGetApp().is_editor() ? SLIC3R_APP_FULL_NAME : GCODEVIEWER_APP_NAME;
|
|
||||||
|
|
||||||
// dynamically get the version to display
|
|
||||||
version = GUI_App::format_display_version();
|
|
||||||
|
|
||||||
// credits infornation
|
|
||||||
credits = "";
|
|
||||||
|
|
||||||
//title_font = Label::Head_16;
|
|
||||||
version_font = Label::Body_13;
|
|
||||||
based_on_font = Label::Body_8;
|
|
||||||
credits_font = Label::Body_8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_constant_text;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@@ -2844,9 +2744,6 @@ bool GUI_App::on_init_inner()
|
|||||||
|
|
||||||
SplashScreen * scrn = nullptr;
|
SplashScreen * scrn = nullptr;
|
||||||
if (app_config->get("show_splash_screen") == "true") {
|
if (app_config->get("show_splash_screen") == "true") {
|
||||||
// make a bitmap with dark grey banner on the left side
|
|
||||||
//BBS make BBL splash screen bitmap
|
|
||||||
wxBitmap bmp = SplashScreen::MakeBitmap();
|
|
||||||
// Detect position (display) to show the splash screen
|
// Detect position (display) to show the splash screen
|
||||||
// Now this position is equal to the mainframe position
|
// Now this position is equal to the mainframe position
|
||||||
wxPoint splashscreen_pos = wxDefaultPosition;
|
wxPoint splashscreen_pos = wxDefaultPosition;
|
||||||
@@ -2858,9 +2755,9 @@ bool GUI_App::on_init_inner()
|
|||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "begin to show the splash screen...";
|
BOOST_LOG_TRIVIAL(info) << "begin to show the splash screen...";
|
||||||
//BBS use BBL splashScreen
|
//BBS use BBL splashScreen
|
||||||
scrn = new SplashScreen(bmp, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT, 1500, splashscreen_pos);
|
scrn = new SplashScreen(splashscreen_pos);
|
||||||
wxYield();
|
wxYield();
|
||||||
scrn->SetText(_L("Loading configuration")+ dots);
|
//scrn->SetText(_L("Loading configuration")+ dots);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "loading systen presets...";
|
BOOST_LOG_TRIVIAL(info) << "loading systen presets...";
|
||||||
|
|||||||
Reference in New Issue
Block a user