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
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "class_base_screen.h" #include "class_base_screen.h"
#ifndef DEFAULT_SIZE_TEXT #ifndef DEFAULT_SIZE_TEXT
# define DEFAULT_SIZE_TEXT 50 # define DEFAULT_SIZE_TEXT 50
#endif #endif
#define EDA_DRAWBASE #define EDA_DRAWBASE
...@@ -22,54 +22,60 @@ ...@@ -22,54 +22,60 @@
/** Function NegableTextLength /** Function NegableTextLength
* Return the text length of a negable string, excluding the ~ markers */ * 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(); int char_count = aText.length();
/* Fix the character count, removing the ~ found */ /* Fix the character count, removing the ~ found */
for (int i = char_count-1; i >= 0; i--) { for( int i = char_count - 1; i >= 0; i-- )
if (aText[i] == '~') { {
char_count--; if( aText[i] == '~' )
} {
char_count--;
}
} }
return char_count; return char_count;
} }
/* Helper function for drawing character polygons */ /* Helper function for drawing character polygons */
static void DrawGraphicTextPline( static void DrawGraphicTextPline(
WinEDA_DrawPanel* aPanel, WinEDA_DrawPanel* aPanel,
wxDC* aDC, wxDC* aDC,
EDA_Colors aColor, EDA_Colors aColor,
int aWidth, int aWidth,
bool sketch_mode, bool sketch_mode,
int point_count, int point_count,
wxPoint *coord, wxPoint* coord,
void (* aCallback) (int x0, int y0, int xf, int yf)) 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, 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 ) 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, 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 else
GRPoly( &aPanel->m_ClipBox, aDC, point_count, coord, 0, GRPoly( &aPanel->m_ClipBox, aDC, point_count, coord, 0,
aWidth, aColor, aColor ); 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 /** Function DrawGraphicText
* Draw a graphic text (like module texts) * Draw a graphic text (like module texts)
* @param aPanel = the current DrawPanel. NULL if draw within a 3D GL Canvas * @param aPanel = the current DrawPanel. NULL if draw within a 3D GL Canvas
...@@ -90,18 +96,18 @@ static int overbar_position(int size_v, int thickness) ...@@ -90,18 +96,18 @@ static int overbar_position(int size_v, int thickness)
*/ */
/****************************************************************************************************/ /****************************************************************************************************/
void DrawGraphicText( WinEDA_DrawPanel* aPanel, void DrawGraphicText( WinEDA_DrawPanel* aPanel,
wxDC* aDC, wxDC* aDC,
const wxPoint& aPos, const wxPoint& aPos,
EDA_Colors aColor, EDA_Colors aColor,
const wxString& aText, const wxString& aText,
int aOrient, int aOrient,
const wxSize& aSize, const wxSize& aSize,
enum GRTextHorizJustifyType aH_justify, enum GRTextHorizJustifyType aH_justify,
enum GRTextVertJustifyType aV_justify, enum GRTextVertJustifyType aV_justify,
int aWidth, int aWidth,
bool aItalic, bool aItalic,
bool aNegable, 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; int char_count, AsciiCode;
...@@ -110,15 +116,16 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -110,15 +116,16 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
SH_CODE f_cod, plume = 'U'; SH_CODE f_cod, plume = 'U';
const SH_CODE* ptcar; const SH_CODE* ptcar;
int ptr; int ptr;
int ux0, uy0, dx, dy; // Draw coordinate for segments to draw. also used in some other calculation int ux0, uy0, dx, dy; // Draw coordinate for segments to draw. also used in some other calculation
int cX, cY; // Texte center int cX, cY; // Texte center
int ox, oy; // Draw coordinates for the current char int ox, oy; // Draw coordinates for the current char
int overbar_x, overbar_y; // Start point for the current overbar int overbar_x, overbar_y; // Start point for the current overbar
int overbars; // Number of ~ seen int overbars; // Number of ~ seen
#define BUF_SIZE 100 #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 sketch_mode = false;
bool italic_reverse = false; // true for mirrored texts with m_Size.x < 0 bool italic_reverse = false; // true for mirrored texts with m_Size.x < 0
size_h = aSize.x; size_h = aSize.x;
size_v = aSize.y; size_v = aSize.y;
...@@ -129,19 +136,22 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -129,19 +136,22 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
sketch_mode = true; sketch_mode = true;
} }
int thickness = aWidth; 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; italic_reverse = true;
if (aNegable) { if( aNegable )
char_count = NegableTextLength(aText); {
} else { char_count = NegableTextLength( aText );
char_count = aText.Len(); }
else
{
char_count = aText.Len();
} }
if( char_count == 0 ) if( char_count == 0 )
return; return;
pitch = (10 * size_h ) / 9; // this is the pitch between chars pitch = (10 * size_h ) / 9; // this is the pitch between chars
if ( pitch > 0 ) if( pitch > 0 )
pitch += thickness; pitch += thickness;
else else
pitch -= thickness; pitch -= thickness;
...@@ -177,11 +187,11 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -177,11 +187,11 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
/* Compute the position ux0, uy0 of the first letter , next */ /* Compute the position ux0, uy0 of the first letter , next */
dx = (pitch * char_count) / 2; dx = (pitch * char_count) / 2;
dy = size_v / 2; /* dx, dy = draw offset between first letter and text center */ dy = size_v / 2; /* dx, dy = draw offset between first letter and text center */
ux0 = uy0 = 0; /* Decalage du centre du texte / coord de ref */ ux0 = uy0 = 0; /* Decalage du centre du texte / coord de ref */
if( (aOrient == 0) || (aOrient == 1800) ) /* Horizontal Text */ if( (aOrient == 0) || (aOrient == 1800) ) /* Horizontal Text */
{ {
switch( aH_justify ) switch( aH_justify )
{ {
...@@ -252,8 +262,9 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -252,8 +262,9 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
if( aPanel && aPanel->GetScreen()->Scale( aSize.x ) == 0 ) if( aPanel && aPanel->GetScreen()->Scale( aSize.x ) == 0 )
return; return;
if( aPanel && ABS( (aPanel->GetScreen()->Scale( aSize.x ) ) ) < 3 ) /* shapes are too small: connot be drawn */ if( aPanel && ABS( ( aPanel->GetScreen()->Scale( aSize.x ) ) ) < 3 ) /* shapes are too small: connot be drawn */
{ /* insteed the text is drawn as a line */ {
/* insteed the text is drawn as a line */
dx = (pitch * char_count) / 2; dx = (pitch * char_count) / 2;
dy = size_v / 2; /* line is always centered */ dy = size_v / 2; /* line is always centered */
...@@ -261,12 +272,12 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -261,12 +272,12 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
uy0 = cY; uy0 = cY;
dx += cX; dx += cX;
dy = cY; dy = cY;
RotatePoint( &ux0, &uy0, cX, cY, aOrient ); RotatePoint( &ux0, &uy0, cX, cY, aOrient );
RotatePoint( &dx, &dy, cX, cY, aOrient ); RotatePoint( &dx, &dy, cX, cY, aOrient );
if ( aCallback ) if( aCallback )
aCallback( ux0, uy0, dx, dy ); aCallback( ux0, uy0, dx, dy );
else else
GRLine( &aPanel->m_ClipBox, aDC, ux0, uy0, dx, dy, aWidth, aColor ); GRLine( &aPanel->m_ClipBox, aDC, ux0, uy0, dx, dy, aWidth, aColor );
...@@ -278,48 +289,53 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -278,48 +289,53 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
ptr = 0; /* ptr = text index */ ptr = 0; /* ptr = text index */
while( ptr < char_count ) while( ptr < char_count )
{ {
if (aNegable) { if( aNegable )
if (aText[ptr+overbars] == '~') { {
/* Found an overbar, adjust the pointers */ if( aText[ptr + overbars] == '~' )
overbars++; {
/* Found an overbar, adjust the pointers */
if (overbars % 2) { overbars++;
/* Starting the overbar */
overbar_x = ox; if( overbars % 2 )
overbar_y = oy-overbar_position(size_v, thickness); {
/* Starting the overbar */
overbar_x = ox;
overbar_y = oy - overbar_position( size_v, thickness );
RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient ); RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient );
} else { }
/* Ending the overbar */ else
coord[0].x = overbar_x; {
coord[0].y = overbar_y; /* Ending the overbar */
overbar_x = ox; coord[0].x = overbar_x;
overbar_y = oy-overbar_position(size_v, thickness); coord[0].y = overbar_y;
overbar_x = ox;
overbar_y = oy - overbar_position( size_v, thickness );
RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient ); RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient );
coord[1].x = overbar_x; coord[1].x = overbar_x;
coord[1].y = overbar_y; coord[1].y = overbar_y;
/* Plot the overbar segment */ /* Plot the overbar segment */
DrawGraphicTextPline(aPanel, aDC, aColor, aWidth, DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
sketch_mode, 2, coord, aCallback); sketch_mode, 2, coord, aCallback );
} }
continue; /* Skip ~ processing */ continue; /* Skip ~ processing */
} }
} }
AsciiCode = aText.GetChar(ptr+overbars); AsciiCode = aText.GetChar( ptr + overbars );
#if defined(wxUSE_UNICODE) && defined(KICAD_CYRILLIC) #if defined(wxUSE_UNICODE) && defined(KICAD_CYRILLIC)
AsciiCode &= 0x7FF; 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; AsciiCode = utf8_to_ascii[AsciiCode - 0x410] & 0xFF;
else else
AsciiCode = AsciiCode & 0xFF; AsciiCode = AsciiCode & 0xFF;
#else #else
AsciiCode &= 0xFF; AsciiCode &= 0xFF;
#endif #endif
ptcar = graphic_fonte_shape[AsciiCode]; /* ptcar pointe la description ptcar = graphic_fonte_shape[AsciiCode]; /* ptcar pointe la description
* du caractere a dessiner */ * du caractere a dessiner */
int point_count; int point_count;
bool endcar; bool endcar;
for( point_count = 0, endcar = false; !endcar; ptcar++ ) for( point_count = 0, endcar = false; !endcar; ptcar++ )
{ {
...@@ -336,9 +352,9 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -336,9 +352,9 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
if( point_count && (plume == 'D' ) ) if( point_count && (plume == 'D' ) )
{ {
if( aWidth <= 1 ) if( aWidth <= 1 )
aWidth = 0; aWidth = 0;
DrawGraphicTextPline(aPanel, aDC, aColor, aWidth, DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
sketch_mode, point_count, coord, aCallback); sketch_mode, point_count, coord, aCallback );
} }
plume = f_cod; point_count = 0; plume = f_cod; point_count = 0;
break; break;
...@@ -348,28 +364,29 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -348,28 +364,29 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
break; break;
default: default:
{ {
int y, k1, k2; int y, k1, k2;
y = k1 = f_cod; /* trace sur axe V */ y = k1 = f_cod; /* trace sur axe V */
k1 = -( (k1 * size_v) / 9 ); k1 = -( (k1 * size_v) / 9 );
ptcar++; ptcar++;
f_cod = *ptcar; f_cod = *ptcar;
k2 = f_cod; /* trace sur axe H */ k2 = f_cod; /* trace sur axe H */
k2 = (k2 * size_h) / 9; k2 = (k2 * size_h) / 9;
// To simulate an italic font, add a x offset depending on the y offset
if ( aItalic ) // To simulate an italic font, add a x offset depending on the y offset
k2 -= italic_reverse ? - k1/8 : k1/8; if( aItalic )
dx = k2 + ox; dy = k1 + oy; k2 -= italic_reverse ? -k1 / 8 : k1 / 8;
dx = k2 + ox; dy = k1 + oy;
RotatePoint( &dx, &dy, cX, cY, aOrient );
coord[point_count].x = dx; RotatePoint( &dx, &dy, cX, cY, aOrient );
coord[point_count].y = dy; coord[point_count].x = dx;
if ( point_count < BUF_SIZE-1 ) coord[point_count].y = dy;
point_count++; if( point_count < BUF_SIZE - 1 )
break; point_count++;
} break;
}
} }
/* end switch */ /* end switch */
...@@ -379,56 +396,56 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ...@@ -379,56 +396,56 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
ptr++; ox += pitch; ptr++; ox += pitch;
} }
if (overbars % 2) {
/* Close the last overbar */ if( overbars % 2 )
coord[0].x = overbar_x; {
coord[0].y = overbar_y; /* Close the last overbar */
overbar_x = ox; coord[0].x = overbar_x;
overbar_y = oy-overbar_position(size_v, thickness); coord[0].y = overbar_y;
RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient ); overbar_x = ox;
coord[1].x = overbar_x; overbar_y = oy - overbar_position( size_v, thickness );
coord[1].y = overbar_y; RotatePoint( &overbar_x, &overbar_y, cX, cY, aOrient );
/* Plot the overbar segment */ coord[1].x = overbar_x;
DrawGraphicTextPline(aPanel, aDC, aColor, aWidth, coord[1].y = overbar_y;
sketch_mode, 2, coord, aCallback); /* Plot the overbar segment */
DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
sketch_mode, 2, coord, aCallback );
} }
} }
/* functions used to plot texts, using DrawGraphicText() with a call back function */ /* 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 void (*MovePenFct)( wxPoint pos, int state ); // a pointer to actual plot function (HPGL, PS, ..)
static bool s_Plotbegin; // Flag to init plot static bool s_Plotbegin; // Flag to init plot
/* /*
* The call back function * The call back function
*/ */
/**********************/ /**********************/
static void static void s_Callback_plot( int x0,
s_Callback_plot(int x0, int y0,
int y0, int xf,
int xf, int yf )
int yf)
/**********************/ /**********************/
{ {
static wxPoint PenLastPos; static wxPoint PenLastPos;
wxPoint pstart; wxPoint pstart;
pstart.x = x0; pstart.x = x0;
pstart.y = y0; pstart.y = y0;
wxPoint pend; wxPoint pend;
pend.x = xf; pend.x = xf;
pend.y = yf; pend.y = yf;
if ( s_Plotbegin ) // First segment to plot if( s_Plotbegin ) // First segment to plot
{ {
MovePenFct( pstart, 'U' ); MovePenFct( pstart, 'U' );
MovePenFct( pend, 'D' ); MovePenFct( pend, 'D' );
s_Plotbegin = false; s_Plotbegin = false;
} }
else 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' ); MovePenFct( pend, 'D' );
} }
...@@ -459,17 +476,17 @@ s_Callback_plot(int x0, ...@@ -459,17 +476,17 @@ s_Callback_plot(int x0,
* @param aNegable = true to enable the ~ char for overbarring * @param aNegable = true to enable the ~ char for overbarring
*/ */
/******************************************************************************************/ /******************************************************************************************/
void PlotGraphicText( int aFormat_plot, void PlotGraphicText( int aFormat_plot,
const wxPoint& aPos, const wxPoint& aPos,
enum EDA_Colors aColor, enum EDA_Colors aColor,
const wxString& aText, const wxString& aText,
int aOrient, int aOrient,
const wxSize& aSize, const wxSize& aSize,
enum GRTextHorizJustifyType aH_justify, enum GRTextHorizJustifyType aH_justify,
enum GRTextVertJustifyType aV_justify, enum GRTextVertJustifyType aV_justify,
int aWidth, int aWidth,
bool aItalic, bool aItalic,
bool aNegable) bool aNegable )
/******************************************************************************************/ /******************************************************************************************/
{ {
// Initialise the actual function used to plot lines: // Initialise the actual function used to plot lines:
...@@ -496,12 +513,11 @@ void PlotGraphicText( int aFormat_plot, ...@@ -496,12 +513,11 @@ void PlotGraphicText( int aFormat_plot,
s_Plotbegin = true; s_Plotbegin = true;
DrawGraphicText( NULL, NULL, aPos, aColor, aText, DrawGraphicText( NULL, NULL, aPos, aColor, aText,
aOrient, aSize, aOrient, aSize,
aH_justify, aV_justify, aH_justify, aV_justify,
aWidth, aItalic, aNegable, aWidth, aItalic, aNegable,
s_Callback_plot); s_Callback_plot );
/* end text : pen UP ,no move */ /* end text : pen UP ,no move */
MovePenFct( wxPoint( 0, 0 ), 'Z' ); MovePenFct( wxPoint( 0, 0 ), 'Z' );
} }
...@@ -856,7 +856,7 @@ static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, wxPoint Points[] ) ...@@ -856,7 +856,7 @@ static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, wxPoint Points[] )
xcliplo = ClipBox->GetX(); xcliplo = ClipBox->GetX();
ycliplo = ClipBox->GetY(); ycliplo = ClipBox->GetY();
xcliphi = ClipBox->GetRight(); xcliphi = ClipBox->GetRight();
ycliphi = ClipBox->GetHeight(); ycliphi = ClipBox->GetBottom();
if( Xmax < xcliplo ) if( Xmax < xcliplo )
return FALSE; 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