Commit 85ae0373 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Global variable removal and coordinate fixes.

* ActiveScreen global variable is gone, yeah!
* Use drawing coordinates instead of screen coordinates when calling
  GeneralControle().
parent 6f9fc8d2
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -13,8 +13,6 @@
#include "id.h"


BASE_SCREEN* ActiveScreen = NULL;

#define CURSOR_SIZE 12  /* size of the cross cursor. */


+11 −13
Original line number Diff line number Diff line
@@ -285,22 +285,19 @@ wxPoint EDA_DRAW_PANEL::GetScreenCenterLogicalPosition()
 */
void EDA_DRAW_PANEL::MouseToCursorSchema()
{
    wxPoint Mouse = CursorScreenPosition();

    MouseTo( Mouse );
    MoveCursor( GetScreen()->m_Curseur );
}


/** Move the mouse cursor to the position "Mouse"
 * @param Mouse = mouse cursor position, in pixels units
 */
void EDA_DRAW_PANEL::MouseTo( const wxPoint& Mouse )
void EDA_DRAW_PANEL::MoveCursor( const wxPoint& aPosition )
{
    int     x, y, xPpu, yPpu;
    wxPoint screenPos, drawingPos;
    wxRect  clientRect( wxPoint( 0, 0 ), GetClientSize() );

    CalcScrolledPosition( Mouse.x, Mouse.y, &screenPos.x, &screenPos.y );
    INSTALL_UNBUFFERED_DC( dc, this );
    screenPos.x = dc.LogicalToDeviceX( aPosition.x );
    screenPos.y = dc.LogicalToDeviceY( aPosition.y );

    // Scroll if the requested mouse position cursor is outside the drawing area.
    if( !clientRect.Contains( screenPos ) )
@@ -309,7 +306,7 @@ void EDA_DRAW_PANEL::MouseTo( const wxPoint& Mouse )
        GetScrollPixelsPerUnit( &xPpu, &yPpu );
        CalcUnscrolledPosition( screenPos.x, screenPos.y, &drawingPos.x, &drawingPos.y );

        wxLogDebug( wxT( "MouseTo() initial screen position(%d, %d) " ) \
        wxLogDebug( wxT( "MoveCursor() initial screen position(%d, %d) " ) \
                    wxT( "rectangle(%d, %d, %d, %d) view(%d, %d)" ),
                    screenPos.x, screenPos.y, clientRect.x, clientRect.y,
                    clientRect.width, clientRect.height, x, y );
@@ -326,7 +323,7 @@ void EDA_DRAW_PANEL::MouseTo( const wxPoint& Mouse )
        Scroll( x, y );
        CalcScrolledPosition( drawingPos.x, drawingPos.y, &screenPos.x, &screenPos.y );

        wxLogDebug( wxT( "MouseTo() scrolled screen position(%d, %d) view(%d, %d)" ),
        wxLogDebug( wxT( "MoveCursor() scrolled screen position(%d, %d) view(%d, %d)" ),
                    screenPos.x, screenPos.y, x, y );
    }

@@ -1007,7 +1004,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
    }

    /* Calling the general function on mouse changes (and pseudo key commands) */
    m_Parent->GeneralControle( &DC, pos );
    m_Parent->GeneralControle( &DC, event.GetLogicalPosition( DC ) );

    /*******************************/
    /* Control of block commands : */
@@ -1221,10 +1218,11 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
    }

    /* Some key commands use the current mouse position: refresh it */
    pos = CalcUnscrolledPosition( wxGetMousePosition() - GetScreenPosition() );
    pos = wxGetMousePosition() - GetScreenPosition();

    // Compute the cursor position in drawing units.  Also known as logical units to wxDC.
    Screen->m_MousePosition = CursorRealPosition( pos );
    pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) );
    Screen->m_MousePosition = pos;

    m_Parent->GeneralControle( &DC, pos );

+0 −2
Original line number Diff line number Diff line
@@ -70,8 +70,6 @@ static void GRSRect( EDA_Rect* aClipBox, wxDC* aDC, int x1, int y1,

/**/

extern BASE_SCREEN* ActiveScreen;

static int          GRLastMoveToX, GRLastMoveToY;
static bool         s_ForceBlackPen;   /* if true: draws in black instead of
                                        * color for printing. */
+4 −3
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ void EDA_DRAW_FRAME::RedrawScreen( bool aWarpPointer )
void EDA_DRAW_FRAME::PutOnGrid( wxPoint* aCoord , wxRealPoint* aGridSize )
{
    wxRealPoint grid_size;

    if( aGridSize )
        grid_size = *aGridSize;
    else
+26 −37
Original line number Diff line number Diff line
@@ -390,27 +390,19 @@ void DISPLAY_FOOTPRINTS_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
    SetToolbars();
}

void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse )
void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* aDC, wxPoint aPosition )
{
    wxRealPoint  delta;
    wxRealPoint gridSize;
    int         flagcurseur = 0;
    wxPoint curpos, oldpos;
    double scalar = GetScreen()->GetScalingFactor();
    wxPoint     oldpos;
    wxPoint     pos = aPosition;

    wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
    cmd.SetEventObject( this );

    curpos = DrawPanel->CursorRealPosition( Mouse );
    PutOnGrid( &pos );
    oldpos = GetScreen()->m_Curseur;

    delta = GetScreen()->GetGridSize();

    delta.x *= scalar;
    delta.y *= scalar;

    if( delta.x <= 0 )
        delta.x = 1;
    if( delta.y <= 0 )
        delta.y = 1;
    gridSize = GetScreen()->GetGridSize();

    switch( g_KeyPressed )
    {
@@ -418,14 +410,14 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse )
        cmd.SetId( ID_POPUP_ZOOM_IN );
        GetEventHandler()->ProcessEvent( cmd );
        flagcurseur = 2;
        curpos = GetScreen()->m_Curseur;
        pos = GetScreen()->m_Curseur;
        break;

    case WXK_F2:
        cmd.SetId( ID_POPUP_ZOOM_OUT );
        GetEventHandler()->ProcessEvent( cmd );
        flagcurseur = 2;
        curpos = GetScreen()->m_Curseur;
        pos = GetScreen()->m_Curseur;
        break;

    case WXK_F3:
@@ -438,14 +430,14 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse )
        cmd.SetId( ID_POPUP_ZOOM_CENTER );
        GetEventHandler()->ProcessEvent( cmd );
        flagcurseur = 2;
        curpos = GetScreen()->m_Curseur;
        pos = GetScreen()->m_Curseur;
        break;

    case WXK_HOME:
        cmd.SetId( ID_ZOOM_PAGE );
        GetEventHandler()->ProcessEvent( cmd );
        flagcurseur = 2;
        curpos = GetScreen()->m_Curseur;
        pos = GetScreen()->m_Curseur;
        break;

    case ' ':
@@ -454,32 +446,30 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse )

    case WXK_NUMPAD8:       /* cursor moved up */
    case WXK_UP:
        Mouse.y -= wxRound(delta.y);
        DrawPanel->MouseTo( Mouse );
        pos.y -= wxRound( gridSize.y );
        DrawPanel->MoveCursor( pos );
        break;

    case WXK_NUMPAD2:       /* cursor moved down */
    case WXK_DOWN:
        Mouse.y += wxRound(delta.y);
        DrawPanel->MouseTo( Mouse );
        pos.y += wxRound( gridSize.y );
        DrawPanel->MoveCursor( pos );
        break;

    case WXK_NUMPAD4:       /*  cursor moved left */
    case WXK_LEFT:
        Mouse.x -= wxRound(delta.x);
        DrawPanel->MouseTo( Mouse );
        pos.x -= wxRound( gridSize.x );
        DrawPanel->MoveCursor( pos );
        break;

    case WXK_NUMPAD6:      /*  cursor moved right */
    case WXK_RIGHT:
        Mouse.x += wxRound(delta.x);
        DrawPanel->MouseTo( Mouse );
        pos.x += wxRound( gridSize.x );
        DrawPanel->MoveCursor( pos );
        break;
    }

    GetScreen()->m_Curseur = curpos;
    /* Put cursor on grid */
    PutOnGrid( &GetScreen()->m_Curseur );
    GetScreen()->m_Curseur = pos;

    if( GetScreen()->IsRefreshReq() )
    {
@@ -491,17 +481,16 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControle( wxDC* DC, wxPoint Mouse )
    {
        if( flagcurseur != 2 )
        {
            curpos = GetScreen()->m_Curseur;
            pos = GetScreen()->m_Curseur;
            GetScreen()->m_Curseur = oldpos;
            DrawPanel->CursorOff( DC );

            GetScreen()->m_Curseur = curpos;
            DrawPanel->CursorOn( DC );
            DrawPanel->CursorOff( aDC );
            GetScreen()->m_Curseur = pos;
            DrawPanel->CursorOn( aDC );
        }

        if( DrawPanel->ManageCurseur )
        {
            DrawPanel->ManageCurseur( DrawPanel, DC, 0 );
            DrawPanel->ManageCurseur( DrawPanel, aDC, 0 );
        }
    }

Loading