Commit 597e98db authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Cursor is in world coordinates.

parent f9f0b46b
Loading
Loading
Loading
Loading
+0 −11
Original line number Original line Diff line number Diff line
@@ -45,8 +45,6 @@
#include <profile.h>
#include <profile.h>
#endif /* __WXDEBUG__ */
#endif /* __WXDEBUG__ */


#define METRIC_UNIT_LENGTH (1e9)

EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
                                        const wxPoint& aPosition, const wxSize& aSize,
                                        const wxPoint& aPosition, const wxSize& aSize,
                                        GalType aGalType ) :
                                        GalType aGalType ) :
@@ -61,11 +59,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
    SwitchBackend( aGalType );
    SwitchBackend( aGalType );
    SetBackgroundStyle( wxBG_STYLE_CUSTOM );
    SetBackgroundStyle( wxBG_STYLE_CUSTOM );


    // Initial display settings
    m_gal->SetLookAtPoint( VECTOR2D( 0, 0 ) );
    m_gal->SetZoomFactor( 1.0 );
    m_gal->ComputeWorldScreenMatrix();

    m_painter = new KIGFX::PCB_PAINTER( m_gal );
    m_painter = new KIGFX::PCB_PAINTER( m_gal );


    m_view = new KIGFX::VIEW( true );
    m_view = new KIGFX::VIEW( true );
@@ -220,10 +213,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
        return;
        return;
    }
    }


    m_gal->SetWorldUnitLength( 1.0 / METRIC_UNIT_LENGTH * 2.54 );   // 1 inch in nanometers
    m_gal->SetScreenDPI( 106 );                                     // Display resolution setting
    m_gal->ComputeWorldScreenMatrix();

    wxSize size = GetClientSize();
    wxSize size = GetClientSize();
    m_gal->ResizeScreen( size.GetX(), size.GetY() );
    m_gal->ResizeScreen( size.GetX(), size.GetY() );


+11 −11
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,


    SetSize( aParent->GetSize() );
    SetSize( aParent->GetSize() );
    screenSize = VECTOR2D( aParent->GetSize() );
    screenSize = VECTOR2D( aParent->GetSize() );
    initCursor( 20 );
    initCursor();


    // Grid color settings are different in Cairo and OpenGL
    // Grid color settings are different in Cairo and OpenGL
    SetGridColor( COLOR4D( 0.1, 0.1, 0.1, 0.8 ) );
    SetGridColor( COLOR4D( 0.1, 0.1, 0.1, 0.8 ) );
@@ -881,11 +881,10 @@ void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent )
}
}




void CAIRO_GAL::initCursor( int aCursorSize )
void CAIRO_GAL::initCursor()
{
{
    cursorPixels      = new wxBitmap( aCursorSize, aCursorSize );
    cursorPixels      = new wxBitmap( cursorSize, cursorSize );
    cursorPixelsSaved = new wxBitmap( aCursorSize, aCursorSize );
    cursorPixelsSaved = new wxBitmap( cursorSize, cursorSize );
    cursorSize        = aCursorSize;


    wxMemoryDC cursorShape( *cursorPixels );
    wxMemoryDC cursorShape( *cursorPixels );


@@ -896,8 +895,8 @@ void CAIRO_GAL::initCursor( int aCursorSize )
    cursorShape.SetPen( pen );
    cursorShape.SetPen( pen );
    cursorShape.Clear();
    cursorShape.Clear();


    cursorShape.DrawLine( 0, aCursorSize / 2, aCursorSize, aCursorSize / 2 );
    cursorShape.DrawLine( 0, cursorSize / 2, cursorSize, cursorSize / 2 );
    cursorShape.DrawLine( aCursorSize / 2, 0, aCursorSize / 2, aCursorSize );
    cursorShape.DrawLine( cursorSize / 2, 0, cursorSize / 2, cursorSize );
}
}




@@ -921,14 +920,15 @@ void CAIRO_GAL::blitCursor( wxBufferedDC& clientDC )
    }
    }


    // Store pixels that are going to be overpainted
    // Store pixels that are going to be overpainted
    cursorSave.Blit( 0, 0, cursorSize, cursorSize, &clientDC, cursorPosition.x, cursorPosition.y );
    VECTOR2D cursorScreen = ToScreen( cursorPosition ) - cursorSize / 2;
    cursorSave.Blit( 0, 0, cursorSize, cursorSize, &clientDC, cursorScreen.x, cursorScreen.y );


    // Draw the cursor
    // Draw the cursor
    clientDC.Blit( cursorPosition.x, cursorPosition.y, cursorSize, cursorSize,
    clientDC.Blit( cursorScreen.x, cursorScreen.y, cursorSize, cursorSize,
                   &cursorShape, 0, 0, wxOR );
                   &cursorShape, 0, 0, wxOR );


    savedCursorPosition.x = (wxCoord) cursorPosition.x;
    savedCursorPosition.x = (wxCoord) cursorScreen.x;
    savedCursorPosition.y = (wxCoord) cursorPosition.y;
    savedCursorPosition.y = (wxCoord) cursorScreen.y;
}
}




+3 −0
Original line number Original line Diff line number Diff line
@@ -39,7 +39,10 @@ GAL::GAL() :
    SetIsStroke( true );
    SetIsStroke( true );
    SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
    SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetLookAtPoint( VECTOR2D( 0, 0 ) );
    SetZoomFactor( 1.0 );
    SetZoomFactor( 1.0 );
    SetWorldUnitLength( 1.0 / METRIC_UNIT_LENGTH * 2.54 );   // 1 inch in nanometers
    SetScreenDPI( 106 );                                     // Display resolution setting
    SetDepthRange( VECTOR2D( GAL::MIN_DEPTH, GAL::MAX_DEPTH ) );
    SetDepthRange( VECTOR2D( GAL::MIN_DEPTH, GAL::MAX_DEPTH ) );
    SetFlip( false, false );
    SetFlip( false, false );
    SetLineWidth( 1.0 );
    SetLineWidth( 1.0 );
+5 −18
Original line number Original line Diff line number Diff line
@@ -86,7 +86,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,


    SetSize( aParent->GetSize() );
    SetSize( aParent->GetSize() );
    screenSize = VECTOR2D( aParent->GetSize() );
    screenSize = VECTOR2D( aParent->GetSize() );
    initCursor( 80 );


    // Grid color settings are different in Cairo and OpenGL
    // Grid color settings are different in Cairo and OpenGL
    SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
    SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
@@ -769,8 +768,8 @@ void OPENGL_GAL::DrawCursor( const VECTOR2D& aCursorPosition )
{
{
    // Now we should only store the position of the mouse cursor
    // Now we should only store the position of the mouse cursor
    // The real drawing routines are in blitCursor()
    // The real drawing routines are in blitCursor()
    cursorPosition = VECTOR2D( aCursorPosition.x,
    VECTOR2D screenCursor = worldScreenMatrix * aCursorPosition;
                               screenSize.y - aCursorPosition.y ); // invert Y axis
    cursorPosition = screenWorldMatrix * VECTOR2D( screenCursor.x, screenSize.y - screenCursor.y );
}
}




@@ -780,13 +779,9 @@ void OPENGL_GAL::drawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd


    // We do not need a very precise comparison here (the lineWidth is set by GAL::DrawGrid())
    // We do not need a very precise comparison here (the lineWidth is set by GAL::DrawGrid())
    if( fabs( lineWidth - 2.0 * gridLineWidth / worldScale ) < 0.1 )
    if( fabs( lineWidth - 2.0 * gridLineWidth / worldScale ) < 0.1 )
    {
        glLineWidth( 1.0 );
        glLineWidth( 1.0 );
    }
    else
    else
    {
        glLineWidth( 2.0 );
        glLineWidth( 2.0 );
    }


    glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
    glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );


@@ -970,12 +965,6 @@ void OPENGL_GAL::initGlew()
}
}




void OPENGL_GAL::initCursor( int aCursorSize )
{
    cursorSize = aCursorSize;
}


void OPENGL_GAL::blitCursor()
void OPENGL_GAL::blitCursor()
{
{
    if( !isCursorEnabled )
    if( !isCursorEnabled )
@@ -983,11 +972,9 @@ void OPENGL_GAL::blitCursor()


    compositor.SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING );
    compositor.SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING );


    VECTOR2D cursorBegin  = ToWorld( cursorPosition -
    VECTOR2D cursorBegin  = cursorPosition - cursorSize / ( 2 * worldScale );
                                     VECTOR2D( cursorSize / 2, cursorSize / 2 ) );
    VECTOR2D cursorEnd    = cursorPosition + cursorSize / ( 2 * worldScale );
    VECTOR2D cursorEnd    = ToWorld( cursorPosition +
    VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
                                     VECTOR2D( cursorSize / 2, cursorSize / 2 ) );
    VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2.0;


    glDisable( GL_TEXTURE_2D );
    glDisable( GL_TEXTURE_2D );
    glLineWidth( 1.0 );
    glLineWidth( 1.0 );
+22 −22
Original line number Original line Diff line number Diff line
@@ -68,11 +68,6 @@ void VIEW_CONTROLS::ShowCursor( bool aEnabled )


void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
{
{
    m_mousePosition.x = aEvent.GetX();
    m_mousePosition.y = aEvent.GetY();

    updateCursor();

    bool isAutoPanning = false;
    bool isAutoPanning = false;


    if( m_autoPanEnabled )
    if( m_autoPanEnabled )
@@ -82,7 +77,7 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
    {
    {
        if( m_state == DRAG_PANNING )
        if( m_state == DRAG_PANNING )
        {
        {
            VECTOR2D   d = m_dragStartPoint - m_mousePosition;
            VECTOR2D   d = m_dragStartPoint - VECTOR2D( aEvent.GetX(), aEvent.GetY() );
            VECTOR2D   delta = m_view->ToWorld( d, false );
            VECTOR2D   delta = m_view->ToWorld( d, false );


            m_view->SetCenter( m_lookStartPoint + delta );
            m_view->SetCenter( m_lookStartPoint + delta );
@@ -197,8 +192,6 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
        dir = m_view->ToWorld( dir, false );
        dir = m_view->ToWorld( dir, false );
        m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed );
        m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed );


        updateCursor();

        // Notify tools that the cursor position has changed in the world coordinates
        // Notify tools that the cursor position has changed in the world coordinates
        wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
        wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );


@@ -236,7 +229,7 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled )
}
}




const VECTOR2D WX_VIEW_CONTROLS::GetMousePosition() const
VECTOR2D WX_VIEW_CONTROLS::GetMousePosition() const
{
{
    wxPoint msp = wxGetMousePosition();
    wxPoint msp = wxGetMousePosition();
    wxPoint winp = m_parentPanel->GetScreenPosition();
    wxPoint winp = m_parentPanel->GetScreenPosition();
@@ -245,6 +238,22 @@ const VECTOR2D WX_VIEW_CONTROLS::GetMousePosition() const
}
}




VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const
{
    if( m_forceCursorPosition )
        return m_forcedPosition;
    else
    {
        VECTOR2D mousePosition = GetMousePosition();

        if( m_snappingEnabled )
            return m_view->ToWorld( m_view->GetGAL()->GetGridPoint( mousePosition ) );
        else
            return m_view->ToWorld( mousePosition );
    }
}


bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
{
{
    VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
    VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
@@ -255,17 +264,19 @@ bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
    double borderEndX = m_view->GetScreenPixelSize().x - borderStart;
    double borderEndX = m_view->GetScreenPixelSize().x - borderStart;
    double borderEndY = m_view->GetScreenPixelSize().y - borderStart;
    double borderEndY = m_view->GetScreenPixelSize().y - borderStart;


    m_panDirection = VECTOR2D();

    if( p.x < borderStart )
    if( p.x < borderStart )
        m_panDirection.x = -( borderStart - p.x );
        m_panDirection.x = -( borderStart - p.x );
    else if( p.x > borderEndX )
    else if( p.x > borderEndX )
        m_panDirection.x = ( p.x - borderEndX );
        m_panDirection.x = ( p.x - borderEndX );
    else
        m_panDirection.x = 0;


    if( p.y < borderStart )
    if( p.y < borderStart )
        m_panDirection.y = -( borderStart - p.y );
        m_panDirection.y = -( borderStart - p.y );
    else if( p.y > borderEndY )
    else if( p.y > borderEndY )
        m_panDirection.y = ( p.y - borderEndY );
        m_panDirection.y = ( p.y - borderEndY );
    else
        m_panDirection.y = 0;


    bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
    bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );


@@ -302,14 +313,3 @@ bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
    wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
    wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
    return false;    // Should not be reached, just avoid the compiler warnings..
    return false;    // Should not be reached, just avoid the compiler warnings..
}
}


void WX_VIEW_CONTROLS::updateCursor()
{
    if( m_forceCursorPosition )
        m_cursorPosition = m_view->ToScreen( m_forcedPosition );
    else if( m_snappingEnabled )
        m_cursorPosition = m_view->GetGAL()->GetGridPoint( m_mousePosition );
    else
        m_cursorPosition = m_mousePosition;
}
Loading