Cursor is in world coordinates.

This commit is contained in:
Maciej Suminski 2014-02-13 20:23:28 +01:00
parent f9f0b46b63
commit 597e98dbf4
13 changed files with 81 additions and 130 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -283,8 +283,6 @@ private:
wxPoint savedCursorPosition; ///< The last cursor position wxPoint savedCursorPosition; ///< The last cursor position
wxBitmap* cursorPixels; ///< Cursor pixels wxBitmap* cursorPixels; ///< Cursor pixels
wxBitmap* cursorPixelsSaved; ///< Saved cursor pixels wxBitmap* cursorPixelsSaved; ///< Saved cursor pixels
int cursorSize; ///< Cursor size
VECTOR2D cursorPosition; ///< Current cursor position
/// Maximum number of arguments for one command /// Maximum number of arguments for one command
static const int MAX_CAIRO_ARGUMENTS = 6; static const int MAX_CAIRO_ARGUMENTS = 6;
@ -354,8 +352,10 @@ private:
*/ */
void skipMouseEvent( wxMouseEvent& aEvent ); void skipMouseEvent( wxMouseEvent& aEvent );
/// @copydoc GAL::initCursor() /**
virtual void initCursor( int aCursorSize ); * @brief Prepares cursor bitmap.
*/
virtual void initCursor();
/** /**
* @brief Blits cursor into the current screen. * @brief Blits cursor into the current screen.

View File

@ -720,17 +720,15 @@ public:
/// @brief Draw the grid /// @brief Draw the grid
void DrawGrid(); void DrawGrid();
/** /**
* Function GetGridPoint() * Function GetGridPoint()
* For a given point it returns the nearest point belonging to the grid. * For a given point it returns the nearest point belonging to the grid in screen coordinates.
* *
* @param aPoint is the point for which the grid point is searched. * @param aPoint is the point for which the grid point is searched.
* @return The nearest grid point. * @return The nearest grid point in screen coordinates.
*/ */
VECTOR2D GetGridPoint( const VECTOR2D& aPoint ) const; VECTOR2D GetGridPoint( const VECTOR2D& aPoint ) const;
/** /**
* @brief Change the grid display style. * @brief Change the grid display style.
* *
@ -786,7 +784,7 @@ public:
/** /**
* @brief Set the cursor size. * @brief Set the cursor size.
* *
* @param aCursorSize is the size of the cursor. * @param aCursorSize is the size of the cursor expressed in pixels.
*/ */
inline void SetCursorSize( unsigned int aCursorSize ) inline void SetCursorSize( unsigned int aCursorSize )
{ {
@ -829,6 +827,8 @@ public:
/// Depth level on which the grid is drawn /// Depth level on which the grid is drawn
static const int GRID_DEPTH = 1024; static const int GRID_DEPTH = 1024;
static const double METRIC_UNIT_LENGTH = 1e9;
protected: protected:
std::stack<double> depthStack; ///< Stored depth values std::stack<double> depthStack; ///< Stored depth values
VECTOR2D screenSize; ///< Screen size in screen coordinates VECTOR2D screenSize; ///< Screen size in screen coordinates
@ -870,7 +870,8 @@ protected:
bool isCursorEnabled; ///< Is the cursor enabled? bool isCursorEnabled; ///< Is the cursor enabled?
COLOR4D cursorColor; ///< Cursor color COLOR4D cursorColor; ///< Cursor color
int cursorSize; ///< Size of the cursor in pixels unsigned int cursorSize; ///< Size of the cursor in pixels
VECTOR2D cursorPosition; ///< Current cursor position (world coordinates)
/// Instance of object that stores information about how to draw texts /// Instance of object that stores information about how to draw texts
STROKE_FONT strokeFont; STROKE_FONT strokeFont;
@ -889,13 +890,6 @@ protected:
*/ */
virtual void drawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) = 0; virtual void drawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) = 0;
/**
* @brief Initialize the cursor.
*
* @param aCursorSize is the size of the cursor.
*/
virtual void initCursor( int aCursorSize ) = 0;
static const int MIN_DEPTH = -2048; static const int MIN_DEPTH = -2048;
static const int MAX_DEPTH = 2047; static const int MAX_DEPTH = 2047;
}; };

View File

@ -299,8 +299,6 @@ private:
bool isShaderInitialized; ///< Was the shader initialized? bool isShaderInitialized; ///< Was the shader initialized?
bool isGrouping; ///< Was a group started? bool isGrouping; ///< Was a group started?
VECTOR2D cursorPosition; ///< Current cursor position
// Polygon tesselation // Polygon tesselation
/// The tessellator /// The tessellator
GLUtesselator* tesselator; GLUtesselator* tesselator;
@ -364,9 +362,6 @@ private:
/// Initialize GLEW /// Initialize GLEW
void initGlew(); void initGlew();
/// @copydoc GAL::initCursor()
virtual void initCursor( int aCursorSize );
/** /**
* @brief Blits cursor into the current screen. * @brief Blits cursor into the current screen.
*/ */

View File

@ -108,21 +108,22 @@ public:
/** /**
* Function GetMousePosition() * Function GetMousePosition()
* Returns the current mouse pointer position in the screen coordinates. Note, that it may be * Returns the current mouse pointer position in screen coordinates. Note, that it may be
* different from the cursor position if snapping is enabled (@see GetCursorPosition()). * different from the cursor position if snapping is enabled (@see GetCursorPosition()).
* *
* @return The current mouse pointer position. * @return The current mouse pointer position in screen coordinates.
*/ */
virtual const VECTOR2D GetMousePosition() const = 0; virtual VECTOR2D GetMousePosition() const = 0;
/** /**
* Function GetCursorPosition() * Function GetCursorPosition()
* Returns the current cursor position in the screen coordinates. Note, that it may be * Returns the current cursor position in world coordinates. Note, that it may be
* different from the mouse pointer position if snapping is enabled (@see GetMousePosition()). * different from the mouse pointer position if snapping is enabled or cursor position
* is forced to specific point.
* *
* @return The current cursor position in screen coordinates. * @return The current cursor position in world coordinates.
*/ */
virtual const VECTOR2D GetCursorPosition() const = 0; virtual VECTOR2D GetCursorPosition() const = 0;
/** /**
@ -131,7 +132,7 @@ public:
* @param aEnabled enable forced cursor position * @param aEnabled enable forced cursor position
* @param aPosition the position * @param aPosition the position
*/ */
virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D(0, 0) ) virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
{ {
m_forcedPosition = aPosition; m_forcedPosition = aPosition;
m_forceCursorPosition = aEnabled; m_forceCursorPosition = aEnabled;

View File

@ -58,13 +58,6 @@ public:
void onEnter( wxMouseEvent& WXUNUSED( aEvent ) ); void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
void onTimer( wxTimerEvent& WXUNUSED( aEvent ) ); void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
///> @copydoc VIEW_CONTROLS::SetSnapping()
void SetSnapping( bool aEnabled )
{
VIEW_CONTROLS::SetSnapping( aEnabled );
updateCursor();
}
/** /**
* Function SetGrabMouse() * Function SetGrabMouse()
* Enables/disables mouse cursor grabbing (limits the movement field only to the panel area). * Enables/disables mouse cursor grabbing (limits the movement field only to the panel area).
@ -88,13 +81,10 @@ public:
} }
/// @copydoc VIEW_CONTROLS::GetMousePosition() /// @copydoc VIEW_CONTROLS::GetMousePosition()
const VECTOR2D GetMousePosition() const; VECTOR2D GetMousePosition() const;
/// @copydoc VIEW_CONTROLS::GetCursorPosition() /// @copydoc VIEW_CONTROLS::GetCursorPosition()
const VECTOR2D GetCursorPosition() const VECTOR2D GetCursorPosition() const;
{
return m_cursorPosition;
}
/// Event that forces mouse move event in the dispatcher (eg. used in autopanning, when mouse /// Event that forces mouse move event in the dispatcher (eg. used in autopanning, when mouse
/// cursor does not move in screen coordinates, but does in world coordinates) /// cursor does not move in screen coordinates, but does in world coordinates)
@ -119,12 +109,6 @@ private:
*/ */
bool handleAutoPanning( const wxMouseEvent& aEvent ); bool handleAutoPanning( const wxMouseEvent& aEvent );
/**
* Function updateCursor()
* Recomputes the cursor coordinates basing on the current snapping settings and mouse position.
*/
void updateCursor();
/// Current state of VIEW_CONTROLS /// Current state of VIEW_CONTROLS
STATE m_state; STATE m_state;

View File

@ -281,7 +281,7 @@ void ROUTER_TOOL::updateEndItem( TOOL_EVENT& aEvent )
else else
{ {
m_endItem = NULL; m_endItem = NULL;
m_endSnapPoint = getView()->ToWorld( ctls->GetCursorPosition() ); m_endSnapPoint = ctls->GetCursorPosition();
ctls->ForceCursorPosition( false ); ctls->ForceCursorPosition( false );
} }

View File

@ -109,7 +109,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
break; break;
@ -254,7 +254,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
{ {
// Enable 45 degrees lines only mode by holding shift // Enable 45 degrees lines only mode by holding shift
bool linesAngle45 = evt->Modifier( MD_SHIFT ); bool linesAngle45 = evt->Modifier( MD_SHIFT );
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
break; break;
@ -343,7 +343,6 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
controls->SetSnapping( false ); controls->SetSnapping( false );
controls->SetAutoPan( false ); controls->SetAutoPan( false );
view->Remove( &preview ); view->Remove( &preview );
setTransitions(); setTransitions();
return 0; return 0;
@ -377,7 +376,7 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {
@ -465,7 +464,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {
@ -606,14 +605,14 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
Activate(); Activate();
VECTOR2D lastCursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I lastCursorPos = controls->GetCursorPosition();
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
// Enable 45 degrees lines only mode by holding shift // Enable 45 degrees lines only mode by holding shift
bool linesAngle45 = evt->Modifier( MD_SHIFT ); bool linesAngle45 = evt->Modifier( MD_SHIFT );
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {
@ -750,14 +749,14 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
Activate(); Activate();
VECTOR2D lastCursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I lastCursorPos = controls->GetCursorPosition();
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
// Enable 45 degrees lines only mode by holding shift // Enable 45 degrees lines only mode by holding shift
bool linesAngle45 = evt->Modifier( MD_SHIFT ); bool linesAngle45 = evt->Modifier( MD_SHIFT );
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {
@ -867,7 +866,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
target->SetLayer( EDGE_N ); target->SetLayer( EDGE_N );
target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth ); target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth );
target->SetSize( Millimeter2iu( 5 ) ); target->SetSize( Millimeter2iu( 5 ) );
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
// Add a VIEW_GROUP that serves as a preview for the new item // Add a VIEW_GROUP that serves as a preview for the new item
@ -883,7 +882,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {
@ -944,7 +943,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
} }
// Init the new item attributes // Init the new item attributes
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() ); VECTOR2I cursorPos = controls->GetCursorPosition();
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
// Add a VIEW_GROUP that serves as a preview for the new item // Add a VIEW_GROUP that serves as a preview for the new item
@ -961,7 +960,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
cursorPos = view->ToWorld( controls->GetCursorPosition() ); cursorPos = controls->GetCursorPosition();
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {

View File

@ -81,7 +81,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
if( !makeSelection( selection ) ) if( !makeSelection( selection ) )
return 0; return 0;
VECTOR2D dragPosition; // The last position of the cursor while dragging VECTOR2I dragPosition; // The last position of the cursor while dragging
m_dragging = false; // Are selected items being dragged? m_dragging = false; // Are selected items being dragged?
bool restore = false; // Should items' state be restored when finishing the tool? bool restore = false; // Should items' state be restored when finishing the tool?
@ -131,8 +131,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
if( m_dragging ) if( m_dragging )
{ {
// Drag items to the current cursor position // Drag items to the current cursor position
VECTOR2D movement = ( getView()->ToWorld( controls->GetCursorPosition() ) - VECTOR2I movement = ( controls->GetCursorPosition() - dragPosition );
dragPosition );
for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
{ {
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( i ) ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( i ) );
@ -151,7 +150,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
} }
selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY );
dragPosition = getView()->ToWorld( controls->GetCursorPosition() ); dragPosition = controls->GetCursorPosition();
} }
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
@ -205,7 +204,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
{ {
// Display properties dialog // Display properties dialog
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( 0 ) ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( 0 ) );
VECTOR2I cursor = getView()->ToWorld( getViewControls()->GetCursorPosition() ); VECTOR2I cursor = getViewControls()->GetCursorPosition();
// Check if user wants to edit pad or module properties // Check if user wants to edit pad or module properties
if( item->Type() == PCB_MODULE_T ) if( item->Type() == PCB_MODULE_T )
@ -451,7 +450,7 @@ wxPoint EDIT_TOOL::getModificationPoint( const SELECTION_TOOL::SELECTION& aSelec
} }
else else
{ {
VECTOR2I cursor = getView()->ToWorld( getViewControls()->GetCursorPosition() ); VECTOR2I cursor = getViewControls()->GetCursorPosition();
return wxPoint( cursor.x, cursor.y ); return wxPoint( cursor.x, cursor.y );
} }
} }