GAL mode: Add small cross option to grid style (now: options are Dots, Grid, Small cross)

This commit is contained in:
jean-pierre charras 2017-03-01 10:29:19 +01:00
parent 96b32861cd
commit 1cffcafe2d
7 changed files with 118 additions and 42 deletions

View File

@ -51,6 +51,7 @@ static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> gridStyleConfigVals =
{
{ KIGFX::GRID_STYLE::DOTS, 0 },
{ KIGFX::GRID_STYLE::LINES, 1 },
{ KIGFX::GRID_STYLE::SMALL_CROSS,2 },
};

View File

@ -267,6 +267,41 @@ void GAL::DrawGrid()
}
}
}
else if( gridStyle == GRID_STYLE::SMALL_CROSS )
{
SetIsFill( false );
SetIsStroke( true );
SetStrokeColor( gridColor );
SetLineWidth( marker );
double lineLen = GetLineWidth() * 2;
// Vertical positions:
for( int j = gridStartY; j != gridEndY; j += dirY )
{
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posY = j * gridSize.y + gridOrigin.y;
// Horizontal positions:
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posX = i * gridSize.x + gridOrigin.x;
drawGridLine( VECTOR2D( posX - lineLen, posY ),
VECTOR2D( posX + lineLen, posY ) );
drawGridLine( VECTOR2D( posX, posY - lineLen ),
VECTOR2D( posX, posY + lineLen ) );
}
}
}
}
}
else // Dotted grid
{
bool tickX, tickY;

View File

@ -906,50 +906,88 @@ void OPENGL_GAL::DrawGrid()
glColor4d( gridColor.r, gridColor.g, gridColor.b, 1.0 );
}
// Vertical lines
for( int j = gridStartY; j != gridEndY; j += dirY )
if( gridStyle == GRID_STYLE::SMALL_CROSS )
{
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
glLineWidth( majorLineWidth );
else
glLineWidth( minorLineWidth );
glLineWidth( minorLineWidth );
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
// calculate a line len = 2 minorLineWidth, in internal unit value
// (in fact the size of cross is lineLen*2)
int lineLen = KiROUND( minorLineWidth / worldScale *2 );
// Vertical positions
for( int j = gridStartY; j != gridEndY; j += dirY )
{
glBegin( GL_LINES );
glVertex2d( gridStartX * gridSize.x, j * gridSize.y + gridOrigin.y );
glVertex2d( gridEndX * gridSize.x, j * gridSize.y + gridOrigin.y );
glEnd();
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posY = j * gridSize.y + gridOrigin.y;
// Horizontal positions
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
int posX = i * gridSize.x + gridOrigin.x;
glBegin( GL_LINES );
glVertex2d( posX -lineLen, posY );
glVertex2d( posX + lineLen, posY );
glVertex2d( posX, posY - lineLen );
glVertex2d( posX, posY + lineLen );
glEnd();
}
}
}
}
}
if( gridStyle == GRID_STYLE::DOTS )
else
{
glStencilFunc( GL_NOTEQUAL, 0, 1 );
glColor4d( gridColor.r, gridColor.g, gridColor.b, 1.0 );
}
// Horizontal lines
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
glLineWidth( majorLineWidth );
else
glLineWidth( minorLineWidth );
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
// Vertical lines
for( int j = gridStartY; j != gridEndY; j += dirY )
{
glBegin( GL_LINES );
glVertex2d( i * gridSize.x + gridOrigin.x, gridStartY * gridSize.y );
glVertex2d( i * gridSize.x + gridOrigin.x, gridEndY * gridSize.y );
glEnd();
}
}
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
glLineWidth( majorLineWidth );
else
glLineWidth( minorLineWidth );
if( gridStyle == GRID_STYLE::DOTS )
glDisable( GL_STENCIL_TEST );
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
glBegin( GL_LINES );
glVertex2d( gridStartX * gridSize.x, j * gridSize.y + gridOrigin.y );
glVertex2d( gridEndX * gridSize.x, j * gridSize.y + gridOrigin.y );
glEnd();
}
}
if( gridStyle == GRID_STYLE::DOTS )
{
glStencilFunc( GL_NOTEQUAL, 0, 1 );
glColor4d( gridColor.r, gridColor.g, gridColor.b, 1.0 );
}
// Horizontal lines
for( int i = gridStartX; i != gridEndX; i += dirX )
{
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
glLineWidth( majorLineWidth );
else
glLineWidth( minorLineWidth );
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold )
{
glBegin( GL_LINES );
glVertex2d( i * gridSize.x + gridOrigin.x, gridStartY * gridSize.y );
glVertex2d( i * gridSize.x + gridOrigin.x, gridEndY * gridSize.y );
glEnd();
}
}
if( gridStyle == GRID_STYLE::DOTS )
glDisable( GL_STENCIL_TEST );
}
glEnable( GL_DEPTH_TEST );
glEnable( GL_TEXTURE_2D );

View File

@ -36,8 +36,9 @@ namespace KIGFX
*/
enum class GRID_STYLE
{
LINES, ///< Use lines for the grid
DOTS ///< Use dots for the grid
LINES, ///< Use lines for the grid
DOTS, ///< Use dots for the grid
SMALL_CROSS ///< Use small cross instead of dots for the grid
};
enum class OPENGL_ANTIALIASING_MODE

View File

@ -59,8 +59,9 @@ static const double gridMinSpacingStep = 5;
static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> gridStyleSelectMap =
{
{ KIGFX::GRID_STYLE::DOTS, 0 }, // Default
{ KIGFX::GRID_STYLE::LINES, 1 },
{ KIGFX::GRID_STYLE::DOTS, 0 }, // Default
{ KIGFX::GRID_STYLE::LINES, 1 },
{ KIGFX::GRID_STYLE::SMALL_CROSS, 2 },
};

View File

@ -49,7 +49,7 @@ DIALOG_DISPLAY_OPTIONS_BASE::DIALOG_DISPLAY_OPTIONS_BASE( wxWindow* parent, wxWi
wxStaticBoxSizer* sGridSettings;
sGridSettings = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Grid Display (OpenGL && Cairo)") ), wxVERTICAL );
wxString m_gridStyleChoices[] = { _("Dots"), _("Lines") };
wxString m_gridStyleChoices[] = { _("Dots"), _("Lines"), _("Small crosses") };
int m_gridStyleNChoices = sizeof( m_gridStyleChoices ) / sizeof( wxString );
m_gridStyle = new wxRadioBox( sGridSettings->GetStaticBox(), wxID_ANY, _("Grid Style"), wxDefaultPosition, wxDefaultSize, m_gridStyleNChoices, m_gridStyleChoices, 1, wxRA_SPECIFY_COLS );
m_gridStyle->SetSelection( 0 );

View File

@ -436,7 +436,7 @@
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="choices">&quot;Dots&quot; &quot;Lines&quot;</property>
<property name="choices">&quot;Dots&quot; &quot;Lines&quot; &quot;Small crosses&quot;</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>