Commit 6fe086ab authored by Maciej Suminski's avatar Maciej Suminski

Added cursor snapping.

parent 215f35e2
......@@ -987,9 +987,6 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
// Set up grid settings
gal->SetGridVisibility( IsGridVisible() );
// Default grid color - dark cyan does not look good
//gal->SetGridColor( KiGfx::COLOR4D( GetGridColor() ) );
gal->SetGridColor( KiGfx::COLOR4D( 0.1, 0.1, 0.1, 1.0 ) );
gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) );
gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) );
gal->SetGridOriginMarkerSize( 15 );
......
......@@ -134,7 +134,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
if( m_view->IsTargetDirty( KiGfx::TARGET_NONCACHED ) )
m_gal->DrawGrid();
m_view->Redraw();
m_gal->DrawCursor( m_viewControls->GetMousePosition() );
m_gal->DrawCursor( m_viewControls->GetCursorPosition() );
m_gal->EndDrawing();
......
......@@ -69,6 +69,9 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
screenSize = VECTOR2D( aParent->GetSize() );
initCursor( 20 );
// Grid color settings are different in Cairo and OpenGL
SetGridColor( COLOR4D( 0.1, 0.1, 0.1, 0.8 ) );
// Allocate memory for pixel storage
allocateBitmaps();
}
......
......@@ -48,7 +48,6 @@ GAL::GAL() :
// Set grid defaults
SetGridVisibility( true );
SetGridStyle( GRID_STYLE_LINES );
SetGridColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
SetCoarseGrid( 10 );
SetGridLineWidth( 0.5 );
......@@ -230,3 +229,14 @@ void GAL::DrawGrid()
}
}
}
VECTOR2D GAL::GetGridPoint( VECTOR2D aPoint ) const
{
VECTOR2D pointWorld = ToWorld( aPoint );
pointWorld.x = round( pointWorld.x / gridSize.x ) * gridSize.x;
pointWorld.y = round( pointWorld.y / gridSize.y ) * gridSize.y;
return ToScreen( pointWorld );
}
......@@ -84,6 +84,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
screenSize = VECTOR2D( aParent->GetSize() );
initCursor( 20 );
// Grid color settings are different in Cairo and OpenGL
SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
// Tesselator initialization
tesselator = gluNewTess();
InitTesselatorCallbacks( tesselator );
......
......@@ -27,6 +27,7 @@
#include <view/view.h>
#include <view/wx_view_controls.h>
#include <gal/graphics_abstraction_layer.h>
using namespace KiGfx;
......@@ -37,6 +38,7 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
m_autoPanEnabled( false ),
m_autoPanMargin( 0.1 ),
m_autoPanSpeed( 0.15 ),
m_snappingEnabled( true ),
m_parentPanel( aParentPanel )
{
m_parentPanel->Connect( wxEVT_MOTION, wxMouseEventHandler(
......@@ -203,7 +205,16 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled )
}
void WX_VIEW_CONTROLS::handleAutoPanning( wxMouseEvent& aEvent )
VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const
{
if( m_snappingEnabled )
return m_view->GetGAL()->GetGridPoint( m_mousePosition );
return m_mousePosition;
}
void WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
{
VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
......
......@@ -652,13 +652,23 @@ public:
/**
* @brief Set the grid size.
*
* @param aGridSize is a vector containing the grid size in x- and y direction.
* @param aGridSize is a vector containing the grid size in x and y direction.
*/
inline void SetGridSize( const VECTOR2D& aGridSize )
{
gridSize = aGridSize;
}
/**
* @brief Returns the grid size.
*
* @return A vector containing the grid size in x and y direction.
*/
inline const VECTOR2D& GetGridSize() const
{
return gridSize;
}
/**
* @brief Set the grid color.
*
......@@ -702,6 +712,17 @@ public:
/// @brief Draw the grid
void DrawGrid();
/**
* Function GetGridPoint()
* For a given point it returns the nearest point belonging to the grid.
*
* @param aPoint is the point for which the grid point is searched.
* @return The nearest grid point.
*/
VECTOR2D GetGridPoint( VECTOR2D aPoint ) const;
/**
* @brief Change the grid display style.
*
......
......@@ -61,10 +61,21 @@ public:
* Function SetGrabMouse()
* Enables/disables mouse cursor grabbing (limits the movement field only to the panel area).
*
* @param aEnabled says whether the option should enabled or disabled.
* @param aEnabled says whether the option should be enabled or disabled.
*/
void SetGrabMouse( bool aEnabled );
/**
* Function SetSnapping()
* Enables/disables snapping cursor to grid.
*
* @param aEnabled says whether the opion should be enabled or disabled.
*/
void SetSnapping( bool aEnabled )
{
m_snappingEnabled = aEnabled;
}
/**
* Function SetAutoPan()
* Enables/disables autopanning (panning when mouse cursor reaches the panel border).
......@@ -73,20 +84,31 @@ public:
*/
void SetAutoPan( bool aEnabled )
{
m_autoPanEnabled = true;
m_autoPanEnabled = aEnabled;
}
/**
* Function GetMousePosition()
* Returns the current mouse cursor position in the screen coordinates.
* Returns the current mouse pointer position in the screen coordinates. Note, that it may be
* different from the cursor position if snapping is enabled (@see GetCursorPosition()).
*
* @return The current mouse cursor position.
* @return The current mouse pointer position.
*/
const VECTOR2D& GetMousePosition() const
{
return m_mousePosition;
}
/**
* Function GetCursorPosition()
* Returns the current cursor position in the screen coordinates. Note, that it may be
* different from the mouse pointer position if snapping is enabled (@see GetMousePosition()).
*
* @return The current cursor position.
*/
VECTOR2D GetCursorPosition() const;
private:
enum State {
IDLE = 1,
......@@ -95,7 +117,7 @@ private:
};
/// Computes new viewport settings while in autopanning mode
void handleAutoPanning( wxMouseEvent& aEvent );
void handleAutoPanning( const wxMouseEvent& aEvent );
/// Current state of VIEW_CONTROLS
State m_state;
......@@ -105,11 +127,16 @@ private:
/// Flag for grabbing the mouse cursor
bool m_grabMouse;
/// Flag for turning on autopanning
bool m_autoPanEnabled;
/// Distance from cursor to VIEW edge when panning is active
float m_autoPanMargin;
/// Should the cursor snap to grid or move freely
bool m_snappingEnabled;
/// How fast is panning when in auto mode
float m_autoPanSpeed;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment