From dbaec237c4e53b9e93901f21274c729d79cce2d5 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Thu, 3 Apr 2025 14:36:54 +0800 Subject: [PATCH] ENH:big_bed_image_popup automatic hide jira: STUDIO-11327 Change-Id: I44a43d67ff909768f5e652a687883742ece14737 --- src/slic3r/GUI/ImageDPIFrame.cpp | 28 ++++++++++++++++++++++++++-- src/slic3r/GUI/ImageDPIFrame.hpp | 6 ++++++ src/slic3r/GUI/Plater.cpp | 23 ++++++++++++++++++----- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/ImageDPIFrame.cpp b/src/slic3r/GUI/ImageDPIFrame.cpp index 409ada8d7..f1b07fd14 100644 --- a/src/slic3r/GUI/ImageDPIFrame.cpp +++ b/src/slic3r/GUI/ImageDPIFrame.cpp @@ -43,6 +43,7 @@ ImageDPIFrame::ImageDPIFrame() SetSizer(m_sizer_main); Layout(); Fit(); + init_timer(); } ImageDPIFrame::~ImageDPIFrame() { @@ -65,16 +66,39 @@ void ImageDPIFrame::on_dpi_changed(const wxRect &suggested_rect) //m_bitmap->Rescale(); } +void ImageDPIFrame::init_timer() +{ + m_refresh_timer = new wxTimer(); + m_refresh_timer->SetOwner(this); + Bind(wxEVT_TIMER, &ImageDPIFrame::on_timer, this); +} + +void ImageDPIFrame::on_timer(wxTimerEvent &event) +{ + if (!IsShown()) {//after 1s to show Frame + if (m_timer_count >= 50) { + Show(); + Raise(); + } + m_timer_count++; + } +} + void ImageDPIFrame::on_show() { if (IsShown()) { on_hide(); } - Show(); - Raise(); + if (m_refresh_timer) { + m_timer_count = 0; + m_refresh_timer->Start(ANIMATION_REFRESH_INTERVAL); + } } void ImageDPIFrame::on_hide() { + if (m_refresh_timer) { + m_refresh_timer->Stop(); + } if (IsShown()) { Hide(); if (wxGetApp().mainframe != nullptr) { diff --git a/src/slic3r/GUI/ImageDPIFrame.hpp b/src/slic3r/GUI/ImageDPIFrame.hpp index b2b9d02f6..02ebb33bf 100644 --- a/src/slic3r/GUI/ImageDPIFrame.hpp +++ b/src/slic3r/GUI/ImageDPIFrame.hpp @@ -19,10 +19,16 @@ public: void set_bitmap(const wxBitmap& bit_map); int get_image_px() { return m_image_px; } +private: + void init_timer(); + void on_timer(wxTimerEvent &event); + private: wxStaticBitmap *m_bitmap = nullptr; wxBoxSizer *m_sizer_main{nullptr}; int m_image_px; + wxTimer * m_refresh_timer{nullptr}; + float m_timer_count = 0; }; }} // namespace Slic3r::GUI #endif // _STEP_MESH_DIALOG_H_ diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 48ae304df..b5b4aee68 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1604,6 +1604,9 @@ Sidebar::Sidebar(Plater *parent) p->image_printer_bed = new wxStaticBitmap(p->panel_printer_bed, wxID_ANY, bitmap_bed.bmp(), wxDefaultPosition, wxDefaultSize, 0); p->image_printer_bed->Bind(wxEVT_LEFT_DOWN, [this](auto &evt) { p->image_printer_bed->Unbind(wxEVT_LEAVE_WINDOW, &Sidebar::on_leave_image_printer_bed, this); + if (p->big_bed_image_popup) { + p->big_bed_image_popup->on_hide(); + } p->combo_printer_bed->wxEvtHandler::ProcessEvent(evt); }); @@ -1621,6 +1624,11 @@ Sidebar::Sidebar(Plater *parent) } e.Skip(); // fix bug:Event spreads to sidebar }); + p->combo_printer_bed->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent &evt) { + if (p->big_bed_image_popup && p->big_bed_image_popup->IsShown()) { + p->big_bed_image_popup->on_hide(); + } + }); p->image_printer_bed->Bind(wxEVT_ENTER_WINDOW, &Sidebar::on_enter_image_printer_bed, this); wxBoxSizer *bed_type_vsizer = new wxBoxSizer(wxVERTICAL); @@ -1952,10 +1960,10 @@ Sidebar::Sidebar(Plater *parent) Sidebar::~Sidebar() {} void Sidebar::on_enter_image_printer_bed(wxMouseEvent &evt) { - p->image_printer_bed->Unbind(wxEVT_LEAVE_WINDOW, &Sidebar::on_leave_image_printer_bed, this); - auto pos = p->image_printer_bed->GetScreenPosition(); - auto rect = p->image_printer_bed->GetRect(); - wxPoint temp_pos(pos.x + rect.GetWidth(), pos.y); + p->image_printer_bed->Bind(wxEVT_LEAVE_WINDOW, &Sidebar::on_leave_image_printer_bed, this); + auto pos = p->panel_printer_bed->GetScreenPosition(); + auto rect = p->panel_printer_bed->GetRect(); + wxPoint temp_pos(pos.x + rect.GetWidth() + FromDIP(3), pos.y); if (p->big_bed_image_popup == nullptr) { p->big_bed_image_popup = new ImageDPIFrame(); auto image_path = get_cur_select_bed_image(); @@ -1967,7 +1975,12 @@ void Sidebar::on_enter_image_printer_bed(wxMouseEvent &evt) { } void Sidebar::on_leave_image_printer_bed(wxMouseEvent &evt) { - p->big_bed_image_popup->on_hide(); + auto pos_x = evt.GetX(); + auto pos_y = evt.GetY(); + auto rect = p->image_printer_bed->GetRect(); + if (pos_x < 0 || pos_y < 0 || pos_x >= rect.GetWidth() && p->big_bed_image_popup) { + p->big_bed_image_popup->on_hide(); + } } void Sidebar::on_change_color_mode(bool is_dark) { const ModelObjectPtrs &mos = wxGetApp().model().objects;