← Back to team overview

kicad-developers team mailing list archive

wxGTK3 patches

 

Two patches to fix some troubles occurring on wxGTK3. The first one
displays a warning when it detects that KiCad is being built against
wxGTK3. The second one makes eeschema functional, just a bit slower when
compared to wxGTK2. The only thing that is really broken is pcbnew
printing, but there are also some other glitches (e.g. black background
in eeschema printing preview, though the actual printouts are ok).

I have tested the patch under Linux and Windows and noticed no influence
on wxMSW/wxGTK2, as expected. I would love to hear from OSX users that
there are no new issues introduced in the patch.

Unfortunately, it does not resolve the recent wxpython-gtk3 issue on
Arch Linux. The problem occurs when KiCad is linked against wxGTK2, but
wxPython uses wxGTK3. In such case KiCad loads wxGTK2 libraries on start
and when wxPython is initialized - it tries to load wxGTK3 causing
symbol conflicts. I guess there is not much we can do about it, apart
from detecting such situation and informing the user about the problem
cause. Any other ideas?

Cheers,
Orson
From c0c6c2ef331d2d03ceeefb27aeba6da16163076e Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@xxxxxxx>
Date: Wed, 7 Feb 2018 13:35:31 +0100
Subject: [PATCH 1/2] GTK3: Display a warning and enable wxGraphicsContext

---
 CMakeLists.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 967927fb5..5cb5b9a20 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -508,6 +508,13 @@ find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml stc R
 # Include wxWidgets macros.
 include( ${wxWidgets_USE_FILE} )
 
+string( FIND "${wxWidgets_LIBRARIES}" "gtk3" GTK3_DETECTED )
+if( NOT ${GTK3_DETECTED} EQUAL -1 )
+    message( WARNING "\nwxWidgets library has been built against GTK3, it causes a lot of problems in KiCad" )
+    add_definitions( -DUSE_WX_GRAPHICS_CONTEXT )
+    add_definitions( -DWXGTK3 )
+endif()
+
 #
 # Find OpenGL library, required
 #
-- 
2.13.3

From b5e5f20e0fa51d4e0bb6902cc281825217181745 Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@xxxxxxx>
Date: Wed, 7 Feb 2018 15:00:26 +0100
Subject: [PATCH 2/2] wxWidgets/GTK3 compatibility fixes for eeschema

---
 common/draw_panel.cpp | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp
index f4b383a4a..97a1cae23 100644
--- a/common/draw_panel.cpp
+++ b/common/draw_panel.cpp
@@ -226,7 +226,14 @@ void EDA_DRAW_PANEL::DrawCrossHair( wxDC* aDC, COLOR4D aColor )
 
     wxPoint cursor = GetParent()->GetCrossHairPosition();
 
+#ifdef USE_WX_GRAPHICS_CONTEXT
+    // Normally cursor color is set to white, so when it is xored with white
+    // background, it is painted black effectively. wxGraphicsContext does not have
+    // xor operation, so we need to invert the color manually.
+    aColor.Invert();
+#else
     GRSetDrawMode( aDC, GR_XOR );
+#endif
 
     if( GetParent()->GetGalDisplayOptions().m_fullscreenCursor )
     {
@@ -597,6 +604,18 @@ void EDA_DRAW_PANEL::DoPrepareDC( wxDC& dc )
         dc.SetLogicalOrigin( pt.x, pt.y );
     }
 
+#if defined( USE_WX_GRAPHICS_CONTEXT )
+    wxGCDC* gcdc = wxDynamicCast( &dc, wxGCDC );
+
+    if( gcdc )
+    {
+        // Reduce the drawing quality to boost the performance
+        wxGraphicsContext* gc = gcdc->GetGraphicsContext();
+        gc->SetAntialiasMode( wxANTIALIAS_NONE );
+        gc->SetInterpolationQuality( wxINTERPOLATION_NONE );
+    }
+#endif
+
     SetClipBox( dc );                         // Reset the clip box to the entire screen.
     GRResetPenAndBrush( &dc );
     dc.SetBackgroundMode( wxTRANSPARENT );
@@ -687,8 +706,6 @@ void EDA_DRAW_PANEL::SetEnableZoomNoCenter( bool aEnable )
 
 void EDA_DRAW_PANEL::DrawBackGround( wxDC* DC )
 {
-    COLOR4D axis_color = COLOR4D( BLUE );
-
     GRSetDrawMode( DC, GR_COPY );
 
     if( GetParent()->IsGridVisible() )
@@ -697,6 +714,7 @@ void EDA_DRAW_PANEL::DrawBackGround( wxDC* DC )
     // Draw axis
     if( GetParent()->m_showAxis )
     {
+        COLOR4D axis_color = COLOR4D( BLUE );
         wxSize  pageSize = GetParent()->GetPageSizeIU();
 
         // Draw the Y axis
@@ -765,10 +783,13 @@ void EDA_DRAW_PANEL::DrawGrid( wxDC* aDC )
     double right = ( double ) m_ClipBox.GetRight();
     double bottom = ( double ) m_ClipBox.GetBottom();
 
-#if defined( __WXMAC__ ) && defined( USE_WX_GRAPHICS_CONTEXT )
+#if defined( USE_WX_GRAPHICS_CONTEXT )
+
     wxGCDC *gcdc = wxDynamicCast( aDC, wxGCDC );
+
     if( gcdc )
     {
+        // Much faster grid drawing on systems using wxGraphicsContext
         wxGraphicsContext *gc = gcdc->GetGraphicsContext();
 
         // Grid point size
@@ -1372,8 +1393,13 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
 #endif
 
     lastPanel = this;
-}
 
+#ifdef USE_WX_GRAPHICS_CONTEXT
+    // Screen has to be updated on every operation, otherwise the cursor leaves a trail (when xor
+    // operation is changed to copy) or is not updated at all.
+    Refresh();
+#endif
+}
 
 
 void EDA_DRAW_PANEL::OnCharHook( wxKeyEvent& event )
@@ -1381,6 +1407,7 @@ void EDA_DRAW_PANEL::OnCharHook( wxKeyEvent& event )
     event.Skip();
 }
 
+
 void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
 {
     int localkey;
-- 
2.13.3

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups