From 6561c8e61a59fdfa2fab3de89ab828a968be67dc Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 7 Feb 2017 00:05:07 +0100 Subject: [PATCH] Fixed a crash occuring on closing pad properties dialog in Windows Fixes: lp:1660276 * https://bugs.launchpad.net/kicad/+bug/1660276 --- common/view/wx_view_controls.cpp | 45 +++++++++++++++++++------------- include/view/wx_view_controls.h | 4 ++- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 1f390fd001..5b14b29d63 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -26,8 +26,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include - #include #include #include @@ -117,7 +115,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) double scrollX = 0.0; double scrollY = 0.0; - if ( m_enableMousewheelPan ) + if( m_enableMousewheelPan ) { if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() ) scrollX = scrollVec.x; @@ -126,7 +124,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) } else { - if ( aEvent.ControlDown() ) + if( aEvent.ControlDown() ) scrollX = -scrollVec.x; else scrollY = -scrollVec.y; @@ -328,9 +326,9 @@ void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent ) const BOX2I& boundary = m_view->GetBoundary(); if( aEvent.GetOrientation() == wxHORIZONTAL ) - center.x = (double) aEvent.GetPosition() * boundary.GetWidth() / m_scrollScale.x + boundary.GetLeft(); + center.x = boundary.GetLeft() + aEvent.GetPosition() / m_scrollScale.x; else if( aEvent.GetOrientation() == wxVERTICAL ) - center.y = (double) aEvent.GetPosition() * boundary.GetHeight() / m_scrollScale.y + boundary.GetTop(); + center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y; m_view->SetCenter( center ); m_parentPanel->Refresh(); @@ -483,19 +481,30 @@ void WX_VIEW_CONTROLS::UpdateScrollbars() const BOX2D viewport = m_view->GetViewport(); const BOX2I& boundary = m_view->GetBoundary(); - m_scrollScale.x = 2e3 * boundary.GetWidth() / viewport.GetWidth(); - m_scrollScale.y = 2e3 * boundary.GetHeight() / viewport.GetHeight(); + m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often + m_scrollScale.y = 2e3 / viewport.GetHeight(); + VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x, + ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y ); - // Another example of wxWidgets being broken by design: scroll position is determined by the - // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant - // (at least for wxGTK 3.0), so we have to add its size to allow user to scroll the workspace - // till the end. - m_parentPanel->SetScrollbars( 1, 1, -#ifdef __LINUX__ - m_scrollScale.x + 1623, m_scrollScale.y + 1623, + // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly + // refreshed (Windows) + if( m_scrollPos != newScroll ) + { + // Another example of wxWidgets being broken by design: scroll position is determined by the + // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant + // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace + // till the end. + + m_parentPanel->SetScrollbars( 1, 1, +#if defined(__LINUX__) + m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623, +#elif defined(__WIN32__) || defined(__WIN64__) + m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741, #else - m_scrollScale.x, m_scrollScale.y, + m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(), #endif - ( viewport.Centre().x - boundary.GetLeft() ) / boundary.GetWidth() * m_scrollScale.x, - ( viewport.Centre().y - boundary.GetTop() ) / boundary.GetHeight() * m_scrollScale.y ); + newScroll.x, newScroll.y, false ); + + m_scrollPos = newScroll; + } } diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 092ae5228c..482a1a8ccb 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -32,7 +32,6 @@ #define __WX_VIEW_CONTROLS_H #include -#include #include @@ -147,6 +146,9 @@ private: /// Ratio used for scaling world coordinates to scrollbar position. VECTOR2D m_scrollScale; + + /// Current scrollbar position + VECTOR2I m_scrollPos; }; } // namespace KIGFX