From e4bac0d91a6d66ba6cffd9b781bce1966cf97d75 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 18 Apr 2013 11:20:19 +0200 Subject: [PATCH] Fixed resize issue (moved GAL panel into pane). Tidied up event handlers. --- common/drawframe.cpp | 13 +++-- common/drawpanel.cpp | 15 ------ common/drawpanel_gal.cpp | 5 +- common/gal/cairo/cairo_gal.cpp | 65 ++--------------------- common/gal/graphics_abstraction_layer.cpp | 2 - common/gal/opengl/opengl_gal.cpp | 8 --- include/class_drawpanel.h | 3 -- include/class_drawpanel_gal.h | 3 -- include/gal/cairo/cairo_gal.h | 11 +--- include/gal/graphics_abstraction_layer.h | 2 - include/gal/opengl/opengl_gal.h | 9 +--- pcbnew/basepcbframe.cpp | 4 +- pcbnew/pcbframe.cpp | 4 ++ 13 files changed, 22 insertions(+), 122 deletions(-) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index c723a30cd0..d2eb982f47 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -966,20 +966,23 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); - m_galCanvas->Show(); - m_galCanvas->Refresh(); + // Switch panes + m_auimgr.GetPane( wxT( "DrawFrame" ) ).Hide(); + m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show(); + m_auimgr.Update(); } else { - m_galCanvas->Hide(); - double zoom = 1 / ( zoomFactor * view->GetScale() ); m_canvas->SetZoom( zoom ); VECTOR2D center = view->GetCenter(); RedrawScreen( wxPoint( center.x, center.y ), false ); - m_canvas->Show(); + // Switch panes + m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Hide(); + m_auimgr.GetPane( wxT( "DrawFrame" ) ).Show(); + m_auimgr.Update(); } m_galCanvasActive = aEnable; diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index cdb2db0dfe..2b8b6d4fd1 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -75,9 +75,6 @@ BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow ) EVT_ERASE_BACKGROUND( EDA_DRAW_PANEL::OnEraseBackground ) EVT_SCROLLWIN( EDA_DRAW_PANEL::OnScroll ) EVT_ACTIVATE( EDA_DRAW_PANEL::OnActivate ) -#ifdef KICAD_GAL - EVT_SIZE( EDA_DRAW_PANEL::OnSize ) -#endif EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, EDA_DRAW_PANEL::OnPan ) END_EVENT_TABLE() @@ -1381,18 +1378,6 @@ void EDA_DRAW_PANEL::OnPan( wxCommandEvent& event ) } -#ifdef KICAD_GAL -void EDA_DRAW_PANEL::OnSize( wxSizeEvent& SizeEv ) -{ - if( GetParent()->GetGalCanvas() != NULL ) - { - GetParent()->GetGalCanvas()->SetPosition( GetPosition() ); - GetParent()->GetGalCanvas()->SetSize( GetSize() ); - } -} -#endif - - void EDA_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title, bool aCallEndFunc ) { diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index 480713012c..77d8faf8fd 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -44,8 +44,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, const wxSize& aSize, GalType aGalType ) : - wxWindow( aParentWindow, aWindowId, aPosition, aSize ), - m_screenSize( aSize.x, aSize.y ), m_parentFrame( aParentWindow ) + wxWindow( aParentWindow, aWindowId, aPosition, aSize ) { m_gal = NULL; m_view = NULL; @@ -78,7 +77,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_viewControls = new KiGfx::WX_VIEW_CONTROLS( m_view, this ); - Connect( KiGfx::EVT_GAL_REDRAW, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); + Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); } diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 410d4d829a..1a6accc113 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -52,7 +52,6 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, SetSize( aParent->GetSize() ); // Connecting the event handlers - Connect( wxEVT_SIZE, wxSizeEventHandler( CAIRO_GAL::onSize ) ); Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) ); // Mouse events are skipped to the parent @@ -115,15 +114,6 @@ void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) allocateBitmaps(); SetSize( wxSize( aWidth, aHeight ) ); - - PostPaint(); -} - - -void CAIRO_GAL::onSize( wxSizeEvent& aEvent ) -{ - ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); - PostPaint(); } @@ -188,46 +178,6 @@ void CAIRO_GAL::EndDrawing() // Force remaining objects to be drawn Flush(); - // FIXME Accelerate support for wxWidgets 2.8.10 - -#if wxCHECK_VERSION( 2, 9, 0 ) - // Copy the cairo image contents to the wxBitmap - wxNativePixelData pixelData( *wxBitmap_ ); - - if( !pixelData ) - { - wxLogError( wxString::FromUTF8( "Can't access pixel data!" ) ); - return; - } - - wxNativePixelData::Iterator pixelIterator( pixelData ); - - int offset = 0; - - // Copy the cairo image to the wxDC bitmap - for( int j = 0; j < screenSize.y; j++ ) - { - offset = j * (int) screenSize.x; - - for( int column = 0; column < clientRectangle.width; column++ ) - { - unsigned int value = bitmapBuffer[offset + column]; - pixelIterator.Red() = value >> 16; - pixelIterator.Green() = value >> 8; - pixelIterator.Blue() = value; - pixelIterator++; - } - - pixelIterator.MoveTo( pixelData, 0, j ); - } - - // Blit the contents to the screen - wxClientDC client_dc( this ); - wxBufferedDC dc( &client_dc ); - dc.DrawBitmap( *wxBitmap_, 0, 0 ); - -#elif wxCHECK_VERSION( 2, 8, 0 ) - // This code was taken from the wxCairo example - it's not the most efficient one // Here is a good place for optimizations @@ -237,12 +187,9 @@ void CAIRO_GAL::EndDrawing() for( size_t count = 0; count < bufferSize; count++ ) { unsigned int value = bitmapBuffer[count]; - // Red pixel - *wxOutputPtr++ = (value >> 16) & 0xff; - // Green pixel - *wxOutputPtr++ = (value >> 8) & 0xff; - // Blue pixel - *wxOutputPtr++ = (value >> 0) & 0xff; + *wxOutputPtr++ = (value >> 16) & 0xff; // Red pixel + *wxOutputPtr++ = (value >> 8) & 0xff; // Green pixel + *wxOutputPtr++ = value & 0xff; // Blue pixel } wxImage img( (int) screenSize.x, (int) screenSize.y, (unsigned char*) wxOutput, true); @@ -252,10 +199,6 @@ void CAIRO_GAL::EndDrawing() // client_dc.DrawBitmap(bmp, 0, 0, false); dc.Init( &client_dc, bmp ); -#else -#error "need wxWidgets-2.8 as a minimum" -#endif - // Destroy Cairo objects cairo_destroy( cairoImage ); cairo_surface_destroy( cairoSurface ); @@ -967,7 +910,6 @@ void CAIRO_GAL::allocateBitmaps() bitmapBuffer = new unsigned int[bufferSize]; bitmapBufferBackup = new unsigned int[bufferSize]; wxOutput = new unsigned char[bufferSize * 4]; - wxBitmap_ = new wxBitmap( screenSize.x, screenSize.y, SCREEN_DEPTH ); } @@ -976,7 +918,6 @@ void CAIRO_GAL::deleteBitmaps() delete[] bitmapBuffer; delete[] bitmapBufferBackup; delete[] wxOutput; - delete wxBitmap_; } diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index e34efb2cba..a996fcbafb 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -33,8 +33,6 @@ using namespace KiGfx; -const wxEventType KiGfx::EVT_GAL_REDRAW = wxNewEventType(); - GAL::GAL() { // Set the default values for the internal variables diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index e0f5270342..1bb9bb3c33 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -88,7 +88,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, SetGridLineWidth( 1.0 ); // Connecting the event handlers. - Connect( wxEVT_SIZE, wxSizeEventHandler( OPENGL_GAL::onSize ) ); Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); // Mouse events are skipped to the parent @@ -147,13 +146,6 @@ void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight ) } -void OPENGL_GAL::onSize( wxSizeEvent& aEvent ) -{ - ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); - PostPaint(); -} - - void OPENGL_GAL::skipMouseEvent( wxMouseEvent& aEvent ) { // Post the mouse event to the event listener registered in constructor, if any diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index dcca64cb88..0e3fe4cf22 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -258,9 +258,6 @@ public: void OnCharHook( wxKeyEvent& event ); void OnPan( wxCommandEvent& event ); -#ifdef KICAD_GAL - void OnSize( wxSizeEvent& event ); -#endif void EraseScreen( wxDC* DC ); void OnScrollWin( wxCommandEvent& event ); diff --git a/include/class_drawpanel_gal.h b/include/class_drawpanel_gal.h index acde693b9a..6629908a3a 100644 --- a/include/class_drawpanel_gal.h +++ b/include/class_drawpanel_gal.h @@ -88,9 +88,6 @@ protected: ///< using GAL KiGfx::WX_VIEW_CONTROLS* m_viewControls; ///< Control for VIEW (moving, zooming, etc.) - VECTOR2D m_screenSize; ///< Stores current screen size - wxWindow* m_parentFrame; ///< Pointer to the parent frame - std::string m_galShaderPath; ///< Path to shader files, used in OpenGL mode }; diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index 767f5a2701..06db9f1f28 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -274,7 +274,7 @@ public: { if( paintListener ) { - wxCommandEvent redrawEvent( EVT_GAL_REDRAW ); + wxPaintEvent redrawEvent; wxPostEvent( paintListener, redrawEvent ); } } @@ -361,10 +361,8 @@ private: cairo_surface_t* cairoSurface; ///< Cairo surface unsigned int* bitmapBuffer; ///< Storage of the cairo image unsigned int* bitmapBufferBackup; ///< Backup storage of the cairo image - wxBitmap* wxBitmap_; ///< Pointer to the wxWidgets bitmap int stride; ///< Stride value for Cairo // wxClientDC* clientDC; ///< Pointer to the clientDC - int screenSizeY; ///< Vertical size of the actual surface // Mapping between Cairo and GAL line attributes std::map lineCapMap; ///< Line cap style mapping @@ -381,13 +379,6 @@ private: */ void onPaint( wxPaintEvent& aEvent ); - /** - * @brief Window resizing event handler. - * - * @param aEvent is the resizing event. - */ - void onSize( wxSizeEvent& aEvent ); - /** * @brief Mouse event handler, forwards the event to the child. * diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 40bf33b5c8..b6a114ca3c 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -38,8 +38,6 @@ namespace KiGfx { -// Event declaration -extern const wxEventType EVT_GAL_REDRAW; /** * LineCap: Type definition of the line end point style diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index bf967c2060..ce4ff73c39 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -292,7 +292,7 @@ public: { if( paintListener ) { - wxCommandEvent redrawEvent( EVT_GAL_REDRAW ); + wxPaintEvent redrawEvent; wxPostEvent( paintListener, redrawEvent ); } } @@ -411,13 +411,6 @@ private: */ void onPaint( wxPaintEvent& aEvent ); - /** - * @brief Window resizing event handler. - * - * @param aEvent is the window resizing event. - */ - void onSize( wxSizeEvent& aEvent ); - /** * @brief Skip the mouse event to the parent. * diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index a2b641508c..6b48ea89ac 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -134,7 +134,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType, #ifdef KICAD_GAL m_galCanvas = new EDA_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ); - m_galCanvas->Hide(); #endif /* KICAD_GAL */ m_auxiliaryToolBar = NULL; @@ -242,6 +241,9 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) } view->SetTopLayer( m_Pcb->GetLayer() ); + + if( m_galCanvasActive ) + m_galCanvas->Refresh(); } #endif } diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 439105b92b..b28b743e5e 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -416,6 +416,10 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); + if( m_galCanvas ) + m_auimgr.AddPane( m_galCanvas, + wxAuiPaneInfo().Name( wxT( "DrawFrameGal" ) ).CentrePane().Hide() ); + if( m_messagePanel ) m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) );