Fixed resize issue (moved GAL panel into pane).

Tidied up event handlers.
This commit is contained in:
Maciej Suminski 2013-04-18 11:20:19 +02:00
parent 9af45c05bb
commit e4bac0d91a
13 changed files with 22 additions and 122 deletions

View File

@ -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;

View File

@ -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 )
{

View File

@ -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 );
}

View File

@ -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_;
}

View File

@ -33,8 +33,6 @@
using namespace KiGfx;
const wxEventType KiGfx::EVT_GAL_REDRAW = wxNewEventType();
GAL::GAL()
{
// Set the default values for the internal variables

View File

@ -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

View File

@ -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 );

View File

@ -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
};

View File

@ -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<LineCap, cairo_line_cap_t> 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.
*

View File

@ -38,8 +38,6 @@
namespace KiGfx
{
// Event declaration
extern const wxEventType EVT_GAL_REDRAW;
/**
* LineCap: Type definition of the line end point style

View File

@ -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.
*

View File

@ -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
}

View File

@ -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) );