Commit bee0d692 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Cleanup

parent 01ebf031
Loading
Loading
Loading
Loading
+26 −29
Original line number Diff line number Diff line
@@ -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 )
+16 −37
Original line number Diff line number Diff line
@@ -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++ )
        {
+8 −8
Original line number Diff line number Diff line
@@ -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 ) );
}


+4 −5
Original line number Diff line number Diff line
@@ -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.)
+0 −1
Original line number Diff line number Diff line
@@ -377,7 +377,6 @@ private:
     * @param aEvent is the paint event.
     */
    void onPaint( wxPaintEvent& aEvent );
    void onEraseBackground( wxEraseEvent& aEvent );

    /**
     * @brief Window resizing event handler.