diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index beb016b902..624d640c53 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -904,10 +904,10 @@ void MainFrame::set_monitor_tab_url(const wxString& url) m_monitor_webview->load_default_url(); } -void Slic3r::GUI::MainFrame::refresh_auth_menu() +void Slic3r::GUI::MainFrame::refresh_auth_menu(bool avatar/* = false */) { // Update User name in TopBar - dynamic_cast(m_tabpanel)->GetTopBarItemsCtrl()->UpdateAuthMenu(); + dynamic_cast(m_tabpanel)->GetTopBarItemsCtrl()->UpdateAuthMenu(avatar); } void MainFrame::add_created_tab(Tab* panel, const std::string& bmp_name /*= ""*/) diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index fdc27083e8..a6d5e6992b 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -223,7 +223,7 @@ public: void set_monitor_tab_url(const wxString& url); bool get_monitor_tab_added() const { return m_monitor_webview_added; } - void refresh_auth_menu(); + void refresh_auth_menu(bool avatar = false); PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 465fdfb015..338f937291 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -889,7 +889,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID); this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text); this->main_frame->disable_connect_tab(); - this->main_frame->refresh_auth_menu(); + this->main_frame->refresh_auth_menu(true); }); this->q->Bind(EVT_PA_ID_USER_SUCCESS, [this](PrusaAuthSuccessEvent& evt) { @@ -953,6 +953,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) file = fopen(png_path.string().c_str(), "wb"); fwrite(evt.data.c_str(), 1, evt.data.size(), file); fclose(file); + this->main_frame->refresh_auth_menu(true); }); wxGetApp().other_instance_message_handler()->init(this->q); diff --git a/src/slic3r/GUI/TopBar.cpp b/src/slic3r/GUI/TopBar.cpp index adb2d34fd7..ac95095464 100644 --- a/src/slic3r/GUI/TopBar.cpp +++ b/src/slic3r/GUI/TopBar.cpp @@ -185,7 +185,7 @@ void TopBarItemsCtrl::CreateAuthMenu() }, get_bmp_bundle("login", 16)); } -void TopBarItemsCtrl::UpdateAuthMenu() +void TopBarItemsCtrl::UpdateAuthMenu(bool avatar/* = false*/) { auto user_account = wxGetApp().plater()->get_user_account(); if (m_login_menu_item) { @@ -198,8 +198,19 @@ void TopBarItemsCtrl::UpdateAuthMenu() m_user_menu_item->SetItemLabel(user_name); m_auth_btn->SetLabel(user_name); - m_auth_btn->SetBitmapMargins(0, 0); - // m_auth_btn->SetBitmap_("icon_name"); + if (avatar) { + if (user_account->is_logged()) { + boost::filesystem::path path = boost::filesystem::path(boost::filesystem::path(Slic3r::data_dir()) / "cache" / "avatar.png"); + ScalableBitmap new_logo(this, path, m_auth_btn->GetBitmapSize()); + if (new_logo.IsOk()) + m_auth_btn->SetBitmap_(new_logo); + else + m_auth_btn->SetBitmap_("user"); + } + else { + m_auth_btn->SetBitmap_("user"); + } + } m_auth_btn->Refresh(); } diff --git a/src/slic3r/GUI/TopBar.hpp b/src/slic3r/GUI/TopBar.hpp index 7dd71780cc..c1ccc5c5af 100644 --- a/src/slic3r/GUI/TopBar.hpp +++ b/src/slic3r/GUI/TopBar.hpp @@ -78,7 +78,7 @@ public: void AppendMenuSeparaorItem(); void ApplyWorkspacesMenu(); void CreateAuthMenu(); - void UpdateAuthMenu(); + void UpdateAuthMenu(bool avatar = false); void CreateSearch(); wxWindow* GetSearchCtrl() { return m_search->GetTextCtrl(); } diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 1fd5d5ce73..3cb671fb02 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -830,6 +830,22 @@ ScalableBitmap(parent, icon_name, icon_size.x, icon_size.y, grayscale) { } +ScalableBitmap::ScalableBitmap(wxWindow* parent, boost::filesystem::path& icon_path, const wxSize icon_size) + :m_parent(parent), m_bmp_width(icon_size.x), m_bmp_height(icon_size.y) +{ + wxString path = Slic3r::GUI::from_u8(icon_path.string()); + wxBitmap bitmap; + const std::string ext = icon_path.extension().string(); + if (ext == ".png") { + bitmap.LoadFile(path, wxBITMAP_TYPE_PNG); + wxBitmap::Rescale(bitmap, icon_size); + m_bmp = wxBitmapBundle(bitmap); + } + else if (ext == ".svg") { + m_bmp = wxBitmapBundle::FromSVGFile(path, icon_size); + } +} + void ScalableBitmap::sys_color_changed() { m_bmp = *get_bmp_bundle(m_icon_name, m_bmp_width, m_bmp_height); @@ -925,12 +941,20 @@ int ScalableButton::GetBitmapHeight() #endif } +wxSize ScalableButton::GetBitmapSize() +{ +#ifdef __APPLE__ + return wxSize(GetBitmap().GetScaledWidth(), GetBitmap().GetScaledHeight()); +#else + return wxSize(GetBitmap().GetWidth(), GetBitmap().GetHeight()); +#endif +} + void ScalableButton::sys_color_changed() { + Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border); if (m_current_icon_name.empty()) return; - Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border); - wxBitmapBundle bmp = *get_bmp_bundle(m_current_icon_name, m_bmp_width, m_bmp_height); SetBitmap(bmp); SetBitmapCurrent(bmp); diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index e4b62bfda2..87b26c6b49 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -167,6 +167,10 @@ public: const wxSize icon_size, const bool grayscale = false); + ScalableBitmap( wxWindow *parent, + boost::filesystem::path& icon_path, + const wxSize icon_size); + ~ScalableBitmap() {} void sys_color_changed(); @@ -181,6 +185,7 @@ public: wxSize GetSize() const { return get_preferred_size(m_bmp, m_parent); } int GetWidth() const { return GetSize().GetWidth(); } int GetHeight() const { return GetSize().GetHeight(); } + bool IsOk() const { return m_bmp.IsOk(); } private: wxWindow* m_parent{ nullptr }; @@ -263,6 +268,7 @@ public: bool SetBitmap_(const std::string& bmp_name); void SetBitmapDisabled_(const ScalableBitmap &bmp); int GetBitmapHeight(); + wxSize GetBitmapSize(); virtual void sys_color_changed();