Removing creation of a wxPaintEvent instance (step 2), not allowed in 3.1.4 wxWidgets:

Remove wxPaintEvent creation in 3D viewer
This commit is contained in:
jean-pierre charras 2020-07-14 15:52:01 +02:00
parent e9da02e2d5
commit 55f4c2b167
3 changed files with 39 additions and 21 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -61,6 +61,9 @@ const wxChar * EDA_3D_CANVAS::m_logTrace = wxT( "KI_TRACE_EDA_3D_CANVAS" );
const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f; const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f;
// A custom event, used to call DoRePaint during an idle time
wxDEFINE_EVENT( wxEVT_REFRESH_CUSTOM_COMMAND, wxEvent);
BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas ) BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas )
EVT_PAINT( EDA_3D_CANVAS::OnPaint ) EVT_PAINT( EDA_3D_CANVAS::OnPaint )
@ -79,6 +82,8 @@ BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas )
// other events // other events
EVT_ERASE_BACKGROUND( EDA_3D_CANVAS::OnEraseBackground ) EVT_ERASE_BACKGROUND( EDA_3D_CANVAS::OnEraseBackground )
//EVT_REFRESH_CUSTOM_COMMAND( ID_CUSTOM_EVENT_1, EDA_3D_CANVAS::OnRefreshRequest )
EVT_CUSTOM(wxEVT_REFRESH_CUSTOM_COMMAND, ID_CUSTOM_EVENT_1, EDA_3D_CANVAS::OnRefreshRequest )
EVT_CLOSE( EDA_3D_CANVAS::OnCloseWindow ) EVT_CLOSE( EDA_3D_CANVAS::OnCloseWindow )
EVT_SIZE( EDA_3D_CANVAS::OnResize ) EVT_SIZE( EDA_3D_CANVAS::OnResize )
@ -331,17 +336,22 @@ void EDA_3D_CANVAS::DisplayStatus()
} }
void EDA_3D_CANVAS::OnPaint( wxPaintEvent &event ) void EDA_3D_CANVAS::OnPaint( wxPaintEvent& aEvent )
{ {
// Please have a look at: // Please have a look at:
// https://lists.launchpad.net/kicad-developers/msg25149.html // https://lists.launchpad.net/kicad-developers/msg25149.html
// wxPaintDC( this ); // wxPaintDC( this );
// event.Skip( false ); // aEvent.Skip( false );
DoRePaint();
}
void EDA_3D_CANVAS::DoRePaint()
{
// SwapBuffer requires the window to be shown before calling // SwapBuffer requires the window to be shown before calling
if( !IsShownOnScreen() ) if( !IsShownOnScreen() )
{ {
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::OnPaint !IsShown" ); wxLogTrace( m_logTrace, "EDA_3D_CANVAS::DoRePaint !IsShown" );
return; return;
} }
@ -721,8 +731,13 @@ void EDA_3D_CANVAS::restart_editingTimeOut_Timer()
void EDA_3D_CANVAS::OnTimerTimeout_Redraw( wxTimerEvent &event ) void EDA_3D_CANVAS::OnTimerTimeout_Redraw( wxTimerEvent &event )
{ {
wxPaintEvent redrawEvent; Request_refresh( true );
wxPostEvent( this, redrawEvent ); }
void EDA_3D_CANVAS::OnRefreshRequest( wxEvent& aEvent )
{
DoRePaint();
} }
@ -730,21 +745,12 @@ void EDA_3D_CANVAS::Request_refresh( bool aRedrawImmediately )
{ {
if( aRedrawImmediately ) if( aRedrawImmediately )
{ {
// On some systems, just calling Refresh does not work always // Just calling Refresh() does not work always
// (Issue experienced on Win7 MSYS2) // Using an event to call DoRepaint ensure the repaint code will be executed,
//Refresh(); // and PostEvent will take priority to other events like mouse movements, keys, etc.
//Update(); // and is executed during the next idle time
wxCommandEvent redrawEvent( wxEVT_REFRESH_CUSTOM_COMMAND, ID_CUSTOM_EVENT_1 );
// Using PostEvent will take priority to other events like mouse movements, keys, etc.
wxPaintEvent redrawEvent;
wxPostEvent( this, redrawEvent ); wxPostEvent( this, redrawEvent );
// This behaves the same
// wxQueueEvent( this,
// From wxWidget documentation: "The heap-allocated and
// non-NULL event to queue, the function takes ownership of it."
// new wxPaintEvent()
// );
} }
else else
{ {

View File

@ -158,11 +158,21 @@ class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
void OnEvent( wxEvent& aEvent ); void OnEvent( wxEvent& aEvent );
private: private:
/** Called by a wxPaintEvent event
*/
void OnPaint( wxPaintEvent& aEvent );
void OnPaint( wxPaintEvent &event ); /**
* The actual function to repaint the canvas.
* It is usually called by OnPaint() but because it does not use a wxPaintDC
* it can be called outside a wxPaintEvent
*/
void DoRePaint();
void OnEraseBackground( wxEraseEvent &event ); void OnEraseBackground( wxEraseEvent &event );
void OnRefreshRequest( wxEvent& aEvent );
void OnMouseWheel( wxMouseEvent &event ); void OnMouseWheel( wxMouseEvent &event );
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )

View File

@ -64,5 +64,7 @@ enum id_3dview_frm
ID_DISABLE_RAY_TRACING, ID_DISABLE_RAY_TRACING,
ID_CUSTOM_EVENT_1, // A id for a custom event (canvas refresh request)
ID_END_COMMAND_3D = ID_KICAD_3D_VIEWER_END, ID_END_COMMAND_3D = ID_KICAD_3D_VIEWER_END,
}; };