Commit bb5832c8 authored by charras's avatar charras

Fixed: incorrect refresh of screen area after closing a popup menu (texts and...

Fixed: incorrect refresh of screen area after closing a popup menu (texts and polygons sometimes not redrawn)
parent 9edace2f
......@@ -22,18 +22,23 @@
/** Function NegableTextLength
* Return the text length of a negable string, excluding the ~ markers */
int NegableTextLength(const wxString& aText)
int NegableTextLength( const wxString& aText )
{
int char_count = aText.length();
/* Fix the character count, removing the ~ found */
for (int i = char_count-1; i >= 0; i--) {
if (aText[i] == '~') {
for( int i = char_count - 1; i >= 0; i-- )
{
if( aText[i] == '~' )
{
char_count--;
}
}
return char_count;
}
/* Helper function for drawing character polygons */
static void DrawGraphicTextPline(
WinEDA_DrawPanel* aPanel,
......@@ -42,34 +47,35 @@ static void DrawGraphicTextPline(
int aWidth,
bool sketch_mode,
int point_count,
wxPoint *coord,
void (* aCallback) (int x0, int y0, int xf, int yf))
wxPoint* coord,
void (* aCallback)(int x0, int y0, int xf, int yf) )
{
if ( aCallback )
if( aCallback )
{
for( int ik = 0; ik < (point_count - 1); ik ++ )
for( int ik = 0; ik < (point_count - 1); ik++ )
{
aCallback( coord[ik].x, coord[ik].y,
coord[ik+1].x, coord[ik+1].y );
coord[ik + 1].x, coord[ik + 1].y );
}
}
else if( sketch_mode )
{
for( int ik = 0; ik < (point_count - 1); ik ++ )
for( int ik = 0; ik < (point_count - 1); ik++ )
GRCSegm( &aPanel->m_ClipBox, aDC, coord[ik].x, coord[ik].y,
coord[ik+1].x, coord[ik+1].y, aWidth, aColor );
coord[ik + 1].x, coord[ik + 1].y, aWidth, aColor );
}
else
GRPoly( &aPanel->m_ClipBox, aDC, point_count, coord, 0,
aWidth, aColor, aColor );
}
static int overbar_position(int size_v, int thickness)
static int overbar_position( int size_v, int thickness )
{
return size_v*1.1+thickness;
return size_v * 1.1 + thickness;
}
/** Function DrawGraphicText
* Draw a graphic text (like module texts)
* @param aPanel = the current DrawPanel. NULL if draw within a 3D GL Canvas
......@@ -101,7 +107,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
int aWidth,
bool aItalic,
bool aNegable,
void (* aCallback) (int x0, int y0, int xf, int yf))
void (* aCallback)(int x0, int y0, int xf, int yf) )
/****************************************************************************************************/
{
int char_count, AsciiCode;
......@@ -115,8 +121,9 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
int ox, oy; // Draw coordinates for the current char
int overbar_x, overbar_y; // Start point for the current overbar
int overbars; // Number of ~ seen
#define BUF_SIZE 100
wxPoint coord[BUF_SIZE+1]; // Buffer coordinate used to draw polylines (one char shape)
wxPoint coord[BUF_SIZE + 1]; // Buffer coordinate used to draw polylines (one char shape)
bool sketch_mode = false;
bool italic_reverse = false; // true for mirrored texts with m_Size.x < 0
......@@ -129,19 +136,22 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
sketch_mode = true;
}
int thickness = aWidth;
if ( aSize.x < 0 ) // text is mirrored using size.x < 0 (mirror / Y axis)
if( aSize.x < 0 ) // text is mirrored using size.x < 0 (mirror / Y axis)
italic_reverse = true;
if (aNegable) {
char_count = NegableTextLength(aText);
} else {
if( aNegable )
{
char_count = NegableTextLength( aText );
}
else
{
char_count = aText.Len();
}
if( char_count == 0 )
return;
pitch = (10 * size_h ) / 9; // this is the pitch between chars
if ( pitch > 0 )
if( pitch > 0 )
pitch += thickness;
else
pitch -= thickness;
......@@ -252,8 +262,9 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
if( aPanel && aPanel->GetScreen()->Scale( aSize.x ) == 0 )
return;
if( aPanel && ABS( (aPanel->GetScreen()->Scale( aSize.x ) ) ) < 3 ) /* shapes are too small: connot be drawn */
{ /* insteed the text is drawn as a line */
if( aPanel && ABS( ( aPanel->GetScreen()->Scale( aSize.x ) ) ) < 3 ) /* shapes are too small: connot be drawn */
{
/* insteed the text is drawn as a line */
dx = (pitch * char_count) / 2;
dy = size_v / 2; /* line is always centered */
......@@ -266,7 +277,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
RotatePoint( &ux0, &uy0, cX, cY, aOrient );
RotatePoint( &dx, &dy, cX, cY, aOrient );
if ( aCallback )
if( aCallback )
aCallback( ux0, uy0, dx, dy );
else
GRLine( &aPanel->m_ClipBox, aDC, ux0, uy0, dx, dy, aWidth, aColor );
......@@ -278,38 +289,43 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
ptr = 0; /* ptr = text index */
while( ptr < char_count )
{
if (aNegable) {
if (aText[ptr+overbars] == '~') {
if( aNegable )
{
if( aText[ptr + overbars] == '~' )
{
/* Found an overbar, adjust the pointers */
overbars++;
if (overbars % 2) {
if( overbars % 2 )
{
/* Starting the overbar */
overbar_x = ox;
overbar_y = oy-overbar_position(size_v, thickness);
overbar_y = oy - overbar_position( size_v, thickness );
RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient );
} else {
}
else
{
/* Ending the overbar */
coord[0].x = overbar_x;
coord[0].y = overbar_y;
overbar_x = ox;
overbar_y = oy-overbar_position(size_v, thickness);
overbar_y = oy - overbar_position( size_v, thickness );
RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient );
coord[1].x = overbar_x;
coord[1].y = overbar_y;
/* Plot the overbar segment */
DrawGraphicTextPline(aPanel, aDC, aColor, aWidth,
sketch_mode, 2, coord, aCallback);
DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
sketch_mode, 2, coord, aCallback );
}
continue; /* Skip ~ processing */
}
}
AsciiCode = aText.GetChar(ptr+overbars);
AsciiCode = aText.GetChar( ptr + overbars );
#if defined(wxUSE_UNICODE) && defined(KICAD_CYRILLIC)
AsciiCode &= 0x7FF;
if ( AsciiCode > 0x40F && AsciiCode < 0x450 ) // big small Cyr
if( AsciiCode > 0x40F && AsciiCode < 0x450 ) // big small Cyr
AsciiCode = utf8_to_ascii[AsciiCode - 0x410] & 0xFF;
else
AsciiCode = AsciiCode & 0xFF;
......@@ -337,8 +353,8 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
{
if( aWidth <= 1 )
aWidth = 0;
DrawGraphicTextPline(aPanel, aDC, aColor, aWidth,
sketch_mode, point_count, coord, aCallback);
DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
sketch_mode, point_count, coord, aCallback );
}
plume = f_cod; point_count = 0;
break;
......@@ -358,15 +374,16 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
k2 = f_cod; /* trace sur axe H */
k2 = (k2 * size_h) / 9;
// To simulate an italic font, add a x offset depending on the y offset
if ( aItalic )
k2 -= italic_reverse ? - k1/8 : k1/8;
if( aItalic )
k2 -= italic_reverse ? -k1 / 8 : k1 / 8;
dx = k2 + ox; dy = k1 + oy;
RotatePoint( &dx, &dy, cX, cY, aOrient );
coord[point_count].x = dx;
coord[point_count].y = dy;
if ( point_count < BUF_SIZE-1 )
if( point_count < BUF_SIZE - 1 )
point_count++;
break;
}
......@@ -379,23 +396,24 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
ptr++; ox += pitch;
}
if (overbars % 2) {
if( overbars % 2 )
{
/* Close the last overbar */
coord[0].x = overbar_x;
coord[0].y = overbar_y;
overbar_x = ox;
overbar_y = oy-overbar_position(size_v, thickness);
overbar_y = oy - overbar_position( size_v, thickness );
RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient );
coord[1].x = overbar_x;
coord[1].y = overbar_y;
/* Plot the overbar segment */
DrawGraphicTextPline(aPanel, aDC, aColor, aWidth,
sketch_mode, 2, coord, aCallback);
DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
sketch_mode, 2, coord, aCallback );
}
}
/* functions used to plot texts, using DrawGraphicText() with a call back function */
static void (*MovePenFct)( wxPoint pos, int state ); // a pointer to actual plot function (HPGL, PS, ..)
static bool s_Plotbegin; // Flag to init plot
......@@ -405,30 +423,29 @@ static bool s_Plotbegin; // Flag to init plot
* The call back function
*/
/**********************/
static void
s_Callback_plot(int x0,
static void s_Callback_plot( int x0,
int y0,
int xf,
int yf)
int yf )
/**********************/
{
static wxPoint PenLastPos;
wxPoint pstart;
pstart.x = x0;
pstart.y = y0;
wxPoint pend;
pend.x = xf;
pend.y = yf;
if ( s_Plotbegin ) // First segment to plot
if( s_Plotbegin ) // First segment to plot
{
MovePenFct( pstart, 'U' );
MovePenFct( pend, 'D' );
s_Plotbegin = false;
}
else
{
if ( PenLastPos == pstart ) // this is a next segment in a polyline
if( PenLastPos == pstart ) // this is a next segment in a polyline
{
MovePenFct( pend, 'D' );
}
......@@ -469,7 +486,7 @@ void PlotGraphicText( int aFormat_plot,
enum GRTextVertJustifyType aV_justify,
int aWidth,
bool aItalic,
bool aNegable)
bool aNegable )
/******************************************************************************************/
{
// Initialise the actual function used to plot lines:
......@@ -499,9 +516,8 @@ void PlotGraphicText( int aFormat_plot,
aOrient, aSize,
aH_justify, aV_justify,
aWidth, aItalic, aNegable,
s_Callback_plot);
s_Callback_plot );
/* end text : pen UP ,no move */
MovePenFct( wxPoint( 0, 0 ), 'Z' );
}
......@@ -856,7 +856,7 @@ static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, wxPoint Points[] )
xcliplo = ClipBox->GetX();
ycliplo = ClipBox->GetY();
xcliphi = ClipBox->GetRight();
ycliphi = ClipBox->GetHeight();
ycliphi = ClipBox->GetBottom();
if( Xmax < xcliplo )
return FALSE;
......
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