Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
6fe086ab
Commit
6fe086ab
authored
Aug 28, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added cursor snapping.
parent
215f35e2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
84 additions
and
12 deletions
+84
-12
drawframe.cpp
common/drawframe.cpp
+0
-3
drawpanel_gal.cpp
common/drawpanel_gal.cpp
+1
-1
cairo_gal.cpp
common/gal/cairo/cairo_gal.cpp
+3
-0
graphics_abstraction_layer.cpp
common/gal/graphics_abstraction_layer.cpp
+11
-1
opengl_gal.cpp
common/gal/opengl/opengl_gal.cpp
+3
-0
wx_view_controls.cpp
common/view/wx_view_controls.cpp
+12
-1
graphics_abstraction_layer.h
include/gal/graphics_abstraction_layer.h
+22
-1
wx_view_controls.h
include/view/wx_view_controls.h
+32
-5
No files found.
common/drawframe.cpp
View file @
6fe086ab
...
@@ -987,9 +987,6 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
...
@@ -987,9 +987,6 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
// Set up grid settings
// Set up grid settings
gal
->
SetGridVisibility
(
IsGridVisible
()
);
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
->
SetGridSize
(
VECTOR2D
(
screen
->
GetGridSize
().
x
,
screen
->
GetGridSize
().
y
)
);
gal
->
SetGridOrigin
(
VECTOR2D
(
screen
->
GetGridOrigin
()
)
);
gal
->
SetGridOrigin
(
VECTOR2D
(
screen
->
GetGridOrigin
()
)
);
gal
->
SetGridOriginMarkerSize
(
15
);
gal
->
SetGridOriginMarkerSize
(
15
);
...
...
common/drawpanel_gal.cpp
View file @
6fe086ab
...
@@ -134,7 +134,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
...
@@ -134,7 +134,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
if
(
m_view
->
IsTargetDirty
(
KiGfx
::
TARGET_NONCACHED
)
)
if
(
m_view
->
IsTargetDirty
(
KiGfx
::
TARGET_NONCACHED
)
)
m_gal
->
DrawGrid
();
m_gal
->
DrawGrid
();
m_view
->
Redraw
();
m_view
->
Redraw
();
m_gal
->
DrawCursor
(
m_viewControls
->
Get
Mouse
Position
()
);
m_gal
->
DrawCursor
(
m_viewControls
->
Get
Cursor
Position
()
);
m_gal
->
EndDrawing
();
m_gal
->
EndDrawing
();
...
...
common/gal/cairo/cairo_gal.cpp
View file @
6fe086ab
...
@@ -69,6 +69,9 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
...
@@ -69,6 +69,9 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
screenSize
=
VECTOR2D
(
aParent
->
GetSize
()
);
screenSize
=
VECTOR2D
(
aParent
->
GetSize
()
);
initCursor
(
20
);
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
// Allocate memory for pixel storage
allocateBitmaps
();
allocateBitmaps
();
}
}
...
...
common/gal/graphics_abstraction_layer.cpp
View file @
6fe086ab
...
@@ -48,7 +48,6 @@ GAL::GAL() :
...
@@ -48,7 +48,6 @@ GAL::GAL() :
// Set grid defaults
// Set grid defaults
SetGridVisibility
(
true
);
SetGridVisibility
(
true
);
SetGridStyle
(
GRID_STYLE_LINES
);
SetGridStyle
(
GRID_STYLE_LINES
);
SetGridColor
(
COLOR4D
(
0.4
,
0.4
,
0.4
,
1.0
)
);
SetCoarseGrid
(
10
);
SetCoarseGrid
(
10
);
SetGridLineWidth
(
0.5
);
SetGridLineWidth
(
0.5
);
...
@@ -230,3 +229,14 @@ void GAL::DrawGrid()
...
@@ -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
);
}
common/gal/opengl/opengl_gal.cpp
View file @
6fe086ab
...
@@ -84,6 +84,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
...
@@ -84,6 +84,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
screenSize
=
VECTOR2D
(
aParent
->
GetSize
()
);
screenSize
=
VECTOR2D
(
aParent
->
GetSize
()
);
initCursor
(
20
);
initCursor
(
20
);
// Grid color settings are different in Cairo and OpenGL
SetGridColor
(
COLOR4D
(
0.8
,
0.8
,
0.8
,
0.1
)
);
// Tesselator initialization
// Tesselator initialization
tesselator
=
gluNewTess
();
tesselator
=
gluNewTess
();
InitTesselatorCallbacks
(
tesselator
);
InitTesselatorCallbacks
(
tesselator
);
...
...
common/view/wx_view_controls.cpp
View file @
6fe086ab
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include <view/view.h>
#include <view/view.h>
#include <view/wx_view_controls.h>
#include <view/wx_view_controls.h>
#include <gal/graphics_abstraction_layer.h>
using
namespace
KiGfx
;
using
namespace
KiGfx
;
...
@@ -37,6 +38,7 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
...
@@ -37,6 +38,7 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
m_autoPanEnabled
(
false
),
m_autoPanEnabled
(
false
),
m_autoPanMargin
(
0.1
),
m_autoPanMargin
(
0.1
),
m_autoPanSpeed
(
0.15
),
m_autoPanSpeed
(
0.15
),
m_snappingEnabled
(
true
),
m_parentPanel
(
aParentPanel
)
m_parentPanel
(
aParentPanel
)
{
{
m_parentPanel
->
Connect
(
wxEVT_MOTION
,
wxMouseEventHandler
(
m_parentPanel
->
Connect
(
wxEVT_MOTION
,
wxMouseEventHandler
(
...
@@ -203,7 +205,16 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled )
...
@@ -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
()
);
VECTOR2D
p
(
aEvent
.
GetX
(),
aEvent
.
GetY
()
);
...
...
include/gal/graphics_abstraction_layer.h
View file @
6fe086ab
...
@@ -652,13 +652,23 @@ public:
...
@@ -652,13 +652,23 @@ public:
/**
/**
* @brief Set the grid size.
* @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
)
inline
void
SetGridSize
(
const
VECTOR2D
&
aGridSize
)
{
{
gridSize
=
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.
* @brief Set the grid color.
*
*
...
@@ -702,6 +712,17 @@ public:
...
@@ -702,6 +712,17 @@ public:
/// @brief Draw the grid
/// @brief Draw the grid
void
DrawGrid
();
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.
* @brief Change the grid display style.
*
*
...
...
include/view/wx_view_controls.h
View file @
6fe086ab
...
@@ -61,10 +61,21 @@ public:
...
@@ -61,10 +61,21 @@ public:
* 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).
*
*
* @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
);
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()
* Function SetAutoPan()
* Enables/disables autopanning (panning when mouse cursor reaches the panel border).
* Enables/disables autopanning (panning when mouse cursor reaches the panel border).
...
@@ -73,20 +84,31 @@ public:
...
@@ -73,20 +84,31 @@ public:
*/
*/
void
SetAutoPan
(
bool
aEnabled
)
void
SetAutoPan
(
bool
aEnabled
)
{
{
m_autoPanEnabled
=
true
;
m_autoPanEnabled
=
aEnabled
;
}
}
/**
/**
* Function GetMousePosition()
* 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
curso
r position.
* @return The current mouse
pointe
r position.
*/
*/
const
VECTOR2D
&
GetMousePosition
()
const
const
VECTOR2D
&
GetMousePosition
()
const
{
{
return
m_mousePosition
;
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
:
private
:
enum
State
{
enum
State
{
IDLE
=
1
,
IDLE
=
1
,
...
@@ -95,7 +117,7 @@ private:
...
@@ -95,7 +117,7 @@ private:
};
};
/// Computes new viewport settings while in autopanning mode
/// Computes new viewport settings while in autopanning mode
void
handleAutoPanning
(
wxMouseEvent
&
aEvent
);
void
handleAutoPanning
(
const
wxMouseEvent
&
aEvent
);
/// Current state of VIEW_CONTROLS
/// Current state of VIEW_CONTROLS
State
m_state
;
State
m_state
;
...
@@ -105,11 +127,16 @@ private:
...
@@ -105,11 +127,16 @@ private:
/// Flag for grabbing the mouse cursor
/// Flag for grabbing the mouse cursor
bool
m_grabMouse
;
bool
m_grabMouse
;
/// Flag for turning on autopanning
/// Flag for turning on autopanning
bool
m_autoPanEnabled
;
bool
m_autoPanEnabled
;
/// Distance from cursor to VIEW edge when panning is active
/// Distance from cursor to VIEW edge when panning is active
float
m_autoPanMargin
;
float
m_autoPanMargin
;
/// Should the cursor snap to grid or move freely
bool
m_snappingEnabled
;
/// How fast is panning when in auto mode
/// How fast is panning when in auto mode
float
m_autoPanSpeed
;
float
m_autoPanSpeed
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment