From 986630c2dc366bc93629e8a8ae790278ece3636f Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 14 May 2018 14:47:13 +0200 Subject: [PATCH] 3DScene's idle even handler moved to c++ --- lib/Slic3r/GUI/3DScene.pm | 10 +++---- xs/src/slic3r/GUI/GLCanvas3D.cpp | 35 ++++++++++++++++++++----- xs/src/slic3r/GUI/GLCanvas3D.hpp | 7 +++-- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 1 + 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 60f119980..9cdc51693 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -236,16 +236,14 @@ sub new { #======================================================================================================================= # EVT_SIZE($self, sub { $self->_dirty(1) }); #======================================================================================================================= - EVT_IDLE($self, sub { #============================================================================================================================== - return unless Slic3r::GUI::_3DScene::is_dirty($self); - return unless Slic3r::GUI::_3DScene::is_shown_on_screen($self); +# EVT_IDLE($self, sub { # return unless $self->_dirty; # return if !$self->IsShownOnScreen; +# $self->Resize( $self->GetSizeWH ); +# $self->Refresh; +# }); #============================================================================================================================== - $self->Resize( $self->GetSizeWH ); - $self->Refresh; - }); EVT_MOUSEWHEEL($self, \&mouse_wheel_event); EVT_MOUSE_EVENTS($self, \&mouse_event); # EVT_KEY_DOWN($self, sub { diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 0e539aaef..c52027974 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -305,13 +305,6 @@ void GLCanvas3D::set_camera_target(const Pointf3& target) m_camera.set_target(target); } -void GLCanvas3D::on_size(wxSizeEvent& evt) -{ - std::cout << "GLCanvas3D::on_size: " << (void*)this << std::endl; - - set_dirty(true); -} - BoundingBoxf3 GLCanvas3D::bed_bounding_box() const { return m_bed.get_bounding_box(); @@ -338,6 +331,24 @@ BoundingBoxf3 GLCanvas3D::max_bounding_box() const return bb; } +void GLCanvas3D::on_size(wxSizeEvent& evt) +{ + set_dirty(true); +} + +void GLCanvas3D::on_idle(wxIdleEvent& evt) +{ + if (!is_dirty() || !is_shown_on_screen()) + return; + + if (m_canvas != nullptr) + { + std::pair size = _get_canvas_size(); + resize((unsigned int)size.first, (unsigned int)size.second); + m_canvas->Refresh(); + } +} + void GLCanvas3D::_zoom_to_bed() { _zoom_to_bounding_box(bed_bounding_box()); @@ -355,5 +366,15 @@ void GLCanvas3D::_zoom_to_bounding_box(const BoundingBoxf3& bbox) // >>>>>>>>>>>>>>>>>>>> TODO <<<<<<<<<<<<<<<<<<<<<<<< } +std::pair GLCanvas3D::_get_canvas_size() const +{ + std::pair ret(0, 0); + + if (m_canvas != nullptr) + m_canvas->GetSize(&ret.first, &ret.second); + + return ret; +} + } // namespace GUI } // namespace Slic3r diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 26d0949f0..7a8e763f9 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -6,6 +6,7 @@ class wxGLCanvas; class wxGLContext; class wxSizeEvent; +class wxIdleEvent; namespace Slic3r { @@ -120,16 +121,18 @@ public: const Pointf3& get_camera_target() const; void set_camera_target(const Pointf3& target); - void on_size(wxSizeEvent& evt); - BoundingBoxf3 bed_bounding_box() const; BoundingBoxf3 volumes_bounding_box() const; BoundingBoxf3 max_bounding_box() const; + void on_size(wxSizeEvent& evt); + void on_idle(wxIdleEvent& evt); + private: void _zoom_to_bed(); void _zoom_to_volumes(); void _zoom_to_bounding_box(const BoundingBoxf3& bbox); + std::pair _get_canvas_size() const; }; } // namespace GUI diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index b9bdde161..a3036c2ad 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -78,6 +78,7 @@ bool GLCanvas3DManager::add(wxGLCanvas* canvas, wxGLContext* context) return false; canvas->Bind(wxEVT_SIZE, [canvas3D](wxSizeEvent& evt) { canvas3D->on_size(evt); }); + canvas->Bind(wxEVT_IDLE, [canvas3D](wxIdleEvent& evt) { canvas3D->on_idle(evt); }); m_canvases.insert(CanvasesMap::value_type(canvas, canvas3D));