From bee0d692892131d880ae4d59fb1ddf7cf7d8f808 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 16 Apr 2013 11:16:27 +0200 Subject: [PATCH] Cleanup --- common/drawpanel_gal.cpp | 55 +++++++++++++++----------------- common/gal/cairo/cairo_gal.cpp | 53 ++++++++++-------------------- common/gal/opengl/opengl_gal.cpp | 16 +++++----- include/class_drawpanel_gal.h | 9 +++--- include/gal/cairo/cairo_gal.h | 1 - 5 files changed, 54 insertions(+), 80 deletions(-) diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index 483bac5fc4..74d95866a8 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -40,30 +40,6 @@ #define METRIC_UNIT_LENGTH (1e9) -void EDA_DRAW_PANEL_GAL::onPaint( wxEvent& event ) -{ - m_gal->BeginDrawing(); - m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0, 0, 0, 1.0 ) ); - m_gal->ClearScreen(); - m_gal->SetGridOrigin( VECTOR2D( 0, 0 ) ); - m_gal->SetGridOriginMarkerSize( 15 ); - m_gal->SetGridSize( VECTOR2D( METRIC_UNIT_LENGTH / 10000.0, METRIC_UNIT_LENGTH / 10000.0 ) ); - m_gal->SetGridDrawThreshold( 10 ); - m_gal->SetLayerDepth( 0 ); - - m_gal->DrawGrid(); - m_view->Redraw(); - - m_gal->EndDrawing(); - m_gal->Flush(); -} - - -void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) -{ - m_gal->ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); -} - EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, const wxSize& aSize, @@ -102,14 +78,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_viewControls = new KiGfx::WX_VIEW_CONTROLS( m_view, this ); - m_painter = new KiGfx::PCB_PAINTER( m_gal ); - m_view->SetPainter( m_painter ); - #if wxCHECK_VERSION( 2, 9, 0 ) - Connect( KiGfx::EVT_GAL_REDRAW, wxEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); + Connect( KiGfx::EVT_GAL_REDRAW, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); #elif wxCHECK_VERSION( 2, 8, 0 ) // FIXME Cairo needs this to be uncommented to remove blinking on refreshing - Connect( wxEVT_PAINT, wxEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); + Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); #endif Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); } @@ -131,6 +104,30 @@ EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL() } +void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& aEvent ) +{ + m_gal->BeginDrawing(); + m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0, 0, 0, 1.0 ) ); + m_gal->ClearScreen(); + m_gal->SetGridOrigin( VECTOR2D( 0, 0 ) ); + m_gal->SetGridOriginMarkerSize( 15 ); + m_gal->SetGridSize( VECTOR2D( METRIC_UNIT_LENGTH / 10000.0, METRIC_UNIT_LENGTH / 10000.0 ) ); + m_gal->SetGridDrawThreshold( 10 ); + m_gal->SetLayerDepth( 0 ); + + m_gal->DrawGrid(); + m_view->Redraw(); + + m_gal->EndDrawing(); +} + + +void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent ) +{ + m_gal->ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); +} + + void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders ) { if( m_gal ) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index abd215f1a9..0d3b892748 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -51,25 +51,16 @@ 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 - this->Connect( wxEVT_SIZE, wxSizeEventHandler( CAIRO_GAL::onSize ) ); - this->Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) ); - this->Connect( wxEVT_ERASE_BACKGROUND, wxEraseEventHandler( CAIRO_GAL::onEraseBackground ) ); - aParent->Connect( wxEVT_ERASE_BACKGROUND, - wxEraseEventHandler( CAIRO_GAL::onEraseBackground ) ); - aParent->GetParent()->Connect( wxEVT_ERASE_BACKGROUND, - wxEraseEventHandler( CAIRO_GAL::onEraseBackground ) ); - - SetBackgroundStyle( wxBG_STYLE_CUSTOM ); - aParent->SetBackgroundStyle( wxBG_STYLE_CUSTOM ); - aParent->GetParent()->SetBackgroundStyle( wxBG_STYLE_CUSTOM ); - - this->Connect( wxEVT_MOTION, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOTION, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); // Initialize line attributes map lineCapMap[LINE_CAP_BUTT] = CAIRO_LINE_CAP_BUTT; @@ -88,8 +79,6 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); initCursor( 21 ); - screenSizeY = screenSize.y; - // Allocate memory allocateBitmaps(); @@ -105,9 +94,7 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, CAIRO_GAL::~CAIRO_GAL() { // TODO Deleting of list contents like groups and paths - delete[] bitmapBuffer; - delete[] bitmapBufferBackup; - delete wxBitmap_; + deleteBitmaps(); } @@ -117,17 +104,10 @@ void CAIRO_GAL::onPaint( wxPaintEvent& aEvent ) } -void CAIRO_GAL::onEraseBackground( wxEraseEvent& aEvent ) -{ - // FIXME -} - - void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) { deleteBitmaps(); - screenSizeY = aHeight; screenSize = VECTOR2D( aWidth, aHeight ); // Recreate the bitmaps @@ -141,9 +121,8 @@ void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) void CAIRO_GAL::onSize( wxSizeEvent& aEvent ) { - wxSize newSize = aEvent.GetSize(); - - ResizeScreen( newSize.x, newSize.y ); + ResizeScreen( aEvent.GetSize().x, aEvent.GetSize().y ); + PostPaint(); } @@ -225,7 +204,7 @@ void CAIRO_GAL::EndDrawing() int offset = 0; // Copy the cairo image to the wxDC bitmap - for( int j = 0; j < screenSizeY; j++ ) + for( int j = 0; j < screenSize.y; j++ ) { offset = j * (int) screenSize.x; @@ -234,7 +213,7 @@ void CAIRO_GAL::EndDrawing() unsigned int value = bitmapBuffer[offset + column]; pixelIterator.Red() = value >> 16; pixelIterator.Green() = value >> 8; - pixelIterator.Blue() = value >> 0; + pixelIterator.Blue() = value; pixelIterator++; } @@ -287,7 +266,7 @@ void CAIRO_GAL::SaveScreen() // Copy the current bitmap to the backup buffer int offset = 0; - for( int j = 0; j < screenSizeY; j++ ) + for( int j = 0; j < screenSize.y; j++ ) { for( int i = 0; i < stride; i++ ) { @@ -302,7 +281,7 @@ void CAIRO_GAL::RestoreScreen() { int offset = 0; - for( int j = 0; j < screenSizeY; j++ ) + for( int j = 0; j < screenSize.y; j++ ) { for( int i = 0; i < stride; i++ ) { diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 301fc26021..c839cb62f0 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -88,16 +88,16 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, SetGridLineWidth( 1.0 ); // Connecting the event handlers. - this->Connect( wxEVT_SIZE, wxSizeEventHandler( OPENGL_GAL::onSize ) ); - this->Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); + Connect( wxEVT_SIZE, wxSizeEventHandler( OPENGL_GAL::onSize ) ); + Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); // Mouse events are skipped to the parent - this->Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); - this->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); + Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); } diff --git a/include/class_drawpanel_gal.h b/include/class_drawpanel_gal.h index 63ed0cc6a1..e0b88da421 100644 --- a/include/class_drawpanel_gal.h +++ b/include/class_drawpanel_gal.h @@ -75,12 +75,11 @@ public: void SetView( KiGfx::VIEW* aView ) { m_view = aView; } KiGfx::VIEW* GetView() const { return m_view; } + //void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ); + protected: - void onPaint( wxEvent& event ); + void onPaint( wxPaintEvent& aEvent ); void onSize( wxSizeEvent& aEvent ); - void onMotion( wxMouseEvent& event ); - void onButton( wxMouseEvent& event ); - void onEraseBackground( wxEvent& event ); KiGfx::GAL* m_gal; ///< Interface for drawing objects on a 2D-surface KiGfx::VIEW* m_view; ///< Stores view settings (scale, center, etc.) @@ -92,7 +91,7 @@ protected: 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 + std::string m_galShaderPath; ///< Path to shader files, used in OpenGL mode }; #endif diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index 002622296d..87100c6016 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -377,7 +377,6 @@ private: * @param aEvent is the paint event. */ void onPaint( wxPaintEvent& aEvent ); - void onEraseBackground( wxEraseEvent& aEvent ); /** * @brief Window resizing event handler.