From 30dc8b31172ae15729a0e26b49e61cdc5af24782 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Fri, 2 Feb 2024 08:52:04 +0800 Subject: [PATCH] ENH: save video ctrl size to reduce layout change Change-Id: I470f29d7f029d304c9badeeb8f94bed281080b29 Jira: STUDIO-6141 --- src/slic3r/GUI/MediaPlayCtrl.cpp | 4 +--- src/slic3r/GUI/wxMediaCtrl2.cpp | 5 ++++- src/slic3r/GUI/wxMediaCtrl2.h | 4 +++- src/slic3r/GUI/wxMediaCtrl2.mm | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index 176bd29308..dc282c8c6 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -772,9 +772,7 @@ void wxMediaCtrl2::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxMediaCtrl::DoSetSize(x, y, width, height, sizeFlags); #endif if (sizeFlags & wxSIZE_USE_EXISTING) return; - wxSize size = GetVideoSize(); - if (size.GetWidth() <= 0) - size = wxSize{16, 9}; + wxSize size = m_video_size; int maxHeight = (width * size.GetHeight() + size.GetHeight() - 1) / size.GetWidth(); if (maxHeight != GetMaxHeight()) { // BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl2::DoSetSize: width: " << width << ", height: " << height << ", maxHeight: " << maxHeight; diff --git a/src/slic3r/GUI/wxMediaCtrl2.cpp b/src/slic3r/GUI/wxMediaCtrl2.cpp index 346baaf52..431f2ca86 100644 --- a/src/slic3r/GUI/wxMediaCtrl2.cpp +++ b/src/slic3r/GUI/wxMediaCtrl2.cpp @@ -216,7 +216,10 @@ wxSize wxMediaCtrl2::GetVideoSize() const // "Loading...". Fake it out for now. return m_loaded ? wxSize(1280, 720) : wxSize{}; #else - return m_imp ? m_imp->GetVideoSize() : wxSize(0, 0); + wxSize size = m_imp ? m_imp->GetVideoSize() : wxSize(0, 0); + if (size.GetWidth() > 0) + const_cast(m_video_size) = size; + return size; #endif } diff --git a/src/slic3r/GUI/wxMediaCtrl2.h b/src/slic3r/GUI/wxMediaCtrl2.h index 8fde180e9..1b510e211 100644 --- a/src/slic3r/GUI/wxMediaCtrl2.h +++ b/src/slic3r/GUI/wxMediaCtrl2.h @@ -49,7 +49,8 @@ private: void create_player(); void * m_player = nullptr; wxMediaState m_state = wxMEDIASTATE_STOPPED; - int m_error = 0; + int m_error = 0; + wxSize m_video_size{16, 9}; }; #else @@ -86,6 +87,7 @@ private: wxString m_idle_image; int m_error = 0; bool m_loaded = false; + wxSize m_video_size{16, 9}; }; #endif diff --git a/src/slic3r/GUI/wxMediaCtrl2.mm b/src/slic3r/GUI/wxMediaCtrl2.mm index 186baa688..3fbc4a90b 100644 --- a/src/slic3r/GUI/wxMediaCtrl2.mm +++ b/src/slic3r/GUI/wxMediaCtrl2.mm @@ -155,6 +155,8 @@ wxSize wxMediaCtrl2::GetVideoSize() const BambuPlayer * player2 = (BambuPlayer *) m_player; if (player2) { NSSize size = [player2 videoSize]; + if (size.width > 0) + const_cast(m_video_size) = {(int) size.width, (int) size.height}; return {(int) size.width, (int) size.height}; } else { return {0, 0};