Commit 20eaf66d authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

Hunted down hardcoded pixel size thresholds for drawing

Dynamic contrast for netname and pin numbers ('halo' text)
Handle netname drawing even on diagonal tracks
parent b525e3be
......@@ -561,6 +561,38 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel,
}
}
void DrawGraphicHaloText( EDA_DRAW_PANEL * aPanel,
wxDC * aDC,
const wxPoint &aPos,
enum EDA_COLOR_T aBgColor,
enum EDA_COLOR_T aColor1,
enum EDA_COLOR_T aColor2,
const wxString &aText,
int aOrient,
const wxSize &aSize,
enum EDA_TEXT_HJUSTIFY_T aH_justify,
enum EDA_TEXT_VJUSTIFY_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
void (*aCallback)( int x0, int y0, int xf, int yf ),
PLOTTER * aPlotter )
{
// Swap color if contrast would be better
if( ColorIsLight( aBgColor ) ) {
EDA_COLOR_T c = aColor1;
aColor1 = aColor2;
aColor2 = c;
}
DrawGraphicText( aPanel, aDC, aPos, aColor1, aText, aOrient, aSize,
aH_justify, aV_justify, aWidth, aItalic, aBold,
aCallback, aPlotter );
DrawGraphicText( aPanel, aDC, aPos, aColor2, aText, aOrient, aSize,
aH_justify, aV_justify, aWidth / 4, aItalic, aBold,
aCallback, aPlotter );
}
/**
* Function PlotGraphicText
......
......@@ -1512,6 +1512,14 @@ EDA_COLOR_T ColorByName( const wxChar *aName )
return UNSPECIFIED_COLOR;
}
bool ColorIsLight( EDA_COLOR_T aColor )
{
const StructColors &c = g_ColorRefs[ColorGetBase( aColor )];
int r = c.m_Red;
int g = c.m_Green;
int b = c.m_Blue;
return ((r * r) + (g * g) + (b * b)) > (128 * 128 * 3);
}
EDA_COLOR_T ColorFindNearest( const wxColour &aColor )
{
......
......@@ -139,6 +139,12 @@ EDA_COLOR_T ColorByName( const wxChar *aName );
/// Find the nearest color match
EDA_COLOR_T ColorFindNearest( const wxColour &aColor );
/**
* Check if a color is light i.e. if black would be more readable than
* white on it
*/
bool ColorIsLight( EDA_COLOR_T aColor );
inline const wxChar *ColorGetName( EDA_COLOR_T aColor )
{
EDA_COLOR_T base = ColorGetBase( aColor );
......
......@@ -88,4 +88,27 @@ void DrawGraphicText( EDA_DRAW_PANEL * aPanel,
PLOTTER * aPlotter = NULL );
/**
* Draw graphic text with a border, so that it can be read on different
* backgrounds. See DrawGraphicText for most of the parameters.
* If aBgColor is a dark color text is drawn in aColor2 with aColor1
* border; otherwise colors are swapped.
*/
void DrawGraphicHaloText( EDA_DRAW_PANEL * aPanel,
wxDC * aDC,
const wxPoint &aPos,
enum EDA_COLOR_T aBgColor,
enum EDA_COLOR_T aColor1,
enum EDA_COLOR_T aColor2,
const wxString &aText,
int aOrient,
const wxSize &aSize,
enum EDA_TEXT_HJUSTIFY_T aH_justify,
enum EDA_TEXT_VJUSTIFY_T aV_justify,
int aWidth,
bool aItalic,
bool aBold,
void (*aCallback)( int x0, int y0, int xf, int yf ) = NULL,
PLOTTER * aPlotter = NULL );
#endif /* __INCLUDE__DRAWTXT_H__ */
......@@ -350,7 +350,7 @@ void DIMENSION::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color,
typeaff = DisplayOpt.DisplayDrawItems;
width = m_Width;
if( DC->LogicalToDeviceXRel( width ) < 2 )
if( DC->LogicalToDeviceXRel( width ) <= MIN_DRAW_WIDTH )
typeaff = LINE;
switch( typeaff )
......
......@@ -209,7 +209,7 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
if( m_Flags & FORCE_SKETCH )
mode = SKETCH;
if( l_trace < DC->DeviceToLogicalXRel( MIN_DRAW_WIDTH ) )
if( DC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH )
mode = LINE;
switch( m_Shape )
......
......@@ -146,7 +146,7 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
typeaff = SKETCH;
}
if( DC->LogicalToDeviceXRel( m_Width ) < MIN_DRAW_WIDTH )
if( DC->LogicalToDeviceXRel( m_Width ) <= MIN_DRAW_WIDTH )
typeaff = LINE;
switch( type_trace )
......
......@@ -115,7 +115,7 @@ void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color,
typeaff = DisplayOpt.DisplayDrawItems;
width = m_Width;
if( DC->LogicalToDeviceXRel( width ) < 2 )
if( DC->LogicalToDeviceXRel( width ) <= MIN_DRAW_WIDTH )
typeaff = LINE;
radius = m_Size / 3;
......
......@@ -433,7 +433,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
switch( m_DrillShape )
{
case PAD_CIRCLE:
if( aDC->LogicalToDeviceXRel( hole ) > 1 )
if( aDC->LogicalToDeviceXRel( hole ) > MIN_DRAW_WIDTH )
GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
aDrawInfo.m_Color, hole_color );
break;
......@@ -487,6 +487,11 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
holepos.x - dx0, holepos.y + dx0, 0, nc_color );
}
if( aDrawInfo.m_DrawMode != GR_XOR )
GRSetDrawMode( aDC, GR_COPY );
else
GRSetDrawMode( aDC, GR_XOR );
// Draw the pad number
if( !aDrawInfo.m_Display_padnum && !aDrawInfo.m_Display_netname )
return;
......@@ -542,15 +547,17 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
numpad_len = std::max( numpad_len, MIN_CHAR_COUNT );
tsize = std::min( AreaSize.y, AreaSize.x / numpad_len );
#define CHAR_SIZE_MIN 5
if( aDC->LogicalToDeviceXRel( tsize ) >= CHAR_SIZE_MIN ) // Not drawable when size too small.
if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable when size too small.
{
// tsize reserve room for marges and segments thickness
tsize = (int) ( tsize * 0.8 );
DrawGraphicText( aDrawInfo.m_DrawPanel, aDC, tpos, WHITE, buffer, t_angle,
wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
tsize = ( tsize * 8 ) / 10;
DrawGraphicHaloText( aDrawInfo.m_DrawPanel, aDC, tpos,
aDrawInfo.m_Color, BLACK, WHITE,
buffer, t_angle,
wxSize( tsize , tsize ), GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
}
}
......@@ -561,7 +568,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
shortname_len = std::max( shortname_len, MIN_CHAR_COUNT );
tsize = std::min( AreaSize.y, AreaSize.x / shortname_len );
if( aDC->LogicalToDeviceXRel( tsize ) >= CHAR_SIZE_MIN ) // Not drawable in size too small.
if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable in size too small.
{
tpos = tpos0;
......@@ -571,10 +578,12 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
RotatePoint( &tpos, shape_pos, angle );
// tsize reserve room for marges and segments thickness
tsize = (int) ( tsize * 0.8 );
DrawGraphicText( aDrawInfo.m_DrawPanel, aDC, tpos, WHITE, m_ShortNetname, t_angle,
wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
tsize = ( tsize * 8 ) / 10;
DrawGraphicHaloText( aDrawInfo.m_DrawPanel, aDC, tpos,
aDrawInfo.m_Color, BLACK, WHITE,
m_ShortNetname, t_angle,
wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
}
}
......
......@@ -275,7 +275,7 @@ void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) panel->GetParent();
int width = m_Thickness;
if( ( frame->m_DisplayModText == LINE )
|| ( DC->LogicalToDeviceXRel( width ) < MIN_DRAW_WIDTH ) )
|| ( DC->LogicalToDeviceXRel( width ) <= MIN_DRAW_WIDTH ) )
width = 0;
else if( frame->m_DisplayModText == SKETCH )
width = -width;
......
This diff is collapsed.
......@@ -50,6 +50,7 @@ class MSG_PANEL_ITEM;
#define UNDEFINED_DRILL_DIAMETER -1 //< Undefined via drill diameter.
#define MIN_VIA_DRAW_SIZE 4 /// Minimum size in pixel for full drawing
/**
* Function GetTrace
......
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