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
544726e4
Commit
544726e4
authored
Jul 31, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New display style for grid (dotted).
parent
d34df18f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
49 deletions
+87
-49
graphics_abstraction_layer.cpp
common/gal/graphics_abstraction_layer.cpp
+76
-46
graphics_abstraction_layer.h
include/gal/graphics_abstraction_layer.h
+11
-3
No files found.
common/gal/graphics_abstraction_layer.cpp
View file @
544726e4
...
...
@@ -47,6 +47,7 @@ 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
);
...
...
@@ -97,7 +98,20 @@ void GAL::DrawGrid()
SetTarget
(
TARGET_NONCACHED
);
// The grid consists of lines
// Draw the origin marker
double
origSize
=
static_cast
<
double
>
(
gridOriginMarkerSize
)
/
worldScale
;
SetLayerDepth
(
0.0
);
SetIsFill
(
false
);
SetIsStroke
(
true
);
SetStrokeColor
(
COLOR4D
(
1.0
,
1.0
,
1.0
,
1.0
)
);
SetLineWidth
(
gridLineWidth
/
worldScale
);
DrawLine
(
gridOrigin
+
VECTOR2D
(
-
origSize
,
-
origSize
),
gridOrigin
+
VECTOR2D
(
origSize
,
origSize
)
);
DrawLine
(
gridOrigin
+
VECTOR2D
(
-
origSize
,
origSize
),
gridOrigin
+
VECTOR2D
(
origSize
,
-
origSize
)
);
DrawCircle
(
gridOrigin
,
origSize
*
0.7
);
// Draw the grid
// For the drawing the start points, end points and increments have
// to be calculated in world coordinates
MATRIX3x3D
inverseMatrix
=
worldScreenMatrix
.
Inverse
();
...
...
@@ -107,23 +121,9 @@ void GAL::DrawGrid()
int
gridScreenSizeDense
=
round
(
gridSize
.
x
*
worldScale
);
int
gridScreenSizeCoarse
=
round
(
gridSize
.
x
*
static_cast
<
double
>
(
gridTick
)
*
worldScale
);
// Compute the line width of the grid
double
width
=
2.0
*
gridLineWidth
/
worldScale
;
double
doubleWidth
=
2.0
*
width
;
SetIsFill
(
false
);
SetIsStroke
(
true
);
// Draw the origin marker
SetLayerDepth
(
0.0
);
double
origSize
=
static_cast
<
double
>
(
gridOriginMarkerSize
)
/
worldScale
;
SetStrokeColor
(
COLOR4D
(
1.0
,
1.0
,
1.0
,
1.0
)
);
SetLineWidth
(
width
);
DrawLine
(
gridOrigin
+
VECTOR2D
(
-
origSize
,
-
origSize
),
gridOrigin
+
VECTOR2D
(
origSize
,
origSize
)
);
DrawLine
(
gridOrigin
+
VECTOR2D
(
-
origSize
,
origSize
),
gridOrigin
+
VECTOR2D
(
origSize
,
-
origSize
)
);
DrawCircle
(
gridOrigin
,
origSize
*
0.7
);
// Compute the line marker or point radius of the grid
double
marker
=
2.0
*
gridLineWidth
/
worldScale
;
double
doubleMarker
=
2.0
*
marker
;
// Check if the grid would not be too dense
if
(
std
::
max
(
gridScreenSizeDense
,
gridScreenSizeCoarse
)
>
gridDrawThreshold
)
...
...
@@ -144,21 +144,22 @@ void GAL::DrawGrid()
gridEndX
+=
1
;
gridEndY
+=
1
;
// Draw the grid behind all layers
// Draw the grid behind all
other
layers
SetLayerDepth
(
depthRange
.
y
*
0.75
);
if
(
gridStyle
==
GRID_STYLE_LINES
)
{
SetIsFill
(
false
);
SetIsStroke
(
true
);
SetStrokeColor
(
gridColor
);
// Now draw the grid, every coarse grid line gets the double width
for
(
int
j
=
gridStartY
;
j
<
gridEndY
;
j
+=
1
)
{
if
(
j
%
gridTick
==
0
&&
gridScreenSizeDense
>
gridDrawThreshold
)
{
SetLineWidth
(
doubleWidth
);
}
SetLineWidth
(
doubleMarker
);
else
{
SetLineWidth
(
width
);
}
SetLineWidth
(
marker
);
if
(
(
j
%
gridTick
==
0
&&
gridScreenSizeCoarse
>
gridDrawThreshold
)
||
gridScreenSizeDense
>
gridDrawThreshold
)
...
...
@@ -171,13 +172,9 @@ void GAL::DrawGrid()
for
(
int
i
=
gridStartX
;
i
<
gridEndX
;
i
+=
1
)
{
if
(
i
%
gridTick
==
0
&&
gridScreenSizeDense
>
gridDrawThreshold
)
{
SetLineWidth
(
doubleWidth
);
}
SetLineWidth
(
doubleMarker
);
else
{
SetLineWidth
(
width
);
}
SetLineWidth
(
marker
);
if
(
(
i
%
gridTick
==
0
&&
gridScreenSizeCoarse
>
gridDrawThreshold
)
||
gridScreenSizeDense
>
gridDrawThreshold
)
...
...
@@ -187,6 +184,39 @@ void GAL::DrawGrid()
}
}
}
else
// Dotted grid
{
bool
tickX
,
tickY
;
SetIsFill
(
true
);
SetIsStroke
(
false
);
SetFillColor
(
gridColor
);
for
(
int
j
=
gridStartY
;
j
<
gridEndY
;
j
+=
1
)
{
if
(
j
%
gridTick
==
0
&&
gridScreenSizeDense
>
gridDrawThreshold
)
tickY
=
true
;
else
tickY
=
false
;
for
(
int
i
=
gridStartX
;
i
<
gridEndX
;
i
+=
1
)
{
if
(
i
%
gridTick
==
0
&&
gridScreenSizeDense
>
gridDrawThreshold
)
tickX
=
true
;
else
tickX
=
false
;
if
(
tickX
||
tickY
||
gridScreenSizeDense
>
gridDrawThreshold
)
{
double
radius
=
(
tickX
&&
tickY
)
?
doubleMarker
:
marker
;
DrawRectangle
(
VECTOR2D
(
i
*
gridSize
.
x
-
radius
,
j
*
gridSize
.
y
-
radius
),
VECTOR2D
(
i
*
gridSize
.
x
+
radius
,
j
*
gridSize
.
y
+
radius
)
);
}
}
}
}
}
}
...
...
include/gal/graphics_abstraction_layer.h
View file @
544726e4
...
...
@@ -44,7 +44,7 @@ namespace KiGfx
/**
* GridStyle: Type definition of the grid style
*/
enum
G
ridStyle
enum
G
RID_STYLE
{
GRID_STYLE_LINES
,
///< Use lines for the grid
GRID_STYLE_DOTS
///< Use dots for the grid
...
...
@@ -668,8 +668,15 @@ public:
/// @brief Draw the grid
void
DrawGrid
();
// TODO Not yet implemented
// virtual void SetGridStyle(GridStyle gridStyle);
/**
* @brief Change the grid display style.
*
* @param aGridStyle is the new style for grid.
*/
inline
virtual
void
SetGridStyle
(
GRID_STYLE
aGridStyle
)
{
gridStyle
=
aGridStyle
;
}
// -------
// Cursor
...
...
@@ -758,6 +765,7 @@ protected:
// Grid settings
bool
gridVisibility
;
///< Should the grid be shown
GRID_STYLE
gridStyle
;
///< Grid display style
VECTOR2D
gridSize
;
///< The grid size
VECTOR2D
gridOrigin
;
///< The grid origin
COLOR4D
gridColor
;
///< Color of the grid
...
...
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