From dd68a39960d9ed8b1d8f8f205afc4db6d8450230 Mon Sep 17 00:00:00 2001 From: asmwarrior Date: Fri, 4 Aug 2023 17:17:15 +0800 Subject: [PATCH 1/2] fix build error under msys2 with wxWidgets option enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit see discussion here: when building this library wxWidgets support under msys2, I got build error, here is a patch to fix the error Issue #210 · MicBosi/VisualizationLibrary — https://github.com/MicBosi/VisualizationLibrary/issues/210 --- src/gui/vlWX/WXGLCanvas.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/vlWX/WXGLCanvas.hpp b/src/gui/vlWX/WXGLCanvas.hpp index 4b555e01e..cf0a931f6 100644 --- a/src/gui/vlWX/WXGLCanvas.hpp +++ b/src/gui/vlWX/WXGLCanvas.hpp @@ -32,15 +32,16 @@ #ifndef vlWXGLCanvas_INCLUDE_ONCE #define vlWXGLCanvas_INCLUDE_ONCE -#include -#include -#include #include #include #include #include #include #include +#include +#include +#include + #if !wxUSE_GLCANVAS #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" From 4e11b4c0eb1b19b1182844c42247fdf53c55c3a2 Mon Sep 17 00:00:00 2001 From: asmwarrior Date: Mon, 7 Aug 2023 23:13:19 +0800 Subject: [PATCH 2/2] fix a mouse double click crash bug, not need to use the mMouseCounter here --- src/gui/vlWX/WXGLCanvas.cpp | 47 ++++++++++++++++++++----------------- src/gui/vlWX/WXGLCanvas.hpp | 3 +-- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/gui/vlWX/WXGLCanvas.cpp b/src/gui/vlWX/WXGLCanvas.cpp index 61cefaa09..a53ec8a40 100644 --- a/src/gui/vlWX/WXGLCanvas.cpp +++ b/src/gui/vlWX/WXGLCanvas.cpp @@ -72,9 +72,8 @@ wxGLCanvas(parent, id, attribList, pos, size, style, name, palette) { // let wxWidgets manage the deletion of this object setAutomaticDelete(false); - mMouseCount = 0; DragAcceptFiles(true); - + mWXGLContext = new wxGLContext(this); } //----------------------------------------------------------------------------- @@ -125,27 +124,37 @@ void WXGLCanvas::OnMouseWheel( wxMouseEvent& ev ) //----------------------------------------------------------------------------- void WXGLCanvas::OnMouseUp( wxMouseEvent& ev ) { - if (ev.GetButton() == wxMOUSE_BTN_NONE) - return; - switch(ev.GetButton()) + if (HasCapture()) { - case wxMOUSE_BTN_LEFT: dispatchMouseUpEvent(LeftButton, ev.GetX(), ev.GetY()); break; - case wxMOUSE_BTN_MIDDLE: dispatchMouseUpEvent(MiddleButton, ev.GetX(), ev.GetY()); break; - case wxMOUSE_BTN_RIGHT: dispatchMouseUpEvent(RightButton, ev.GetX(), ev.GetY()); break; - default: - case wxMOUSE_BTN_ANY: dispatchMouseUpEvent(UnknownButton, ev.GetX(), ev.GetY()); break; - } - mMouseCount--; - // release only once - if (!mMouseCount) + // Release the mouse capture ReleaseMouse(); - VL_CHECK(mMouseCount>=0) + + if (ev.GetButton() == wxMOUSE_BTN_NONE) + { + ev.Skip(); + return; + } + switch(ev.GetButton()) + { + case wxMOUSE_BTN_LEFT: dispatchMouseUpEvent(LeftButton, ev.GetX(), ev.GetY()); break; + case wxMOUSE_BTN_MIDDLE: dispatchMouseUpEvent(MiddleButton, ev.GetX(), ev.GetY()); break; + case wxMOUSE_BTN_RIGHT: dispatchMouseUpEvent(RightButton, ev.GetX(), ev.GetY()); break; + default: + case wxMOUSE_BTN_ANY: dispatchMouseUpEvent(UnknownButton, ev.GetX(), ev.GetY()); break; + } + ev.Skip(); + } } //----------------------------------------------------------------------------- void WXGLCanvas::OnMouseDown( wxMouseEvent& ev ) { + CaptureMouse(); + if (ev.GetButton() == wxMOUSE_BTN_NONE) + { + ev.Skip(); return; + } switch(ev.GetButton()) { case wxMOUSE_BTN_LEFT: dispatchMouseDownEvent(LeftButton, ev.GetX(), ev.GetY()); break; @@ -154,11 +163,7 @@ void WXGLCanvas::OnMouseDown( wxMouseEvent& ev ) default: case wxMOUSE_BTN_ANY: dispatchMouseDownEvent(UnknownButton, ev.GetX(), ev.GetY()); break; } - // capture only once - VL_CHECK(mMouseCount>=0) - if (!mMouseCount) - CaptureMouse(); - mMouseCount++; + ev.Skip(); } //----------------------------------------------------------------------------- void WXGLCanvas::OnSize(wxSizeEvent& ev) @@ -365,7 +370,7 @@ bool WXGLCanvas::setFullscreen(bool fullscreen) void WXGLCanvas::quitApplication() { wxApp* app = dynamic_cast(wxApp::GetInstance()); - if ( app ) + if ( app ) { app->ExitMainLoop(); } diff --git a/src/gui/vlWX/WXGLCanvas.hpp b/src/gui/vlWX/WXGLCanvas.hpp index cf0a931f6..72166b171 100644 --- a/src/gui/vlWX/WXGLCanvas.hpp +++ b/src/gui/vlWX/WXGLCanvas.hpp @@ -53,7 +53,7 @@ namespace vlWX class VLWX_EXPORT WXGLCanvas: public wxGLCanvas, public vl::OpenGLContext { public: - WXGLCanvas( + WXGLCanvas( wxWindow* parent, wxWindowID id = wxID_ANY, const int *attribList = NULL, @@ -102,7 +102,6 @@ namespace vlWX private: wxCursor mCursor; - int mMouseCount; wxGLContext* mWXGLContext; DECLARE_EVENT_TABLE() };